Search in sources :

Example 76 with AxisConfiguration

use of org.apache.axis2.engine.AxisConfiguration in project wso2-synapse by wso2.

the class DeferredMessageBuilder method getDocument.

public OMElement getDocument(MessageContext msgCtx, InputStream in) throws XMLStreamException, IOException {
    /**
     * HTTP Delete requests may contain entity body or not. Hence if the request is a HTTP DELETE, we have to verify
     * that the payload stream is empty or not.
     */
    if (HTTPConstants.HEADER_DELETE.equals(msgCtx.getProperty(Constants.Configuration.HTTP_METHOD)) && RelayUtils.isEmptyPayloadStream(in)) {
        msgCtx.setProperty(PassThroughConstants.NO_ENTITY_BODY, Boolean.TRUE);
        return TransportUtils.createSOAPEnvelope(null);
    }
    String contentType = (String) msgCtx.getProperty(Constants.Configuration.CONTENT_TYPE);
    String _contentType = getContentType(contentType, msgCtx);
    in = HTTPTransportUtils.handleGZip(msgCtx, in);
    AxisConfiguration configuration = msgCtx.getConfigurationContext().getAxisConfiguration();
    Parameter useFallbackParameter = configuration.getParameter(Constants.Configuration.USE_DEFAULT_FALLBACK_BUILDER);
    boolean useFallbackBuilder = false;
    if (useFallbackParameter != null) {
        useFallbackBuilder = JavaUtils.isTrueExplicitly(useFallbackParameter.getValue(), useFallbackBuilder);
    }
    Map transportHeaders = (Map) msgCtx.getProperty(MessageContext.TRANSPORT_HEADERS);
    String contentLength = null;
    String trasferEncoded = null;
    if (transportHeaders != null) {
        contentLength = (String) transportHeaders.get(HTTP.CONTENT_LEN);
        trasferEncoded = (String) transportHeaders.get(HTTP.TRANSFER_ENCODING);
        if (contentType.equals(PassThroughConstants.DEFAULT_CONTENT_TYPE) && (contentLength == null || Integer.valueOf(contentLength) == 0) && trasferEncoded == null) {
            msgCtx.setProperty(PassThroughConstants.NO_ENTITY_BODY, true);
            msgCtx.setProperty(Constants.Configuration.CONTENT_TYPE, "");
            msgCtx.setProperty(PassThroughConstants.RELAY_EARLY_BUILD, true);
            return new SOAP11Factory().getDefaultEnvelope();
        }
    }
    OMElement element = null;
    Builder builder;
    if (contentType != null) {
        // loading builder from externally..
        // builder = configuration.getMessageBuilder(_contentType,useFallbackBuilder);
        builder = MessageProcessorSelector.getMessageBuilder(_contentType, msgCtx);
        if (builder != null) {
            try {
                if (contentLength != null && "0".equals(contentLength) && !msgCtx.isDoingREST()) {
                    element = new org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory().getDefaultEnvelope();
                    // since we are setting an empty envelop to achieve the empty body, we have to set a different
                    // content-type other than text/xml, application/soap+xml or any other content-type which will
                    // invoke the soap builder, otherwise soap builder will get hit and an empty envelope
                    // will be send out
                    msgCtx.setProperty(Constants.Configuration.MESSAGE_TYPE, "application/xml");
                } else {
                    element = builder.processDocument(in, contentType, msgCtx);
                }
            } catch (AxisFault axisFault) {
                log.error("Error building message", axisFault);
                throw axisFault;
            }
        }
    }
    if (element == null) {
        if (msgCtx.isDoingREST()) {
            try {
                element = BuilderUtil.getPOXBuilder(in, null).getDocumentElement();
            } catch (XMLStreamException e) {
                log.error("Error building message using POX Builder", e);
                throw e;
            }
        } else {
            // switch to default
            builder = new SOAPBuilder();
            try {
                if (contentLength != null && "0".equals(contentLength)) {
                    element = new SOAP11Factory().getDefaultEnvelope();
                    // since we are setting an empty envelop to achieve the empty body, we have to set a different
                    // content-type other than text/xml, application/soap+xml or any other content-type which will
                    // invoke the soap builder, otherwise soap builder will get hit and an empty envelope
                    // will be send out
                    msgCtx.setProperty(Constants.Configuration.MESSAGE_TYPE, "application/xml");
                } else {
                    element = builder.processDocument(in, contentType, msgCtx);
                }
            } catch (AxisFault axisFault) {
                log.error("Error building message using SOAP builder");
                throw axisFault;
            }
        }
    }
    // build the soap headers and body
    if (element instanceof SOAPEnvelope) {
        SOAPEnvelope env = (SOAPEnvelope) element;
        env.hasFault();
    }
    // setting up original contentType (resetting the content type)
    if (contentType != null && !contentType.isEmpty()) {
        msgCtx.setProperty(Constants.Configuration.CONTENT_TYPE, contentType);
    }
    return element;
}
Also used : AxisFault(org.apache.axis2.AxisFault) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) OMElement(org.apache.axiom.om.OMElement) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) XMLStreamException(javax.xml.stream.XMLStreamException) SOAP11Factory(org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory) Parameter(org.apache.axis2.description.Parameter) HashMap(java.util.HashMap) Map(java.util.Map)

Example 77 with AxisConfiguration

use of org.apache.axis2.engine.AxisConfiguration in project pentaho-platform by pentaho.

the class AxisServiceExecutorTest method setUp.

@Before
public void setUp() throws Exception {
    StandaloneSession session = new StandaloneSession("test");
    StubServiceSetup serviceSetup = new StubServiceSetup();
    serviceSetup.setSession(session);
    AxisConfiguration axisCfg = serviceSetup.getAxisConfiguration();
    ConfigurationContext configContext = new ConfigurationContext(axisCfg);
    serviceSetup.loadServices();
    TransportInDescription tIn = new TransportInDescription(DEAFULT_TRANSPOT_PROTOCOL);
    StubTransportListener receiver = new StubTransportListener();
    tIn.setReceiver(receiver);
    axisCfg.addTransportIn(tIn);
    TransportOutDescription tOut = new TransportOutDescription(DEAFULT_TRANSPOT_PROTOCOL);
    StubTransportSender sender = new StubTransportSender();
    tOut.setSender(sender);
    axisCfg.addTransportOut(tOut);
    AxisWebServiceManager.currentAxisConfiguration = axisCfg;
    AxisWebServiceManager.currentAxisConfigContext = configContext;
    out = new ByteArrayOutputStream();
    IOutputHandler outputHandler = new SimpleOutputHandler(out, false);
    outputHandler.setMimeTypeListener(new MimeTypeListener());
    contentGenerator = new AxisServiceExecutor();
    contentGenerator.setOutputHandler(outputHandler);
    contentGenerator.setMessagesList(new ArrayList<String>());
    contentGenerator.setSession(session);
    contentGenerator.setUrlFactory(new SimpleUrlFactory(BASE_URL + "?"));
    assertNotNull("contentGenerator is null", contentGenerator);
    assertNotNull("Logger is null", contentGenerator.getLogger());
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) StubTransportSender(org.pentaho.test.platform.plugin.services.webservices.StubTransportSender) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) TransportInDescription(org.apache.axis2.description.TransportInDescription) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOutputHandler(org.pentaho.platform.api.engine.IOutputHandler) StubServiceSetup(org.pentaho.test.platform.plugin.services.webservices.StubServiceSetup) MimeTypeListener(org.pentaho.test.platform.plugin.services.webservices.MimeTypeListener) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) StubTransportListener(org.pentaho.test.platform.plugin.services.webservices.StubTransportListener) TransportOutDescription(org.apache.axis2.description.TransportOutDescription) Before(org.junit.Before)

Example 78 with AxisConfiguration

use of org.apache.axis2.engine.AxisConfiguration in project pentaho-platform by pentaho.

the class WsdlPageTest method setUp.

@Before
public void setUp() {
    beforeTestCfg = AxisWebServiceManager.currentAxisConfiguration;
    beforeTestCtx = AxisWebServiceManager.currentAxisConfigContext;
    AxisConfiguration axisCfg = new AxisConfiguration();
    AxisWebServiceManager.currentAxisConfiguration = axisCfg;
    AxisWebServiceManager.currentAxisConfigContext = new ConfigurationContext(axisCfg);
    out = new ByteArrayOutputStream();
    IOutputHandler outputHandler = new SimpleOutputHandler(out, false);
    outputHandler.setMimeTypeListener(new MimeTypeListener());
    StandaloneSession session = new StandaloneSession("test");
    StubServiceSetup serviceSetup = new StubServiceSetup();
    serviceSetup.setSession(session);
    contentGenerator = new AxisServiceWsdlGenerator();
    contentGenerator.setOutputHandler(outputHandler);
    contentGenerator.setMessagesList(new ArrayList<String>());
    contentGenerator.setSession(session);
    contentGenerator.setUrlFactory(new SimpleUrlFactory(BASE_URL + "?"));
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisServiceWsdlGenerator(org.pentaho.platform.plugin.services.webservices.content.AxisServiceWsdlGenerator) IOutputHandler(org.pentaho.platform.api.engine.IOutputHandler) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) Before(org.junit.Before)

Example 79 with AxisConfiguration

use of org.apache.axis2.engine.AxisConfiguration in project wso2-synapse by wso2.

the class TargetResponseTest method testCompletingStateTransition.

@Test
public void testCompletingStateTransition() throws Exception {
    PowerMockito.whenNew(DefaultConnectionReuseStrategy.class).withNoArguments().thenReturn(connStrategy);
    PowerMockito.when(connStrategy.keepAlive(any(HttpResponse.class), any(HttpContext.class))).thenReturn(true);
    ConfigurationContext configurationContext = new ConfigurationContext(new AxisConfiguration());
    WorkerPool workerPool = new NativeWorkerPool(3, 4, 5, 5, "name", "id");
    PassThroughTransportMetricsCollector metrics = new PassThroughTransportMetricsCollector(true, "testScheme");
    TargetConfiguration targetConfiguration = new TargetConfiguration(configurationContext, null, workerPool, metrics, null);
    HttpResponse response = PowerMockito.mock(HttpResponse.class, Mockito.RETURNS_DEEP_STUBS);
    NHttpClientConnection conn = PowerMockito.mock(NHttpClientConnection.class, Mockito.RETURNS_DEEP_STUBS);
    TargetConnections connections = PowerMockito.mock(TargetConnections.class);
    targetConfiguration.setConnections(connections);
    PowerMockito.mockStatic(TargetContext.class);
    TargetResponse targetResponse = new TargetResponse(targetConfiguration, response, conn, false, false);
    try {
        targetResponse.start(conn);
        // Verify that the following mock method was called exactly 1 time
        PowerMockito.verifyStatic(Mockito.times(1));
        TargetContext.updateState(conn, ProtocolState.RESPONSE_DONE);
    } catch (Exception e) {
        logger.error(e);
        Assert.fail("Unable to start the target response!");
    }
}
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) TargetConfiguration(org.apache.synapse.transport.passthru.config.TargetConfiguration) PassThroughTransportMetricsCollector(org.apache.synapse.transport.passthru.jmx.PassThroughTransportMetricsCollector) NativeWorkerPool(org.apache.axis2.transport.base.threads.NativeWorkerPool) HttpContext(org.apache.http.protocol.HttpContext) HttpResponse(org.apache.http.HttpResponse) TargetConnections(org.apache.synapse.transport.passthru.connections.TargetConnections) NHttpClientConnection(org.apache.http.nio.NHttpClientConnection) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 80 with AxisConfiguration

use of org.apache.axis2.engine.AxisConfiguration in project wso2-synapse by wso2.

the class TargetResponseTest method testRead.

/**
 * Testing reading from a pipe
 * @throws Exception
 */
@Test
public void testRead() throws Exception {
    ConfigurationContext configurationContext = new ConfigurationContext(new AxisConfiguration());
    WorkerPool workerPool = new NativeWorkerPool(3, 4, 5, 5, "name", "id");
    PassThroughTransportMetricsCollector metrics = new PassThroughTransportMetricsCollector(true, "testScheme");
    TargetConfiguration targetConfiguration = new TargetConfiguration(configurationContext, null, workerPool, metrics, null);
    targetConfiguration.build();
    HttpResponse response = PowerMockito.mock(HttpResponse.class, Mockito.RETURNS_DEEP_STUBS);
    NHttpClientConnection conn = PowerMockito.mock(NHttpClientConnection.class, Mockito.RETURNS_DEEP_STUBS);
    ContentDecoder decoder = PowerMockito.mock(ContentDecoder.class);
    TargetConnections connections = PowerMockito.mock(TargetConnections.class);
    targetConfiguration.setConnections(connections);
    PowerMockito.mockStatic(TargetContext.class);
    PowerMockito.mockStatic(HttpRequest.class);
    HttpRequest httpRequest = new BasicHttpRequest("GET", "test.com");
    PowerMockito.when(conn.getContext().getAttribute("http.request")).thenReturn(httpRequest);
    TargetContext cntxt = new TargetContext(targetConfiguration);
    PowerMockito.when(TargetContext.get(any(NHttpClientConnection.class))).thenReturn(cntxt);
    PowerMockito.when(decoder.read(any(ByteBuffer.class))).thenReturn(12);
    PowerMockito.when(decoder.isCompleted()).thenReturn(true);
    TargetResponse targetResponse = new TargetResponse(targetConfiguration, response, conn, true, false);
    targetResponse.start(conn);
    int result = targetResponse.read(conn, decoder);
    Assert.assertEquals(12, result);
}
Also used : BasicHttpRequest(org.apache.http.message.BasicHttpRequest) HttpRequest(org.apache.http.HttpRequest) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) TargetConfiguration(org.apache.synapse.transport.passthru.config.TargetConfiguration) PassThroughTransportMetricsCollector(org.apache.synapse.transport.passthru.jmx.PassThroughTransportMetricsCollector) NativeWorkerPool(org.apache.axis2.transport.base.threads.NativeWorkerPool) ContentDecoder(org.apache.http.nio.ContentDecoder) HttpResponse(org.apache.http.HttpResponse) NHttpClientConnection(org.apache.http.nio.NHttpClientConnection) ByteBuffer(java.nio.ByteBuffer) BasicHttpRequest(org.apache.http.message.BasicHttpRequest) WorkerPool(org.apache.axis2.transport.base.threads.WorkerPool) NativeWorkerPool(org.apache.axis2.transport.base.threads.NativeWorkerPool) TargetConnections(org.apache.synapse.transport.passthru.connections.TargetConnections) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

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