Package javax.ws.rs.ext

Examples of javax.ws.rs.ext.MessageBodyWriter


                entityStream.write(EOL);
            }

            final MediaType eventMediaType =
                    outboundEvent.getMediaType() == null ? MediaType.TEXT_PLAIN_TYPE : outboundEvent.getMediaType();
            final MessageBodyWriter messageBodyWriter = workersProvider.get().getMessageBodyWriter(outboundEvent.getType(),
                    outboundEvent.getGenericType(), annotations, eventMediaType);
            messageBodyWriter.writeTo(
                    outboundEvent.getData(),
                    outboundEvent.getType(),
                    outboundEvent.getGenericType(),
                    annotations,
                    eventMediaType,
View Full Code Here


            if (bodyEntity instanceof BodyPartEntity) {
                bodyClass = InputStream.class;
                bodyEntity = ((BodyPartEntity) bodyEntity).getInputStream();
            }

            final MessageBodyWriter bodyWriter = providers.getMessageBodyWriter(
                    bodyClass,
                    bodyClass,
                    EMPTY_ANNOTATIONS,
                    bodyMediaType);

            if (bodyWriter == null) {
                throw new IllegalArgumentException(LocalizationMessages.NO_AVAILABLE_MBW(bodyClass, mediaType));
            }

            bodyWriter.writeTo(
                    bodyEntity,
                    bodyClass,
                    bodyClass,
                    EMPTY_ANNOTATIONS,
                    bodyMediaType,
View Full Code Here

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

                final MessageBodyWriter writer = workers.getMessageBodyWriter(context.getType(), context.getGenericType(),
                        context.getAnnotations(), context.getMediaType(), WriterInterceptorExecutor.this);

                if (writer == null) {
                    LOGGER.log(Level.SEVERE, LocalizationMessages.ERROR_NOTFOUND_MESSAGEBODYWRITER(
                            context.getMediaType(), context.getType(), context.getGenericType()));
View Full Code Here

        final TracingLogger tracingLogger = TracingLogger.getInstance(propertiesDelegate);
        MessageBodyWriter<T> selected = null;
        final Iterator<MessageBodyWriter> iterator = writers.iterator();
        while (iterator.hasNext()) {
            final MessageBodyWriter p = iterator.next();
            if (MbwModel.isWriteable(p, c, t, as, mediaType)) {
                selected = (MessageBodyWriter<T>) p;
                tracingLogger.log(MsgTraceEvent.MBW_SELECTED, selected);
                break;
            }
            tracingLogger.log(MsgTraceEvent.MBW_NOT_WRITEABLE, p);
        }

        if (tracingLogger.isLogEnabled(MsgTraceEvent.MBW_SKIPPED)) {
            while (iterator.hasNext()) {
                final MessageBodyWriter p = iterator.next();
                tracingLogger.log(MsgTraceEvent.MBW_SKIPPED, p);
            }
        }
        return selected;
    }
View Full Code Here

        final Class entityClass = entity.getClass();

        ByteArrayOutputStream out = new ByteArrayOutputStream();


        MessageBodyWriter writer = messageBodyWorkers.getMessageBodyWriter(entityClass,
                entityType, EMPTY_ANNOTATIONS, MediaType.APPLICATION_FORM_URLENCODED_TYPE);

        try {
            writer.writeTo(entity, entityClass, entityType,
                    EMPTY_ANNOTATIONS, MediaType.APPLICATION_FORM_URLENCODED_TYPE, null, out);
        } catch (WebApplicationException wae) {
            throw new IllegalStateException(wae);
        } catch (IOException ioe) {
            throw new IllegalStateException(ioe);
View Full Code Here

            List<MediaType> availableContentTypes =
                computeAvailableContentTypes(message, response)
           
            Method invoked = operation == null ? null : operation.getMethodToInvoke();
           
            MessageBodyWriter writer = null;
            MediaType responseType = null;
            for (MediaType type : availableContentTypes) {
                writer = ProviderFactory.getInstance()
                    .createMessageBodyWriter(targetType,
                          invoked != null ? invoked.getGenericReturnType() : null,
                          invoked != null ? invoked.getAnnotations() : new Annotation[]{},
                          type,
                          exchange.getInMessage());
               
                if (writer != null) {
                    responseType = type;
                    break;
                }
            }
       
            OutputStream out = message.getContent(OutputStream.class);
            if (writer == null) {
                message.put(Message.RESPONSE_CODE, 406);
                writeResponseErrorMessage(out,
                      "NO_MSG_WRITER",
                      invoked != null ? invoked.getReturnType().getSimpleName() : "");
                return;
            }
           
            try {
               
                responseType = checkFinalContentType(responseType);
                LOG.fine("Response content type is: " + responseType.toString());
                message.put(Message.CONTENT_TYPE, responseType.toString());
               
                LOG.fine("Response EntityProvider is: " + writer.getClass().getName());
                writer.writeTo(responseObj, targetType, invoked.getGenericReturnType(),
                               invoked != null ? invoked.getAnnotations() : new Annotation[]{},
                               responseType,
                               response.getMetadata(),
                               out);
               
View Full Code Here

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

   
    @Test
    public void testGetBinaryProvider() throws Exception {
        verifyProvider(byte[].class, BinaryDataProvider.class, "*/*");
        verifyProvider(InputStream.class, BinaryDataProvider.class, "image/png");
        MessageBodyWriter writer = ProviderFactory.getInstance()
            .createMessageBodyWriter(File.class, null, null, JAXRSUtils.ALL_TYPES, null);
        assertTrue(BinaryDataProvider.class == writer.getClass());
    }
View Full Code Here

       
        MessageBodyReader reader = ProviderFactory.getInstance()
            .createMessageBodyReader(type, null, null, mType, null);
        assertSame(errorMessage, provider, reader.getClass());
   
        MessageBodyWriter writer = ProviderFactory.getInstance()
            .createMessageBodyWriter(type, null, null, mType, null);
        assertTrue(errorMessage, provider == writer.getClass());
    }
View Full Code Here

     * @throws IOException
     */
    protected void writeBody(OutputStream os, Providers providers) throws IOException {

        if (getBody() != null) {
            MessageBodyWriter writer =
                providers.getMessageBodyWriter(getBody().getClass(), null, null, MediaType
                    .valueOf(getContentType()));
            if (writer == null) {
                logger
                    .warn("Could not find a writer for {} and {}. Try to find JAF DataSourceProvider",
                          getBody().getClass(),
                          getContentType());
                throw new WebApplicationException(500);
            }
            writer.writeTo(getBody(), getBody().getClass(), null, null, MediaType
                .valueOf(getContentType()), getHeaders(), os);
        }
    }
View Full Code Here

TOP

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

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.