import javax.xml.namespace.QName;

import java.net.MalformedURLException;
import java.net.URL;

import com.netaps.xml.webservices.DataSource;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.rpc.client.RPCServiceClient;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;

/**
 * <h4>Brief Description</h4> <p> </p> <h4>Usage and Examples</h4> <p> </p>
 * @author Amit
 * @since ${SinceVersion}
 */
public class TestAxis2ServiceClient
{
    public static void main(String[] args) throws AxisFault,InterruptedException
    {
        // creates a new connection manager and a http client object
        for (int i = 0; i < 1000; i++)
        {
            callWebservice();
        }
    }



    public static void callWebservice() throws AxisFault
    {
        RPCServiceClient serviceClient = new RPCServiceClient();
        Options options = serviceClient.getOptions();

        EndpointReference targetEPR = new EndpointReference(
                "http://localhost:9090/optessa/services/TestAxis2Service");
        options.setTo(targetEPR);

        serviceClient.getOptions().setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Constants.VALUE_TRUE);

        Object[] arguments = new Object[]{};
        QName opGetWeather =
                  new QName("http://webservices.optessa.com", "lookupDbConfigPrimary");

        Class[] returnTypes = new Class[]{String.class};

        Object[] object = serviceClient.invokeBlocking(opGetWeather, arguments,returnTypes);
        System.out.println(object[0]);

        // some cleanup
        serviceClient.cleanupTransport();
        serviceClient.cleanup();

    }
}
