You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by al...@abuis.net on 2012/06/26 19:20:34 UTC
Programmatically creating service from WSDL URL through http proxy
I'm trying to use a CXF generated client to connect to a web service. The
problem however is that in order to connect to the service I need to
connect through a (HTTP) proxy.
I found plenty of documentation on how to configure a proxy when using
Spring, or how to programmatically setup a http proxy for a service port,
but I cannot find any hints on how to programmatically configure a HTTP
proxy to be used when creating the service from the WSDL URL.
Using Spring is not an option (I'm am building a small component that runs
in a huge framework in which the authors do not want to include Spring).
So I need to solve it programmatically, but all documentation I have found
presents a bootstrap problem, best explained using example:
http://cxf.apache.org/docs/client-http-transport-including-ssl-support.html#ClientHTTPTransport%28includingSSLsupport%29-HowtoconfiguretheHTTPConduitfortheSOAPClient%3F
:
SoapService service = new SoapService(wsdlURL);
MyPort port = service.getMyPort();
Client client = ClientProxy.getClient(port);
HTTPConduit http = (HTTPConduit) client.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
httpClientPolicy.setProxyServer("1.2.3.4");
httpClientPolicy.setProxyServerPort(8088);
httpClientPolicy.setProxyServerType(ProxyServerType.HTTP);
http.setClient(httpClientPolicy);
This example clearly explains how to set a proxy once you have a port for
the service, but as one can see, the initial service object is created
from a WDSL URL, but how to configure CXF to also use a HTTP Proxy when
connecting to that initial WSDL URL?
I have also tried to use the standard mechanisms from Java to configure a
JVM global proxy servers (using -Dhttp.proxyHost, -Dhttp.proxyPort and
related system properties), but this has proven to not be reliable, hence
the effort to explicitly configure the proxy from code. (Standalone
app/client works fine using (just) these system properties, but when
embedded in the target framework (some of) these properties seem to be
ignored: No HTTPS proxy will be used if no HTTP proxy is set, no matter
what (HTTP/HTTPS) proxy ports are configured, for HTTPS it always tries to
connect to port 443, no matter what proxy port has been configured)
Any help/hints on this is appreciated :-)
Thanks in advance!
--Alex Buisman
Re: Programmatically creating service from WSDL URL through http proxy
Posted by Daniel Kulp <dk...@apache.org>.
Hmm... this is definitely not an "easy" thing to do. If you are using CXF
2.6.x, it IS quite a bit easier and I'd definitely recommend upgrading to
2.6.x for this use case.
With 2.6.x, you can create an instance of:
org.apache.cxf.transport.http.HTTPConduitConfigurer
and call:
Bus bus = BusFactory.getDefaultBus();
// or similar to get the bus you will use
bus.setExtension(HTTPConduitConfigurer.class, myConfig)
to register it. The runtime will call off to that object when a conduit
is created giving you the opportunity to configure the conduit with any
settings you may need.
If you are stuck with 2.5.x or older, you would need to grab the
Configurer.class extension from the Bus, wrapper it with a new one that
would trap the Conduit config calls, and set the new one onto the Bus.
Completely doable, but a bit more complex.
Dan
On Tuesday, June 26, 2012 07:20:34 PM alex@abuis.net wrote:
> I'm trying to use a CXF generated client to connect to a web service. The
> problem however is that in order to connect to the service I need to
> connect through a (HTTP) proxy.
>
> I found plenty of documentation on how to configure a proxy when using
> Spring, or how to programmatically setup a http proxy for a service port,
> but I cannot find any hints on how to programmatically configure a HTTP
> proxy to be used when creating the service from the WSDL URL.
>
> Using Spring is not an option (I'm am building a small component that runs
> in a huge framework in which the authors do not want to include Spring).
> So I need to solve it programmatically, but all documentation I have
> found presents a bootstrap problem, best explained using example:
> http://cxf.apache.org/docs/client-http-transport-including-ssl-support.htm
> l#ClientHTTPTransport%28includingSSLsupport%29-HowtoconfiguretheHTTPCondui
> tfortheSOAPClient%3F
>
>
> SoapService service = new SoapService(wsdlURL);
> MyPort port = service.getMyPort();
>
> Client client = ClientProxy.getClient(port);
> HTTPConduit http = (HTTPConduit) client.getConduit();
> HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
>
> httpClientPolicy.setProxyServer("1.2.3.4");
> httpClientPolicy.setProxyServerPort(8088);
> httpClientPolicy.setProxyServerType(ProxyServerType.HTTP);
>
> http.setClient(httpClientPolicy);
>
> This example clearly explains how to set a proxy once you have a port for
> the service, but as one can see, the initial service object is created
> from a WDSL URL, but how to configure CXF to also use a HTTP Proxy when
> connecting to that initial WSDL URL?
>
> I have also tried to use the standard mechanisms from Java to configure a
> JVM global proxy servers (using -Dhttp.proxyHost, -Dhttp.proxyPort and
> related system properties), but this has proven to not be reliable, hence
> the effort to explicitly configure the proxy from code. (Standalone
> app/client works fine using (just) these system properties, but when
> embedded in the target framework (some of) these properties seem to be
> ignored: No HTTPS proxy will be used if no HTTP proxy is set, no matter
> what (HTTP/HTTPS) proxy ports are configured, for HTTPS it always tries to
> connect to port 443, no matter what proxy port has been configured)
>
> Any help/hints on this is appreciated :-)
>
> Thanks in advance!
>
> --Alex Buisman
--
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com