+

Search Tips   |   Advanced Search

Configure a web services client to access resources using a web proxy

We can configure a web services client to access resources through a web proxy server.

We can configure a web services client to access resources by connecting to a web proxy server either with or without requiring authentication, just like other HTTP client applications. We can configure HTTP transport properties for a web service acting as a client to another web service. The HTTP transport values you configure are used at runtime. Configure the HTTP transport values in one of the following ways:

To programmatically configure the properties using the Java API XML-based Remote Procedure Call (JAX-RPC) programming model or the JAX-WS programming model, review the JAX-RPC or JAX-WS specifications.

For Java API XML-based Remote Procedure Call (JAX-RPC) web services, the HTTP transport values take the following precedence order with the programmatic method being the most significant:

  1. values specified programmatically on the Call object

  2. values defined in the deployment descriptors in each portQNameBinding attribute using an assembly tool

  3. values defined as JVM system properties

For JAX-WS web services, the HTTP transport values specified in the policy set definitions take precedence over the values defined programmatically. Subsequently, the HTTP transport values you define programmatically take precedence over the values defined as JVM system properties. For JAX-WS applications, deployment descriptors are not supported. Use annotations to specify deployment information.

  1. Configure the HTTP or HTTPS proxyHost and proxyPort transport properties for the web services in one of the following ways:

    • using the Java Virtual Machine (JVM) custom property panel in the administrative console

    • using the wsadmin command-line tool

    • using assembly tools

    • programmatically using the application programming model

    To access the web proxy over HTTP:

    • http.proxyHost

    • http.proxyPort

    To access the web proxy over HTTPS:

    • https.proxyHost

    • https.proxyPort

  2. If HTTP proxy authentication is required for the web services client, then additionally configure the HTTP or HTTPS proxyUser and proxyPassword transport properties using one of the methods specified in the previous step.

    To access the web proxy over HTTP:

    • http.proxyUser

    • http.proxyPassword

    To access the web proxy over HTTPS:

    • https.proxyUser

    • https.proxyPassword

  3. If we are specifying the HTTP or HTTPS properties programmatically, set the properties in the Stub or Call instance to configure the HTTP proxy authentication.

    1. We can set the HTTP or HTTPS properties programmatically using the following web services constants:
      com.ibm.wsspi.webservices.Constants.HTTP_PROXYHOST_PROPERTY
      com.ibm.wsspi.webservices.Constants.HTTP_PROXYPORT_PROPERTY
      com.ibm.wsspi.webservices.Constants.HTTP_PROXYUSER_PROPERTY
      com.ibm.wsspi.webservices.Constants.HTTP_PROXYPASSWORD_PROPERTY
      com.ibm.wsspi.webservices.Constants.HTTPS_PROXYHOST_PROPERTY
      com.ibm.wsspi.webservices.Constants.HTTPS_PROXYPORT_PROPERTY
      com.ibm.wsspi.webservices.Constants.HTTPS_PROXYUSER_PROPERTY
      com.ibm.wsspi.webservices.Constants.HTTPS_PROXYPASSWORD_PROPERTY

  4. Use tunneling in the web services transport layer to enable the Web services client to access resources through a Web proxy server. Set the JVM property, com.ibm.ws.websvcs.transport.enableProxyTunnel to a value of true.


Results

You have configured the web services client to use a Web proxy server to access resources.

We can optionally set the http.nonProxyHosts property to specify the host names of machines to which requests will not be sent through the proxy server. Any requests invoked by the client application sent to a host whose name is contained in this property will not pass through the proxy server. This property applies for both HTTP and HTTPS connections. To learn more about the http.nonProxyHosts property and other HTTP properties that we can configure, read about HTTP transport custom properties for web services applications.


Example

The following code allows us to configure the HTTP proxy programmatically:

import com.ibm.wsspi.webservices.Constants
Properties prop = new Properties();
InitialContext ctx = new InitialContext(prop);
Service service = (Service)ctx.lookup("java:comp/env/service/StockQuoteService");
QName portQname = new QName("http://httpchannel.test.wsfvt.ws.ibm.com", "StockQuoteHttp");
StockQuote sq = (StockQuote)service.getPort(portQname, StockQuote.class);
((javax.xml.rpc.Stub) sq)._setProperty(Constants.HTTP_PROXYHOST_PROPERTY, "proxyHost1.ibm.com");
((javax.xml.rpc.Stub) sq)._setProperty(Constants.HTTP_PROXYPORT_PROPERTY, "80");

For JAX-WS, the following code allows us to specify the HTTP or HTTPS properties programmatically with RequestContext of BindingProvider:

//Set the https.proxyHost as a property on the RequestContext.
BindingProvider bp = (Binding Provider)port;
bp.getRequestContext().put("https.proxyHost", "proxyHost1.ibm.com");
bp.getRequestContext().put("https.proxyPort", "80");


Related concepts

  • Web services transactions, high availability, firewalls and intermediary nodes


    Related tasks

  • Implement static JAX-WS web services clients
  • Implement JAX-RPC web services clients
  • Configure additional HTTP transport properties for JAX-RPC web services with an assembly tool
  • Configure additional HTTP transport properties using wsadmin-line tool
  • Configure additional HTTP transport properties using the JVM custom property panel in the administrative console
  • Configure HTTP basic authentication for JAX-RPC web services programmatically
  • Secure web services applications at the transport level

  • HTTP transport custom properties for web services applications
  • Java virtual machine custom properties
  • Web services specifications and APIs


    Related information:

  • Class Constants