/** * Returns the response associated to this exception. * * @return The response associated to this exception. */ public Response getResponse() { return (this.resource != null) ? this.resource.getResponse() : null; }
/** * Returns the set of methods allowed for the current client by the * resource. The result can vary based on the client's user agent, * authentication and authorization data provided by the client. * * @return The set of allowed methods. */ public Set<Method> getAllowedMethods() { return getResponse() == null ? null : getResponse().getAllowedMethods(); }
/** * Returns the modifiable series of cookie settings provided by the server. * Creates a new instance if no one has been set. * * @return The cookie settings provided by the server. * @see Response#getCookieSettings() */ public Series<CookieSetting> getCookieSettings() { return getResponse() == null ? null : getResponse().getCookieSettings(); }
/** * Returns the modifiable set of selecting dimensions on which the response * entity may vary. If some server-side content negotiation is done, this * set should be properly updated, other it can be left empty. Creates a new * instance if no one has been set. * * @return The set of dimensions on which the response entity may vary. * @see Response#getDimensions() */ public Set<Dimension> getDimensions() { return getResponse() == null ? null : getResponse().getDimensions(); }
/** * Returns the list of authentication requests sent by an origin server to a * client. If none is available, an empty list is returned. * * @return The list of authentication requests. * @see Response#getChallengeRequests() */ public List<ChallengeRequest> getChallengeRequests() { return getResponse() == null ? null : getResponse() .getChallengeRequests(); }
/** * Returns the list of proxy authentication requests sent by an origin * server to a client. If none is available, an empty list is returned. * * @return The list of proxy authentication requests. * @see Response#getProxyChallengeRequests() */ public List<ChallengeRequest> getProxyChallengeRequests() { return getResponse() == null ? null : getResponse() .getProxyChallengeRequests(); }
/** * Returns the response attributes. * * @return The response attributes. * @see Response#getAttributes() */ public Map<String, Object> getResponseAttributes() { return getResponse() == null ? null : getResponse().getAttributes(); }
/** * Returns the response entity representation. * * @return The response entity representation. */ public Representation getResponseEntity() { return getResponse() == null ? null : getResponse().getEntity(); }
/** * Returns the reference that the client should follow for redirections or * resource creations. * * @return The redirection reference. * @see Response#getLocationRef() */ public Reference getLocationRef() { return getResponse() == null ? null : getResponse().getLocationRef(); }
/** * Returns the status. * * @return The status. * @see Response#getStatus() */ public Status getStatus() { return getResponse() == null ? null : getResponse().getStatus(); }
/** * Returns the server-specific information. Creates a new instance if no one * has been set. * * @return The server-specific information. * @see Response#getServerInfo() */ public ServerInfo getServerInfo() { return getResponse() == null ? null : getResponse().getServerInfo(); }
/** * Returns the response cache directives. Note that when used with HTTP * connectors, this property maps to the "Cache-Control" header. * * @return The cache directives. */ public List<CacheDirective> getResponseCacheDirectives() { return getResponse() == null ? null : getResponse() .getCacheDirectives(); }
/** * Removes all the representations of the resource and effectively the * resource itself. The default behavior is to set the response status to * {@link Status#SERVER_ERROR_INTERNAL}.<br> * <br> * This is the higher-level method that let you process DELETE requests. */ public void removeRepresentations() throws ResourceException { getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); }
/** * Accepts and processes a representation posted to the resource. The * default behavior is to set the response status to * {@link Status#SERVER_ERROR_INTERNAL}.<br> * <br> * This is the higher-level method that let you process POST requests. * * @param entity * The posted entity. */ public void acceptRepresentation(Representation entity) throws ResourceException { getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); }
/** * Stores a representation put to the resource and replaces all existing * representations of the resource. If the resource doesn't exist yet, it * should create it and use the entity as its initial representation. The * default behavior is to set the response status to * {@link Status#SERVER_ERROR_INTERNAL}.<br> * <br> * This is the higher-level method that let you process PUT requests. * * @param entity */ public void storeRepresentation(Representation entity) throws ResourceException { getResponse().setStatus(Status.SERVER_ERROR_INTERNAL); }
@Override public Status toStatus(Throwable throwable, Resource resource) { Status status = Status.SERVER_ERROR_INTERNAL; Response response = resource.getResponse(); Series<Header> responseHeaders = response.getHeaders(); responseHeaders.add(new Header( "Some-Header", "my custom message")); return status; }
@Override public String toString() { return (getRequest() == null ? "" : getRequest().toString()) + (getResponse() == null ? "" : " => " + getResponse().toString()); } }
@Override public Representation toRepresentation(Object source, Variant target, Resource resource) throws IOException { if (source instanceof Template) { TemplateRepresentation tr = new TemplateRepresentation( (Template) source, target.getMediaType()); tr.setDataModel(resource.getRequest(), resource.getResponse()); return tr; } return null; }
@Override public Representation toRepresentation(Object source, Variant target, Resource resource) throws IOException { if (source instanceof Template) { return new TemplateRepresentation((Template) source, new ResolverHashModel(Resolver.createResolver( resource.getRequest(), resource.getResponse())), target.getMediaType()); } return null; }
@Override public Representation toRepresentation(Object source, Variant target, Resource resource) throws IOException { if (source instanceof Template) { Locale locale = getLocale(resource); TemplateRepresentation tr = new TemplateRepresentation( ((Template) source).getTemplateName(), locale, target.getMediaType()); tr.setDataModel(resource.getRequest(), resource.getResponse()); return tr; } return null; }