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;
}
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);
}
}
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);
}
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);
}
}
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());
}
}
}
Aggregations