@Override public Integer statusCode(Response response) { return response.status(); }
@Override public Exception decode(String methodKey, Response response) { if (response.status() == HttpStatus.NOT_FOUND.value()) { return new ReservationExpireException("tcc reservation expired", response); } if (response.status() == HttpStatus.CONFLICT.value()) { String conflictionDetails; try { conflictionDetails = IOUtils.toString(response.body().asInputStream(), Charsets.UTF_8); } catch (IOException e) { LOGGER.error("read conflict response body exception. {}", e.toString()); conflictionDetails = "{}"; } return new PartialConfirmException(conflictionDetails); } return FeignException.errorStatus(methodKey, response); } }
@Override public int getHttpStatusCode() { return response.status(); } }
@Override public boolean isScopeExist(String name) { int status = scopeRegistrationServiceStub.isScopeExist(name).status(); return status == APIMgtConstants.HTTPStatusCodes.SC_200_OK; }
@Override public boolean isScopeExist(String name) { int status = wso2ISScopeRegistrationServiceStub.isScopeExist(name).status(); return status == APIMgtConstants.HTTPStatusCodes.SC_200_OK; }
@SuppressWarnings("unchecked") private <T> ResponseEntity<T> createResponse(Object instance, Response response) { MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); for (String key : response.headers().keySet()) { headers.put(key, new LinkedList<>(response.headers().get(key))); } return new ResponseEntity<>((T) instance, headers, HttpStatus.valueOf(response .status())); } }
@SuppressWarnings("unchecked") private <T> ResponseEntity<T> createResponse(Object instance, Response response) { MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); for (String key : response.headers().keySet()) { headers.put(key, new LinkedList<>(response.headers().get(key))); } return new ResponseEntity<>((T) instance, headers, HttpStatus.valueOf(response .status())); } }
@Override public boolean deleteScope(String name) throws KeyManagementException { Response response = scopeRegistrationServiceStub.deleteScope(name); if (response.status() == APIMgtConstants.HTTPStatusCodes.SC_200_OK) { return true; } else { throw new KeyManagementException("Scope deletion failed" + name, ExceptionCodes.SCOPE_DELETE_FAILED); } }
@Override public Exception decode(String methodKey, Response response) { return new MarathonException(response.status(), response.reason()); } }
default Optional<String> getAgentSandboxFileAsString(final String agentId, final String path) throws DCOSException { final feign.Response response = getAgentSandboxFile(agentId, path); if (response.status() == 404 || response.body() == null) { return Optional.empty(); } try (final Reader reader = response.body().asReader()) { return Optional.of(IOUtils.toString(reader)); } catch (IOException e) { return Optional.empty(); } }
@Override public boolean deleteScope(String name) throws KeyManagementException { Response response = scopeRegistrationServiceStub.deleteScope(name); if (response.status() == APIMgtConstants.HTTPStatusCodes.SC_200_OK) { return true; } else { throw new KeyManagementException("Scope deletion failed" + name, ExceptionCodes.SCOPE_DELETE_FAILED); } }
@Override public Exception decode(String methodKey, Response response) { String details; try { details = IOUtils.toString(response.body().asInputStream(), "UTF-8"); } catch (NullPointerException | IOException e) { details = "Unable to read response body"; } return new DCOSException(response.status(), response.reason(), methodKey, details); } }
@Override public Object decode(Response response, Type type) throws FeignException, IOException { Object object = delegate.decode(response, type); Preconditions.checkNotNull(object, "Unexpected null body", SafeArg.of("status", response.status())); return object; } }
@Override public Object decode(Response response, Type type) throws FeignException, IOException { Object object = delegate.decode(response, type); Preconditions.checkNotNull(object, "Unexpected null body", SafeArg.of("status", response.status())); return object; } }
@Override public boolean registerScope(Scope scope) throws KeyManagementException { ScopeInfo scopeInfo = getScopeInfo(scope); Response response = scopeRegistrationServiceStub.registerScope(scopeInfo); if (response.status() == APIMgtConstants.HTTPStatusCodes.SC_201_CREATED) { return true; } else { throw new KeyManagementException("Scope Registration Failed", ExceptionCodes.SCOPE_REGISTRATION_FAILED); } }
@Override public Object decode(Response response, Type type) throws FeignException, IOException { Object object = delegate.decode(response, type); Preconditions.checkNotNull(object, "Unexpected null body", SafeArg.of("status", response.status())); return object; } }
@Override public boolean updateScope(Scope scope) throws KeyManagementException { ScopeInfo scopeInfo = getScopeInfo(scope); Response response = scopeRegistrationServiceStub.updateScope(scopeInfo, scope.getName()); if (response.status() == APIMgtConstants.HTTPStatusCodes.SC_200_OK) { return true; } else { throw new KeyManagementException("Scope update failed", ExceptionCodes.INTERNAL_ERROR); } }
@Test public void execute_BadStatusGiven_ShouldRespondWithBadStatus() throws IOException { FeignLambdaClientImpl client = new FeignLambdaClientImpl(serviceResponse); when(serviceResponse.getStatusCode()).thenReturn(400); feign.Response response = client.execute(feignRequest, null); assertEquals(400, response.status()); }
public boolean uploadFile(String fileName, File file) { FileUploadResource fileUploadResource = Feign.builder() .encoder(new FormEncoder(new JacksonEncoder())) .target(FileUploadResource.class, HTTP_FILE_UPLOAD_URL); Response response = fileUploadResource.uploadFile("Example file", file); return response.status() == 200; }