/** * Used when following links ( * {@link RestfulClient#follow(LinkRepresentation)}). */ public ClientRequestConfigurer configureArgs(final JsonRepresentation requestArgs) { if (clientRequest.getHttpMethod() == null) { throw new IllegalStateException("Must set up http method first"); } getHttpMethod().setUpArgs(this, requestArgs); return this; }
/** * Prerequisite to {@link #configureArgs(JsonRepresentation)} or * {@link #configureArgs(Map)}. */ public ClientRequestConfigurer setHttpMethod(final RestfulHttpMethod httpMethod) { clientRequest.setHttpMethod(httpMethod.getJavaxRsMethod()); return this; }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((getHref() == null) ? 0 : getHref().hashCode()); result = prime * result + ((getHttpMethod() == null) ? 0 : getHttpMethod().hashCode()); return result; }
RestfulHttpMethod getHttpMethod() { final String httpMethod = clientRequest.getHttpMethod(); return RestfulHttpMethod.valueOf(httpMethod); }
public LinkRepresentation withMethod(final RestfulHttpMethod httpMethod) { asObjectNode().put("method", httpMethod.name()); return this; }
public RestfulHttpMethod getHttpMethod() { final String methodStr = asObjectNode().path("method").getTextValue(); return RestfulHttpMethod.valueOf(methodStr); }
/** * Used when creating a request with arguments to execute. * * <p> * Typical flow is: * <ul> * <li> {@link RestfulClient#createRequest(RestfulHttpMethod, String)} * <li> {@link RestfulRequest#withArg(RequestParameter, Object)} for each arg * <li> {@link RestfulRequest#execute()} - which calls this method. * </ul> */ public ClientRequestConfigurer configureArgs(final Map<RequestParameter<?>, Object> args) { if (clientRequest.getHttpMethod() == null) { throw new IllegalStateException("Must set up http method first"); } final JsonRepresentation argsAsMap = JsonRepresentation.newMap(); for (final RequestParameter<?> requestParam : args.keySet()) { put(args, requestParam, argsAsMap); } getHttpMethod().setUpArgs(this, argsAsMap); return this; }
@Override public void visit(final DomainObjectLayoutData domainObjectLayoutData) { Link link = new Link( Rel.ELEMENT.getName(), RestfulHttpMethod.GET.getJavaxRsMethod(), getResourceContext().urlFor( "objects/" + domainType + "/" + instanceId ), RepresentationType.DOMAIN_OBJECT.getJsonMediaType().toString()); domainObjectLayoutData.setLink(link); }
private void setsUpQueryString(final RestfulHttpMethod httpMethod) throws UnsupportedEncodingException { context.checking(new Expectations() { { one(requestConfigurer).setHttpMethod(httpMethod); one(requestConfigurer).queryString(repr); } }); httpMethod.setUpArgs(requestConfigurer, repr); }
@Override public void visit(final CollectionLayoutData collectionLayoutData) { Link link = new Link( Rel.COLLECTION.getName(), RestfulHttpMethod.GET.getJavaxRsMethod(), getResourceContext().urlFor( "objects/" + domainType + "/" + instanceId + "/collections/" + collectionLayoutData.getId() ), RepresentationType.OBJECT_COLLECTION.getJsonMediaType().toString()); collectionLayoutData.setLink(link); } });
private void setsUpQueryString(final RestfulHttpMethod httpMethod) throws UnsupportedEncodingException { context.checking(new Expectations() { { one(requestConfigurer).setHttpMethod(httpMethod); one(requestConfigurer).queryString(repr); } }); httpMethod.setUpArgs(requestConfigurer, repr); }
@Override public void visit(final ServiceActionLayoutData actionLayoutData) { final String objectType = actionLayoutData.getObjectType(); final String relativeUrl = String.format( "objects/%s/%s/actions/%s", objectType, PersistenceSession.SERVICE_IDENTIFIER, actionLayoutData.getId()); Link link = new Link( Rel.ACTION.getName(), RestfulHttpMethod.GET.getJavaxRsMethod(), getResourceContext().urlFor(relativeUrl), RepresentationType.OBJECT_ACTION.getJsonMediaType().toString()); actionLayoutData.setLink(link); } });
private void setsUpBody(final RestfulHttpMethod httpMethod) throws UnsupportedEncodingException { context.checking(new Expectations() { { one(requestConfigurer).setHttpMethod(httpMethod); one(requestConfigurer).body(repr); } }); httpMethod.setUpArgs(requestConfigurer, repr); }
@Override public void visit(final PropertyLayoutData propertyLayoutData) { Link link = new Link( Rel.PROPERTY.getName(), RestfulHttpMethod.GET.getJavaxRsMethod(), getResourceContext().urlFor( "objects/" + domainType + "/" + instanceId + "/properties/" + propertyLayoutData.getId() ), RepresentationType.OBJECT_PROPERTY.getJsonMediaType().toString()); propertyLayoutData.setLink(link); }
private void setsUpBody(final RestfulHttpMethod httpMethod) throws UnsupportedEncodingException { context.checking(new Expectations() { { one(requestConfigurer).setHttpMethod(httpMethod); one(requestConfigurer).body(repr); } }); httpMethod.setUpArgs(requestConfigurer, repr); }
@Override public void visit(final ActionLayoutData actionLayoutData) { Link link = new Link( Rel.ACTION.getName(), RestfulHttpMethod.GET.getJavaxRsMethod(), getResourceContext().urlFor( "objects/" + domainType + "/" + instanceId + "/actions/" + actionLayoutData.getId() ), RepresentationType.OBJECT_ACTION.getJsonMediaType().toString()); actionLayoutData.setLink(link); }