9

I have an application that is running on a Java EE 7 application server (WildFly), that queries another service using REST resources.

In previous applications I have used the Jersey 1.x client API. Access to the REST service is granted through a web proxy.

In Jersey I create the Client instance like this:

public Client create() {

    Client client;
    if ( proxyConfiguration != null && proxyConfiguration.getHost() != null && !proxyConfiguration.getHost().trim().isEmpty() ) {
        HttpURLConnectionFactory urlConnectionFactory = new ProxyUrlConnectionFactory( proxyConfiguration );
        client = new Client( new URLConnectionClientHandler( urlConnectionFactory ), clientConfig );
    } else {
        client = Client.create( clientConfig );
    }

    return client;
}

Running on a Java EE 7 application server I wanted to use the JAX-RS 2.0 client API which is provided by the application server.

Now I am having a really hard time to find information on how to configure the JAX-RS 2.0 client in a platform independent way. Setting the http.proxyHost and http.proxyPort system properties had no effect in WildFly (I would prefer to not configure it globally anyway).

Does anyone know how to solve this?

cassiomolin
  • 124,154
  • 35
  • 280
  • 359
Max Fichtelmann
  • 3,366
  • 1
  • 22
  • 27

2 Answers2

13

I think there's no vendor independent solution (at least, I didn't find anything related to proxies in the JAX-RS API).

For Jersey 2.x, you can try:

ClientConfig config = new ClientConfig();
config.property(ClientProperties.PROXY_URI, "192.168.1.254:8080");  
Client client = ClientBuilder.withConfig(config).build();

ClientProperties is a class from Jersey API.


For RESTEasy, the configuration is:

Client client = new ResteasyClientBuilder()
                   .defaultProxy("192.168.1.254", 8080, "http")
                   .build();

ResteasyClientBuilder is a class from RESTEasy API.

cassiomolin
  • 124,154
  • 35
  • 280
  • 359
  • 1
    thank you very much. I feared that much - I guess I could specify Resteasy as provided dependency. I hoped to avoid vendor-lockin – Max Fichtelmann Nov 23 '15 at 15:22
  • 1
    @MaxFichtelmann Actually, I'm not happy with this solution. The [JAX-RS 2.0 JSR](http://download.oracle.com/otn-pub/jcp/jaxrs-2_0-fr-eval-spec/jsr339-jaxrs-2.0-final-spec.pdf) mentions the word *proxy* only once and, unfortunately, it's not related to *network proxies*. IMHO, that's the kind of thing that could be covered by the next version of the specification. – cassiomolin Nov 23 '15 at 15:34
0

With (WildFly and) RESTEasy (6.2.1.Final) set a proxy with:

final Client client = ClientBuilder.newBuilder()
    .property("org.jboss.resteasy.jaxrs.client.proxy.host", "192.168.1.254")
    .property("org.jboss.resteasy.jaxrs.client.proxy.port", 8080)
.build();

See Jakarta RESTFul Web Services: 51.3.3. HTTP proxy.

Toru
  • 905
  • 1
  • 9
  • 28