/** * 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(); }
private void result( Object resultValue ) throws Exception { if( resultValue != null ) { if( !responseWriter.writeResponse( resultValue, Response.getCurrent() ) ) { throw new ResourceException( Status.SERVER_ERROR_INTERNAL, "No result writer for type " + resultValue.getClass() .getName() ); } } }
private void result( Object resultValue ) throws Exception { if( resultValue != null ) { if( !responseWriter.writeResponse( resultValue, Response.getCurrent() ) ) { throw new ResourceException( Status.SERVER_ERROR_INTERNAL, "No result writer for type " + resultValue.getClass() .getName() ); } } }
private void result( Object resultValue ) throws Exception { if( resultValue != null ) { if( !responseWriter.writeResponse( resultValue, Response.getCurrent() ) ) { throw new ResourceException( Status.SERVER_ERROR_INTERNAL, "No result writer for type " + resultValue.getClass() .getName() ); } } }
public void subResource( Class<? extends ContextResource> subResourceClass ) { Uniform subResource = subResources.get( subResourceClass ); if( subResource == null ) { // Instantiate and store subresource instance subResource = objectFactory.newObject( subResourceClass, this ); subResources.put( subResourceClass, subResource ); } subResource.handle( Request.getCurrent(), Response.getCurrent() ); }
public void subResource( Class<? extends ContextResource> subResourceClass ) { Uniform subResource = subResources.get( subResourceClass ); if( subResource == null ) { // Instantiate and store subresource instance subResource = objectFactory.newObject( subResourceClass, this ); subResources.put( subResourceClass, subResource ); } subResource.handle( Request.getCurrent(), Response.getCurrent() ); }
public void subResource( Class<? extends ContextResource> subResourceClass ) { Uniform subResource = subResources.get( subResourceClass ); if( subResource == null ) { // Instantiate and store subresource instance subResource = module.newObject( subResourceClass, this ); subResources.put( subResourceClass, subResource ); } subResource.handle( Request.getCurrent(), Response.getCurrent() ); }
final Context currentContext = Context.getCurrent(); final Integer currentVirtualHost = org.restlet.routing.VirtualHost .getCurrent(); final Response currentResponse = Response.getCurrent();
/** * @return the character set of the current entity, or null, if no entity or * no character set is available. */ private String getCurrentResponseEntityCharset() { String result = null; Response rsp = Response.getCurrent(); if (rsp == null) { Context.getCurrentLogger().warning( "Unable to find the current response"); } else { Representation entity = Response.getCurrent().getEntity(); if (entity == null) return null; CharacterSet characterSet = entity.getCharacterSet(); if (characterSet == null) return null; result = characterSet.toString(); } return result; }
/** * Handles the case, if no resource method was found. If a Restlet to handle * this case was given (see {@link #setNoResMethodHandler(Restlet)}), it is * called. Otherwise a {@link WebApplicationException} with status 404 is * thrown (see JAX-RS specification) * * @throws WebApplicationException * @throws RequestHandledException */ public void resourceMethodNotFound() throws WebApplicationException, RequestHandledException { if (this.noResMethodHandler != null) { this.noResMethodHandler.handle(Request.getCurrent(), org.restlet.Response.getCurrent()); throw new RequestHandledException(); } throw new WebApplicationException(Status.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); }
/** * Handles the case, if no root resource class was found. If a Restlet to * handle this case was given (see {@link #setNoRootResClHandler(Restlet)}), * it is called. Otherwise a {@link WebApplicationException} with status 404 * is thrown (see JAX-RS specification, section 3.7.2, item 1d) * * @throws WebApplicationException * @throws RequestHandledException */ public void rootResourceNotFound() throws WebApplicationException, RequestHandledException { if (this.noRootResClHandler != null) { this.noRootResClHandler.handle(Request.getCurrent(), org.restlet.Response.getCurrent()); throw new RequestHandledException(); } throw new WebApplicationException(Status.NOT_FOUND); }
final Context currentContext = Context.getCurrent(); final Integer currentVirtualHost = VirtualHost.getCurrent(); final Response currentResponse = Response.getCurrent();
/** * @see MessageBodyWriter#writeTo(Object, Type, Annotation[], MediaType, * MultivaluedMap, OutputStream) */ @Override public void writeTo(Reader reader, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { CharacterSet cs = Response.getCurrent().getEntity().getCharacterSet(); IoUtils.copy(reader, IoUtils.getWriter(entityStream, cs)); } }
handleException( Response.getCurrent(), e );
handleException( Response.getCurrent(), e );
handleException( Response.getCurrent(), e );
public Representation login( String name, String password ) { context( Login.class ).login( name, password ); EmptyRepresentation rep = new EmptyRepresentation(); Response.getCurrent().getCookieSettings().add( "user", name ); return rep; } }
Map<Class<?>, Class<?>> additional = (Map<Class<?>, Class<?>>) Response.getCurrent().getAttributes().get(ADDITIONAL_MIXINS_ATTRIBUTE);
@SubResource public void administration() { ChallengeResponse challenge = Request.getCurrent().getChallengeResponse(); if( challenge == null ) { Response.getCurrent() .setChallengeRequests( Collections.singletonList( new ChallengeRequest( ChallengeScheme.HTTP_BASIC, "Forum" ) ) ); throw new ResourceException( Status.CLIENT_ERROR_UNAUTHORIZED ); } User user = select( Users.class, Users.USERS_ID ).userNamed( challenge.getIdentifier() ); if( user == null || !user.isCorrectPassword( new String( challenge.getSecret() ) ) ) { throw new ResourceException( Status.CLIENT_ERROR_UNAUTHORIZED ); } current().select( user ); subResource( AdministrationResource.class ); }