Search in sources :

Example 36 with Message

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

the class AbstractTransportSender method createResponseMessageContext.

/**
 * Create a new axis MessageContext for an incoming response message
 * through this transport, for the given outgoing message
 *
 * @param outMsgCtx the outgoing message
 * @return the newly created message context
 */
public MessageContext createResponseMessageContext(MessageContext outMsgCtx) {
    MessageContext responseMsgCtx = null;
    try {
        responseMsgCtx = outMsgCtx.getOperationContext().getMessageContext(WSDL2Constants.MESSAGE_LABEL_IN);
    } catch (AxisFault af) {
        log.error("Error getting IN message context from the operation context", af);
    }
    if (responseMsgCtx == null) {
        responseMsgCtx = new MessageContext();
        responseMsgCtx.setOperationContext(outMsgCtx.getOperationContext());
    }
    responseMsgCtx.setIncomingTransportName(getTransportName());
    responseMsgCtx.setTransportOut(transportOut);
    responseMsgCtx.setTransportIn(transportIn);
    responseMsgCtx.setMessageID(UUIDGenerator.getUUID());
    responseMsgCtx.setDoingREST(outMsgCtx.isDoingREST());
    responseMsgCtx.setProperty(MessageContext.TRANSPORT_IN, outMsgCtx.getProperty(MessageContext.TRANSPORT_IN));
    responseMsgCtx.setAxisMessage(outMsgCtx.getOperationContext().getAxisOperation().getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE));
    responseMsgCtx.setTo(null);
    return responseMsgCtx;
}
Also used : AxisFault(org.apache.axis2.AxisFault) MessageContext(org.apache.axis2.context.MessageContext)

Example 37 with Message

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

the class ProtocolEndpoint method createMessageContext.

public MessageContext createMessageContext() throws AxisFault {
    MessageContext msgContext = listener.createMessageContext();
    if (service != null) {
        msgContext.setAxisService(service);
        // find the operation for the message, or default to one
        Parameter operationParam = service.getParameter(BaseConstants.OPERATION_PARAM);
        QName operationQName = (operationParam != null ? BaseUtils.getQNameFromString(operationParam.getValue()) : BaseConstants.DEFAULT_OPERATION);
        AxisOperation operation = service.getOperation(operationQName);
        if (operation != null) {
            msgContext.setAxisOperation(operation);
            msgContext.setAxisMessage(operation.getMessage(WSDL2Constants.MESSAGE_LABEL_IN));
            msgContext.setSoapAction("urn:" + operation.getName().getLocalPart());
        }
    }
    return msgContext;
}
Also used : AxisOperation(org.apache.axis2.description.AxisOperation) QName(javax.xml.namespace.QName) Parameter(org.apache.axis2.description.Parameter) MessageContext(org.apache.axis2.context.MessageContext)

Example 38 with Message

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

the class MinConcurrencyTest method runTest.

@Override
protected void runTest() throws Throwable {
    int endpointCount = channels.length;
    int expectedConcurrency = endpointCount * messages;
    final MessageReceiver messageReceiver = new MessageReceiver() {

        public void receive(MessageContext msgContext) throws AxisFault {
            synchronized (concurrencyReachedLock) {
                concurrencyReached++;
                concurrencyReachedLock.notifyAll();
            }
            try {
                synchronized (shutdownAwaitLock) {
                    shutdownAwaitLock.wait();
                }
            } catch (InterruptedException ex) {
            }
        }
    };
    TestResourceSet[] clientResourceSets = new TestResourceSet[endpointCount];
    TestResourceSet[] endpointResourceSets = new TestResourceSet[endpointCount];
    try {
        for (int i = 0; i < endpointCount; i++) {
            TestResourceSet clientResourceSet = new TestResourceSet(getResourceSet());
            AsyncChannel channel = channels[i];
            clientResourceSet.addResource(channel);
            AxisAsyncTestClient client = new AxisAsyncTestClient(false);
            clientResourceSet.addResource(client);
            clientResourceSet.setUp();
            clientResourceSets[i] = clientResourceSet;
            TestResourceSet endpointResourceSet = new TestResourceSet(clientResourceSet);
            endpointResourceSet.addResource(new AxisTestEndpoint() {

                @Override
                protected AxisOperation createOperation() {
                    AxisOperation operation = new InOnlyAxisOperation(new QName("in"));
                    operation.setMessageReceiver(messageReceiver);
                    return operation;
                }

                @Override
                protected void onTransportError(Throwable ex) {
                // TODO Auto-generated method stub
                }
            });
            if (!preloadMessages) {
                endpointResourceSet.setUp();
                endpointResourceSets[i] = endpointResourceSet;
            }
            for (int j = 0; j < messages; j++) {
                ClientOptions options = new ClientOptions(client, new ContentType(SOAP11Constants.SOAP_11_CONTENT_TYPE), "UTF-8");
                AxisMessage message = new AxisMessage();
                message.setMessageType(SOAP11Constants.SOAP_11_CONTENT_TYPE);
                SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
                SOAPEnvelope envelope = factory.getDefaultEnvelope();
                message.setEnvelope(envelope);
                client.sendMessage(options, new ContentType(message.getMessageType()), message);
            }
            if (preloadMessages) {
                endpointResourceSet.setUp();
                endpointResourceSets[i] = endpointResourceSet;
            }
        }
        long startTime = System.currentTimeMillis();
        while (concurrencyReached < expectedConcurrency && System.currentTimeMillis() < (startTime + 5000)) {
            synchronized (concurrencyReachedLock) {
                concurrencyReachedLock.wait(5000);
            }
        }
        synchronized (shutdownAwaitLock) {
            shutdownAwaitLock.notifyAll();
        }
        if (concurrencyReached < expectedConcurrency) {
            fail("Concurrency reached is " + concurrencyReached + ", but expected " + expectedConcurrency);
        }
    } finally {
        for (int i = 0; i < endpointCount; i++) {
            if (endpointResourceSets[i] != null) {
                endpointResourceSets[i].tearDown();
            }
            if (clientResourceSets[i] != null) {
                clientResourceSets[i].tearDown();
            }
        }
    }
}
Also used : ClientOptions(org.apache.axis2.transport.testkit.client.ClientOptions) InOnlyAxisOperation(org.apache.axis2.description.InOnlyAxisOperation) AxisOperation(org.apache.axis2.description.AxisOperation) ContentType(javax.mail.internet.ContentType) QName(javax.xml.namespace.QName) AsyncChannel(org.apache.axis2.transport.testkit.channel.AsyncChannel) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) AxisTestEndpoint(org.apache.axis2.transport.testkit.axis2.endpoint.AxisTestEndpoint) SOAPFactory(org.apache.axiom.soap.SOAPFactory) InOnlyAxisOperation(org.apache.axis2.description.InOnlyAxisOperation) MessageReceiver(org.apache.axis2.engine.MessageReceiver) AxisTestEndpoint(org.apache.axis2.transport.testkit.axis2.endpoint.AxisTestEndpoint) AxisAsyncTestClient(org.apache.axis2.transport.testkit.axis2.client.AxisAsyncTestClient) MessageContext(org.apache.axis2.context.MessageContext) TestResourceSet(org.apache.axis2.transport.testkit.tests.TestResourceSet) AxisMessage(org.apache.axis2.transport.testkit.message.AxisMessage)

Example 39 with Message

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

the class XMPPListener method start.

/**
 * Start a pool of Workers. For each connection in connectionFactories,
 * assign a packer listener. This packet listener will trigger when a
 * message arrives.
 */
public void start() throws AxisFault {
    // create thread pool of workers
    ExecutorService workerPool = new ThreadPoolExecutor(1, WORKERS_MAX_THREADS, WORKER_KEEP_ALIVE, TIME_UNIT, new LinkedBlockingQueue(), new org.apache.axis2.util.threadpool.DefaultThreadFactory(new ThreadGroup("XMPP Worker thread group"), "XMPPWorker"));
    Iterator iter = connectionFactories.values().iterator();
    while (iter.hasNext()) {
        XMPPConnectionFactory connectionFactory = (XMPPConnectionFactory) iter.next();
        XMPPPacketListener xmppPacketListener = new XMPPPacketListener(connectionFactory, this.configurationContext, workerPool);
        connectionFactory.listen(xmppPacketListener);
    }
}
Also used : XMPPConnectionFactory(org.apache.axis2.transport.xmpp.util.XMPPConnectionFactory) XMPPPacketListener(org.apache.axis2.transport.xmpp.util.XMPPPacketListener) ExecutorService(java.util.concurrent.ExecutorService) Iterator(java.util.Iterator) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 40 with Message

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

the class XMPPClientConnectionFactory method connect.

/**
 * Connects to a XMPP server based on the details available in serverCredentials object
 * @param serverCredentials
 * @throws XMPPException
 */
public XMPPConnection connect(final XMPPServerCredentials serverCredentials) throws AxisFault {
    // XMPPConnection.DEBUG_ENABLED = true;
    if (XMPPConstants.XMPP_SERVER_TYPE_JABBER.equals(serverCredentials.getServerType())) {
        xmppConnection = new XMPPConnection(serverCredentials.getServerUrl());
        try {
            xmppConnection.connect();
        } catch (XMPPException e) {
            log.error("Failed to connect to server :" + serverCredentials.getServerUrl(), e);
            throw new AxisFault("Failed to connect to server :" + serverCredentials.getServerUrl());
        }
        // This prevents random ssl exception from Smack API
        try {
            Thread.sleep(100);
        } catch (InterruptedException e5) {
            log.debug("Sleep interrupted ", e5);
        }
        if (xmppConnection.isConnected()) {
            String resource = serverCredentials.getResource() + new Object().hashCode();
            if (!xmppConnection.isAuthenticated()) {
                try {
                    // xmppConnection.login(serverCredentials.getAccountName()+"@"+
                    // serverCredentials.getServerUrl(),
                    xmppConnection.login(serverCredentials.getAccountName(), serverCredentials.getPassword(), resource, true);
                } catch (XMPPException e) {
                    try {
                        log.error("Login failed for " + serverCredentials.getAccountName() + "@" + serverCredentials.getServerUrl() + ".Retrying in 2 secs", e);
                        Thread.sleep(2000);
                        // xmppConnection.login(serverCredentials.getAccountName()+"@"+
                        // serverCredentials.getServerUrl(),
                        xmppConnection.login(serverCredentials.getAccountName(), serverCredentials.getPassword(), resource, true);
                    } catch (InterruptedException e1) {
                        log.error("Sleep interrupted.", e1);
                    } catch (XMPPException e2) {
                        log.error("Login failed for : " + serverCredentials.getAccountName() + "@" + serverCredentials.getServerUrl(), e2);
                        throw new AxisFault("Login failed for : " + serverCredentials.getAccountName() + "@" + serverCredentials.getServerUrl());
                    }
                }
                // Listen for Message type packets from specified server url
                // packetFilter = new AndFilter(new PacketTypeFilter(Message.class),
                // new FromContainsFilter(serverCredentials.getServerUrl()));
                packetFilter = new FromContainsFilter(serverCredentials.getServerUrl());
            }
        }
    } else if (XMPPConstants.XMPP_SERVER_TYPE_GOOGLETALK.equals(serverCredentials.getServerType())) {
        ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration(XMPPConstants.GOOGLETALK_URL, XMPPConstants.GOOGLETALK_PORT, XMPPConstants.GOOGLETALK_SERVICE_NAME);
        xmppConnection = new XMPPConnection(connectionConfiguration);
        try {
            xmppConnection.connect();
            xmppConnection.login(serverCredentials.getAccountName(), serverCredentials.getPassword(), serverCredentials.getResource(), true);
            // packetFilter = new AndFilter(new PacketTypeFilter(Message.class),
            // new FromContainsFilter(XMPPConstants.GOOGLETALK_FROM));
            // packetFilter = new FromContainsFilter(XMPPConstants.GOOGLETALK_FROM);
            packetFilter = new ToContainsFilter("@gmail.com");
        } catch (XMPPException e1) {
            log.error("Error occured while connecting to Googletalk server.", e1);
            throw new AxisFault("Error occured while connecting to Googletalk server.");
        }
    }
    ConnectionListener connectionListener = null;
    connectionListener = new ConnectionListener() {

        public void connectionClosed() {
            log.debug("Connection closed normally");
        }

        public void connectionClosedOnError(Exception e1) {
            log.error("Connection to " + serverCredentials.getServerUrl() + " closed with error.", e1);
        }

        public void reconnectingIn(int seconds) {
            log.error("Connection to " + serverCredentials.getServerUrl() + " failed. Reconnecting in " + seconds + "s");
        }

        public void reconnectionFailed(Exception e) {
            log.error("Reconnection to " + serverCredentials.getServerUrl() + " failed.", e);
        }

        public void reconnectionSuccessful() {
            log.debug("Reconnection to " + serverCredentials.getServerUrl() + " successful.");
        }
    };
    if (xmppConnection != null && xmppConnection.isConnected()) {
        xmppConnection.addConnectionListener(connectionListener);
        log.info("Connected to " + serverCredentials.getAccountName() + "@" + serverCredentials.getServerUrl() + "/" + serverCredentials.getResource());
    } else {
        log.warn(" Not Connected to " + serverCredentials.getAccountName() + "@" + serverCredentials.getServerUrl() + "/" + serverCredentials.getResource());
    }
    return xmppConnection;
}
Also used : AxisFault(org.apache.axis2.AxisFault) ToContainsFilter(org.jivesoftware.smack.filter.ToContainsFilter) ConnectionConfiguration(org.jivesoftware.smack.ConnectionConfiguration) FromContainsFilter(org.jivesoftware.smack.filter.FromContainsFilter) XMPPConnection(org.jivesoftware.smack.XMPPConnection) ConnectionListener(org.jivesoftware.smack.ConnectionListener) XMPPException(org.jivesoftware.smack.XMPPException) XMPPException(org.jivesoftware.smack.XMPPException)

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