/** * Adds a new inbound filter to the chain. * * @param filter * The inbound filter to add. */ protected synchronized void addInboundFilter(Filter filter) { Restlet next = getInboundNext(); if (getFirstInboundFilter() == null) { setFirstInboundFilter(filter); } else if (getLastInboundFilter() != null) { getLastInboundFilter().setNext(filter); } setLastInboundFilter(filter); setInboundNext(next); }
/** * Adds a new outbound filter to the chain. * * @param filter * The outbound filter to add. */ protected synchronized void addOutboundFilter(Filter filter) { Restlet next = getOutboundNext(); if (getFirstOutboundFilter() == null) { setFirstOutboundFilter(filter); } else if (getLastOutboundFilter() != null) { getLastOutboundFilter().setNext(filter); } setLastOutboundFilter(filter); setOutboundNext(next); }
/** * Clears the chain. Sets the first and last filters to null. */ public void clear() { setFirstInboundFilter(null); setFirstOutboundFilter(null); setInboundNext(null); setLastInboundFilter(null); setLastOutboundFilter(null); setOutboundNext(null); }
@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."); } } }
/** * Sets the next Restlet after the outbound chain. * * @param next * The Restlet to process after the outbound chain. */ protected synchronized void setOutboundNext(Restlet next) { if (getLastOutboundFilter() != null) { getLastOutboundFilter().setNext(next); } this.outboundNext = next; }
/** * Sets the next Restlet after the inbound chain. * * @param next * The Restlet to process after the inbound chain. */ protected synchronized void setInboundNext(Restlet next) { if (getLastInboundFilter() != null) { getLastInboundFilter().setNext(next); } this.inboundNext = next; }
/** * In addition to the default behavior, it saves the current application * instance into the current thread. * * @param request * The request to handle. * @param response * The response to update. */ @Override public void handle(Request request, Response response) { Application current = Application.getCurrent(); // Save the current application Application.setCurrent(getHelped()); // Actually handle call try { super.handle(request, response); } finally { // restaure the current application Application.setCurrent(current); } }
/** * Returns the next Restlet in the outbound chain. * * @return The next Restlet in the outbound chain. */ public synchronized Restlet getOutboundNext() { Restlet result = null; if (getLastOutboundFilter() != null) { result = getLastOutboundFilter().getNext(); } else { result = this.outboundNext; } return result; }
/** * Returns the next Restlet in the inbound chain. * * @return The next Restlet in the inbound chain. */ protected synchronized Restlet getInboundNext() { Restlet result = null; if (getLastInboundFilter() != null) { result = getLastInboundFilter().getNext(); } else { result = this.inboundNext; } return result; }