Search in sources :

Example 36 with MessageContext

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;
}
Also used : OMElement(org.apache.axiom.om.OMElement) MessageContext(org.apache.axis2.context.MessageContext) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 37 with 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));
}
Also used : MessageContext(org.apache.axis2.context.MessageContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OMOutputFormat(org.apache.axiom.om.OMOutputFormat) PlainTextFormatter(org.apache.axis2.format.PlainTextFormatter)

Example 38 with MessageContext

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;
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) OMElement(org.apache.axiom.om.OMElement) MessageContext(org.apache.axis2.context.MessageContext) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SOAPFactory(org.apache.axiom.soap.SOAPFactory)

Example 39 with MessageContext

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);
    }
}
Also used : MessageContext(org.apache.axis2.context.MessageContext) OMOutputFormat(org.apache.axiom.om.OMOutputFormat) PlainTextFormatter(org.apache.axis2.format.PlainTextFormatter)

Example 40 with MessageContext

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;
}
Also used : AxisFault(org.apache.axis2.AxisFault) QName(javax.xml.namespace.QName) MessageContext(org.apache.axis2.context.MessageContext) InOutAxisOperation(org.apache.axis2.description.InOutAxisOperation) AbstractInOutMessageReceiver(org.apache.axis2.receivers.AbstractInOutMessageReceiver)

Aggregations

MessageContext (org.apache.axis2.context.MessageContext)35 AxisFault (org.apache.axis2.AxisFault)25 OMElement (org.apache.axiom.om.OMElement)13 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)12 IOException (java.io.IOException)11 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)11 XMLStreamException (javax.xml.stream.XMLStreamException)9 QName (javax.xml.namespace.QName)8 MessageFormatter (org.apache.axis2.transport.MessageFormatter)8 AxisOperation (org.apache.axis2.description.AxisOperation)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 InputStream (java.io.InputStream)5 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)5 SOAPFactory (org.apache.axiom.soap.SOAPFactory)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 OMFactory (org.apache.axiom.om.OMFactory)4 Options (org.apache.axis2.client.Options)4 Message (org.jivesoftware.smack.packet.Message)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 OutputStream (java.io.OutputStream)3