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);
}
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;
}
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);
}
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);
}
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);
}
Aggregations