Package javax.ws.rs.ext

Examples of javax.ws.rs.ext.MessageBodyReader


    private <T> MessageBodyReader<T> _getMessageBodyReader(Class<T> c, Type t,
            Annotation[] as,
            MediaType mediaType,
            Map<MediaType, List<MessageBodyReader>> providers) {
        MessageBodyReader p = null;
        if (mediaType != null) {
            p = _getMessageBodyReader(c, t, as, mediaType, mediaType, providers);
            if (p == null)
                p = _getMessageBodyReader(c, t, as, mediaType,
                        MediaTypes.getTypeWildCart(mediaType), providers);
View Full Code Here


   
    private <T> MessageBodyReader<T> _getMessageBodyReader(Class<T> c, Type t,
            Annotation[] as,
            MediaType mediaType, MediaType lookup) {

        MessageBodyReader reader;

        if(!customReaderProviders.isEmpty()) {
            reader = _getMessageBodyReader(c, t, as, mediaType, lookup, customReaderProviders);
            if(reader != null)
                return reader;
View Full Code Here

        final ParameterizedType pt = (ParameterizedType)genericType;
        final Type t = pt.getActualTypeArguments()[0];
        final Class entityClass = (t instanceof Class) ? (Class)t : (Class)((ParameterizedType)t).getRawType();
        final Type entityGenericType = (t instanceof Class) ? entityClass : t;

        MessageBodyReader br = bodyWorker.getMessageBodyReader(entityClass, entityGenericType, annotations, mediaType);
        if (br == null) {
            LOGGER.severe("A message body reader for the type, " + type + ", could not be found");
            throw new WebApplicationException();
        }
        Object o = br.readFrom(entityClass, entityGenericType, annotations, mediaType, httpHeaders, entityStream);
        return new EntityHolder(o);
    }
View Full Code Here

            FormDataBodyPart fdbp = (fdbps != null) ? fdbps.get(0) : null;

            MediaType mediaType = (fdbp != null)
                    ? fdbp.getMediaType() : MediaType.TEXT_PLAIN_TYPE;

            MessageBodyReader reader = mbws.getMessageBodyReader(
                    param.getParameterClass(),
                    param.getParameterType(),
                    param.getAnnotations(),
                    mediaType);
          
            if (reader != null) {
                InputStream in = null;
                if (fdbp == null) {
                    if (param.getDefaultValue() != null) {
                        // Convert default value to bytes
                        in = new ByteArrayInputStream(param.getDefaultValue().getBytes());
                    } else {
                        return null;
                    }
                } else {
                    in = ((BodyPartEntity) fdbp.getEntity()).getInputStream();
                }

                try {
                    return reader.readFrom(
                            param.getParameterClass(),
                            param.getParameterType(),
                            param.getAnnotations(),
                            mediaType,
                            context.getRequest().getRequestHeaders(),
                            in);
                } catch (IOException e) {
                    throw new ContainerException(e);
                }
            } else if (extractor != null) {
                MultivaluedMap<String, String> map = new MultivaluedMapImpl();
                if (fdbp != null) {
                    try {
                        for (FormDataBodyPart p : fdbps) {
                            mediaType = p.getMediaType();

                            reader = mbws.getMessageBodyReader(
                                    String.class,
                                    String.class,
                                    param.getAnnotations(),
                                    mediaType);

                            String value = (String) reader.readFrom(
                                    String.class,
                                    String.class,
                                    param.getAnnotations(),
                                    mediaType,
                                    context.getRequest().getRequestHeaders(),
View Full Code Here

     *          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 IllegalStateException(LocalizationMessages.EVENT_DATA_READER_NOT_FOUND());
        }
        return readAndCast(type, effectiveMediaType, reader);
View Full Code Here

            MediaType mediaType = (formDataBodyPart != null) ? formDataBodyPart.getMediaType() : MediaType.TEXT_PLAIN_TYPE;

            MessageBodyWorkers messageBodyWorkers = request.getWorkers();

            MessageBodyReader reader = messageBodyWorkers.getMessageBodyReader(
                    parameter.getRawType(),
                    parameter.getType(),
                    parameter.getAnnotations(),
                    mediaType);

            if (reader != null && !isPrimitiveType(parameter.getRawType())) {
                InputStream in;
                if (formDataBodyPart == null) {
                    if (parameter.getDefaultValue() != null) {
                        // Convert default value to bytes.
                        in = new ByteArrayInputStream(parameter.getDefaultValue().getBytes());
                    } else {
                        return null;
                    }
                } else {
                    in = ((BodyPartEntity) formDataBodyPart.getEntity()).getInputStream();
                }


                try {
                    //noinspection unchecked
                    return reader.readFrom(
                            parameter.getRawType(),
                            parameter.getType(),
                            parameter.getAnnotations(),
                            mediaType,
                            request.getHeaders(),
                            in);
                } catch (IOException e) {
                    throw new FormDataParamException(e, extractor.getName(), extractor.getDefaultValueString());
                }
            } else if (extractor != null) {
                MultivaluedMap<String, String> map = new MultivaluedStringMap();
                try {
                    if (formDataBodyPart != null) {
                        for (FormDataBodyPart p : formDataBodyParts) {
                            mediaType = p.getMediaType();

                            reader = messageBodyWorkers.getMessageBodyReader(
                                    String.class,
                                    String.class,
                                    parameter.getAnnotations(),
                                    mediaType);

                            @SuppressWarnings("unchecked") String value = (String) reader.readFrom(
                                    String.class,
                                    String.class,
                                    parameter.getAnnotations(),
                                    mediaType,
                                    request.getHeaders(),
View Full Code Here

        final TracingLogger tracingLogger = TracingLogger.getInstance(propertiesDelegate);
        MessageBodyReader<T> selected = null;
        final Iterator<MessageBodyReader> iterator = readers.iterator();
        while (iterator.hasNext()) {
            final MessageBodyReader p = iterator.next();
            if (MbrModel.isReadable(p, c, t, as, mediaType)) {
                selected = (MessageBodyReader<T>) p;
                tracingLogger.log(MsgTraceEvent.MBR_SELECTED, selected);
                break;
            }
            tracingLogger.log(MsgTraceEvent.MBR_NOT_READABLE, p);
        }

        if (tracingLogger.isLogEnabled(MsgTraceEvent.MBR_SKIPPED)) {
            while (iterator.hasNext()) {
                final MessageBodyReader p = iterator.next();
                tracingLogger.log(MsgTraceEvent.MBR_SKIPPED, p);
            }
        }

        return selected;
View Full Code Here

            throw new IllegalStateException(ioe);
        }

        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());

        MessageBodyReader reader = messageBodyWorkers.getMessageBodyReader(MultivaluedMap.class,
                MultivaluedMap.class, EMPTY_ANNOTATIONS, MediaType.APPLICATION_FORM_URLENCODED_TYPE);

        try {
            return (MultivaluedMap<String, String>) reader.readFrom(MultivaluedMap.class,
                    MultivaluedMap.class, EMPTY_ANNOTATIONS, MediaType.APPLICATION_FORM_URLENCODED_TYPE, null, in);
        } catch (IOException ioe) {
            throw new IllegalStateException(ioe);
        }
    }
View Full Code Here

                            (context.getGenericType() instanceof Class ?
                                    ((Class) context.getGenericType()).getName() : context.getGenericType()),
                            String.valueOf(context.getMediaType()), java.util.Arrays.toString(context.getAnnotations()));
                }

                final MessageBodyReader bodyReader = workers.getMessageBodyReader(
                        context.getType(),
                        context.getGenericType(),
                        context.getAnnotations(),
                        context.getMediaType(),
                        ReaderInterceptorExecutor.this);
View Full Code Here

    private static class MessageBodyReaderComparator
        implements Comparator<ProviderInfo<MessageBodyReader>> {
       
        public int compare(ProviderInfo<MessageBodyReader> p1,
                           ProviderInfo<MessageBodyReader> p2) {
            MessageBodyReader e1 = p1.getProvider();
            MessageBodyReader e2 = p2.getProvider();
           
            ConsumeMime c = e1.getClass().getAnnotation(ConsumeMime.class);
            String[] mimeType1 = {"*/*"};
            if (c != null) {
                mimeType1 = c.value();              
            }
           
            ConsumeMime c2 = e2.getClass().getAnnotation(ConsumeMime.class);
            String[] mimeType2 = {"*/*"};
            if (c2 != null) {
                mimeType2 = c2.value();              
            }
   
View Full Code Here

TOP

Related Classes of javax.ws.rs.ext.MessageBodyReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.