Pashok
Pashok

Reputation: 157

Connection to web service through proxy

I've created java code from wsdl file using wsimport.

I want to connect to a web service using proxy, i got this code (generated):

package siri.siriservices;

import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.WebServiceFeature;


/**
 * This class was generated by the JAX-WS RI.
 * JAX-WS RI 2.2.4-b01
 * Generated source version: 2.2
 * 
 */
@WebServiceClient(name = "SiriServices", targetNamespace = "http://someip/Siri/SiriServices/", wsdlLocation = "file:/C:/Users/Pavel/git/stop-scanner/StopScanner/SIRI%20-%20ISRAEL/siri_wsProducer%20-%20Israel.wsdl")
public class SiriServices
    extends Service
{

    private final static URL SIRISERVICES_WSDL_LOCATION;
    private final static WebServiceException SIRISERVICES_EXCEPTION;
    private final static QName SIRISERVICES_QNAME = new QName("http://someip/Siri/SiriServices/", "SiriServices");

    static {
        URL url = null;
        WebServiceException e = null;
        try {
            url = new URL("file:/C:/Users/Pavel/git/stop-scanner/StopScanner/SIRI%20-%20ISRAEL/siri_wsProducer%20-%20Israel.wsdl");
        } catch (MalformedURLException ex) {
            e = new WebServiceException(ex);
        }
        SIRISERVICES_WSDL_LOCATION = url;
        SIRISERVICES_EXCEPTION = e;
    }

    public SiriServices() {
        super(__getWsdlLocation(), SIRISERVICES_QNAME);
    }

    public SiriServices(WebServiceFeature... features) {
        super(__getWsdlLocation(), SIRISERVICES_QNAME, features);
    }

    public SiriServices(URL wsdlLocation) {
        super(wsdlLocation, SIRISERVICES_QNAME);
    }

    public SiriServices(URL wsdlLocation, WebServiceFeature... features) {
        super(wsdlLocation, SIRISERVICES_QNAME, features);
    }

    public SiriServices(URL wsdlLocation, QName serviceName) {
        super(wsdlLocation, serviceName);
    }

    public SiriServices(URL wsdlLocation, QName serviceName, WebServiceFeature... features) {
        super(wsdlLocation, serviceName, features);
    }

    /**
     * 
     * @return
     *     returns SOAPPort
     */
    @WebEndpoint(name = "SiriWSPort")
    public SOAPPort getSiriWSPort() {
        return super.getPort(new QName("http://someip/Siri/SiriServices/", "SiriWSPort"), SOAPPort.class);
    }

    /**
     * 
     * @param features
     *     A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy.  Supported features not in the <code>features</code> parameter will have their default values.
     * @return
     *     returns SOAPPort
     */
    @WebEndpoint(name = "SiriWSPort")
    public SOAPPort getSiriWSPort(WebServiceFeature... features) {
        return super.getPort(new QName("http://someip/Siri/SiriServices/", "SiriWSPort"), SOAPPort.class, features);
    }

    private static URL __getWsdlLocation() {
        if (SIRISERVICES_EXCEPTION!= null) {
            throw SIRISERVICES_EXCEPTION;
        }
        return SIRISERVICES_WSDL_LOCATION;
    }

}

I have an option to configure the proxy passing WebServiceFeature to getSiriWSPort constructor as described in the comment:

 /**
     * 
     * @param features
     *     A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy.  Supported features not in the <code>features</code> parameter will have their default values.
     * @return
     *     returns SOAPPort
     */
    @WebEndpoint(name = "SiriWSPort")
    public SOAPPort getSiriWSPort(WebServiceFeature... features) {
        return super.getPort(new QName("http://someip/Siri/SiriServices/", "SiriWSPort"), SOAPPort.class, features);
    }

I found some info about the configuration here, but i can't find jar containing ClientProxyFeature.

Thanks!

Upvotes: 4

Views: 7349

Answers (1)

NeplatnyUdaj
NeplatnyUdaj

Reputation: 6242

You should have a look at CXF.

I'm using CXF-based client with http proxy and certificate authentication and it works quite good. I don't have IDE by hand, but in your case I guess it could look something like this:

SiriServices siri = new SiriServices();
SOAPPort port = siri.getSiriWSPort();
org.apache.cxf.endpoint.Client client = ClientProxy.getClient(port);
HTTPConduit conduit = (HTTPConduit) client.getConduit();
conduit.getClient().setProxyServer("...");
conduit.getClient().setProxyServerPort(...);

Upvotes: 1

Related Questions