Package org.apache.cxf.jaxrs.ext

Examples of org.apache.cxf.jaxrs.ext.MessageContext


        }
    }
   
    protected XMLStreamWriter getStreamWriter(Object obj, OutputStream os, MediaType mt) {
        XMLStreamWriter writer = null;
        MessageContext mc = getContext();
        if (mc != null) {
            writer = mc.getContent(XMLStreamWriter.class);
            if (writer == null) {
                XMLOutputFactory factory = (XMLOutputFactory)mc.get(XMLOutputFactory.class.getName());
                if (factory != null) {
                    try {
                        writer = factory.createXMLStreamWriter(os);
                    } catch (XMLStreamException e) {
                        throw ExceptionUtils.toInternalServerErrorException(
View Full Code Here


                                           Class<?> pClass, Type genericType,
                                           Annotation[] paramAnns,
                                           String defaultValue,
                                           boolean decode) {
       
        MessageContext mc = new MessageContextImpl(m);
        MediaType mt = mc.getHttpHeaders().getMediaType();
       
        @SuppressWarnings("unchecked")
        MultivaluedMap<String, String> params =
            (MultivaluedMap<String, String>)m.get(FormUtils.FORM_PARAM_MAP);
       
View Full Code Here

            out.close();
        }
    }
   
    protected XMLStreamReader getReaderFromMessage() {
        MessageContext mc = getContext();
        if (mc != null) {
            return mc.getContent(XMLStreamReader.class);
        } else {
            return null;
        }
    }
View Full Code Here

                        MediaType mt) {
        return -1;
    }
   
    protected String getPreferredSource() {
        MessageContext mc = getContext();
        String source = null;
        if (mc != null) {
            source = (String)mc.getContextualProperty(PREFERRED_FORMAT);
        }
        return source != null ? source : "sax";
       
    }
View Full Code Here

        MessageBodyReader<Book> customJaxbReader = pf.createMessageBodyReader(Book.class, null, null,
                                                              MediaType.TEXT_XML_TYPE, message);
        assertTrue(customJaxbReader instanceof JAXBElementProvider);
       
        JAXBElementProvider<Book> provider = (JAXBElementProvider<Book>)customJaxbReader;
        MessageContext mc = provider.getContext();
        assertNotNull(mc);
        UriInfo ui = mc.getUriInfo();
        MultivaluedMap<String, String> queries = ui.getQueryParameters();
        assertEquals(1, queries.size());
        List<String> uriQuery = queries.get("uri");
        assertEquals(1, uriQuery.size());
        assertEquals(property, uriQuery.get(0));
View Full Code Here

    private static Object processFormParam(Message m, String key,
                                           Class<?> pClass, Type genericType,
                                           String defaultValue,
                                           boolean decode) {
       
        MessageContext mc = new MessageContextImpl(m);
        MediaType mt = mc.getHttpHeaders().getMediaType();
       
        @SuppressWarnings("unchecked")
        MultivaluedMap<String, String> params = (MultivaluedMap<String, String>)m.get(FORM_PARAM_MAP);
       
        if (params == null) {
View Full Code Here

            LOG.severe("No template is available");
            throw new WebApplicationException(500);
        }
       
        TemplatesImpl templ =  new TemplatesImpl(templates);
        MessageContext mc = getContext();
        if (mc != null) {
            UriInfo ui = mc.getUriInfo();
            MultivaluedMap<String, String> params = ui.getPathParameters();
            for (Map.Entry<String, List<String>> entry : params.entrySet()) {
                String value = entry.getValue().get(0);
                int ind = value.indexOf(";");
                if (ind > 0) {
View Full Code Here

        }
        return unmarshalFromInputStream(unmarshaller, is, mt);
    }
   
    protected XMLStreamReader getStreamReader(InputStream is, Class<?> type, MediaType mt) {
        MessageContext mc = getContext();
        XMLStreamReader reader = mc != null ? mc.getContent(XMLStreamReader.class) : null;
        if (reader == null && mc != null) {
            XMLInputFactory factory = (XMLInputFactory)mc.get(XMLInputFactory.class.getName());
            if (factory != null) {
                try {
                    reader = factory.createXMLStreamReader(is);
                } catch (XMLStreamException e) {
                    throw new WebApplicationException(
View Full Code Here

                attachments));
        }
    }
   
    private Collection<Attachment> getAttachments() {
        MessageContext mc = getContext();
        if (mc != null) {
            return CastUtils.cast((Collection<?>)mc.get(Message.ATTACHMENTS));
        } else {
            return null;
        }
    }
View Full Code Here

        throws Exception {
       
        for (Map.Entry<String, Object> entry : mProperties.entrySet()) {
            ms.setProperty(entry.getKey(), entry.getValue());
        }
        MessageContext mc = getContext();
        if (mc != null) {
            // check Marshaller properties which might've been set earlier on,
            // they'll overwrite statically configured ones
            for (String key : MARSHALLER_PROPERTIES) {
                Object value = mc.get(key);
                if (value != null) {
                    ms.setProperty(key, value);
                }
            }
           
        }
        XMLStreamWriter writer = getStreamWriter(obj, os, mt);
        if (writer != null) {
            if (mc != null) {
                if (mc.getContent(XMLStreamWriter.class) != null) {
                    ms.setProperty(Marshaller.JAXB_FRAGMENT, true);
                }
                mc.put(XMLStreamWriter.class.getName(), writer);
            }   
            marshalToWriter(ms, obj, writer, mt);
            if (mc != null && mc.getContent(XMLStreamWriter.class) != null) {
                writer.writeEndDocument();
                writer.flush();
                writer.close();
            }
        } else {
View Full Code Here

TOP

Related Classes of org.apache.cxf.jaxrs.ext.MessageContext

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.