Search in sources :

Example 51 with Message

use of org.apache.axis2.transport.msmq.util.Message in project wso2-axis2-transports by wso2.

the class DefaultSMSMessageBuilderImpl method buildMessaage.

public MessageContext buildMessaage(SMSMessage msg, ConfigurationContext configurationContext) throws InvalidMessageFormatException {
    String message = msg.getContent();
    String sender = msg.getSender();
    String receiver = msg.getReceiver();
    String[] parts = message.split(":");
    // may be can add feature to send message format for a request like ????
    if (parts.length < 2) {
        throw new InvalidMessageFormatException("format must be  \"service_name \" : \"opration_name\" : " + "\"parm_1=val_1\" :..:\"param_n = val_n\"");
    } else {
        AxisConfiguration repo = configurationContext.getAxisConfiguration();
        MessageContext messageContext = configurationContext.createMessageContext();
        parts = trimSplited(parts);
        try {
            AxisService axisService = repo.getService(parts[0]);
            if (axisService == null) {
                throw new InvalidMessageFormatException("Service : " + parts[0] + "does not exsist");
            } else {
                messageContext.setAxisService(axisService);
                AxisOperation axisOperation = axisService.getOperation(new QName(parts[1]));
                if (axisOperation == null) {
                    throw new InvalidMessageFormatException("Operation: " + parts[1] + " does not exsist");
                }
                messageContext.setAxisOperation(axisOperation);
                messageContext.setAxisMessage(axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE));
                Map params = getParams(parts, 2);
                SOAPEnvelope soapEnvelope = createSoapEnvelope(messageContext, params);
                messageContext.setServerSide(true);
                messageContext.setEnvelope(soapEnvelope);
                TransportInDescription in = configurationContext.getAxisConfiguration().getTransportIn("sms");
                TransportOutDescription out = configurationContext.getAxisConfiguration().getTransportOut("sms");
                messageContext.setIncomingTransportName("sms");
                messageContext.setProperty(SMSTransportConstents.SEND_TO, sender);
                messageContext.setProperty(SMSTransportConstents.DESTINATION, receiver);
                messageContext.setTransportIn(in);
                messageContext.setTransportOut(out);
                handleSMSProperties(msg, messageContext);
                return messageContext;
            }
        } catch (AxisFault axisFault) {
            log.debug("[DefaultSMSMessageBuilderImpl] Error while extracting the axis2Service \n" + axisFault);
        }
    }
    return null;
}
Also used : AxisFault(org.apache.axis2.AxisFault) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) QName(javax.xml.namespace.QName) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) MessageContext(org.apache.axis2.context.MessageContext) HashMap(java.util.HashMap) Map(java.util.Map)

Example 52 with Message

use of org.apache.axis2.transport.msmq.util.Message 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 53 with Message

use of org.apache.axis2.transport.msmq.util.Message 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 54 with Message

use of org.apache.axis2.transport.msmq.util.Message 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)

Example 55 with Message

use of org.apache.axis2.transport.msmq.util.Message in project wso2-axis2-transports by wso2.

the class MSMQUtil method setSOAPEnvelope.

public static void setSOAPEnvelope(Message message, MessageContext msgContext, String contentType) throws AxisFault {
    if (contentType == null) {
        // TODO;we only support text/plain
        contentType = "text/plain";
        if (log.isDebugEnabled()) {
            log.debug("No content type specified; assuming " + contentType);
        }
    }
    int index = contentType.indexOf(';');
    String type = index > 0 ? contentType.substring(0, index) : contentType;
    Builder builder = BuilderUtil.getBuilderFromSelector(type, msgContext);
    String messageBody = null;
    try {
        messageBody = message.getBodyAsString();
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    if (builder == null) {
        if (log.isDebugEnabled()) {
            log.debug("No message builder found for type' " + type + ".Using SOAP builder");
        }
        builder = new SOAPBuilder();
    }
    OMElement documentElement;
    // TODO: we need to handle the message types separately. Assume text message builder format
    TextMessageBuilder textMessageBuilder;
    if (builder instanceof TextMessageBuilder) {
        textMessageBuilder = (TextMessageBuilder) builder;
    } else {
        textMessageBuilder = new TextMessageBuilderAdapter(builder);
    }
    documentElement = textMessageBuilder.processDocument(messageBody, contentType, msgContext);
    msgContext.setEnvelope(TransportUtils.createSOAPEnvelope(documentElement));
}
Also used : TextMessageBuilderAdapter(org.apache.axis2.format.TextMessageBuilderAdapter) SOAPBuilder(org.apache.axis2.builder.SOAPBuilder) Builder(org.apache.axis2.builder.Builder) TextMessageBuilder(org.apache.axis2.format.TextMessageBuilder) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SOAPBuilder(org.apache.axis2.builder.SOAPBuilder) OMElement(org.apache.axiom.om.OMElement) TextMessageBuilder(org.apache.axis2.format.TextMessageBuilder)

Aggregations

AxisFault (org.apache.axis2.AxisFault)25 MessageContext (org.apache.axis2.context.MessageContext)20 IOException (java.io.IOException)9 OMOutputFormat (org.apache.axiom.om.OMOutputFormat)8 MessageFormatter (org.apache.axis2.transport.MessageFormatter)8 ContentType (javax.mail.internet.ContentType)7 OMElement (org.apache.axiom.om.OMElement)7 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)6 IncomingMessage (org.apache.axis2.transport.testkit.message.IncomingMessage)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)5 AxisOperation (org.apache.axis2.description.AxisOperation)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 OutputStream (java.io.OutputStream)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 XMPPConnection (org.jivesoftware.smack.XMPPConnection)4 XMPPException (org.jivesoftware.smack.XMPPException)4 Message (org.jivesoftware.smack.packet.Message)4 AMQP (com.rabbitmq.client.AMQP)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3