4

I am making a http request to external stream server; for that I am using jaxws-rs-api.

I am able to make the request and getting response succesfully. but when I tried to make the request via proxy, it is not going through proxy (even not validating the proxy host, if I give some wrong ip also it will make a call).

This is what I tried.

/**
 * 
 */
package com.rrr.test;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response;

import org.glassfish.jersey.client.ChunkedInput;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.client.HttpUrlConnectorProvider;


public class ClientCall {
private static final String BOUNDARY = "\r\n";

    public void makeCall() {

        //passing by passing apache connectors as an input to client config 
        // It is giving runtime error; versioning error, it is supportable for jdk8 it seems
        //In my case, I am using JDK7

        /*
         *  ClientConfig clientConfig = new ClientConfig();
         *  clientConfig.connectorProvider(new ApacheConnectorProvider());
         *  client.property(ClientProperties.PROXY_URI, "https://123.123.123.123"); 
         */


        ClientConfig clientConfig = new ClientConfig();
        clientConfig.connectorProvider(new HttpUrlConnectorProvider());
        clientConfig.property(ClientProperties.PROXY_URI, "https://123.123.123.123:8080"); 
        Client client = ClientBuilder.newClient().register(BasicAuthentication.class);

        //passing as inline command line params

        /*
         * System.setProperty ("http.proxyHost", "10.1.224.60");
         * System.setProperty ("http.proxyPort", "8080");
        */

        WebTarget target = client.target("https://external/stream/v1/");
        Builder request = target.request();
        Response response = request.get();
        System.out.println("Result " +response.getStatus());

        final ChunkedInput<String> chunkedInput = response.readEntity(new GenericType<ChunkedInput<String>>() {
        });
        chunkedInput.setParser(ChunkedInput.createParser(BOUNDARY));
        String chunk =null;
        while ((chunk = chunkedInput.read()) != null) {
            System.out.println(chunk);
        }
    }



    public static void main(String[] args) {
        ClientCall client = new ClientCall();
        client.makeCall();
    }
}

In my case, I don't have an option to choose Java8. please suggest me if any library supports with JDK7.

Dependencies I included for this:

commons-collections-4-1,javax-servlet-api-2-5,log4j,slf4j-api-1-7-5,slf4j-log4j12-1-7-5,spring-framework-4-3-0,commons-logging-1-1,commons-configuration,commons-lang,jackson-core-asl-1-9-10,jackson-mapper-asl-1-9-10,spring-context-support-4-3-0,gson-2-8-2,httpcore-4-4-1,httpasyncclient-4-0-1,httpcore-nio-4-4-6,jackson-core-2-8-4,jackson-annotations-2-8-4,jackson-databind-2-8-4,httpclient-4-4-1,httpcore-4-4-1
Ram Kowsu
  • 711
  • 2
  • 10
  • 30

2 Answers2

0

The variable clientConfig is not used by your ClientBuilder. I suggest you to instantiate your JAXRS client using:

Client client = ClientBuilder.newBuilder()
       .withConfig(clientConfig)
       .register(...)
       .build();
TacheDeChoco
  • 3,683
  • 1
  • 14
  • 17
  • I tried that as well; and it is not even validating the proxy IP; if I give wrong IP also, request will go. – Ram Kowsu Jun 21 '18 at 05:52
0

Try setting the proxies in the Java code as follows:

System.setProperty("http.proxyHost","11.111.111.1");
System.setProperty("http.proxyPort","80");
System.setProperty("http.proxyUser", "domain/usr_name");
System.setProperty("http.proxyPassword", "paswd");
System.setProperty("https.proxyHost", "11.111.111.1");
System.setProperty("https.proxyPort", "443");

PS: Update the dummy values above to your organization specific values. If this doesn't work. You can also try setting these values as environment variables and then trying out the same.

harshlal028
  • 1,539
  • 1
  • 16
  • 25
  • thanks for your answer. I tried this option as well; it didn't even validate the host name/IP – Ram Kowsu Jun 27 '18 at 15:36
  • do you have a domain name in username as well. Also are there special characters in password and username. If it is then you might need to encode the special characters for it to work. Can you try that. Also add the corresponding https counterpart as updated in the answer above. – harshlal028 Jun 27 '18 at 15:49
  • @Harshal, I tried with offc IP and hostname as well by using system setpropeties; but no luck – Ram Kowsu Jun 28 '18 at 10:41
  • It seems like, for JDK7 there is no proxy support given by jaxrs api framework, I can see that If I use java8 and jesey latest version; it is working as excepected – Ram Kowsu Jun 28 '18 at 10:42