Search in sources :

Example 1 with MessageBodyProviderNotFoundException

use of org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException in project jersey by jersey.

the class ParameterValueHelper method getParameterValues.

/**
     * Get the array of parameter values.
     *
     * @param valueProviders a list of value providers.
     * @return array of parameter values provided by the value providers.
     */
public static Object[] getParameterValues(List<ParamValueFactoryWithSource<?>> valueProviders) {
    final Object[] params = new Object[valueProviders.size()];
    try {
        int entityProviderIndex = -1;
        int index = 0;
        for (ParamValueFactoryWithSource<?> paramValProvider : valueProviders) {
            // entity provider has to be called last; see JERSEY-2642
            if (paramValProvider.getSource().equals(Parameter.Source.ENTITY)) {
                entityProviderIndex = index++;
                continue;
            }
            params[index++] = paramValProvider.get();
        }
        if (entityProviderIndex != -1) {
            params[entityProviderIndex] = valueProviders.get(entityProviderIndex).get();
        }
        return params;
    } catch (WebApplicationException e) {
        throw e;
    } catch (MessageBodyProviderNotFoundException e) {
        throw new NotSupportedException(e);
    } catch (ProcessingException e) {
        throw e;
    } catch (RuntimeException e) {
        if (e.getCause() instanceof WebApplicationException) {
            throw (WebApplicationException) e.getCause();
        }
        throw new MappableException("Exception obtaining parameters", e);
    }
}
Also used : MappableException(org.glassfish.jersey.server.internal.process.MappableException) WebApplicationException(javax.ws.rs.WebApplicationException) MessageBodyProviderNotFoundException(org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException) NotSupportedException(javax.ws.rs.NotSupportedException) ProcessingException(javax.ws.rs.ProcessingException)

Example 2 with MessageBodyProviderNotFoundException

use of org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException in project jersey by jersey.

the class InboundEvent method readData.

/**
     * Read event data as a given generic type.
     *
     * @param type      generic 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
     */
public <T> T readData(GenericType<T> type, MediaType mediaType) {
    final MediaType effectiveMediaType = mediaType == null ? this.mediaType : mediaType;
    final MessageBodyReader reader = messageBodyWorkers.getMessageBodyReader(type.getRawType(), type.getType(), annotations, mediaType);
    if (reader == null) {
        throw new MessageBodyProviderNotFoundException(LocalizationMessages.EVENT_DATA_READER_NOT_FOUND());
    }
    return readAndCast(type, effectiveMediaType, reader);
}
Also used : MessageBodyReader(javax.ws.rs.ext.MessageBodyReader) MessageBodyProviderNotFoundException(org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException) MediaType(javax.ws.rs.core.MediaType)

Aggregations

MessageBodyProviderNotFoundException (org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException)2 NotSupportedException (javax.ws.rs.NotSupportedException)1 ProcessingException (javax.ws.rs.ProcessingException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 MediaType (javax.ws.rs.core.MediaType)1 MessageBodyReader (javax.ws.rs.ext.MessageBodyReader)1 MappableException (org.glassfish.jersey.server.internal.process.MappableException)1