/** * Set the message entity type information. * <p> * This method overrides any computed or previously set entity type information. * * @param type overriding message entity type. */ public void setEntityType(Type type) { this.entityType = new GenericType(type); }
/** * Set the message entity type information. * <p> * This method overrides any computed or previously set entity type information. * * @param type overriding message entity type. */ public void setEntityType(Type type) { this.entityType = new GenericType(type); }
/** * Read event data as a given Java type. * * @param type Java type to be used for event data de-serialization. * @return event data de-serialized as an instance of a given type. * @throws javax.ws.rs.ProcessingException when provided type can't be read. The thrown exception wraps the original cause. * @since 2.3 */ public <T> T readData(Class<T> type) { return readData(new GenericType<T>(type), null); }
/** * Create a {@link javax.ws.rs.core.GenericType generic type} information for a given * Java {@code instance}. * <p> * If the supplied instance is an instance of {@link javax.ws.rs.core.GenericEntity}, the generic type * information will be computed using the {@link javax.ws.rs.core.GenericEntity#getType()} * information. Otherwise the {@code instance.getClass()} will be used. * </p> * * @param instance Java instance for which the {@code GenericType} description should be created. * @return {@code GenericType} describing the Java {@code instance}. */ public static GenericType genericTypeFor(final Object instance) { final GenericType genericType; if (instance instanceof GenericEntity) { genericType = new GenericType(((GenericEntity) instance).getType()); } else { genericType = (instance == null) ? null : new GenericType(instance.getClass()); } return genericType; }
/** * Create a {@link javax.ws.rs.core.GenericType generic type} information for a given * Java {@code instance}. * <p> * If the supplied instance is an instance of {@link javax.ws.rs.core.GenericEntity}, the generic type * information will be computed using the {@link javax.ws.rs.core.GenericEntity#getType()} * information. Otherwise the {@code instance.getClass()} will be used. * </p> * * @param instance Java instance for which the {@code GenericType} description should be created. * @return {@code GenericType} describing the Java {@code instance}. */ public static GenericType genericTypeFor(final Object instance) { final GenericType genericType; if (instance instanceof GenericEntity) { genericType = new GenericType(((GenericEntity) instance).getType()); } else { genericType = (instance == null) ? null : new GenericType(instance.getClass()); } return genericType; }
/** * Read event data as a given Java type. * * @param messageType Java type to be used for event data de-serialization. * @param mediaType {@link MediaType media type} to be used for event data de-serialization. * @return event data de-serialized as an instance of a given type. * @throws javax.ws.rs.ProcessingException when provided type can't be read. The thrown exception wraps the original cause. * @since 2.3 */ @SuppressWarnings("unused") public <T> T readData(Class<T> messageType, MediaType mediaType) { return readData(new GenericType<T>(messageType), mediaType); }
/** * Set a new message message entity. * * @param entity entity object. * @param type declared entity class. * @param annotations annotations attached to the entity. * @see javax.ws.rs.ext.MessageBodyWriter */ public void setEntity(Object entity, Type type, Annotation[] annotations) { setEntity(entity, new GenericType(type)); setEntityAnnotations(annotations); }
/** * Set a new message message entity. * * @param entity entity object. * @param type declared entity class. * @param annotations annotations attached to the entity. * @see javax.ws.rs.ext.MessageBodyWriter */ public void setEntity(Object entity, Type type, Annotation[] annotations) { setEntity(entity, new GenericType(type)); setEntityAnnotations(annotations); }
/** * Set event data and java type of event data. * * Type information will be used for {@link javax.ws.rs.ext.MessageBodyWriter} lookup. * <p> * Note that multiple invocations of this method result in previous even data being replaced with new one. * </p> * * @param type java type of supplied data. Must not be {@code null}. * @param data event data. Must not be {@code null}. * @return updated builder instance. * @throws NullPointerException in case either {@code type} or {@code data} parameter is {@code null}. */ public Builder data(Class type, Object data) { if (data == null) { throw new NullPointerException(LocalizationMessages.OUT_EVENT_DATA_NULL()); } if (type == null) { throw new NullPointerException(LocalizationMessages.OUT_EVENT_DATA_TYPE_NULL()); } this.type = new GenericType(type); this.data = data; return this; }
/** * @param ar abstract resource * @param am abstract method * @param p parameter * @return parameter * @see org.glassfish.jersey.server.wadl.WadlGenerator#createParam(org.glassfish.jersey.server.model.Resource, * org.glassfish.jersey.server.model.ResourceMethod, org.glassfish.jersey.server.model.Parameter) */ public Param createParam(final org.glassfish.jersey.server.model.Resource ar, final org.glassfish.jersey.server.model.ResourceMethod am, final Parameter p) { final Param param = wadlGeneratorDelegate.createParam(ar, am, p); // If the parameter is an entity we probably want to convert this to XML if (p.getSource() == Parameter.Source.ENTITY) { nameCallbacks.add(new TypeCallbackPair( new GenericType(p.getType()), new NameCallbackSetter() { public void setName(final QName name) { param.setType(name); } })); } return param; }
/** * @param ar abstract resource * @param am abstract method * @param p parameter * @return parameter * @see org.glassfish.jersey.server.wadl.WadlGenerator#createParam(org.glassfish.jersey.server.model.Resource, * org.glassfish.jersey.server.model.ResourceMethod, org.glassfish.jersey.server.model.Parameter) */ public Param createParam(final org.glassfish.jersey.server.model.Resource ar, final org.glassfish.jersey.server.model.ResourceMethod am, final Parameter p) { final Param param = wadlGeneratorDelegate.createParam(ar, am, p); // If the parameter is an entity we probably want to convert this to XML if (p.getSource() == Parameter.Source.ENTITY) { nameCallbacks.add(new TypeCallbackPair( new GenericType(p.getType()), new NameCallbackSetter() { public void setName(final QName name) { param.setType(name); } })); } return param; }
/** * @param resource abstract resource * @param resourceMethod abstract resource method * @return response * @see org.glassfish.jersey.server.wadl.WadlGenerator#createResponses(org.glassfish.jersey.server.model.Resource, * org.glassfish.jersey.server.model.ResourceMethod) */ public List<Response> createResponses(final org.glassfish.jersey.server.model.Resource resource, final org.glassfish.jersey.server.model.ResourceMethod resourceMethod) { final List<Response> responses = wadlGeneratorDelegate.createResponses(resource, resourceMethod); if (responses != null) { for (final Response response : responses) { for (final Representation representation : response.getRepresentation()) { // Process each representation nameCallbacks.add(new TypeCallbackPair( new GenericType(resourceMethod.getInvocable().getResponseType()), new NameCallbackSetter() { public void setName(final QName name) { representation.setElement(name); } })); } } } return responses; }
/** * @param ar abstract resource * @param arm abstract resource method * @param mt media type * @return respresentation type * @see org.glassfish.jersey.server.wadl.WadlGenerator#createRequestRepresentation(org.glassfish.jersey.server.model.Resource, * org.glassfish.jersey.server.model.ResourceMethod, javax.ws.rs.core.MediaType) */ public Representation createRequestRepresentation( final org.glassfish.jersey.server.model.Resource ar, final org.glassfish.jersey.server.model.ResourceMethod arm, final MediaType mt) { final Representation rt = wadlGeneratorDelegate.createRequestRepresentation(ar, arm, mt); for (final Parameter p : arm.getInvocable().getParameters()) { if (p.getSource() == Parameter.Source.ENTITY) { nameCallbacks.add(new TypeCallbackPair( new GenericType(p.getType()), new NameCallbackSetter() { @Override public void setName(final QName name) { rt.setElement(name); } })); } } return rt; }
@Override public void completed(final ClientResponse response, final RequestScope scope) { if (responseFuture.isCancelled()) { response.close(); failed(new ProcessingException( new CancellationException(LocalizationMessages.ERROR_REQUEST_CANCELLED()))); return; } final T result; if (callbackParamClass == Response.class) { result = callbackParamClass.cast(new InboundJaxrsResponse(response, scope)); responseFuture.complete(result); callback.completed(result); } else if (response.getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL) { result = response.readEntity(new GenericType<T>(callbackParamType)); responseFuture.complete(result); callback.completed(result); } else { failed(convertToException(new InboundJaxrsResponse(response, scope))); } }
@Override public void completed(final ClientResponse response, final RequestScope scope) { if (responseFuture.isCancelled()) { response.close(); failed(new ProcessingException( new CancellationException(LocalizationMessages.ERROR_REQUEST_CANCELLED()))); return; } final T result; if (callbackParamClass == Response.class) { result = callbackParamClass.cast(new InboundJaxrsResponse(response, scope)); responseFuture.complete(result); callback.completed(result); } else if (response.getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL) { result = response.readEntity(new GenericType<T>(callbackParamType)); responseFuture.complete(result); callback.completed(result); } else { failed(convertToException(new InboundJaxrsResponse(response, scope))); } }
/** * Write (serialize) the entity set in this request into the {@link #getEntityStream() entity stream}. The method * use {@link javax.ws.rs.ext.WriterInterceptor writer interceptors} and {@link javax.ws.rs.ext.MessageBodyWriter * message body writer}. * <p/> * This method modifies the state of this request and therefore it can be called only once per request life cycle otherwise * IllegalStateException is thrown. * <p/> * Note that {@link #setStreamProvider(org.glassfish.jersey.message.internal.OutboundMessageContext.StreamProvider)} * and optionally {@link #enableBuffering()} must be called before calling this method. * * @throws IOException In the case of IO error. */ public void writeEntity() throws IOException { Preconditions.checkState(!entityWritten, LocalizationMessages.REQUEST_ENTITY_ALREADY_WRITTEN()); entityWritten = true; ensureMediaType(); final GenericType<?> entityType = new GenericType(getEntityType()); doWriteEntity(workers, entityType); }
/** * Write (serialize) the entity set in this request into the {@link #getEntityStream() entity stream}. The method * use {@link javax.ws.rs.ext.WriterInterceptor writer interceptors} and {@link javax.ws.rs.ext.MessageBodyWriter * message body writer}. * <p/> * This method modifies the state of this request and therefore it can be called only once per request life cycle otherwise * IllegalStateException is thrown. * <p/> * Note that {@link #setStreamProvider(org.glassfish.jersey.message.internal.OutboundMessageContext.StreamProvider)} * and optionally {@link #enableBuffering()} must be called before calling this method. * * @throws IOException In the case of IO error. */ public void writeEntity() throws IOException { Preconditions.checkState(!entityWritten, LocalizationMessages.REQUEST_ENTITY_ALREADY_WRITTEN()); entityWritten = true; ensureMediaType(); final GenericType<?> entityType = new GenericType(getEntityType()); doWriteEntity(workers, entityType); }
private void ensureMediaType() { if (getMediaType() == null) { // Content-Type is not present choose a default type final GenericType<?> entityType = new GenericType(getEntityType()); final List<MediaType> mediaTypes = workers.getMessageBodyWriterMediaTypes( entityType.getRawType(), entityType.getType(), getEntityAnnotations()); setMediaType(getMediaType(mediaTypes)); } }
private void ensureMediaType() { if (getMediaType() == null) { // Content-Type is not present choose a default type final GenericType<?> entityType = new GenericType(getEntityType()); final List<MediaType> mediaTypes = workers.getMessageBodyWriterMediaTypes( entityType.getRawType(), entityType.getType(), getEntityAnnotations()); setMediaType(getMediaType(mediaTypes)); } }
private void ensureMediaType() { if (getMediaType() == null) { // Content-Type is not present choose a default type final GenericType<?> entityType = new GenericType(getEntityType()); final List<MediaType> mediaTypes = workers.getMessageBodyWriterMediaTypes( entityType.getRawType(), entityType.getType(), getEntityAnnotations()); setMediaType(getMediaType(mediaTypes)); } }