use of org.apache.axis2.context.ServiceContext in project wso2-synapse by wso2.
the class OAuthUtilsTest method createMessageContext.
/**
* Create a empty message context
*
* @return A context with empty message
* @throws AxisFault on an error creating a context
*/
private static MessageContext createMessageContext() throws AxisFault {
Axis2SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(new SynapseConfiguration());
org.apache.axis2.context.MessageContext axis2MC = new org.apache.axis2.context.MessageContext();
axis2MC.setConfigurationContext(new ConfigurationContext(new AxisConfiguration()));
ServiceContext svcCtx = new ServiceContext();
OperationContext opCtx = new OperationContext(new InOutAxisOperation(), svcCtx);
axis2MC.setServiceContext(svcCtx);
axis2MC.setOperationContext(opCtx);
axis2MC.setTransportIn(new TransportInDescription("http"));
MessageContext mc = new Axis2MessageContext(axis2MC, new SynapseConfiguration(), synapseEnvironment);
mc.setMessageID(UIDGenerator.generateURNString());
mc.setEnvelope(OMAbstractFactory.getSOAP12Factory().createSOAPEnvelope());
mc.getEnvelope().addChild(OMAbstractFactory.getSOAP12Factory().createSOAPBody());
return mc;
}
use of org.apache.axis2.context.ServiceContext in project wso2-synapse by wso2.
the class DynamicLoadBalanceEndpointTest method createMessageContext.
/**
* Create a empty message context
*
* @return A context with empty message
* @throws AxisFault on an error creating a context
*/
private MessageContext createMessageContext() throws AxisFault {
Axis2SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(new SynapseConfiguration());
org.apache.axis2.context.MessageContext axis2MC = new org.apache.axis2.context.MessageContext();
axis2MC.setConfigurationContext(new ConfigurationContext(new AxisConfiguration()));
ServiceContext svcCtx = new ServiceContext();
OperationContext opCtx = new OperationContext(new InOutAxisOperation(), svcCtx);
axis2MC.setServiceContext(svcCtx);
axis2MC.setOperationContext(opCtx);
axis2MC.setTransportIn(new TransportInDescription("http"));
axis2MC.setTo(new EndpointReference("http://localhost:9000/services/SimpleStockQuoteService"));
MessageContext mc = new Axis2MessageContext(axis2MC, new SynapseConfiguration(), synapseEnvironment);
mc.setMessageID(UIDGenerator.generateURNString());
mc.setEnvelope(OMAbstractFactory.getSOAP12Factory().createSOAPEnvelope());
mc.getEnvelope().addChild(OMAbstractFactory.getSOAP12Factory().createSOAPBody());
return mc;
}
use of org.apache.axis2.context.ServiceContext 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.context.ServiceContext in project wso2-synapse by wso2.
the class RequestResponseTest 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 {
PowerMockito.mockStatic(AxisEngine.class);
PowerMockito.doAnswer(new Answer<Void>() {
public Void answer(InvocationOnMock invocation) throws Exception {
MessageContext axis2MessageContext = invocation.getArgument(0);
axis2MessageContext.setTo(null);
if (axis2MessageContext.getServiceContext() == null) {
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");
ServiceUtils.receive(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);
String response = method.getResponseBodyAsString();
Assert.assertEquals("Response code mismatched", 200, responseCode);
Assert.assertEquals("Response", "<msg>hello</msg>", response);
}
use of org.apache.axis2.context.ServiceContext 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);
}
Aggregations