use of org.apache.axis2.engine.AxisConfiguration in project wso2-synapse by wso2.
the class ProxyServiceMessageReceiverTest method getMockedSynapseEnvironment.
/**
* Create a mock SynapseEnvironment object.
*
* @return Axis2SynapseEnvironment instance
* @throws AxisFault on creating/mocking object
*/
private Axis2SynapseEnvironment getMockedSynapseEnvironment() throws AxisFault {
Axis2SynapseEnvironment synapseEnvironment = PowerMockito.mock(Axis2SynapseEnvironment.class);
ConfigurationContext axis2ConfigurationContext = new ConfigurationContext(new AxisConfiguration());
Mockito.when(synapseEnvironment.getAxis2ConfigurationContext()).thenReturn(axis2ConfigurationContext);
return synapseEnvironment;
}
use of org.apache.axis2.engine.AxisConfiguration 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.engine.AxisConfiguration in project wso2-synapse by wso2.
the class PassThroughHttpSenderTest method testInit.
/**
* This method tests the initialization of PassThroughHttpSender
* @throws Exception
*/
@Test
public void testInit() throws Exception {
ConfigurationContext configurationContext = new ConfigurationContext(new AxisConfiguration());
WorkerPool workerPool = new NativeWorkerPool(3, 4, 5, 5, "name", "id");
configurationContext.setProperty(PassThroughConstants.PASS_THROUGH_TRANSPORT_WORKER_POOL, workerPool);
TransportOutDescription transportOutDescription = new TransportOutDescription("passthru");
PassThroughHttpSender passThroughHttpSender = new PassThroughHttpSender();
passThroughHttpSender.init(configurationContext, transportOutDescription);
}
use of org.apache.axis2.engine.AxisConfiguration in project wso2-synapse by wso2.
the class BaseConfigurationTest method setUp.
@Before
public void setUp() throws Exception {
Parameter portParam = new Parameter("port", PORT);
portParam.setParameterElement(AXIOMUtil.stringToOM("<parameter name=\"port\" locked=\"false\">" + PORT + "</parameter>"));
Parameter hostParam = new Parameter("hostname", HOST);
transportInDescription.addParameter(portParam);
transportInDescription.addParameter(hostParam);
cfgCtx = new ConfigurationContext(new AxisConfiguration());
cfgCtx.setServicePath("services");
cfgCtx.setContextRoot("/");
scheme = new Scheme(transportInDescription.getName(), PORT, false);
metrics = new PassThroughTransportMetricsCollector(true, scheme.getName());
baseConfiguration = new SourceConfiguration(cfgCtx, transportInDescription, scheme, PassThroughTestUtils.getWorkerPool(conf), metrics);
baseConfiguration.build();
}
use of org.apache.axis2.engine.AxisConfiguration in project wso2-synapse by wso2.
the class RelaySecuirtyMessageBuilderDispatchandler method invoke.
@Override
public InvocationResponse invoke(MessageContext messageContext) throws AxisFault {
InvocationResponse invocationResponse = super.invoke(messageContext);
EndpointReference toEPR = messageContext.getTo();
Pipe pipe = (Pipe) messageContext.getProperty(PassThroughConstants.PASS_THROUGH_PIPE);
if (pipe != null || RequestResponseUtils.isHttpCarbonMessagePresent(messageContext)) {
if (toEPR != null) {
ConfigurationContext configurationContext = messageContext.getConfigurationContext();
AxisConfiguration registry = configurationContext.getAxisConfiguration();
String filePart = toEPR.getAddress();
if (filePart != null) {
String serviceOpPart = Utils.getServiceAndOperationPart(filePart, messageContext.getConfigurationContext().getServiceContextPath());
AxisService axisService = null;
// only service context path onwards values will be taken
if (messageContext.getConfigurationContext().getServiceContextPath() != null && serviceOpPart != null) {
axisService = registry.getService(serviceOpPart);
if (axisService != null) {
Parameter parameter = axisService.getParameter(SERVICE_TYPE);
if (parameter != null) {
if (!parameter.getValue().equals(PROXY)) {
build(messageContext);
}
} else {
build(messageContext);
}
}
}
}
}
if (messageContext.isEngaged(PassThroughConstants.SECURITY_MODULE_NAME)) {
SOAPHeader header = null;
if (messageContext.getEnvelope().getHeader() != null) {
header = messageContext.getEnvelope().getHeader();
}
build(messageContext);
this.handlePOXRequests(messageContext, header);
}
}
return invocationResponse;
}
Aggregations