use of org.apache.axis2.context.MessageContext in project wso2-axis2-transports by wso2.
the class PlainTextFormatterTest method createMessageContext.
private MessageContext createMessageContext(String textPayload) throws AxisFault {
MessageContext messageContext = new MessageContext();
SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope envelope = factory.getDefaultEnvelope();
OMElement textWrapper = factory.createOMElement(BaseConstants.DEFAULT_TEXT_WRAPPER);
textWrapper.setText(textPayload);
envelope.getBody().addChild(textWrapper);
messageContext.setEnvelope(envelope);
return messageContext;
}
use of org.apache.axis2.context.MessageContext in project wso2-axis2-transports by wso2.
the class PlainTextFormatterTest method testWriteTo.
private void testWriteTo(String encoding) throws Exception {
MessageContext messageContext = createMessageContext(testString);
OMOutputFormat format = new OMOutputFormat();
format.setCharSetEncoding(encoding);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new PlainTextFormatter().writeTo(messageContext, format, baos, false);
assertEquals(testString, new String(baos.toByteArray(), encoding));
}
use of org.apache.axis2.context.MessageContext in project wso2-axis2-transports by wso2.
the class PlainTextFormatterTest method createElementMessageContextElement.
private MessageContext createElementMessageContextElement(String textPayload) throws AxisFault {
try {
MessageContext messageContext = new MessageContext();
SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope envelope = factory.getDefaultEnvelope();
OMElement textWrapper = factory.createOMElement(BaseConstants.DEFAULT_TEXT_WRAPPER);
OMElement payload = AXIOMUtil.stringToOM(textPayload);
textWrapper.addChild(payload);
envelope.getBody().addChild(textWrapper);
messageContext.setEnvelope(envelope);
return messageContext;
} catch (XMLStreamException e) {
// This is highly unlikely to happen
return null;
}
}
use of org.apache.axis2.context.MessageContext in project wso2-axis2-transports by wso2.
the class PlainTextFormatterTest method testElementGetBytes.
private void testElementGetBytes(String encoding) throws Exception {
MessageContext messageContext = createElementMessageContextElement(testElementString);
if (messageContext != null) {
OMOutputFormat format = new OMOutputFormat();
format.setCharSetEncoding(encoding);
byte[] bytes = new PlainTextFormatter().getBytes(messageContext, format);
assertEquals(testElementString, new String(bytes, encoding));
} else {
assertTrue(false);
}
}
use of org.apache.axis2.context.MessageContext in project wso2-axis2-transports by wso2.
the class AxisEchoEndpoint method createOperation.
@Override
protected InOutAxisOperation createOperation() {
InOutAxisOperation operation = new InOutAxisOperation(new QName("echo"));
operation.setMessageReceiver(new AbstractInOutMessageReceiver() {
@Override
public void invokeBusinessLogic(MessageContext inMessage, MessageContext outMessage) throws AxisFault {
outMessage.setEnvelope(inMessage.getEnvelope());
}
});
return operation;
}
Aggregations