public <V> V getHeader(final Header<V> header) { return getHeader(response, header); }
@SuppressWarnings("unchecked") public static <T extends JsonRepresentation> RestfulResponse<T> ofT(final Response response) { return (RestfulResponse<T>) of(response); }
@SuppressWarnings({ "rawtypes", "unchecked" }) public static RestfulResponse<JsonRepresentation> of(final Response response) { final MediaType jaxRsMediaType = getHeader(response, Header.CONTENT_TYPE); final RepresentationType representationType = RepresentationType.lookup(jaxRsMediaType); final Class<? extends JsonRepresentation> returnType = representationType.getRepresentationClass(); return new RestfulResponse(response, returnType); }
/** * The entity returned from the previous walk. * * <p> * Will return null if the previous walk returned an error. */ public JsonRepresentation getEntity() throws JsonParseException, JsonMappingException, IOException { final Step currentStep = currentStep(); if (currentStep.response == null || currentStep.error != null) { return null; } return currentStep.response.getEntity(); }
private Step addStep(final String key, final LinkRepresentation link, final JsonRepresentation body, final RestfulResponse<JsonRepresentation> jsonResp, final String error, final Exception ex) { final Step step = new Step(key, link, body, jsonResp, error, ex); steps.add(0, step); if (error != null) { if (jsonResp.getStatus().getFamily() != Family.SUCCESSFUL) { step.error = "response status code: " + jsonResp.getStatus(); } } return step; }
public RestfulResponse<JsonRepresentation> execute() { try { if (!args.isEmpty()) { clientRequestConfigurer.configureArgs(args); } final ClientRequest clientRequest = clientRequestConfigurer.getClientRequest(); final Response response = clientRequest.execute(); // this is a bit hacky @SuppressWarnings("unchecked") final BaseClientResponse<String> restEasyResponse = (BaseClientResponse<String>) response; restEasyResponse.setReturnType(String.class); return RestfulResponse.ofT(response); } catch (final Exception ex) { throw new RuntimeException(ex); } }
JsonRepresentation entity; try { entity = jsonResponse.getEntity(); } catch (final Exception e) { addStep(path, null, null, null, "exception: " + e.getMessage(), e);
public RepresentationWalker(final RestfulClient restfulClient, final Response response) { this.restfulClient = restfulClient; final RestfulResponse<JsonRepresentation> jsonResp = RestfulResponse.of(response); addStep(null, null, null, jsonResp, null, null); }