public RepresentationWalker createWalker(final Response response) { return new RepresentationWalker(this, response); }
/** * The error (if any) that occurred from the previous walk. */ public String getError() { final Step currentStep = currentStep(); return currentStep != null ? currentStep.error : null; }
public void walk(final String path) { walk(path, null); }
public void walk(final String path, final JsonRepresentation invokeBody) { final Step previousStep = currentStep(); if (previousStep.error != null) { return; entity = jsonResponse.getEntity(); } catch (final Exception e) { addStep(path, null, null, null, "exception: " + e.getMessage(), e); return; link = entity.getLink(path); } catch (final Exception e) { addStep(path, null, null, null, "exception: " + e.getMessage(), e); return; addStep(path, null, null, null, "no such link '" + path + "'", null); return; addStep(path, link, null, null, "failed to follow link: " + e.getMessage(), e); return; addStep(path, link, null, response, null, null);
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); }
/** * 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; }
/** * 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 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(); }