Calling API Proxy within a Java code

How to call a API Proxy inside my Java code.

For example. http://tapajyotigiri-eval-test.apigee.net/apitargetproxy this is an API Proxy which returns JSON. I want to get the JSON and display in Java.

Solved Solved
0 3 2,275
1 ACCEPTED SOLUTION

@tapajyoti giri

You can use Java http client APIs to make calls to your API. One such widely used library is the Apache http client. You can use the Jackson or Google gson libraries to parse the json response.

View solution in original post

3 REPLIES 3

@tapajyoti giri

You can use Java http client APIs to make calls to your API. One such widely used library is the Apache http client. You can use the Jackson or Google gson libraries to parse the json response.

I am getting a

Exception in thread "main" java.net.ConnectException: Connection timed out: connect

This is my code.

		String url = "http://tapajyotigiri-eval-test.apigee.net/apitargetproxy";
		URL obj = new URL(url);
		HttpURLConnection con = (HttpURLConnection) obj.openConnection();
		con.setRequestMethod("GET");
		con.setRequestProperty("User-Agent", "Mozilla/5.0");
		int responseCode = con.getResponseCode();
		System.out.println("\nSending 'GET' request to URL : " + url);
		System.out.println("Response Code : " + responseCode);
		BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
		String inputLine;
		StringBuffer response = new StringBuffer();


		while ((inputLine = in.readLine()) != null) {
			response.append(inputLine);
		}
		in.close();
		System.out.println(response.toString());

@Tapajyoti Giri

This seems more of a network issue and nothing related to Apigee.

This means your request did not get a response within some (default) timeframe.

1. Check if the same url works from postman

2. Check if you have internet access from the machine where the java code is executed

3. Check if you have a firewall that is blocking requests to that particular host from the machine where the java code is executed

4. Check for internet proxy settings if you have one configured for the machine where you are executing the code