Search in sources :

Example 51 with OMOutputFormat

use of org.apache.axiom.om.OMOutputFormat in project wso2-axis2-transports by wso2.

the class BaseUtils method getOMOutputFormat.

/**
 * Get the OMOutput format for the given message
 * @param msgContext the axis message context
 * @return the OMOutput format to be used
 */
public static OMOutputFormat getOMOutputFormat(MessageContext msgContext) {
    OMOutputFormat format = new OMOutputFormat();
    msgContext.setDoingMTOM(TransportUtils.doWriteMTOM(msgContext));
    msgContext.setDoingSwA(TransportUtils.doWriteSwA(msgContext));
    msgContext.setDoingREST(TransportUtils.isDoingREST(msgContext));
    format.setSOAP11(msgContext.isSOAP11());
    format.setDoOptimize(msgContext.isDoingMTOM());
    format.setDoingSWA(msgContext.isDoingSwA());
    format.setCharSetEncoding(TransportUtils.getCharSetEncoding(msgContext));
    Object mimeBoundaryProperty = msgContext.getProperty(Constants.Configuration.MIME_BOUNDARY);
    if (mimeBoundaryProperty != null) {
        format.setMimeBoundary((String) mimeBoundaryProperty);
    }
    return format;
}
Also used : OMOutputFormat(org.apache.axiom.om.OMOutputFormat)

Example 52 with OMOutputFormat

use of org.apache.axiom.om.OMOutputFormat in project webservices-axiom by apache.

the class OMDataSourceExtBase method serialize.

@Override
public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
    if (log.isDebugEnabled()) {
        log.debug("serialize xmlWriter=" + xmlWriter);
    }
    // Some XMLStreamWriters (e.g. MTOMXMLStreamWriter)
    // provide direct access to the OutputStream.
    // This allows faster writing.
    OutputStream os = getOutputStream(xmlWriter);
    if (os != null) {
        if (log.isDebugEnabled()) {
            log.debug("serialize OutputStream optimisation: true");
        }
        String encoding = getCharacterEncoding(xmlWriter);
        OMOutputFormat format = new OMOutputFormat();
        format.setCharSetEncoding(encoding);
        serialize(os, format);
    } else {
        if (log.isDebugEnabled()) {
            log.debug("serialize OutputStream optimisation: false");
        }
        // Read the bytes into a reader and
        // write to the writer.
        XMLStreamReader xmlReader = getReader();
        reader2writer(xmlReader, xmlWriter);
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) OutputStream(java.io.OutputStream) OMOutputFormat(org.apache.axiom.om.OMOutputFormat)

Example 53 with OMOutputFormat

use of org.apache.axiom.om.OMOutputFormat in project wso2-synapse by wso2.

the class XFormURLEncodedFormatterTest method testGetContentTypeWithCharsetEncoding.

public void testGetContentTypeWithCharsetEncoding() throws AxisFault {
    OMOutputFormat format = new OMOutputFormat();
    format.setCharSetEncoding("UTF-8");
    XFormURLEncodedFormatter formatter = new XFormURLEncodedFormatter();
    MessageContext messageContext = Util.newMessageContext();
    String contentType = formatter.getContentType(messageContext, format, "");
    assertEquals("Invalid content type", "application/x-www-form-urlencoded; charset=UTF-8", contentType);
}
Also used : MessageContext(org.apache.axis2.context.MessageContext) OMOutputFormat(org.apache.axiom.om.OMOutputFormat)

Example 54 with OMOutputFormat

use of org.apache.axiom.om.OMOutputFormat in project wso2-synapse by wso2.

the class HttpCoreNIOSender method sendUsingOutputStream.

private void sendUsingOutputStream(MessageContext msgContext) throws AxisFault {
    OMOutputFormat format = NhttpUtil.getOMOutputFormat(msgContext);
    MessageFormatter messageFormatter = MessageFormatterDecoratorFactory.createMessageFormatterDecorator(msgContext);
    OutputStream out = (OutputStream) msgContext.getProperty(MessageContext.TRANSPORT_OUT);
    if (msgContext.isServerSide()) {
        OutTransportInfo transportInfo = (OutTransportInfo) msgContext.getProperty(Constants.OUT_TRANSPORT_INFO);
        if (transportInfo != null) {
            transportInfo.setContentType(messageFormatter.getContentType(msgContext, format, msgContext.getSoapAction()));
        } else {
            throw new AxisFault(Constants.OUT_TRANSPORT_INFO + " has not been set");
        }
    }
    try {
        messageFormatter.writeTo(msgContext, format, out, false);
        out.close();
    } catch (IOException e) {
        handleException("IO Error sending response message", e);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) OutTransportInfo(org.apache.axis2.transport.OutTransportInfo) OutputStream(java.io.OutputStream) MessageFormatter(org.apache.axis2.transport.MessageFormatter) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) OMOutputFormat(org.apache.axiom.om.OMOutputFormat)

Example 55 with OMOutputFormat

use of org.apache.axiom.om.OMOutputFormat in project wso2-synapse by wso2.

the class TargetRequestHandler method getContentType.

public static String getContentType(MessageContext msgCtx, boolean isContentTypePreservedHeader, Map trpHeaders) throws AxisFault {
    String setEncoding = (String) msgCtx.getProperty(PassThroughConstants.SET_CHARACTER_ENCODING);
    // Need to avoid this for multipart headers, need to add MIME Boundary property
    if (trpHeaders != null && (trpHeaders).get(HTTPConstants.HEADER_CONTENT_TYPE) != null && (isContentTypePreservedHeader || PassThroughConstants.VALUE_FALSE.equals(setEncoding)) && !RequestResponseUtils.isMultipartContent((trpHeaders).get(HTTPConstants.HEADER_CONTENT_TYPE).toString())) {
        if (msgCtx.getProperty(org.apache.axis2.Constants.Configuration.CONTENT_TYPE) != null) {
            return (String) msgCtx.getProperty(org.apache.axis2.Constants.Configuration.CONTENT_TYPE);
        } else if (msgCtx.getProperty(org.apache.axis2.Constants.Configuration.MESSAGE_TYPE) != null) {
            return (String) msgCtx.getProperty(org.apache.axis2.Constants.Configuration.MESSAGE_TYPE);
        }
    }
    MessageFormatter formatter = MessageProcessorSelector.getMessageFormatter(msgCtx);
    OMOutputFormat format = PassThroughTransportUtils.getOMOutputFormat(msgCtx);
    if (formatter != null) {
        return formatter.getContentType(msgCtx, format, msgCtx.getSoapAction());
    } else {
        String contentType = (String) msgCtx.getProperty(org.apache.axis2.Constants.Configuration.CONTENT_TYPE);
        if (contentType != null) {
            return contentType;
        } else {
            return new SOAPMessageFormatter().getContentType(msgCtx, format, msgCtx.getSoapAction());
        }
    }
}
Also used : SOAPMessageFormatter(org.apache.axis2.transport.http.SOAPMessageFormatter) MessageFormatter(org.apache.axis2.transport.MessageFormatter) SOAPMessageFormatter(org.apache.axis2.transport.http.SOAPMessageFormatter) OMOutputFormat(org.apache.axiom.om.OMOutputFormat)

Aggregations

OMOutputFormat (org.apache.axiom.om.OMOutputFormat)64 MessageFormatter (org.apache.axis2.transport.MessageFormatter)24 ByteArrayOutputStream (java.io.ByteArrayOutputStream)21 OutputStream (java.io.OutputStream)18 IOException (java.io.IOException)16 AxisFault (org.apache.axis2.AxisFault)13 MessageContext (org.apache.axis2.context.MessageContext)12 OMElement (org.apache.axiom.om.OMElement)11 DataHandler (javax.activation.DataHandler)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStream (java.io.InputStream)6 StringWriter (java.io.StringWriter)6 XMLStreamException (javax.xml.stream.XMLStreamException)6 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)6 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)5 OMText (org.apache.axiom.om.OMText)5 Map (java.util.Map)4 MultipartBody (org.apache.axiom.mime.MultipartBody)4 SOAPFactory (org.apache.axiom.soap.SOAPFactory)4 Collection (java.util.Collection)3