use of org.apache.axis2.builder.SOAPBuilder in project wso2-axis2-transports by wso2.
the class MSMQUtil method setSOAPEnvelope.
public static void setSOAPEnvelope(Message message, MessageContext msgContext, String contentType) throws AxisFault {
if (contentType == null) {
// TODO;we only support text/plain
contentType = "text/plain";
if (log.isDebugEnabled()) {
log.debug("No content type specified; assuming " + contentType);
}
}
int index = contentType.indexOf(';');
String type = index > 0 ? contentType.substring(0, index) : contentType;
Builder builder = BuilderUtil.getBuilderFromSelector(type, msgContext);
String messageBody = null;
try {
messageBody = message.getBodyAsString();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (builder == null) {
if (log.isDebugEnabled()) {
log.debug("No message builder found for type' " + type + ".Using SOAP builder");
}
builder = new SOAPBuilder();
}
OMElement documentElement;
// TODO: we need to handle the message types separately. Assume text message builder format
TextMessageBuilder textMessageBuilder;
if (builder instanceof TextMessageBuilder) {
textMessageBuilder = (TextMessageBuilder) builder;
} else {
textMessageBuilder = new TextMessageBuilderAdapter(builder);
}
documentElement = textMessageBuilder.processDocument(messageBody, contentType, msgContext);
msgContext.setEnvelope(TransportUtils.createSOAPEnvelope(documentElement));
}
use of org.apache.axis2.builder.SOAPBuilder in project wso2-axis2-transports by wso2.
the class RabbitMQUtils method setSOAPEnvelope.
public static void setSOAPEnvelope(RabbitMQMessage message, MessageContext msgContext, String contentType) throws AxisFault {
int index = contentType.indexOf(';');
String type = index > 0 ? contentType.substring(0, index) : contentType;
Builder builder = BuilderUtil.getBuilderFromSelector(type, msgContext);
if (builder == null) {
if (log.isDebugEnabled()) {
log.debug("No message builder found for type '" + type + "'. Falling back to SOAP.");
}
builder = new SOAPBuilder();
}
OMElement documentElement;
String charSetEnc = null;
try {
if (contentType != null) {
charSetEnc = new ContentType(contentType).getParameter("charset");
}
} catch (ParseException ex) {
log.debug("Parse error", ex);
}
msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);
documentElement = builder.processDocument(new ByteArrayInputStream(message.getBody()), contentType, msgContext);
msgContext.setEnvelope(TransportUtils.createSOAPEnvelope(documentElement));
}
Aggregations