Search in sources :

Example 11 with ClientOptions

use of org.apache.axis2.transport.testkit.client.ClientOptions in project wso2-axis2-transports by wso2.

the class RequestResponseTestClientAdapter method sendMessage.

public IncomingMessage<O> sendMessage(ClientOptions options, ContentType contentType, M message) throws Exception {
    IncomingMessage<P> response = target.sendMessage(options, encoder.getContentType(options, contentType), encoder.encode(options, message));
    ContentType responseContentType = response.getContentType();
    return new IncomingMessage<O>(responseContentType, decoder.decode(responseContentType, response.getData()));
}
Also used : ContentType(javax.mail.internet.ContentType) IncomingMessage(org.apache.axis2.transport.testkit.message.IncomingMessage)

Example 12 with ClientOptions

use of org.apache.axis2.transport.testkit.client.ClientOptions in project wso2-axis2-transports by wso2.

the class JMSRequestResponseClient method sendMessage.

public IncomingMessage<T> sendMessage(ClientOptions options, ContentType contentType, T message) throws Exception {
    String correlationId = doSendMessage(options, contentType, message);
    MessageConsumer consumer = replySession.createConsumer(replyDestination, "JMSCorrelationID = '" + correlationId + "'");
    try {
        Message replyMessage = consumer.receive(8000);
        return new IncomingMessage<T>(new ContentType(replyMessage.getStringProperty("Content-Type")), jmsMessageFactory.parseMessage(replyMessage));
    } finally {
        consumer.close();
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) IncomingMessage(org.apache.axis2.transport.testkit.message.IncomingMessage) Message(javax.jms.Message) ContentType(javax.mail.internet.ContentType) IncomingMessage(org.apache.axis2.transport.testkit.message.IncomingMessage)

Example 13 with ClientOptions

use of org.apache.axis2.transport.testkit.client.ClientOptions in project carbon-business-process by wso2.

the class AxisServiceUtils method getOperationClient.

private static OperationClient getOperationClient(ServiceInvocationContext partnerMessageContext, ConfigurationContext clientConfigCtx) throws AxisFault {
    AxisService anonymousService = AnonymousServiceFactory.getAnonymousService(partnerMessageContext.getService(), partnerMessageContext.getPort(), clientConfigCtx.getAxisConfiguration(), partnerMessageContext.getCaller());
    anonymousService.engageModule(clientConfigCtx.getAxisConfiguration().getModule("UEPModule"));
    anonymousService.getParent().addParameter("hiddenService", "true");
    ServiceGroupContext sgc = new ServiceGroupContext(clientConfigCtx, (AxisServiceGroup) anonymousService.getParent());
    ServiceContext serviceCtx = sgc.getServiceContext(anonymousService);
    // get a reference to the DYNAMIC operation of the Anonymous Axis2 service
    AxisOperation axisAnonymousOperation = anonymousService.getOperation(partnerMessageContext.isTwoWay() ? ServiceClient.ANON_OUT_IN_OP : ServiceClient.ANON_OUT_ONLY_OP);
    Options clientOptions = cloneOptions(partnerMessageContext.getInMessageContext().getOptions());
    clientOptions.setExceptionToBeThrownOnSOAPFault(false);
    /* This value doesn't overrideend point config. */
    clientOptions.setTimeOutInMilliSeconds(60000);
    return axisAnonymousOperation.createClient(serviceCtx, clientOptions);
}
Also used : Options(org.apache.axis2.client.Options) AxisOperation(org.apache.axis2.description.AxisOperation) ServiceGroupContext(org.apache.axis2.context.ServiceGroupContext) ServiceContext(org.apache.axis2.context.ServiceContext) AxisService(org.apache.axis2.description.AxisService)

Example 14 with ClientOptions

use of org.apache.axis2.transport.testkit.client.ClientOptions 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 15 with ClientOptions

use of org.apache.axis2.transport.testkit.client.ClientOptions 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)

Aggregations

Options (org.apache.axis2.client.Options)7 AxisOperation (org.apache.axis2.description.AxisOperation)7 ServiceContext (org.apache.axis2.context.ServiceContext)6 ServiceGroupContext (org.apache.axis2.context.ServiceGroupContext)6 AxisService (org.apache.axis2.description.AxisService)6 ContentType (javax.mail.internet.ContentType)5 IncomingMessage (org.apache.axis2.transport.testkit.message.IncomingMessage)5 QName (javax.xml.namespace.QName)4 OperationClient (org.apache.axis2.client.OperationClient)4 MessageContext (org.apache.axis2.context.MessageContext)4 SynapseException (org.apache.synapse.SynapseException)4 EndpointReference (org.apache.axis2.addressing.EndpointReference)3 MessageContext (org.apache.synapse.MessageContext)3 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)3 Set (java.util.Set)2 SOAPFactory (org.apache.axiom.soap.SOAPFactory)2 AxisFault (org.apache.axis2.AxisFault)2 AxisMessage (org.apache.axis2.transport.testkit.message.AxisMessage)2 AbstractEndpoint (org.apache.synapse.endpoints.AbstractEndpoint)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1