Package org.wso2.esb.integration.servlet.transport

Source Code of org.wso2.esb.integration.servlet.transport.POXOverServletTransportTest

/*
*  Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
*  WSO2 Inc. licenses this file to you under the Apache License,
*  Version 2.0 (the "License"); you may not use this file except
*  in compliance with the License.
*  You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.esb.integration.servlet.transport;

import org.apache.axiom.om.OMElement;
import org.apache.axis2.AxisFault;
import org.apache.http.HttpRequest;
import org.wso2.esb.integration.ESBIntegrationTest;
import org.wso2.esb.integration.axis2.StockQuoteClient;
import org.wso2.esb.integration.http.RequestInterceptor;
import org.wso2.esb.integration.http.SimpleHttpServer;

import java.io.File;
import java.io.IOException;
import java.rmi.RemoteException;

/**
* This test case starts an ESB instance with the servlet transport and performs a SOAP to
* POX conversion through it. It makes sure that POX messages are passed to backend service
* properly. This test case verifies the fixes done for CARBON-5993.
*/
public class POXOverServletTransportTest extends ESBIntegrationTest {

    private StockQuoteClient axis2Client;

    @Override
    public void init() {
        super.init();
        axis2Client = new StockQuoteClient();
        log.info("Verifying functionality against the bug: CARBON-5993");
    }

    @Override
    protected void copyArtifacts() throws IOException {
        log.info("Updating axis2.xml to enable the servlet transports");

        String targetPath = "repository" + File.separator + "conf" + File.separator + "axis2.xml";
        copyResourceFile("/pox_servlet_transport_axis2.xml", targetPath);

        log.info("Successfully updated the axis2.xml file");
    }

    @Override
    public void successfulScenario() throws RemoteException {
        updateESBConfiguration("/soap_2_pox.xml");
        SimpleHttpServer httpServer = new SimpleHttpServer();
        try {
            httpServer.start();
        } catch (IOException e) {
            handleError("Error while starting the HTTP server", e);
        }

        TestRequestInterceptor interceptor = new TestRequestInterceptor();
        httpServer.getRequestHandler().setInterceptor(interceptor);

        try {
            OMElement response = axis2Client.sendSimpleStockQuoteRequest(
                    getProxyServiceURL("SOAP2POX", true),
                    "http://localhost:9000/services/SimpleStockQuoteService", "WSO2");
            log.info("Response received: " + response);
            assertEquals("/services/SimpleStockQuoteService", interceptor.getLastRequestURI());
        } catch (AxisFault axisFault) {
            handleError("Error while invoking the SOAP2POX proxy", axisFault);
        }

        try {
            httpServer.stop();
        } catch (IOException e) {
            log.warn("Error while shutting down the HTTP server", e);
        }
    }

    @Override
    public void cleanup() {
        super.cleanup();
        axis2Client.destroy();
    }

    private static class TestRequestInterceptor implements RequestInterceptor {

        private String lastRequestURI;

        public void requestReceived(HttpRequest request) {
            lastRequestURI = request.getRequestLine().getUri();
        }

        public String getLastRequestURI() {
            return lastRequestURI;
        }
    }
}
TOP

Related Classes of org.wso2.esb.integration.servlet.transport.POXOverServletTransportTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.