/** * Constructor. * * @param context * The context from which the client dispatcher will be * retrieved. * @param categoriesUri * The feed URI. * @throws IOException */ public Categories(Context context, String categoriesUri) throws IOException { this(context.getClientDispatcher() .handle(new Request(Method.GET, categoriesUri)).getEntity()); }
@Override public synchronized void start() throws Exception { wrappedRestlet.start(); }
/** * Checks the context and sets it if necessary. * * @param target * The target Restlet. */ protected void checkContext(Restlet target) { if ((target.getContext() == null) && (this.parentContext != null)) { target.setContext(this.parentContext.createChildContext()); } }
/** * Sets the outbound root Restlet. * * @param outboundRoot * The outbound root Restlet. */ public synchronized void setOutboundRoot(Restlet outboundRoot) { this.outboundRoot = outboundRoot; if ((outboundRoot != null) && (outboundRoot.getContext() == null)) { outboundRoot.setContext(getContext()); } }
Response response = this.context.getClientDispatcher().handle( new Request(Method.GET, targetUri)); if (response.getStatus().isSuccess() && response.isEntityAvailable()) { try { result = new StreamSource(response.getEntity().getStream()); result.setSystemId(targetUri); this.context.getLogger().log(Level.WARNING, "I/O error while getting the response stream", e);
public void handle(Request request, Response response) { if (request.getResourceRef().getScheme().equalsIgnoreCase("clap")) { request.getAttributes().put("org.restlet.clap.classLoader", bundleClassLoader); } dispatcher.handle(request, response); } }
Response.setCurrent(response); if (getContext() != null) { Context.setCurrent(getContext()); if (isStopped()) { try { start(); } catch (Exception e) { if (getContext() != null) { getContext().getLogger().log(Level.WARNING, UNABLE_TO_START, e); } else { Context.getCurrentLogger().log(Level.WARNING, UNABLE_TO_START, e); response.setStatus(Status.SERVER_ERROR_INTERNAL); if (!isStarted()) { getContext().getLogger().log(Level.WARNING, UNABLE_TO_START); response.setStatus(Status.SERVER_ERROR_INTERNAL);
@Override public void handle(Request request, Response response) { LOG.debug("MethodRouter [{}] received request method: [{}]" , uriPattern, request.getMethod()); Restlet target = routes.get(request.getMethod()); if (target != null) { target.handle(request, response); } else { LOG.debug("No route for request method: [{}]", request.getMethod()); response.setStatus(Status.CLIENT_ERROR_NOT_FOUND); } }
@Override public Representation put(Representation entity) throws ResourceException { if (!this.directory.isModifiable()) { setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED, "The directory is not modifiable."); return null; } // Transfer of PUT calls is only allowed if the readOnly flag is not set. Request contextRequest = new Request(Method.PUT, this.targetUri); // Add support of partial PUT calls. contextRequest.getRanges().addAll(getRanges()); contextRequest.setEntity(entity); Response contextResponse = new Response(contextRequest); contextRequest.setResourceRef(this.targetUri); getClientDispatcher().handle(contextRequest, contextResponse); setStatus(contextResponse.getStatus()); return null; }
/** * Posts a member to the collection resulting in the creation of a new * resource. * * @param member * The member representation to post. * @return The reference of the new resource. * @throws Exception */ public Reference postMember(Representation member) throws Exception { final Request request = new Request(Method.POST, getHref(), member); final Response response = getWorkspace().getService() .getClientDispatcher().handle(request); if (response.getStatus().equals(Status.SUCCESS_CREATED)) { return response.getLocationRef(); } throw new Exception( "Couldn't post the member representation. Status returned: " + response.getStatus()); }
/** * Returns a representation of the resource at the target URI. Leverages the * client dispatcher of the parent directory's context. * * @param resourceUri * The URI of the target resource. * @param acceptedMediaType * The accepted media type or null. * @return A response with the representation if success. */ protected Response getRepresentation(String resourceUri, MediaType acceptedMediaType) { Request request = new Request(Method.GET, resourceUri); if (acceptedMediaType != null) { request.getClientInfo().accept(acceptedMediaType); } return getClientDispatcher().handle(request); }
@Override public void handle(Request request, Response response) { super.handle(request, response); if (getFirstInboundFilter() != null) { getFirstInboundFilter().handle(request, response); } else { final Restlet next = this.inboundNext; if (next != null) { next.handle(request, response); } else { response.setStatus(Status.SERVER_ERROR_INTERNAL); getHelped() .getLogger() .log(Level.SEVERE, "The " + getHelped().getClass().getName() + " class has no Restlet defined to process calls. Maybe it wasn't properly started."); } } }
/** * Handles a call by invoking the next Restlet if it is available. * * @param request * The request to handle. * @param response * The response to update. */ @Override public void handle(Request request, Response response) { super.handle(request, response); Restlet next = getNext(request, response); if (next != null) { doHandle(next, request, response); } else { response.setStatus(Status.CLIENT_ERROR_NOT_FOUND); } }
/** * Handles the case, if no resource class was found. If a Restlet to handle * this case was given (see {@link #setNoResourceClHandler(Restlet)}), it is * called. Otherwise a {@link WebApplicationException} with status 404 is * thrown (see spec, section 3.7.2, item 2e) * * @throws WebApplicationException * @throws RequestHandledException */ public void resourceNotFound() throws WebApplicationException, RequestHandledException { if (this.noResourceClHandler != null) { this.noResourceClHandler.handle(Request.getCurrent(), org.restlet.Response.getCurrent()); throw new RequestHandledException(); } throw new WebApplicationException(Status.NOT_FOUND); }
@Override public void handle(Request request, Response response) { wrappedRestlet.handle(request, response); }
/** * Returns the helped Restlet logger. * * @return The helped Restlet logger. */ public Logger getLogger() { return (getHelped().getContext() != null) ? getHelped().getContext() .getLogger() : Context.getCurrentLogger(); }
/** * Returns a representation of the resource at the target URI. Leverages the * client dispatcher of the parent directory's context. * * @param resourceUri * The URI of the target resource. * @return A response with the representation if success. */ private Response getRepresentation(String resourceUri) { return getClientDispatcher().handle( new Request(Method.GET, resourceUri)); }