Search in sources :

Example 71 with AxisConfiguration

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;
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration)

Example 72 with AxisConfiguration

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);
}
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 73 with AxisConfiguration

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);
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) WorkerPool(org.apache.axis2.transport.base.threads.WorkerPool) NativeWorkerPool(org.apache.axis2.transport.base.threads.NativeWorkerPool) NativeWorkerPool(org.apache.axis2.transport.base.threads.NativeWorkerPool) TransportOutDescription(org.apache.axis2.description.TransportOutDescription) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 74 with AxisConfiguration

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();
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) Scheme(org.apache.synapse.transport.http.conn.Scheme) PassThroughTransportMetricsCollector(org.apache.synapse.transport.passthru.jmx.PassThroughTransportMetricsCollector) Parameter(org.apache.axis2.description.Parameter) Before(org.junit.Before)

Example 75 with AxisConfiguration

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;
}
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) Pipe(org.apache.synapse.transport.passthru.Pipe) SOAPHeader(org.apache.axiom.soap.SOAPHeader) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Aggregations

AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)211 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)122 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)95 Test (org.junit.Test)68 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)65 Parameter (org.apache.axis2.description.Parameter)62 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)62 OMElement (org.apache.axiom.om.OMElement)40 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)35 AxisService (org.apache.axis2.description.AxisService)33 DeploymentEngine (org.apache.axis2.deployment.DeploymentEngine)32 MessageContext (org.apache.synapse.MessageContext)32 AxisFault (org.apache.axis2.AxisFault)31 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)28 TransportOutDescription (org.apache.axis2.description.TransportOutDescription)21 DeploymentException (org.apache.axis2.deployment.DeploymentException)20 SynapseException (org.apache.synapse.SynapseException)20 IOException (java.io.IOException)19 XMLStreamException (javax.xml.stream.XMLStreamException)16 File (java.io.File)15