/** * 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(); }
/** * The error (if any) that occurred from the previous walk. */ public String getError() { final Step currentStep = currentStep(); return currentStep != null ? currentStep.error : null; }
public <T extends JsonRepresentation> RestfulResponse<T> follow(final ClientExecutor executor, final JsonRepresentation requestArgs) throws Exception { final ClientRequestConfigurer clientRequestConfigurer = ClientRequestConfigurer.create(executor, getHref()); clientRequestConfigurer.accept(MediaType.APPLICATION_JSON_TYPE); clientRequestConfigurer.setHttpMethod(getHttpMethod()); clientRequestConfigurer.configureArgs(requestArgs); final RestfulRequest restfulRequest = new RestfulRequest(clientRequestConfigurer); return restfulRequest.executeT(); }
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; }
@Override void setUpArgs(final ClientRequestConfigurer clientRequestConfigurer, final JsonRepresentation requestArgs) { clientRequestConfigurer.body(requestArgs); } };
@Override void setUpArgs(final ClientRequestConfigurer clientRequestConfigurer, final JsonRepresentation requestArgs) { clientRequestConfigurer.queryString(requestArgs); } },
@Override void setUpArgs(final ClientRequestConfigurer clientRequestConfigurer, final JsonRepresentation requestArgs) { clientRequestConfigurer.queryArgs(requestArgs); } },
@Override public String toString() { return getName(); } }
@Override public String toString() { return getName(); } }
@SuppressWarnings("unchecked") public <T extends JsonRepresentation> RestfulResponse<T> executeT() { final RestfulResponse<JsonRepresentation> restfulResponse = execute(); return (RestfulResponse<T>) restfulResponse; }
public <T> RestfulRequest withHeader(final Header<T> header, final T t) { header.setHeader(clientRequestConfigurer, t); return this; }
@Override public String valueOf(String str) { return stripPrefix(str, PREFIX); }
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); }
public void walk(final String path) { walk(path, null); }
public RepresentationWalker createWalker(final Response response) { return new RepresentationWalker(this, response); }
/** * The response returned from the previous walk. * * <p> * Once a walk/performed has been attempted, is guaranteed to return a * non-null value. (Conversely, will return <tt>null</tt> immediately after * instantiation and prior to a walk being attempted/performed). */ public RestfulResponse<?> getResponse() { final Step currentStep = currentStep(); return currentStep != null ? currentStep.response : null; }
/** * The exception (if any) that occurred from the previous walk. * * <p> * Will only ever be populated if {@link #getError()} is non-null. */ public Exception getException() { final Step currentStep = currentStep(); return currentStep != null ? currentStep.exception : null; }