Using the HttpTransportInfo API to Specify the Proxy Server

6-14 Getting Started With JAX-RPC Web Services for Oracle WebLogic Server 2. Unzip the wseeclient.zip file into the appropriate directory. For example, you might unzip the file into a directory that contains other classes used by your client application. 3. Add the wseeclient.jar file unzipped from the wseeclient.zip file to your CLASSPATH.

6.5 Using a Proxy Server When Invoking a Web Service

You can use a proxy server to proxy requests from a client application to an application server either WebLogic or non-WebLogic that hosts the invoked Web service. You typically use a proxy server when the application server is behind a firewall. There are two ways to specify the proxy server in your client application: programmatically using the WebLogic HttpTransportInfo API or using system properties.

6.5.1 Using the HttpTransportInfo API to Specify the Proxy Server

You can programmatically specify within the Java client application itself the details of the proxy server that will proxy the Web service invoke by using the standard java.net. classes and the WebLogic-specific HttpTransportInfo API. You use the java.net classes to create a Proxy object that represents the proxy server, and then use the WebLogic API and properties to set the proxy server on the JAX-RPC stub, as shown in the following sample client that invokes the echo operation of the HttpProxySampleService Web service. The code in bold is described after the example: package dev2dev.proxy.client; import java.net.Proxy; import java.net.InetSocketAddress; import weblogic.wsee.connection.transport.http.HttpTransportInfo; Sample client to invoke a service through a proxy server via programmatic API public class HttpProxySampleClient { public static void mainString[] args throws Throwable{ assert args.length == 5; String endpoint = args[0]; String proxyHost = args[1]; String proxyPort = args[2]; String user = args[3]; String pass = args[4]; create service and port HttpProxySampleService service = new HttpProxySampleService_Impl; HttpProxySamplePortType port = service.getHttpProxySamplePortTypeSoapPort; set endpoint address Stubport._setPropertyStub.ENDPOINT_ADDRESS_PROPERTY, endpoint; set proxy server info Proxy p = new ProxyProxy.Type.HTTP, new InetSocketAddressproxyHost, Integer.parseIntproxyPort; HttpTransportInfo info = new HttpTransportInfo; info.setProxyp; Note: Also be sure that your CLASSPATH includes the JAR file that contains the Ant classes ant.jar. This JAR file is typically located in the lib directory of the Ant distribution. Invoking Web Services 6-15 Stubport._setPropertyweblogic.wsee.connection.transportinfo,info; set proxy-authentication info Stubport._setPropertyweblogic.webservice.client.proxyusername,user; Stubport._setPropertyweblogic.webservice.client.proxypassword,pass; invoke String s = port.echoHello World; System.out.printlnecho: + s; } } The sections of the preceding example to note are as follows: ■ Import the required java.net. classes: import java.net.Proxy; import java.net.InetSocketAddress; ■ Import the WebLogic HttpTransportInfo API: import weblogic.wsee.connection.transport.http.HttpTransportInfo; ■ Create a Proxy object that represents the proxy server: Proxy p = new ProxyProxy.Type.HTTP, new InetSocketAddressproxyHost, Integer.parseIntproxyPort; The proxyHost and proxyPort arguments refer to the host computer and port of the proxy server. ■ Create an HttpTransportInfo object and use the setProxy method to set the proxy server information: HttpTransportInfo info = new HttpTransportInfo; info.setProxyp; ■ Use the weblogic.wsee.connection.transportinfo WebLogic stub property to set the HttpTransportInfo object on the JAX-RPC stub: Stubport._setPropertyweblogic.wsee.connection.transportinfo,info; ■ Use weblogic.webservice.client.proxyusername and weblogic.webservice.client.proxypassword WebLogic-specific stub properties to specify the username and password of a user who is authenticated to access the proxy server: Stubport._setPropertyweblogic.webservice.client.proxyusername,user; Stubport._ setPropertyweblogic.webservice.client.proxypassword,pass; Alternatively, you can use the setProxyUsername and setProxyPassword methods of the HttpTransportInfo API to set the proxy username and password, as shown in the following example: info.setProxyUsernamejuliet.getBytes; info.setProxyPasswordsecret.getBytes;

6.5.2 Using System Properties to Specify the Proxy Server