- Invoking Web Services through a proxy using JAX-RPC
- Invoking Web Services through a proxy using JAX-WS
There's More ...
Invoking Web Services through a proxy using JAX-RPC
- Generate the Web Service Proxy classes using the following ant task.
<taskdef name="clientgen" classname="weblogic.wsee.tools.anttasks.ClientGenTask" />
<target name="build-client">
<clientgen
wsdl="[path_to_WSDL]"
destDir="./src"
packageName="com.my.client"
type="JAXRPC"/>
</target> - When the client classes are generated the type as JAXRPC, the generated classes will consist of Service, ServiceImpl, PortType and ProtTypeImpl etc files. To invoke the service you have to create the PortType from the Service. When working behind a proxy, you have to instantiate the ServiceImpl by using a constructor that takes in a weblogic.wsee.connection.transport.http.HttpTransportInfo.HttpTransportInfo object as a parameter as shown below.
private HttpTransportInfo getHttpInfo() {
When using SSL, you can use the weblogic.wsee.connection.transport.https.HttpsTransportInfo class which can be created in the same way as above.
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxyServer", 9090));
HttpTransportInfo httpInfo = new HttpTransportInfo();
httpInfo.setProxy(proxy);
httpInfo.setProxyUsername("proxyuser".getBytes());
httpInfo.setProxyPassword("proxypassword".getBytes());
return httpInfo;
}
Invoking Web Services through a proxy using JAX-WS
- When using JAX-WS, you have to change the clientgen task's "type" attribute to JAXWS, as shown below
<taskdef name="clientgen" classname="weblogic.wsee.tools.anttasks.ClientGenTask" />
Make sure that the "path_to_WSDL" is to a local copy of the WSDL, as the properties which we set in the following steps are after the initialization of the service.
<target name="build-client">
<clientgen
wsdl="[path_to_WSDL]"
destDir="./src"
packageName="com.my.client"
type="JAXWS"/>
</target> - Running clientgen with JAXWS will create classes of the type *Service and *ServiceSoap
- Setting up the client for proxy server involves setting a couple of request paramters: Username and password as shown below.
MyService service = null;
Note that we don't specify the Proxy Server here. JAX-WS sends authentication information for the proxy in request headers.
service = new MyService();
MyServiceSoap port = service.getMyServiceSoap();
BindingProvider bp = (BindingProvider) port;
Binding binding = bp.getBinding();
Map<String, Object> ctx = bp.getRequestContext();
ctx.put(BindingProvider.USERNAME_PROPERTY, "proxyuser");
ctx.put(BindingProvider.PASSWORD_PROPERTY, "proxypassword");
Hi Abhi,
ReplyDeleteJust wondering if you're interested in contributing to http://www.jtraining.com. We've just launched and are looking for some quality Java content. Hope to see you there!
Many thanks, cheers.
The Web Services Invocation Framework (WSIF) is a simple Java API for invoking Web services, no matter how or where the services are provided. Please refer to the release notes before you proceed with using WSIF.
ReplyDeletevitamin a
Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites
ReplyDeleteinternship for web development | internship in electrical engineering | mini project topics for it 3rd year | online internship with certificate | final year project for cse