@Override public boolean isConfidential() { return getRequest().isConfidential(); }
/** * Ask the connector to abort the related network connection, for example * immediately closing the socket. */ public void abort() { getRequest().abort(); }
/** * Displays a synthesis of the response like an HTTP status line. * * @return A synthesis of the response like an HTTP status line. */ public String toString() { return ((getRequest() == null) ? "?" : getRequest().getProtocol()) + " - " + getStatus(); } }
/** * Asks the server connector to immediately flush the network buffers. Note * that this calls back {@link Request#flushBuffers()} on the parent request * which holds the link with the underlying network connection. * * @throws IOException */ @Override public void flushBuffers() throws IOException { getRequest().flushBuffers(); }
/** * Returns the associated request * * @return The associated request */ @Override public Request getRequest() { return getWrappedResponse().getRequest(); }
@Override public void write( Writer writer ) throws IOException { Map<String, Object> context = new HashMap<>(); context.put( "request", response.getRequest() ); context.put( "response", response ); context.put( "result", result ); try { cfg.getTemplate( "links.htm" ).process( context, writer ); } catch( TemplateException e ) { throw new IOException( e ); } } };
@Override public void write( Writer writer ) throws IOException { Map<String, Object> context = new HashMap<String, Object>(); context.put( "request", response.getRequest() ); context.put( "response", response ); context.put( "result", result ); try { template.process( context, writer ); } catch( TemplateException e ) { throw new IOException( e ); } } };
@Override public void write( Writer writer ) throws IOException { Map<String, Object> context = new HashMap<>(); context.put( "request", response.getRequest() ); context.put( "response", response ); context.put( "result", result ); try { cfg.getTemplate( "links.atom" ).process( context, writer ); } catch( TemplateException e ) { throw new IOException( e ); } } };
@Override public void write( Writer writer ) throws IOException { Map<String, Object> context = new HashMap<>(); context.put( "request", response.getRequest() ); context.put( "response", response ); context.put( "result", result ); try { cfg.getTemplate( "form.htm" ).process( context, writer ); } catch( TemplateException e ) { throw new IOException( e ); } } };
@Override public void write( Writer writer ) throws IOException { Map<String, Object> context = new HashMap<>(); context.put( "request", response.getRequest() ); context.put( "response", response ); context.put( "result", result ); try { cfg.getTemplate( "table.htm" ).process( context, writer ); } catch( TemplateException e ) { throw new IOException( e ); } } };
@Override public void write( Writer writer ) throws IOException { Map<String, Object> context = new HashMap<>(); context.put( "request", response.getRequest() ); context.put( "response", response ); context.put( "result", result ); try { cfg.getTemplate( "table.htm" ).process( context, writer ); } catch( TemplateException e ) { throw new IOException( e ); } } };
/** * Asks the server connector to immediately commit the given response, * making it ready to be sent back to the client. Note that all server * connectors don't necessarily support this feature.<br> * <br> * When the response is in autoCommit mode (see related property), then * calling this method isn't necessary. Also, be aware that committing the * response doesn't necessarily means that is will be immediately be written * on the network as some buffering can occurs. If you want to ensure that * response buffers are flushed,<br> * <br> * Note that this calls back {@link Request#commit(Response)} on the parent * request which holds the link with the underlying network connection. */ public void commit() { getRequest().commit(this); }
/** * Returns the request associated to the current thread. This is reusing the {@link Response#getCurrent()} method.<br> * <br> * Warning: this method should only be used under duress. You should by * default prefer obtaining the current context using methods such as * {@link org.restlet.resource.Resource#getRequest()}. * * @return The thread's request. */ public static Request getCurrent() { return (Response.getCurrent() == null) ? null : Response.getCurrent() .getRequest(); }
/** * Format an access log entry. If the log template property isn't provided, * then a default IIS like format is used. * * @param response * The response to log. * @param duration * The call duration. * @return The formatted log entry. */ public String getResponseLogMessage(Response response, int duration) { String result = null; // Format the call into a log entry if (this.responseLogTemplate != null) { result = this.responseLogTemplate.format(response.getRequest(), response); } else { result = getDefaultResponseLogMessage(response, duration); } return result; }
@Override public void challenge(Response response, boolean stale) { // Load the FreeMarker template Representation ftl = new ClientResource( LocalReference.createClapReference(getClass().getPackage()) + "/Login.ftl").get(); // Wraps the bean with a FreeMarker representation response.setEntity(new TemplateRepresentation(ftl, response .getRequest().getResourceRef(), MediaType.TEXT_HTML)); response.setStatus(Status.CLIENT_ERROR_UNAUTHORIZED); }
@Override public void challenge(Response response, boolean stale) { // Load the FreeMarker template Representation ftl = new ClientResource( LocalReference.createClapReference(getClass().getPackage()) + "/Login.ftl").get(); // Wraps the bean with a FreeMarker representation response.setEntity(new TemplateRepresentation(ftl, response .getRequest().getResourceRef(), MediaType.TEXT_HTML)); response.setStatus(Status.CLIENT_ERROR_UNAUTHORIZED); }
@Override public boolean writeResponse( final Object result, final Response response ) throws ResourceException { MediaType type = getVariant( response.getRequest(), ENGLISH, supportedMediaTypes ).getMediaType(); if( MediaType.APPLICATION_JSON.equals( type ) ) { if( result instanceof String || result instanceof Number || result instanceof Boolean ) { StringRepresentation representation = new StringRepresentation( result.toString(), MediaType.APPLICATION_JSON ); response.setEntity( representation ); return true; } } return false; } }
@Override public boolean writeResponse( final Object result, final Response response ) throws ResourceException { MediaType type = getVariant( response.getRequest(), ENGLISH, supportedMediaTypes ).getMediaType(); if( MediaType.APPLICATION_JSON.equals( type ) ) { if( result instanceof String || result instanceof Number || result instanceof Boolean ) { StringRepresentation representation = new StringRepresentation( result.toString(), MediaType.APPLICATION_JSON ); response.setEntity( representation ); return true; } } return false; } }
@Override public boolean writeResponse( final Object result, final Response response ) throws ResourceException { MediaType type = getVariant( response.getRequest(), ENGLISH, supportedMediaTypes ).getMediaType(); if( MediaType.APPLICATION_JSON.equals( type ) ) { if( result instanceof String || result instanceof Number || result instanceof Boolean ) { StringRepresentation representation = new StringRepresentation( result.toString(), MediaType.APPLICATION_JSON ); response.setEntity( representation ); return true; } } return false; } }
@Override public Representation handleInbound(Response response) { Representation result = null; // Verify that the request was synchronous if (response.getRequest().isSynchronous()) { if (response.getStatus().isError()) { doError(response.getStatus()); // DO NOT DISPOSE THE RESPONSE. }/* else { */ result = (response == null) ? null : response.getEntity(); /* } */ } return result; }