Search in sources :

Example 56 with Message

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

the class RabbitMQSender method sendOverAMQP.

/**
 * Perform actual sending of the AMQP message
 */
private void sendOverAMQP(RabbitMQConnectionFactory factory, MessageContext msgContext, String targetEPR) throws AxisFault {
    try {
        RabbitMQMessage message = new RabbitMQMessage(msgContext);
        Hashtable<String, String> epProperties = BaseUtils.getEPRProperties(targetEPR);
        if (!StringUtils.isEmpty(epProperties.get(RabbitMQConstants.REPLY_TO_NAME))) {
            // request-response scenario
            RabbitMQRPCMessageSender sender = new RabbitMQRPCMessageSender(factory, targetEPR, epProperties);
            RabbitMQMessage responseMessage = sender.send(message, msgContext);
            MessageContext responseMsgCtx = createResponseMessageContext(msgContext);
            RabbitMQUtils.setSOAPEnvelope(responseMessage, responseMsgCtx, responseMessage.getContentType());
            handleIncomingMessage(responseMsgCtx, RabbitMQUtils.getTransportHeaders(responseMessage), responseMessage.getSoapAction(), responseMessage.getContentType());
        } else {
            // Basic out only publish
            RabbitMQMessageSender sender = new RabbitMQMessageSender(factory, targetEPR, epProperties);
            sender.send(message, msgContext);
        }
    } catch (AxisRabbitMQException e) {
        handleException("Error occurred while sending message out", e);
    } catch (IOException e) {
        handleException("Error occurred while sending message out", e);
    }
}
Also used : RabbitMQRPCMessageSender(org.apache.axis2.transport.rabbitmq.rpc.RabbitMQRPCMessageSender) AxisRabbitMQException(org.apache.axis2.transport.rabbitmq.utils.AxisRabbitMQException) MessageContext(org.apache.axis2.context.MessageContext) IOException(java.io.IOException)

Example 57 with Message

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

the class RabbitMQUtils method setSOAPEnvelope.

public static void setSOAPEnvelope(RabbitMQMessage message, MessageContext msgContext, String contentType) throws AxisFault {
    int index = contentType.indexOf(';');
    String type = index > 0 ? contentType.substring(0, index) : contentType;
    Builder builder = BuilderUtil.getBuilderFromSelector(type, msgContext);
    if (builder == null) {
        if (log.isDebugEnabled()) {
            log.debug("No message builder found for type '" + type + "'. Falling back to SOAP.");
        }
        builder = new SOAPBuilder();
    }
    OMElement documentElement;
    String charSetEnc = null;
    try {
        if (contentType != null) {
            charSetEnc = new ContentType(contentType).getParameter("charset");
        }
    } catch (ParseException ex) {
        log.debug("Parse error", ex);
    }
    msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);
    documentElement = builder.processDocument(new ByteArrayInputStream(message.getBody()), contentType, msgContext);
    msgContext.setEnvelope(TransportUtils.createSOAPEnvelope(documentElement));
}
Also used : ContentType(javax.mail.internet.ContentType) ByteArrayInputStream(java.io.ByteArrayInputStream) SOAPBuilder(org.apache.axis2.builder.SOAPBuilder) Builder(org.apache.axis2.builder.Builder) SOAPBuilder(org.apache.axis2.builder.SOAPBuilder) OMElement(org.apache.axiom.om.OMElement) LongString(com.rabbitmq.client.LongString) ParseException(javax.mail.internet.ParseException)

Example 58 with Message

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

the class GSMImplManager method sendSMS.

public void sendSMS(SMSMessage sm) throws AxisFault {
    if (service == null && !serviceRepo.gatewayInUse(gsmTransportOutDetails.getGatewayId())) {
        // Operating in the Out Only mode
        service = new Service();
        gateway = new SerialModemGateway(gsmTransportOutDetails.getGatewayId(), gsmTransportOutDetails.getComPort(), gsmTransportOutDetails.getBaudRate(), gsmTransportOutDetails.getManufacturer(), gsmTransportOutDetails.getModel());
        // Set the modem protocol to PDU (alternative is TEXT). PDU is the default, anyway...
        gateway.setProtocol(AGateway.Protocols.PDU);
        // Do we want the Gateway to be used for Outbound messages?
        gateway.setOutbound(true);
        // Let SMSLib know which is the SIM PIN.
        gateway.setSimPin("0000");
        try {
            // Add the Gateway to the Service object.
            this.service.addGateway(gateway);
            // Similarly, you may define as many Gateway objects, representing
            // various GSM modems, add them in the Service object and control all of them.
            // Start! (i.e. connect to all defined Gateways)
            this.service.startService();
        } catch (Exception e) {
            throw new AxisFault(e.getMessage(), e);
        }
    } else if (serviceRepo.gatewayInUse(gsmTransportOutDetails.getGatewayId())) {
        service = serviceRepo.getService(gsmTransportOutDetails.getGatewayId());
    }
    OutboundMessage msg = new OutboundMessage(sm.getReceiver(), sm.getContent());
    try {
        // a blocking call.This will be blocked untill the message is sent.
        // normal rate is about 6msgs per minute
        service.sendMessage(msg);
    } catch (Exception e) {
        throw new AxisFault(e.getMessage(), e);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) SerialModemGateway(org.smslib.modem.SerialModemGateway)

Example 59 with Message

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

the class SMPPDispatcher method dispatch.

void dispatch(String source, String receiver, String message, Map<String, Object> properties) throws AxisFault {
    synchronized (this) {
        smsMessage = new SMSMessage(source, receiver, message, SMSMessage.IN_MESSAGE);
        smsMessage.getProperties().putAll(properties);
    }
    manager.dispatchToAxis2(smsMessage);
}
Also used : SMSMessage(org.apache.axis2.transport.sms.SMSMessage)

Example 60 with Message

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

the class AxisTestClient method afterReceive.

public void afterReceive() throws Exception {
    if (sender instanceof ManagementSupport) {
        ManagementSupport sender = (ManagementSupport) this.sender;
        synchronized (metrics) {
            long start = System.currentTimeMillis();
            while (true) {
                try {
                    Assert.assertEquals(1, metrics.getMessagesSent());
                    Assert.assertEquals(messagesSent + 1, sender.getMessagesSent());
                    long thisBytesSent = metrics.getBytesSent();
                    Assert.assertTrue("No increase in bytes sent in message level metrics", thisBytesSent != 0);
                    long newBytesSent = sender.getBytesSent();
                    Assert.assertTrue("No increase in bytes sent in transport level metrics", newBytesSent > bytesSent);
                    Assert.assertEquals("Mismatch between message and transport level metrics", thisBytesSent, newBytesSent - bytesSent);
                    break;
                } catch (AssertionFailedError ex) {
                    // SYNAPSE-491: Maybe the transport sender didn't finish updating the
                    // metrics yet. We give it a couple of seconds to do so.
                    long remaining = start + 5000 - System.currentTimeMillis();
                    if (remaining <= 0) {
                        throw ex;
                    } else {
                        log.debug("The transport sender didn't update the metrics yet (" + ex.getMessage() + "). Waiting for " + remaining + " ms.");
                        metrics.wait(remaining);
                    }
                }
            }
        }
        log.debug("Message level metrics check OK");
    }
}
Also used : ManagementSupport(org.apache.axis2.transport.base.ManagementSupport) AssertionFailedError(junit.framework.AssertionFailedError)

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