/ Monitor / Documentation / Monitoring / Web Services Monitoring / Monitoring a JAX-WS Client with a Proxy Selector

Monitoring a JAX-WS Client with a ProxySelector

Membrane Monitor can be placed between a JAX-WS client and a service in two different ways. One way is to use a reverse proxy as described in HowTo monitor a JAX-WS Client. The other possibility is to use a HTTP proxy. The client sends all requests, even requests for WSDL documents to the proxy and the proxy talks to the service on behalf of the client. This document describes how you can use Membrane Monitor as HTTP proxy to capture messages between a JAX-WS client and a service.

Preparing Membrane SOA Monitor

First start Membrane Monitor. Add a new Rule by clicking on the green button.

Add a rule in Membrane SOAP Monitor
Figure 1: Add a rule in Membrane SOAP Monitor

Select a HTTP Proxy Rule as new rule.

Selecting a HTTP Proxy Rule
Figure 2: Selecting a HTTP Proxy Rule

Membrane needs to know a TCP port it has to listen to. In this tutorial we choose port number 3128.

Selecting a port Membrane is listening to
Figure 3: Selecting a Port Membrane is listening to

Changing the JAX-WS Client

The system properties http.proxyHost and http.proxyPort were used to configure proxy settings in Java. This mechanism does not work anymore in JAX-WS. To specify a proxy that is used to fetch a WSDL document and to invoke of Web services you have to use a ProxySelector.

Now you have to change your client. In this tutorial we use a client for the BLZService for demonstration. Add to your project a Java class which extends java.net.ProxySelector. Override the select and the connectFailed methods as shown in Listing 1:

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.*;
import java.util.*;

public class MyProxySelector extends ProxySelector {

    @Override
    public List<Proxy> select(URI uri) {
        Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", 3128));
        ArrayList list = new ArrayList();
        list.add(proxy);
        return list;
    }

    @Override
    public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
        System.err.println("Connection to " + uri + " failed.");
    }

}
Listing 1: Extension of java.net.ProxySelector

Line 10 of Listing 2 shows how to set the ProxySelector in the web service client.

import com.thomas_bayer.blz.*;
import java.net.ProxySelector;

public class Main {

    public static void main(String[] args) throws Exception {

        ProxySelector.setDefault(new MyProxySelector());

        BLZService service = new BLZService();
        BLZServicePortType port = service.getBLZServiceSOAP11PortHttp();

        DetailsType result = port.getBank("38250110");
        System.out.println("Result = " + result.getBezeichnung());
    }
}
Listing 2: BLZClient using a ProxySelector

After starting the client have a look at Membrane Monitor. It should have intercepted a call to the service as shown in figure 4.

Monitored SOAP Message
Figure 4: Monitored SOAP Message