use of org.apache.axiom.om.OMOutputFormat in project wso2-axis2-transports by wso2.
the class MqttSender method createMqttMessage.
private MqttMessage createMqttMessage(MessageContext messageContext) {
OMOutputFormat format = BaseUtils.getOMOutputFormat(messageContext);
MessageFormatter messageFormatter;
try {
messageFormatter = MessageProcessorSelector.getMessageFormatter(messageContext);
} catch (AxisFault axisFault) {
throw new AxisMqttException("Unable to get the message formatter to use");
}
OutputStream out;
StringWriter sw = new StringWriter();
try {
out = new WriterOutputStream(sw, format.getCharSetEncoding());
} catch (UnsupportedCharsetException ex) {
throw new AxisMqttException("Unsupported encoding " + format.getCharSetEncoding(), ex);
}
try {
messageFormatter.writeTo(messageContext, format, out, true);
out.close();
} catch (IOException e) {
throw new AxisMqttException("IO Error while creating BytesMessage", e);
}
MqttMessage mqttMessage = new MqttMessage();
mqttMessage.setPayload(sw.toString().getBytes());
return mqttMessage;
}
use of org.apache.axiom.om.OMOutputFormat in project wso2-synapse by wso2.
the class XFormURLEncodedFormatterTest method testGetBytes.
public void testGetBytes() throws AxisFault, XMLStreamException {
XFormURLEncodedFormatter formatter = new XFormURLEncodedFormatter();
MessageContext messageContext = Util.newMessageContext("<test><test>123</test></test>");
byte[] bytes = formatter.getBytes(messageContext, new OMOutputFormat());
assertEquals("Invalid X-form URL Encoded string", "test=123", new String(bytes));
}
use of org.apache.axiom.om.OMOutputFormat in project wso2-synapse by wso2.
the class XFormURLEncodedFormatterTest method testGetContentTypeWithSoapAction.
public void testGetContentTypeWithSoapAction() throws AxisFault, XMLStreamException {
XFormURLEncodedFormatter formatter = new XFormURLEncodedFormatter();
MessageContext messageContext = Util.newMessageContext();
String contentType = formatter.getContentType(messageContext, new OMOutputFormat(), "urn:mediate");
assertEquals("Invalid content type", "application/x-www-form-urlencoded;action=\"urn:mediate\";", contentType);
}
use of org.apache.axiom.om.OMOutputFormat in project wso2-synapse by wso2.
the class XFormURLEncodedFormatterTest method testGetContentType.
public void testGetContentType() throws AxisFault, XMLStreamException {
XFormURLEncodedFormatter formatter = new XFormURLEncodedFormatter();
MessageContext messageContext = Util.newMessageContext();
String contentType = formatter.getContentType(messageContext, new OMOutputFormat(), "");
assertEquals("Invalid content type", "application/x-www-form-urlencoded", contentType);
}
use of org.apache.axiom.om.OMOutputFormat in project wso2-synapse by wso2.
the class JsonDataSourceTest method testSerializeXml.
public void testSerializeXml() throws FileNotFoundException, XMLStreamException {
JsonDataSource jsonDataSource = createJsonDatasource();
OutputStream outputStream = Util.newOutputStream();
OMOutputFormat outputFormat = new OMOutputFormat();
outputFormat.setContentType("text/xml");
jsonDataSource.serialize(outputStream, outputFormat);
assertEquals("Invalid serialization", expectedXML, outputStream.toString());
}
Aggregations