I have written a java method which calls an API of Japanese dictionary->Parse the JSON response->Return first node(String) to caller as appropriate translation of English word. Program works perfectly fine when executed from Eclipse IDE. However, when I run it's executable jar ( created using export feature of Eclipse) I get no response from API. I am failing to understand cause of this behavior and would really help if anyone guide me on this.
I always get "GET request not worked" printed on console when I execute entire program as
java -jar JtoETranslate.jar
Java Method:
public static String sendGET(String param) throws IOException
{
BufferedWriter writer = null;
Properties systemSettings = System.getProperties();
systemSettings.put("proxySet", "true");
systemSettings.put("http.proxyHost","172.29.44.61");
systemSettings.put("http.proxyPort", "8080");
URL obj = new URL(GET_URL+param);
HttpURLConnection con = (HttpURLConnection)obj.openConnection();
con.setRequestMethod("GET");
int responseCode = con.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK)
{
BufferedReader in = new BufferedReader(new InputStreamReader(
con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
// print result
try
{
writer = new BufferedWriter( new FileWriter("./docs/response.json"));
writer.write(response.toString());
}
catch ( IOException e)
{
}
finally
{
try
{
if ( writer != null)
writer.close( );
return parseJSON("./docs/response.json");
}
catch ( IOException e)
{
}
}
System.out.println("Got response");
} else {
System.out.println("GET request not worked");
}return null;
}
EDIT
As suggested in one of comments below, I added a debugging statement to see exactly what request is getting formed, and here is the request to API.
Can anyone help me for how can I make Jar understand for UTF-8 encoding.