Search in sources :

Example 46 with Message

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

the class MailRequestResponseClient method sendMessage.

public IncomingMessage<byte[]> sendMessage(ClientOptions options, ContentType contentType, byte[] message) throws Exception {
    String msgId = sendMessage(contentType, message);
    Message reply = waitForReply(msgId);
    Assert.assertNotNull("No response received", reply);
    Assert.assertEquals(channel.getSender().getAddress(), ((InternetAddress) reply.getRecipients(Message.RecipientType.TO)[0]).getAddress());
    Assert.assertEquals(channel.getRecipient().getAddress(), ((InternetAddress) reply.getFrom()[0]).getAddress());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    reply.getDataHandler().writeTo(baos);
    return new IncomingMessage<byte[]>(new ContentType(reply.getContentType()), baos.toByteArray());
}
Also used : Message(javax.mail.Message) IncomingMessage(org.apache.axis2.transport.testkit.message.IncomingMessage) MimeMessage(javax.mail.internet.MimeMessage) ContentType(javax.mail.internet.ContentType) IncomingMessage(org.apache.axis2.transport.testkit.message.IncomingMessage) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 47 with Message

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

the class MailRequestResponseClient method getMessage.

private Message getMessage(String requestMsgId) throws Exception {
    MimeMessage response = null;
    Folder folder = store.getFolder(MailConstants.DEFAULT_FOLDER);
    folder.open(Folder.READ_WRITE);
    Message[] msgs = folder.getMessages();
    log.debug(msgs.length + " messages in mailbox");
    loop: for (Message m : msgs) {
        MimeMessage mimeMessage = (MimeMessage) m;
        String[] inReplyTo = mimeMessage.getHeader(MailConstants.MAIL_HEADER_IN_REPLY_TO);
        log.debug("Found message " + mimeMessage.getMessageID() + " in reply to " + Arrays.toString(inReplyTo));
        if (inReplyTo != null && inReplyTo.length > 0) {
            for (int j = 0; j < inReplyTo.length; j++) {
                if (requestMsgId.equals(inReplyTo[j])) {
                    log.debug("Identified message " + mimeMessage.getMessageID() + " as the response to " + requestMsgId + "; retrieving it from the store");
                    // We need to create a copy so that we can delete the original and close the folder
                    response = new MimeMessage(mimeMessage);
                    log.debug("Flagging message " + mimeMessage.getMessageID() + " for deletion");
                    mimeMessage.setFlag(Flags.Flag.DELETED, true);
                    break loop;
                }
            }
        }
        log.warn("Don't know what to do with message " + mimeMessage.getMessageID() + "; skipping");
    }
    folder.close(true);
    return response;
}
Also used : Message(javax.mail.Message) IncomingMessage(org.apache.axis2.transport.testkit.message.IncomingMessage) MimeMessage(javax.mail.internet.MimeMessage) MimeMessage(javax.mail.internet.MimeMessage) Folder(javax.mail.Folder)

Example 48 with Message

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

the class MqttUtils method invoke.

public static void invoke(MqttMessage mqttMessage, MessageContext msgContext, String contentType) throws AxisFault, AxisMqttException {
    if (contentType == null) {
        contentType = "text/plain";
    }
    Builder builder = BuilderUtil.getBuilderFromSelector(contentType, msgContext);
    if (builder == null) {
        if (log.isDebugEnabled()) {
            log.debug("No message builder found for type '" + contentType + "'. Falling back to SOAP.");
        }
        builder = new SOAPBuilder();
    }
    msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, "UTF-8");
    OMElement documentElement = null;
    byte[] bytes = mqttMessage.getPayload();
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
    documentElement = builder.processDocument(byteArrayInputStream, contentType, msgContext);
    msgContext.setEnvelope(TransportUtils.createSOAPEnvelope(documentElement));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) SOAPBuilder(org.apache.axis2.builder.SOAPBuilder) Builder(org.apache.axis2.builder.Builder) TextMessageBuilder(org.apache.axis2.format.TextMessageBuilder) SOAPBuilder(org.apache.axis2.builder.SOAPBuilder) OMElement(org.apache.axiom.om.OMElement)

Example 49 with Message

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

the class MSMQCamelClient method send.

public void send(Message message) throws AxisFault {
    try {
        MsmqMessage msg = new MsmqMessage();
        String payload = message.getBodyAsString();
        ByteArray sendbuffer = new ByteArray(payload.length());
        msg.setMsgBody(sendbuffer.cast());
        msg.setBodySize(payload.length());
        for (int i = 0; i < payload.length(); ++i) {
            sendbuffer.setitem(i, payload.getBytes()[i]);
        }
        msg.setCorrelationId(message.getCorrelationId());
        msg.setAppSpecifc(CtypeMapClazz.getIdByName(message.getLabel()));
        msmqQueue.sendMessage(msg);
    } catch (Exception e) {
        log.error("Error while sending message to destination", e);
        throw new AxisFault("Error while sending message to destination", e);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) ByteArray(org.apache.camel.component.msmq.native_support.ByteArray) MsmqMessage(org.apache.camel.component.msmq.native_support.MsmqMessage) CharacterCodingException(java.nio.charset.CharacterCodingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 50 with Message

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

the class RabbitMQRPCMessageSender method send.

public RabbitMQMessage send(RabbitMQMessage message, MessageContext msgContext) throws AxisRabbitMQException, IOException {
    publish(message, msgContext);
    RabbitMQMessage responseMessage = processResponse(message.getCorrelationId());
    // release the dual channel to the pool
    try {
        connectionFactory.pushRPCChannel(dualChannel);
    } catch (InterruptedException e) {
        handleException(e.getMessage());
    }
    return responseMessage;
}
Also used : RabbitMQMessage(org.apache.axis2.transport.rabbitmq.RabbitMQMessage)

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