- 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");
No comments:
Post a Comment