Search in sources :

Example 51 with MessageContext

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

the class SMSManager method sendSMS.

/**
 * send a SMS form the message comming form the Axis2 Engine
 * @param messageContext that is comming form the Axis2
 */
public void sendSMS(MessageContext messageContext) throws AxisFault {
    try {
        SMSMessage sms = messageFormatter.formatSMS(messageContext);
        sms.addProperty(SMSTransportConstents.INVERT_SOURCE_AND_DESTINATION, "" + invertSourceAndDestination);
        currentImplimentation.sendSMS(sms);
    } catch (Exception e) {
        log.error("Error while sending the SMS ", e);
        throw new AxisFault(e.getMessage(), e);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault)

Example 52 with MessageContext

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

the class TCPTransportSender method waitForReply.

private void waitForReply(MessageContext msgContext, Socket socket, String contentType) throws AxisFault {
    if (!(msgContext.getAxisOperation() instanceof OutInAxisOperation) && msgContext.getProperty(org.apache.axis2.Constants.PIGGYBACK_MESSAGE) == null) {
        return;
    }
    if (contentType == null) {
        contentType = TCPConstants.TCP_DEFAULT_CONTENT_TYPE;
    }
    try {
        MessageContext responseMsgCtx = createResponseMessageContext(msgContext);
        SOAPEnvelope envelope = TransportUtils.createSOAPMessage(msgContext, socket.getInputStream(), contentType);
        responseMsgCtx.setEnvelope(envelope);
        AxisEngine.receive(responseMsgCtx);
    } catch (Exception e) {
        handleException("Error while processing response", e);
    }
}
Also used : MessageContext(org.apache.axis2.context.MessageContext) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) OutInAxisOperation(org.apache.axis2.description.OutInAxisOperation) IOException(java.io.IOException)

Example 53 with MessageContext

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

the class TCPTwoChannelEchoRawXMLTest method testEchoXMLCompleteASync.

public void testEchoXMLCompleteASync() throws Exception {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://localhost/my", "my");
    OMElement method = fac.createOMElement("echoOMElement", omNs);
    OMElement value = fac.createOMElement("myValue", omNs);
    value.setText("Isaac Asimov, The Foundation Trilogy");
    method.addChild(value);
    ServiceClient sender;
    try {
        Options options = new Options();
        options.setTo(targetEPR);
        options.setTransportInProtocol(Constants.TRANSPORT_TCP);
        options.setUseSeparateListener(true);
        options.setAction(operationName.getLocalPart());
        AxisCallback axisCallback = new AxisCallback() {

            public void onMessage(MessageContext msgContext) {
                try {
                    msgContext.getEnvelope().serialize(StAXUtils.createXMLStreamWriter(System.out));
                    finish = true;
                } catch (XMLStreamException e) {
                    onError(e);
                }
            }

            public void onFault(MessageContext msgContext) {
                try {
                    msgContext.getEnvelope().serialize(StAXUtils.createXMLStreamWriter(System.out));
                    finish = true;
                } catch (XMLStreamException e) {
                    onError(e);
                }
            }

            public void onError(Exception e) {
                log.info(e.getMessage());
                finish = true;
            }

            public void onComplete() {
                finish = true;
            }
        };
        AxisService serviceClient = Utils.createSimpleServiceforClient(serviceName, Echo.class.getName(), operationName);
        sender = new ServiceClient(configContext, serviceClient);
        sender.setOptions(options);
        sender.sendReceiveNonBlocking(operationName, method, axisCallback);
        int index = 0;
        while (!finish) {
            Thread.sleep(1000);
            index++;
            if (index > 10) {
                throw new AxisFault("Server was shutdown as the async response take too long to complete");
            }
        }
    } finally {
        if (finish) {
        }
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) Options(org.apache.axis2.client.Options) OMNamespace(org.apache.axiom.om.OMNamespace) AxisCallback(org.apache.axis2.client.async.AxisCallback) AxisService(org.apache.axis2.description.AxisService) OMElement(org.apache.axiom.om.OMElement) XMLStreamException(javax.xml.stream.XMLStreamException) OMFactory(org.apache.axiom.om.OMFactory) XMLStreamException(javax.xml.stream.XMLStreamException) ServiceClient(org.apache.axis2.client.ServiceClient) MessageContext(org.apache.axis2.context.MessageContext)

Example 54 with MessageContext

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

the class MailTransportListener method processMail.

/**
 * Process a mail message through Axis2
 *
 * @param message the email message
 * @param entry   the poll table entry
 * @throws MessagingException on error
 * @throws IOException        on error
 */
private void processMail(Message message, PollTableEntry entry) throws MessagingException, IOException {
    updateMetrics(message);
    // populate transport headers using the mail headers
    Map trpHeaders = getTransportHeaders(message, entry);
    // Allow the content type to be overridden by configuration.
    String contentType = entry.getContentType();
    Part messagePart;
    if (contentType != null) {
        messagePart = message;
    } else {
        messagePart = getMessagePart(message, cfgCtx.getAxisConfiguration());
        contentType = messagePart.getContentType();
    }
    // FIXME: remove this ugly hack when Axis2 has learned that content types are case insensitive...
    int idx = contentType.indexOf(';');
    if (idx == -1) {
        contentType = contentType.toLowerCase();
    } else {
        contentType = contentType.substring(0, idx).toLowerCase() + contentType.substring(idx);
    }
    // if the content type was not found, we have an error
    if (contentType == null) {
        processFailure("Unable to determine Content-type for message : " + message.getMessageNumber() + " :: " + message.getSubject(), null, entry);
        return;
    } else if (log.isDebugEnabled()) {
        log.debug("Processing message as Content-Type : " + contentType);
    }
    MessageContext msgContext = entry.createMessageContext();
    // Extract the charset encoding from the configured content type and
    // set the CHARACTER_SET_ENCODING property as e.g. SOAPBuilder relies on this.
    String charSetEnc;
    try {
        charSetEnc = new ContentType(contentType).getParameter("charset");
    } catch (ParseException ex) {
        // ignore
        charSetEnc = null;
    }
    msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);
    MailOutTransportInfo outInfo = buildOutTransportInfo(message, entry);
    // save out transport information
    msgContext.setProperty(Constants.OUT_TRANSPORT_INFO, outInfo);
    // this property only useful for supporting smtp with Sandesha2.
    msgContext.setProperty(RequestResponseTransport.TRANSPORT_CONTROL, new MailRequestResponseTransport());
    // set message context From
    if (outInfo.getFromAddress() != null) {
        msgContext.setFrom(new EndpointReference(MailConstants.TRANSPORT_PREFIX + outInfo.getFromAddress().getAddress()));
    }
    // save original mail message id message context MessageID
    msgContext.setMessageID(outInfo.getRequestMessageID());
    // set the message payload to the message context
    InputStream in = messagePart.getInputStream();
    try {
        try {
            msgContext.setEnvelope(TransportUtils.createSOAPMessage(msgContext, in, contentType));
        } catch (XMLStreamException ex) {
            handleException("Error parsing message", ex);
        }
        String soapAction = (String) trpHeaders.get(BaseConstants.SOAPACTION);
        if (soapAction == null && message.getSubject() != null && message.getSubject().startsWith(BaseConstants.SOAPACTION)) {
            soapAction = message.getSubject().substring(BaseConstants.SOAPACTION.length());
            if (soapAction.startsWith(":")) {
                soapAction = soapAction.substring(1).trim();
            }
        }
        handleIncomingMessage(msgContext, trpHeaders, soapAction, contentType);
    } finally {
        in.close();
    }
    if (log.isDebugEnabled()) {
        log.debug("Processed message : " + message.getMessageNumber() + " :: " + message.getSubject());
    }
}
Also used : ContentType(javax.mail.internet.ContentType) XMLStreamException(javax.xml.stream.XMLStreamException) MimeBodyPart(javax.mail.internet.MimeBodyPart) InputStream(java.io.InputStream) MessageContext(org.apache.axis2.context.MessageContext) ParseException(javax.mail.internet.ParseException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 55 with MessageContext

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

the class MSMQMessageReceiver method processThroughEngine.

/**
 * Set up message properties to header as it received as MSMQ message properties
 *
 * @param message
 * @return
 * @throws AxisFault
 */
private boolean processThroughEngine(Message message) throws AxisFault {
    // TODO: this only support text messages, need to improve it for binay
    // messages
    // Get the contentType from the MSMQ message
    String contentType = message.getLabel();
    if (log.isDebugEnabled()) {
        log.info("Content Type of the message is : " + contentType);
    }
    MessageContext msgContext = endpoint.createMessageContext();
    SOAPEnvelope soapEnvelope;
    if (message.getCorrelationId() != null) {
        msgContext.setProperty(MSMQConstants.MSMQ_CORRELATION_ID, message.getCorrelationId());
    }
    if (msgContext.getParameter(MSMQConstants.PARAM_CONTENT_TYPE).getValue() != null) {
        // Overwrite the message's content type with the defined content type in the proxy
        contentType = String.valueOf(msgContext.getParameter(MSMQConstants.PARAM_CONTENT_TYPE).getValue());
    }
    /*
		 * ContentTypeInfo contentTypeInfo =
		 * endpoint.getContentTypeRuleSet().getContentTypeInfo(message);
		 */
    MSMQUtil.setSOAPEnvelope(message, msgContext, contentType);
    soapEnvelope = msgContext.getEnvelope();
    msmqListener.handleIncomingMessage(msgContext, MSMQUtil.getTransportHeaders(message), null, contentType);
    return true;
}
Also used : MessageContext(org.apache.axis2.context.MessageContext) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope)

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