+49 228 5552576-0


info@predic8.com

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 an 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 Monitor

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

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

Select a HTTP Proxy Rule

Selecting an HTTP Proxy Type
Figure 2: Selecting an HTTP Proxy Type

Membrane needs to know a TCP port it has to listen to. In this tutorial we choose the 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 with JAX-WS anymore. To specify a proxy that is used to fetch a WSDL document and to invoke a Web service you have to use a ProxySelector.

First 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 1 shows how to specify the port and host of the proxy.

ProxySelector is applied in line 8 of Listing 2

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

Copyright © 2008-2013 predic8 GmbH
Moltkestr. 40, 53173 Bonn, Tel. +49 (228) 555 25 76-0