• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java NoContentException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中javax.ws.rs.core.NoContentException的典型用法代码示例。如果您正苦于以下问题:Java NoContentException类的具体用法?Java NoContentException怎么用?Java NoContentException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



NoContentException类属于javax.ws.rs.core包,在下文中一共展示了NoContentException类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: readFrom

import javax.ws.rs.core.NoContentException; //导入依赖的package包/类
@Override public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations,
    MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
    throws IOException, WebApplicationException {
  JsonAdapter<Object> adapter = moshi.adapter(genericType);
  BufferedSource source = Okio.buffer(Okio.source(entityStream));
  if (!source.request(1)) {
    throw new NoContentException("Stream is empty");
  }
  return adapter.fromJson(source);
  // Note: we do not close the InputStream per the interface documentation.
}
 
开发者ID:JakeWharton,项目名称:jax-rs-moshi,代码行数:12,代码来源:MoshiMessageBodyReader.java


示例2: readEntity

import javax.ws.rs.core.NoContentException; //导入依赖的package包/类
/**
 * Reads entity of given type from response. Returns null when the response has a zero-length content.
 *
 * @param response
 *            service response
 * @param responseType
 *            expected response type
 * @return the response entity
 * @throws RestException
 */
private <RES> RES readEntity(final Response response, final Class<RES> responseType) throws RestException {
    boolean buffered = false;
    try {
        buffered = response.bufferEntity();
        return response.readEntity(responseType);
    } catch (final ProcessingException ex) {
        if (response.getStatus() == Response.Status.NO_CONTENT.getStatusCode() || ex.getCause() instanceof NoContentException) {
            return null;
        } else {
            if ((response.getStatusInfo().getFamily() == Response.Status.Family.CLIENT_ERROR)
                    || (response.getStatusInfo().getFamily() == Response.Status.Family.SERVER_ERROR)) {
                return null; // Ignore content interpretation errors if status is an error already
            }
            final String body = buffered ? " '" + response.readEntity(String.class) + "' of type '"
                    + response.getMediaType() + "'" : "";
            throw new RestException("Could not interpret the response body" + body, ex);
        }
    }
}
 
开发者ID:Labs64,项目名称:NetLicensingClient-java,代码行数:30,代码来源:RestProviderJersey.java


示例3: emptyReadThrows

import javax.ws.rs.core.NoContentException; //导入依赖的package包/类
@Test public void emptyReadThrows() throws IOException {
  Buffer data = new Buffer();
  Class<Object> type = (Class) String.class;
  try {
    reader.readFrom(type, type, new Annotation[0], APPLICATION_JSON_TYPE,
        new MultivaluedHashMap<>(),
        data.inputStream());
    fail();
  } catch (NoContentException ignored) {
  }
}
 
开发者ID:JakeWharton,项目名称:jax-rs-moshi,代码行数:12,代码来源:MoshiMessageBodyReaderTest.java


示例4: isNoContentException

import javax.ws.rs.core.NoContentException; //导入依赖的package包/类
/**
 * Checks whether given exception is a {@link ProcessingException} that wraps a message body reader
 * {@link NoContentException}.
 * @param exception Exception to check
 * @return <code>true</code> if given it a no content exception
 */
protected static boolean isNoContentException(Exception exception) {
	if (exception != null && exception instanceof ProcessingException && exception.getCause() != null) {
		return exception.getCause() instanceof NoContentException;
	}
	return false;
}
 
开发者ID:holon-platform,项目名称:holon-jaxrs,代码行数:13,代码来源:JaxrsResponseEntity.java


示例5: readFrom

import javax.ws.rs.core.NoContentException; //导入依赖的package包/类
@Override
public T readFrom(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType,
        MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
        throws IOException, WebApplicationException {
    try (Reader entityReader = new InputStreamReader(entityStream, Charsets.UTF_8)) {
        String entity = CharStreams.toString(entityReader);
        if (entity == null || entity.isEmpty()) {
            throw new NoContentException("failed to deserialize JSON entity: " + "empty/null entity stream");
        }
        return JsonUtils.toObject(JsonUtils.parseJsonString(entity), type);
    } catch (IllegalArgumentException | JsonParseException e) {
        // produce a 400 http response
        throw new WebApplicationException(e, Response.status(Status.BAD_REQUEST).entity(new ErrorType(e)).build());
    }
}
 
开发者ID:elastisys,项目名称:scale.commons,代码行数:16,代码来源:GsonMessageBodyReader.java


示例6: doCommand

import javax.ws.rs.core.NoContentException; //导入依赖的package包/类
/**
 * calls IOFabric Controller endpoind and returns Json result
 * 
 * @param command - endpoint to be called
 * @param queryParams - query string parameters
 * @param postParams - post parameters
 * @return result in Json format
 * @throws Exception
 */
public JsonObject doCommand(String command, Map<String, Object> queryParams, Map<String, Object> postParams) throws Exception {
	if (!controllerUrl.toLowerCase().startsWith("https"))
		throw new Exception("unable to connect over non-secure connection");
	JsonObject result = null;
	
	StringBuilder uri = new StringBuilder(controllerUrl);
	
	uri.append("instance/")
		.append(command)
		.append("/id/").append(instanceId)
		.append("/token/").append(accessToken);
	
	if (queryParams != null)
		queryParams.entrySet().forEach(entry -> {
			uri.append("/").append(entry.getKey())
				.append("/").append(entry.getValue());
		});

	List<NameValuePair> postData = new ArrayList<NameValuePair>();		
	if (postParams != null)
		postParams.entrySet().forEach(entry -> {
			String value = entry.getValue().toString();
			if (value == null)
				value = "";
			postData.add(new BasicNameValuePair(entry.getKey(), value));
		});
	

	try {
		initialize();
		RequestConfig config = getRequestConfig();
		HttpPost post = new HttpPost(uri.toString());
		post.setConfig(config);
		post.setEntity(new UrlEncodedFormEntity(postData));

		CloseableHttpResponse response = client.execute(post);
		
		if (response.getStatusLine().getStatusCode() == 403){
			throw new ForbiddenException();
		} else if (response.getStatusLine().getStatusCode() == 204){
			throw new NoContentException("");
		}
		
		BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
		result = Json.createReader(in).readObject();
	} catch (Exception e) {
		throw e;
	}
	
	return result;
}
 
开发者ID:iotracks,项目名称:iofabric,代码行数:61,代码来源:Orchestrator.java



注:本文中的javax.ws.rs.core.NoContentException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CloudQueue类代码示例发布时间:2022-05-23
下一篇:
Java SoundEventAccessor类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap