当前位置: 首页>>代码示例>>Java>>正文


Java DecodeException类代码示例

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


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

示例1: decodingExceptionGetWrappedInDecode404Mode

import feign.codec.DecodeException; //导入依赖的package包/类
@Test
public void decodingExceptionGetWrappedInDecode404Mode() throws Exception {
  server.enqueue(new MockResponse().setResponseCode(404));
  thrown.expect(DecodeException.class);
  thrown.expectCause(isA(NoSuchElementException.class));;

  TestInterface api = new TestInterfaceBuilder()
      .decode404()
      .decoder(new Decoder() {
        @Override
        public Object decode(Response response, Type type) throws IOException {
          assertEquals(404, response.status());
          throw new NoSuchElementException();
        }
      }).target("http://localhost:" + server.getPort());
  api.post();
}
 
开发者ID:wenwu315,项目名称:XXXX,代码行数:18,代码来源:FeignTest.java

示例2: okIfDecodeRootCauseHasNoMessage

import feign.codec.DecodeException; //导入依赖的package包/类
@Test
public void okIfDecodeRootCauseHasNoMessage() throws Exception {
  server.enqueue(new MockResponse().setBody("success!"));
  thrown.expect(DecodeException.class);

  TestInterface api = new TestInterfaceBuilder()
      .decoder(new Decoder() {
        @Override
        public Object decode(Response response, Type type) throws IOException {
          throw new RuntimeException();
        }
      }).target("http://localhost:" + server.getPort());

  api.post();
}
 
开发者ID:wenwu315,项目名称:XXXX,代码行数:16,代码来源:FeignTest.java

示例3: decode

import feign.codec.DecodeException; //导入依赖的package包/类
@Override
public Object decode(Response response, Type type) throws IOException, DecodeException {
  if (response.status() == 404) return Util.emptyValueOf(type);
  if (response.body() == null) return null;
  ContentHandlerWithResult.Factory<?> handlerFactory = handlerFactories.get(type);
  checkState(handlerFactory != null, "type %s not in configured handlers %s", type,
             handlerFactories.keySet());
  ContentHandlerWithResult<?> handler = handlerFactory.create();
  try {
    XMLReader xmlReader = XMLReaderFactory.createXMLReader();
    xmlReader.setFeature("http://xml.org/sax/features/namespaces", false);
    xmlReader.setFeature("http://xml.org/sax/features/validation", false);
    /* Explicitly control sax configuration to prevent XXE attacks */
    xmlReader.setFeature("http://xml.org/sax/features/external-general-entities", false);
    xmlReader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
    xmlReader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", false);
    xmlReader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
    xmlReader.setContentHandler(handler);
    InputStream inputStream = response.body().asInputStream();
    try {
      xmlReader.parse(new InputSource(inputStream));
    } finally {
      ensureClosed(inputStream);
    }
    return handler.result();
  } catch (SAXException e) {
    throw new DecodeException(e.getMessage(), e);
  }
}
 
开发者ID:wenwu315,项目名称:XXXX,代码行数:30,代码来源:SAXDecoder.java

示例4: decode

import feign.codec.DecodeException; //导入依赖的package包/类
@Override
public Object decode(Response response, Type type) throws IOException, DecodeException, FeignException {
	Collection<String> contentTypes = response.headers().get("Content-Type");
	if (contentTypes.contains(MimeTypeUtils.TEXT_PLAIN.toString())) {
		return defaultDecoder.decode(response, type);
	}
	else {
		return gsonDecoder.decode(response, type);
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-deployer-mesos,代码行数:11,代码来源:ChronosClient.java

示例5: decode

import feign.codec.DecodeException; //导入依赖的package包/类
public Object decode(Response resp, Type type) throws IOException, DecodeException, FeignException {
	Request request = resp.request();

	String reqTransactionStr = this.getHeaderValue(request, HEADER_TRANCACTION_KEY);
	String reqPropagationStr = this.getHeaderValue(request, HEADER_PROPAGATION_KEY);

	String respTransactionStr = this.getHeaderValue(resp, HEADER_TRANCACTION_KEY);
	String respPropagationStr = this.getHeaderValue(resp, HEADER_PROPAGATION_KEY);

	if (StringUtils.isBlank(reqTransactionStr)) {
		return this.delegate.decode(resp, type);
	} else if (StringUtils.isBlank(reqPropagationStr)) {
		return this.delegate.decode(resp, type);
	}

	try {
		String transactionStr = StringUtils.isBlank(respTransactionStr) ? reqTransactionStr : respTransactionStr;
		String propagationStr = StringUtils.isBlank(respPropagationStr) ? reqPropagationStr : respPropagationStr;

		byte[] byteArray = ByteUtils.stringToByteArray(transactionStr);
		TransactionContext transactionContext = (TransactionContext) CommonUtils.deserializeObject(byteArray);

		SpringCloudBeanRegistry beanRegistry = SpringCloudBeanRegistry.getInstance();
		RemoteCoordinator remoteCoordinator = beanRegistry.getConsumeCoordinator(propagationStr);

		TransactionResponseImpl response = new TransactionResponseImpl();
		response.setTransactionContext(transactionContext);
		response.setSourceTransactionCoordinator(remoteCoordinator);
	} catch (IOException ex) {
		logger.error("Error occurred while decoding response({})!", resp, ex);
	}

	return this.delegate.decode(resp, type);
}
 
开发者ID:liuyangming,项目名称:ByteTCC,代码行数:35,代码来源:CompensableFeignDecoder.java

示例6: decode

import feign.codec.DecodeException; //导入依赖的package包/类
@Override
public Object decode(final Response response, Type type)
		throws IOException, FeignException {
	if (type instanceof Class || type instanceof ParameterizedType
			|| type instanceof WildcardType) {
		@SuppressWarnings({ "unchecked", "rawtypes" })
		HttpMessageConverterExtractor<?> extractor = new HttpMessageConverterExtractor(
				type, this.messageConverters.getObject().getConverters());

		return extractor.extractData(new FeignResponseAdapter(response));
	}
	throw new DecodeException(
			"type is not an instance of Class or ParameterizedType: " + type);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:15,代码来源:SpringDecoder.java

示例7: networkStatusCantParse

import feign.codec.DecodeException; //导入依赖的package包/类
@Test
public void networkStatusCantParse() throws Exception {
  thrown.expect(DecodeException.class);
  thrown.expectMessage("Content is not allowed in prolog.");

  server.enqueue(new MockResponse().setBody("{\"foo\": \"bar\"}"));

  mockApi().getNeustarNetworkStatus();
}
 
开发者ID:Netflix,项目名称:denominator,代码行数:10,代码来源:UltraDNSTest.java

示例8: decode

import feign.codec.DecodeException; //导入依赖的package包/类
/**
 * Transforms HTTP response body into object using decoder.
 *
 * @param response HTTP response
 *
 * @return decoded result
 *
 * @throws IOException IO exception during the reading of InputStream of
 *      response
 * @throws DecodeException when decoding failed due to a checked or unchecked
 *      exception besides IOException
 * @throws FeignException when decoding succeeds, but conveys the operation
 *      failed
 */
private Object decode(final Response response) throws IOException,
    FeignException {
  try {
    return decoder.decode(response, metadata.returnType());
  } catch (FeignException feignException) {
    /* All feign exception including decode exceptions */
    throw feignException;
  } catch (RuntimeException unexpectedException) {
    /* Any unexpected exception */
    throw new DecodeException(
        unexpectedException.getMessage(), unexpectedException);
  }
}
 
开发者ID:OpenFeign,项目名称:feign-vertx,代码行数:28,代码来源:AsynchronousMethodHandler.java


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