/** * Sets the next handler such as a Restlet or a Filter. * * In addition, this method will set the context of the next Restlet if it * is null by passing a reference to its own context. * * @param next * The next handler. */ public void setNext(org.restlet.Uniform next) { if (next instanceof Restlet) { Restlet nextRestlet = (Restlet) next; if (nextRestlet.getContext() == null) { nextRestlet.setContext(getContext()); } } this.next = next; // If true, it must be updated after calling this method this.nextCreated = false; }
private ClientResource createClientResource(String url, boolean buffering) { ClientResource clientResource = new ClientResource(new Context(), url); clientResource.getContext().getParameters().add("socketConnectTimeoutMs", String.valueOf(CONNECTION_TIMEOUT)); clientResource.getContext().getParameters().add("maxIoIdleTimeMs", String.valueOf(CONNECTION_TIMEOUT)); clientResource.setEntityBuffering(buffering); return clientResource; }
/** * Creates a next Restlet is no one is set. By default, it creates a new * {@link Client} based on the protocol of the resource's URI reference. * * @return The created next Restlet or null. */ protected Uniform createNext() { Uniform result = null; // Prefer the outbound root result = getApplication().getOutboundRoot(); if ((result == null) && (getContext() != null)) { // Try using directly the client dispatcher result = getContext().getClientDispatcher(); } if (result == null) { // As a final option, try creating a client connector Protocol rProtocol = getProtocol(); Reference rReference = getReference(); Protocol protocol = (rProtocol != null) ? rProtocol : (rReference != null) ? rReference.getSchemeProtocol() : null; if (protocol != null) { org.restlet.engine.util.TemplateDispatcher dispatcher = new org.restlet.engine.util.TemplateDispatcher(); dispatcher.setContext(getContext()); dispatcher.setNext(new Client(protocol)); result = dispatcher; } } return result; }
/** * Constructor. * * @param resource * The client resource to copy. */ public ClientResource(ClientResource resource) { Request request = new Request(resource.getRequest()); Response response = new Response(request); this.next = resource.getNext(); this.maxRedirects = resource.getMaxRedirects(); this.retryOnError = resource.isRetryOnError(); this.retryDelay = resource.getRetryDelay(); this.retryAttempts = resource.getRetryAttempts(); this.followingRedirects = resource.isFollowingRedirects(); this.requestEntityBuffering = resource.isRequestEntityBuffering(); this.responseEntityBuffering = resource.isResponseEntityBuffering(); setApplication(resource.getApplication()); init(resource.getContext(), request, response); }