Search in sources :

Example 26 with MessageContext

use of org.apache.axis2.context.MessageContext in project wso2-axis2-transports by wso2.

the class SMSManager method dispatchToAxis2.

/**
 * Dispatch the SMS message to Axis2 Engine
 * @param sms
 */
public void dispatchToAxis2(SMSMessage sms) {
    try {
        MessageContext msgctx = messageBuilder.buildMessaage(sms, configurationContext);
        msgctx.setReplyTo(new EndpointReference("sms://" + sms.getSender() + "/"));
        AxisEngine.receive(msgctx);
    } catch (InvalidMessageFormatException e) {
        log.debug("Invalid message format " + e);
    } catch (AxisFault axisFault) {
        log.debug(axisFault);
    } catch (Throwable e) {
        log.debug("Unknown Exception ", e);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) MessageContext(org.apache.axis2.context.MessageContext) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 27 with MessageContext

use of org.apache.axis2.context.MessageContext in project wso2-axis2-transports by wso2.

the class TCPTransportSender method writeMessageOut.

/**
 * Writing the message to the output stream of the TCP socket after applying correct message formatter
 * This method is synchronized because there will be issue when formatter write to same output stream which causes
 * to mixed messages
 *
 * @param msgContext the message context
 * @param outputStream the socket output stream
 * @throws AxisFault if error occurred
 * @throws IOException if IO exception occurred
 */
private synchronized void writeMessageOut(MessageContext msgContext, OutputStream outputStream, String delimiter, String delimiterType) throws AxisFault, IOException {
    MessageFormatter messageFormatter = BaseUtils.getMessageFormatter(msgContext);
    OMOutputFormat format = BaseUtils.getOMOutputFormat(msgContext);
    messageFormatter.writeTo(msgContext, format, outputStream, true);
    if (delimiter != null && !delimiter.isEmpty()) {
        if (TCPConstants.BYTE_DELIMITER_TYPE.equalsIgnoreCase(delimiterType)) {
            outputStream.write((char) Integer.parseInt(delimiter.split("0x")[1], 16));
        } else {
            outputStream.write(delimiter.getBytes());
        }
    }
    outputStream.flush();
}
Also used : MessageFormatter(org.apache.axis2.transport.MessageFormatter) OMOutputFormat(org.apache.axiom.om.OMOutputFormat)

Example 28 with MessageContext

use of org.apache.axis2.context.MessageContext in project wso2-axis2-transports by wso2.

the class PlainTextFormatter method writeTo.

public void writeTo(MessageContext messageContext, OMOutputFormat format, OutputStream outputStream, boolean preserve) throws AxisFault {
    // preserve boolean is not used because new implementation doesn't need it. However, it's there to
    // to have backward compatibility.
    OMElement textElt = messageContext.getEnvelope().getBody().getFirstElement();
    if (BaseConstants.DEFAULT_TEXT_WRAPPER.equals(textElt.getQName())) {
        try {
            Writer out = new OutputStreamWriter(outputStream, format.getCharSetEncoding());
            out.write(textElt.getFirstElement() == null ? textElt.getText() : textElt.getFirstElement().toString());
            out.flush();
        } catch (IOException e) {
            throw new AxisFault("Error writing text message to stream", e);
        } catch (Exception e) {
            throw new AxisFault("Error extracting the text payload from the message", e);
        }
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) OMElement(org.apache.axiom.om.OMElement) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 29 with MessageContext

use of org.apache.axis2.context.MessageContext in project wso2-axis2-transports by wso2.

the class AbstractTransportListener method createMessageContext.

/**
 * Create a new axis MessageContext for an incoming message through this transport
 * @return the newly created message context
 */
public MessageContext createMessageContext() {
    MessageContext msgCtx = new MessageContext();
    msgCtx.setConfigurationContext(cfgCtx);
    msgCtx.setIncomingTransportName(getTransportName());
    msgCtx.setTransportOut(transportOut);
    msgCtx.setTransportIn(transportIn);
    msgCtx.setServerSide(true);
    msgCtx.setMessageID(UUIDGenerator.getUUID());
    // There is a discrepency in what I thought, Axis2 spawns a nes threads to
    // send a message is this is TRUE - and I want it to be the other way
    msgCtx.setProperty(MessageContext.CLIENT_API_NON_BLOCKING, Boolean.valueOf(!isNonBlocking));
    return msgCtx;
}
Also used : MessageContext(org.apache.axis2.context.MessageContext)

Example 30 with MessageContext

use of org.apache.axis2.context.MessageContext in project wso2-axis2-transports by wso2.

the class PlainTextFormatterTest method testGetBytes.

private void testGetBytes(String encoding) throws Exception {
    MessageContext messageContext = createMessageContext(testString);
    OMOutputFormat format = new OMOutputFormat();
    format.setCharSetEncoding(encoding);
    byte[] bytes = new PlainTextFormatter().getBytes(messageContext, format);
    assertEquals(testString, new String(bytes, encoding));
}
Also used : MessageContext(org.apache.axis2.context.MessageContext) OMOutputFormat(org.apache.axiom.om.OMOutputFormat) PlainTextFormatter(org.apache.axis2.format.PlainTextFormatter)

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