/** * Indicates if the response should be chunked because its length is * unknown. * * @param response * The response to analyze. * @return True if the response should be chunked. */ public boolean shouldResponseBeChunked(Response response) { return (response.getEntity() != null) && !response.getEntity().hasKnownSize(); }
/** * Returns the entity representation. * * @return The entity representation. */ @Override public Representation getEntity() { return getWrappedResponse().getEntity(); }
@Override public void handle(Request request, Response response) { super.handle(request, response); Optional.ofNullable(response.getEntity()) .ifPresent(r -> r.setCharacterSet(CharacterSet.UTF_8)); } }
/** * If the response entity comes back with no identifier, automatically set * the request's resource reference's identifier. This is very useful to * resolve relative references in XSLT for example. */ @Override protected void afterHandle(Request request, Response response) { if ((response.getEntity() != null) && (response.getEntity().getLocationRef() == null)) { response.getEntity().setLocationRef( request.getResourceRef().getTargetRef().toString()); } }
/** * Returns the response entity representation. * * @return The response entity representation. */ public Representation getResponseEntity() { return getResponse() == null ? null : getResponse().getEntity(); }
/** * Returns the response entity representation. * * @return The response entity representation. */ public static Representation getResourceResponseEntity() { return getResourceResponse() == null ? null : getResourceResponse().getEntity(); }
/** * Constructor. * * @param clientDispatcher * The client HTTP dispatcher. * @param entryUri * The entry URI. * @throws IOException */ public Entry(Client clientDispatcher, String entryUri) throws IOException { this(clientDispatcher.handle(new Request(Method.GET, entryUri)) .getEntity()); }
@Override protected void afterHandle(Request request, Response response) { if (response.isEntityAvailable() && response.getEntity().getEncodings() .contains(Encoding.FREEMARKER)) { TemplateRepresentation representation = new TemplateRepresentation( response.getEntity(), this.configuration, response .getEntity().getMediaType()); representation.setDataModel(createDataModel(request, response)); response.setEntity(representation); } }
/** * Constructor. * * @param clientDispatcher * The client HTTP dispatcher. * @param feedUri * The feed URI. * @throws IOException */ public Feed(Client clientDispatcher, String feedUri) throws IOException { this(clientDispatcher.handle(new Request(Method.GET, feedUri)) .getEntity()); }
/** * Constructor. * * @param clientDispatcher * The client HTTP dispatcher. * @param entryUri * The entry URI. * @throws IOException */ public Entry(Client clientDispatcher, String entryUri) throws IOException { this(clientDispatcher.handle(new Request(Method.GET, entryUri)) .getEntity()); }
/** * Constructor. * * @param clientDispatcher * The client HTTP dispatcher. * @param feedUri * The feed URI. * @throws IOException */ public Feed(Client clientDispatcher, String feedUri) throws IOException { this(clientDispatcher.handle(new Request(Method.GET, feedUri)) .getEntity()); }
/** * Constructor. * * @param clientDispatcher * The client HTTP dispatcher. * @param categoriesUri * The feed URI. * @throws IOException */ public Categories(Client clientDispatcher, String categoriesUri) throws IOException { this(clientDispatcher.handle(new Request(Method.GET, categoriesUri)) .getEntity()); }
/** * Retrieves a resource representation. * * @param uri * The resource URI. * @return The resource representation. */ public Representation getResource(String uri) { return getClientDispatcher().handle(new Request(Method.GET, uri)) .getEntity(); }
/** * Retrieves a resource representation. * * @param uri * The resource URI. * @return The resource representation. */ public Representation getResource(String uri) { return getClientDispatcher().handle(new Request(Method.GET, uri)) .getEntity(); }
void updateResponse( Response response ) { if( entity != null ) { EntityState state = spi.entityStateOf( entity ); Tag tag = new Tag( state.entityReference().identity() + "/" + state.version() ); response.getEntity().setModificationDate( java.util.Date.from( state.lastModified() ) ); response.getEntity().setTag( tag ); } }
void updateResponse( Response response ) { if( entity != null ) { EntityState state = spi.entityStateOf( entity ); Tag tag = new Tag( state.entityReference().identity() + "/" + state.version() ); response.getEntity().setModificationDate( java.util.Date.from( state.lastModified() ) ); response.getEntity().setTag( tag ); } }
public void updateResponse( Response response ) { if( entity != null ) { EntityState state = spi.entityStateOf( entity ); Date lastModified = new Date( state.lastModified() ); Tag tag = new Tag( state.identity().identity() + "/" + state.version() ); response.getEntity().setModificationDate( lastModified ); response.getEntity().setTag( tag ); } }
@Override public void doError(Status errorStatus) { Representation representation = getResponse().getEntity(); if (representation.getMediaType().equals(MediaType.APPLICATION_JSON)) { // Do not throw an exception here. getLogger().fine("OAuth response is found."); // XXX: after #doError, the representation will disposed in // #handleInbound. return; } // ResourceException will be thrown. super.doError(errorStatus); }
/** * @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)); } }