# How Do I: Use a Web Service from Behind a Proxy Server?

If you want to create a Web Service control that accesses an external web service and you are working form behind a proxy server such as a firewall, you first need to configure WebLogic Workshop to work with the proxy server. This configuration involves two separate steps. First, you need to configure the Weblogic Workshop IDE to recognize the proxy server. Second, you need to configure the WebLogic Workshop runtime.

To Configure the WebLogic Workshop IDE

1. From the Tools menu, select IDE Properties. The IDE Properties dialog appears.
2. In the left-hand pane, select Proxy Server.
3. In the right-hand pane, select Use Proxy Server, and provide the Hostname and port. If the proxy server requires authentication, select Proxy server requires authentication and provide a username and password. Click OK.

At this point you can design a web service control for an external web service in the IDE.

To Configure the WebLogic Workshop RunTime

To configure the WebLogic Workshop runtime, you must first create a JAR containing a SoapProxyAuthenticator class, and then configure WebLogic Workshop server to include the JAR.

#### To Build the Jar

To build the JAR, you need to create a Java project. For more information on working with a Java project, see How Do I: Reuse Existing Java Code?

To build the JAR:

1. Create a new Java project.
2. Create a source folder webservices, and in this folder create the Java file SoapProxyAuthenticator.java. Add the following code to this file, providing the correct values in the PROXY_USER and PROXY_PASSWORD fields:

   package webservices;
   public class SoapProxyAuthenticator implements weblogic.common.ProxyAuthenticator
   {
   public final static String PROXY_USER = "http.proxyUser";
   public final static String PROXY_PASSWORD = "http.proxyPassword";
   public SoapProxyAuthenticator() {}
   public String[] getLoginAndPassword()
   {
   String proxyUser = System.getProperty(PROXY_USER);
   String proxyPassword = System.getProperty(PROXY_PASSWORD);
   if (proxyUser == null || proxyPassword == null) return null;
   return new String[]{ proxyUser, proxyPassword };
   }
   public void init(String httpProxyHost, int httpProxyPort, String authenticationType,String loginPrompt)
   {
   this.httpProxyHost = httpProxyHost;
   this.httpProxyPort = httpProxyPort;
   this.authenticationType = authenticationType;
   this.loginPrompt = loginPrompt;
   if (DEBUG)
   {
   System.out.println("[SoapProxyAuthenticator.init(String,int,String,String)] httpProxyHost=" + httpProxyHost);
   System.out.println("[SoapProxyAuthenticator.init(String,int,String,String)] httpProxyPort=" + httpProxyPort);
   System.out.println("[SoapProxyAuthenticator.init(String,int,String,String)] authenticationType=" + authenticationType);
   System.out.println("[SoapProxyAuthenticator.init(String,int,String,String)] loginPrompt=" + loginPrompt);
   }
   }
   //private:
   private final static boolean DEBUG = true;
   private String httpProxyHost;
   private int httpProxyPort;
   private String authenticationType;
   private String loginPrompt;
   }

3. Build the JAR and call it webservice-proxy-auth.jar. The JAR will be stored in your application's Libraries folder in the IDE, which corresponds to the APP-INF/lib folder in the root of your application folder in the file system.

#### To Configure WebLogic Workshop Server

1. Copy the JAR you just created to the BEA-HOME\weblogic81\server\lib folder.
2. Locate the start script of the server the application is using. You can find the start script by going to the Tools menu and selecting WebLogic Server-->Server Properties. The folder is given in the Start Command field. The script will typically be called startWebLogic.cmd.
3. Add the following line to the start script:

   set PROXY_PROPERTIES=-Dweblogic.net.proxyAuthenticatorClassName=webservices.SoapProxyAuthenticator -Dhttp.proxyHost=Your proxy server's address -Dhttp.proxyPort=Your proxy server's port -Dhttp.proxyUser=Your proxy server's username -Dhttp.proxyPassword=Your proxy server's password -Dhttp.nonProxyHosts=localhost

4. Edit the existing SET PRE_CLASSPATH entry in the start script:

   REM
   REM SET UP CLASSPATHS
   REM
   set PRE_CLASSPATH=%WL_HOME%\common\lib\log4j.jar;%ARDIR%\ojdbc14.jar;%ARDIR%\debugging.jar;%ARDIR%\knex.jar;%ARDIR%\javelin.jar;%ARDIR%\wlw-lang.jar;%ARDIR%\webservice-proxy-auth.jar;

5. Edit the existing set JAVA_OPTIONS entry in the start script:

   @REM STUFF DONE ONLY BY US
   @set JAVA_OPTIONS=%JAVA_OPTIONS% %JAVA_PROPERTIES% %PROXY_PROPERTIES% -Dweblogic.Name=%SERVER_NAME% -Dweblogic.security.SSL.ignoreHostnameVerify=false - Dwlw.iterativeDev=%iterativeDevFlag% -Dwlw.testConsole=%testConsoleFlag% -XX:MaxPermSize=128m –ea

6. Restart the server.

Related Topics

How Do I: Call One Web Service from Another?

Web Service Control