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 = Base64.getDecoder().decode(transactionStr); // ByteUtils.stringToByteArray(transactionStr); TransactionContext transactionContext = (TransactionContext) SerializeUtils.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); }
private void verifyNotDelegated(Response response) throws IOException { textDelegateDecoder.decode(response, String.class); verify(delegate, never()).decode(any(), any()); } }
private void verifyDelegated(Response response) throws IOException { textDelegateDecoder.decode(response, mock(Type.class)); verify(delegate).decode(any(), any()); }
@Override public Exception decode(String methodKey, Response response) { try { return (Exception) decoder.decode(response, GitHubClientError.class); } catch (IOException fallbackToDefault) { return defaultDecoder.decode(methodKey, response); } } }
@Override public Object decode(Response response, Type type) throws IOException, FeignException { Collection<String> contentTypes = HeaderAccessUtils.caseInsensitiveGet(response.headers(), HttpHeaders.CONTENT_TYPE); if (contentTypes == null) { contentTypes = ImmutableSet.of(); } // In the case of multiple content types, or an unknown content type, we'll use the delegate instead. if (contentTypes.size() == 1 && Iterables.getOnlyElement(contentTypes, "").startsWith(MediaType.TEXT_PLAIN)) { return stringDecoder.decode(response, type); } return delegate.decode(response, type); } }
@Override public Object decode(Response response, Type type) throws IOException, FeignException { Collection<String> contentTypes = HeaderAccessUtils.caseInsensitiveGet(response.headers(), HttpHeaders.CONTENT_TYPE); if (contentTypes == null) { contentTypes = ImmutableSet.of(); } // In the case of multiple content types, or an unknown content type, we'll use the delegate instead. if (contentTypes.size() == 1 && Iterables.getOnlyElement(contentTypes, "").equals(MediaType.TEXT_PLAIN)) { return stringDecoder.decode(response, type); } return delegate.decode(response, type); } }
@Override public Object decode(Response response, Type type) throws IOException, FeignException { Collection<String> contentTypes = HeaderAccessUtils.caseInsensitiveGet(response.headers(), HttpHeaders.CONTENT_TYPE); if (contentTypes == null) { contentTypes = ImmutableSet.of(); } // In the case of multiple content types, or an unknown content type, we'll use the delegate instead. if (contentTypes.size() == 1 && Iterables.getOnlyElement(contentTypes, "").startsWith(MediaType.TEXT_PLAIN)) { return stringDecoder.decode(response, type); } return delegate.decode(response, type); } }
Object decode(Response response) throws Throwable { try { return decoder.decode(response, metadata.returnType()); } catch (FeignException e) { throw e; } catch (RuntimeException e) { throw new DecodeException(e.getMessage(), e); } }
@Override public Object decode(Response response, Type type) throws IOException, FeignException { if (Types.getRawType(type).equals(com.google.common.base.Optional.class)) { if (response.status() == 204) { return com.google.common.base.Optional.absent(); } else { Object decoded = checkNotNull(delegate.decode(response, getInnerType(type)), "Unexpected null content for response status %s", response.status()); return com.google.common.base.Optional.of(decoded); } } else { return delegate.decode(response, type); } }
@Override public Object decode(Response response, Type type) throws IOException, FeignException { if (Types.getRawType(type).equals(Optional.class)) { if (response.status() == 204) { return Optional.empty(); } else { Object decoded = checkNotNull(delegate.decode(response, getInnerType(type)), "Unexpected null content for response status %s", response.status()); return Optional.of(decoded); } } else { return delegate.decode(response, type); } }
@Override public Object decode(Response response, Type type) throws IOException, FeignException { if (Types.getRawType(type).equals(Optional.class)) { if (response.status() == 204) { return Optional.absent(); } else { Object decoded = checkNotNull(delegate.decode(response, getInnerType(type)), "Unexpected null content for response status %s", response.status()); return Optional.of(decoded); } } else { return delegate.decode(response, type); } }
@Override public Object decode(Response response, Type type) throws IOException, FeignException { if (Types.getRawType(type).equals(Optional.class)) { if (response.status() == 204) { return Optional.empty(); } else { Object decoded = checkNotNull(delegate.decode(response, getInnerType(type)), "Unexpected null content for response status %s", response.status()); return Optional.of(decoded); } } else { return delegate.decode(response, type); } }
@Override public Object decode(Response response, Type type) throws IOException, FeignException { if (Types.getRawType(type).equals(Optional.class)) { if (response.status() == 204) { return Optional.absent(); } else { Object decoded = checkNotNull(delegate.decode(response, getInnerType(type)), "Unexpected null content for response status %d", response.status()); return Optional.of(decoded); } } else { return delegate.decode(response, type); } }
@Override public Object decode(Response response, Type type) throws IOException, FeignException { if (Types.getRawType(type).equals(Optional.class)) { if (response.status() == 204) { return Optional.empty(); } else { Object decoded = checkNotNull(delegate.decode(response, getInnerType(type)), "Unexpected null content for response status %s", response.status()); return Optional.of(decoded); } } else { return delegate.decode(response, type); } }
@Override public Object decode(Response response, Type type) throws IOException, FeignException { if (type.equals(InputStream.class)) { byte[] body = Util.toByteArray(response.body().asInputStream()); return new ByteArrayInputStream(body); } else { return delegate.decode(response, type); } } }
@Override public Object decode(final Response response, final Type type) throws IOException, FeignException { final Object ret; if (isParameterizeHttpEntity(type)) { final Type type_ = ((ParameterizedType) type).getActualTypeArguments()[0]; final Object decodedObject = decoder.decode(response, type_); ret = createResponse(decodedObject, response); } else if (isHttpEntity(type)) { ret = createResponse(null, response); } else { ret = decoder.decode(response, type); } return ret; }
@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); } } }
@Override public Object decode(final Response response, final Type type) throws IOException, FeignException { final Object ret; if (isParameterizeHttpEntity(type)) { final Type type_ = ((ParameterizedType) type).getActualTypeArguments()[0]; final Object decodedObject = decoder.decode(response, type_); ret = createResponse(decodedObject, response); } else if (isHttpEntity(type)) { ret = createResponse(null, response); } else { ret = decoder.decode(response, type); } return ret; }
@Override public Object decode(Response response, Type type) throws IOException, FeignException { if (type.equals(InputStream.class)) { byte[] body = response.body() != null ? Util.toByteArray(response.body().asInputStream()) : new byte[0]; return new ByteArrayInputStream(body); } else { return delegate.decode(response, type); } } }
@Override public Object decode(Response response, Type type) throws IOException, FeignException { if (type.equals(InputStream.class)) { byte[] body = response.body() != null ? Util.toByteArray(response.body().asInputStream()) : new byte[0]; return new ByteArrayInputStream(body); } else { return delegate.decode(response, type); } } }