Search in sources :

Example 6 with TransportOutDescription

use of org.apache.axis2.description.TransportOutDescription in project wso2-synapse by wso2.

the class NHttpTransportListenerTest method testRequestAndResponse.

/**
 * Test the Source Handler respond to client.
 * Send a message to http listener and get the same request message as a response using PassThroughHttpSender
 */
@Test
public void testRequestAndResponse() throws Exception {
    RequestURIBasedDispatcher requestURIBasedDispatcher = Mockito.mock(RequestURIBasedDispatcher.class);
    Mockito.when(requestURIBasedDispatcher.findService(any(MessageContext.class))).thenReturn(new AxisService("myservice"));
    PowerMockito.whenNew(RequestURIBasedDispatcher.class).withNoArguments().thenReturn(requestURIBasedDispatcher);
    PowerMockito.mockStatic(AxisEngine.class);
    PowerMockito.doAnswer(new Answer<Void>() {

        public Void answer(InvocationOnMock invocation) throws Exception {
            MessageContext axis2MessageContext = invocation.getArgument(0);
            ServiceContext svcCtx = new ServiceContext();
            OperationContext opCtx = new OperationContext(new InOutAxisOperation(), svcCtx);
            axis2MessageContext.setServiceContext(svcCtx);
            axis2MessageContext.setOperationContext(opCtx);
            axis2MessageContext.getOperationContext().setProperty(org.apache.axis2.Constants.RESPONSE_WRITTEN, "SKIP");
            axis2MessageContext.setTo(null);
            axis2MessageContext.setProperty("synapse.isresponse", true);
            HttpCoreNIOSender sender = new HttpCoreNIOSender();
            ConfigurationContext cfgCtx = new ConfigurationContext(new AxisConfiguration());
            sender.init(cfgCtx, new TransportOutDescription("http"));
            sender.invoke(axis2MessageContext);
            return null;
        }
    }).when(AxisEngine.class, "receive", any(MessageContext.class));
    HttpClient client = new HttpClient();
    PostMethod method = new PostMethod(ServiceUtils.getServiceEndpoint("myservice", HOST, PORT));
    method.setRequestHeader("Content-Type", "application/xml");
    StringRequestEntity stringRequestEntity = new StringRequestEntity("<msg>hello</msg>", "application/xml", "UTF-8");
    method.setRequestEntity(stringRequestEntity);
    int responseCode = client.executeMethod(method);
    Assert.assertEquals("Response code mismatched", 200, responseCode);
    String response = method.getResponseBodyAsString();
    Assert.assertEquals("Response", "<msg>hello</msg>", response);
}
Also used : OperationContext(org.apache.axis2.context.OperationContext) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) StringRequestEntity(org.apache.commons.httpclient.methods.StringRequestEntity) RequestURIBasedDispatcher(org.apache.axis2.dispatchers.RequestURIBasedDispatcher) PostMethod(org.apache.commons.httpclient.methods.PostMethod) ServiceContext(org.apache.axis2.context.ServiceContext) AxisService(org.apache.axis2.description.AxisService) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) HttpClient(org.apache.commons.httpclient.HttpClient) MessageContext(org.apache.axis2.context.MessageContext) InOutAxisOperation(org.apache.axis2.description.InOutAxisOperation) TransportOutDescription(org.apache.axis2.description.TransportOutDescription) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with TransportOutDescription

use of org.apache.axis2.description.TransportOutDescription in project wso2-synapse by wso2.

the class VFSTransportDescriptionFactory method createTransportOutDescription.

public TransportOutDescription createTransportOutDescription() throws Exception {
    TransportOutDescription trpOutDesc = new TransportOutDescription("vfs");
    trpOutDesc.setSender(new VFSTransportSender());
    trpOutDesc.addParameter(new Parameter(VFSConstants.TRANSPORT_FILE_LOCKING, VFSConstants.TRANSPORT_FILE_LOCKING_ENABLED));
    return trpOutDesc;
}
Also used : Parameter(org.apache.axis2.description.Parameter) TransportOutDescription(org.apache.axis2.description.TransportOutDescription)

Example 8 with TransportOutDescription

use of org.apache.axis2.description.TransportOutDescription in project wso2-synapse by wso2.

the class ServiceUtils method receive.

/**
 * This will provide the mocking functionality of AxisEngine.receive() method.
 * when AxisEngine is mocked, this method can be used with doAnswer
 *
 * @param axis2MessageContext
 * @throws IOException
 * @throws HttpException
 */
public static void receive(MessageContext axis2MessageContext) throws IOException, HttpException {
    if (axis2MessageContext.getServiceContext() == null) {
        ServiceContext svcCtx = new ServiceContext();
        OperationContext opCtx = new OperationContext(new InOutAxisOperation(), svcCtx);
        axis2MessageContext.setServiceContext(svcCtx);
        axis2MessageContext.setOperationContext(opCtx);
    }
    PassThroughHttpSender sender = new PassThroughHttpSender();
    ConfigurationContext cfgCtx = new ConfigurationContext(new AxisConfiguration());
    sender.init(cfgCtx, new TransportOutDescription("http"));
    sender.invoke(axis2MessageContext);
}
Also used : OperationContext(org.apache.axis2.context.OperationContext) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) PassThroughHttpSender(org.apache.synapse.transport.passthru.PassThroughHttpSender) ServiceContext(org.apache.axis2.context.ServiceContext) InOutAxisOperation(org.apache.axis2.description.InOutAxisOperation) TransportOutDescription(org.apache.axis2.description.TransportOutDescription)

Example 9 with TransportOutDescription

use of org.apache.axis2.description.TransportOutDescription in project wso2-synapse by wso2.

the class FIXTransportListenerTest method testFIXTransportListenerInit.

@Test
public void testFIXTransportListenerInit() throws Exception {
    AxisService axisService = new AxisService("testFIXService");
    axisService.addParameter(new Parameter(FIXConstants.FIX_ACCEPTOR_CONFIG_URL_PARAM, "/sample/path/Mock.cfg"));
    axisService.addParameter(new Parameter(FIXConstants.FIX_INITIATOR_CONFIG_URL_PARAM, "/sample/path/Mock2.cfg"));
    ConfigurationContext cfgCtx = new ConfigurationContext(new AxisConfiguration());
    TransportDescriptionFactory transportDescriptionFactory = new TransportDescriptionFactory() {

        @Override
        public TransportOutDescription createTransportOutDescription() throws Exception {
            TransportOutDescription trpOutDesc = new TransportOutDescription("fix");
            trpOutDesc.setSender(new FIXTransportSender());
            return trpOutDesc;
        }

        @Override
        public TransportInDescription createTransportInDescription() throws Exception {
            TransportInDescription trpInDesc = new TransportInDescription("fix");
            trpInDesc.setReceiver(new FIXTransportListener());
            return trpInDesc;
        }
    };
    TransportInDescription transportInDescription = null;
    try {
        transportInDescription = transportDescriptionFactory.createTransportInDescription();
    } catch (Exception e) {
        logger.error(e);
        Assert.fail("Error occurred while creating transport in description");
    }
    FIXTransportListener listner = new FIXTransportListener();
    listner.init(cfgCtx, transportInDescription);
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) AxisService(org.apache.axis2.description.AxisService) Parameter(org.apache.axis2.description.Parameter) TransportInDescription(org.apache.axis2.description.TransportInDescription) TransportDescriptionFactory(org.apache.axis2.transport.testkit.axis2.TransportDescriptionFactory) TransportOutDescription(org.apache.axis2.description.TransportOutDescription) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 10 with TransportOutDescription

use of org.apache.axis2.description.TransportOutDescription in project wso2-synapse by wso2.

the class FIXTransportSenderTest method testFIXTransportSenderInit.

@Test
public void testFIXTransportSenderInit() throws Exception {
    AxisService axisService = new AxisService("testFIXService");
    axisService.addParameter(new Parameter(FIXConstants.FIX_ACCEPTOR_CONFIG_URL_PARAM, "/sample/path/Mock.cfg"));
    axisService.addParameter(new Parameter(FIXConstants.FIX_INITIATOR_CONFIG_URL_PARAM, "/sample/path/Mock2.cfg"));
    ConfigurationContext cfgCtx = new ConfigurationContext(new AxisConfiguration());
    TransportOutDescription trpOutDesc = new TransportOutDescription("fix");
    FIXTransportSender fixTransportSender = new FIXTransportSender();
    fixTransportSender.init(cfgCtx, trpOutDesc);
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) AxisService(org.apache.axis2.description.AxisService) Parameter(org.apache.axis2.description.Parameter) TransportOutDescription(org.apache.axis2.description.TransportOutDescription) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

TransportOutDescription (org.apache.axis2.description.TransportOutDescription)28 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)20 Parameter (org.apache.axis2.description.Parameter)17 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)16 MessageContext (org.apache.axis2.context.MessageContext)11 AxisFault (org.apache.axis2.AxisFault)9 QName (javax.xml.namespace.QName)7 OMElement (org.apache.axiom.om.OMElement)6 AxisService (org.apache.axis2.description.AxisService)6 TransportInDescription (org.apache.axis2.description.TransportInDescription)6 IOException (java.io.IOException)4 Map (java.util.Map)4 ServiceContext (org.apache.axis2.context.ServiceContext)4 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 HashMap (java.util.HashMap)3 OperationContext (org.apache.axis2.context.OperationContext)3 InOutAxisOperation (org.apache.axis2.description.InOutAxisOperation)3 OutTransportInfo (org.apache.axis2.transport.OutTransportInfo)3 VFSOutTransportInfo (org.apache.synapse.commons.vfs.VFSOutTransportInfo)3