Java Code Examples for org.apache.cxf.jaxrs.ext.MessageContext#get()

The following examples show how to use org.apache.cxf.jaxrs.ext.MessageContext#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AttachmentUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static MultipartBody getMultipartBody(MessageContext mc,
    String attachmentDir, String attachmentThreshold, String attachmentMaxSize) {
    if (attachmentDir != null) {
        mc.put(AttachmentDeserializer.ATTACHMENT_DIRECTORY, attachmentDir);
    }
    if (attachmentThreshold != null) {
        mc.put(AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, attachmentThreshold);
    }
    if (attachmentMaxSize != null) {
        mc.put(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, attachmentMaxSize);
    }

    boolean embeddedAttachment = mc.get("org.apache.cxf.multipart.embedded") != null;
    String propertyName = embeddedAttachment ? MultipartBody.INBOUND_MESSAGE_ATTACHMENTS + ".embedded"
        : MultipartBody.INBOUND_MESSAGE_ATTACHMENTS;

    MultipartBody body = (MultipartBody)mc.get(propertyName);
    if (!embeddedAttachment && mc.get(IN_FILTERS) != null) {
        List<MultipartInputFilter> filters = CastUtils.cast((List<?>)mc.get(IN_FILTERS));
        for (MultipartInputFilter filter : filters) {
            filter.filter(body.getAllAttachments());
        }
    }
    return body;
}
 
Example 2
Source File: JAXBElementProvider.java    From cxf with Apache License 2.0 6 votes vote down vote up
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(
                        new RuntimeException("Cant' create XMLStreamWriter", e), null);
                }
            }
        }
        if (writer == null && getEnableStreaming()) {
            writer = StaxUtils.createXMLStreamWriter(os);
        }
    }

    if (writer == null && os == null) {
        writer = getStreamHandlerFromCurrentMessage(XMLStreamWriter.class);
    }
    return createTransformWriterIfNeeded(writer, os, true);
}
 
Example 3
Source File: JSONProvider.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected List<String> getArrayKeys() {
    MessageContext mc = getContext();
    if (mc != null) {
        Object prop = mc.get(ARRAY_KEYS_PROPERTY);
        if (prop instanceof List) {
            return CastUtils.cast((List<?>)prop);
        }
    }
    return arrayKeys;
}
 
Example 4
Source File: JAXBElementProvider.java    From cxf with Apache License 2.0 5 votes vote down vote up
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 ExceptionUtils.toInternalServerErrorException(
                    new RuntimeException("Can not create XMLStreamReader", e), null);
            }
        }
    }

    if (reader == null && is == null) {
        reader = getStreamHandlerFromCurrentMessage(XMLStreamReader.class);
    }

    reader = createTransformReaderIfNeeded(reader, is);
    reader = createDepthReaderIfNeeded(reader, is);
    if (InjectionUtils.isSupportedCollectionOrArray(type)) {
        return new JAXBCollectionWrapperReader(TransformUtils.createNewReaderIfNeeded(reader, is));
    }
    return reader;

}
 
Example 5
Source File: JAXBElementProvider.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected String resolveXMLResourceURI(String path) {
    MessageContext mc = getContext();
    if (mc != null) {
        String httpBasePath = (String)mc.get("http.base.path");
        UriBuilder builder = null;
        if (httpBasePath != null) {
            builder = UriBuilder.fromPath(httpBasePath);
        } else {
            builder = mc.getUriInfo().getBaseUriBuilder();
        }
        return builder.path(path).path(xmlResourceOffset).build().toString();
    }
    return path;
}
 
Example 6
Source File: JAXBElementProvider.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected final void marshal(Object obj, Class<?> cls, Type genericType,
                       String enc, OutputStream os,
                       Annotation[] anns, MediaType mt, Marshaller ms)
    throws Exception {
//CHECKSTYLE:ON
    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 (os == null) {
            ms.setProperty(Marshaller.JAXB_FRAGMENT, true);
        } else 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, anns, mt);
        if (mc != null) {
            writer.writeEndDocument();
        }
    } else {
        marshalToOutputStream(ms, obj, os, anns, mt);
    }
}
 
Example 7
Source File: Utils.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static ExecutorService getExecutorService(MessageContext mc) {
    ExecutorService es = (ExecutorService) mc.get(ExecutorService.class);
    if (es == null) {
        es = AccessController.doPrivileged((PrivilegedAction<ExecutorService>) () -> {
            return ForkJoinPool.commonPool();
        });
    }
    return es;
}
 
Example 8
Source File: JSONProvider.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected List<String> getArrayKeys() {
    MessageContext mc = getContext();
    if (mc != null) {
        Object prop = mc.get(ARRAY_KEYS_PROPERTY);
        if (prop instanceof List) {
            return CastUtils.cast((List<?>)prop);
        }
    }
    return arrayKeys;
}
 
Example 9
Source File: JSONProvider.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected boolean getBooleanJsonProperty(String name, boolean defaultValue) {
    MessageContext mc = getContext();
    if (mc != null) {
        Object prop = mc.get(name);
        if (prop != null) {
            return PropertyUtils.isTrue(prop);
        }
    }
    return defaultValue;
}
 
Example 10
Source File: AttachmentUtils.java    From cxf with Apache License 2.0 4 votes vote down vote up
public static MultipartBody getMultipartBody(MessageContext mc) {
    return (MultipartBody)mc.get(MultipartBody.INBOUND_MESSAGE_ATTACHMENTS);
}
 
Example 11
Source File: ThreadLocalMessageContext.java    From cxf with Apache License 2.0 4 votes vote down vote up
public Object get(Object key) {
    MessageContext mc = getCurrentMessageContext();
    return mc != null ? mc.get(key) : null;
}