0

I am trying to do SOAP Web Service Automation, I figured out an Exception while executing. java.io.FileNotFoundException was thrown when i tried to run/debug, I also found that the response code that I received was 404. I am using a JKS format keystore for security.

Code:

HttpURLConnection httpConnection = null;
String strResponse = null;
java.net.URL url = new URL(strURL);
if (url.getProtocol().equalsIgnoreCase("http")) {
httpConnection = (HttpURLConnection) url.openConnection();      
}
httpConnection.setDoOutput(true);
httpConnection.setDoInput(true);
httpConnection.setRequestMethod("POST");
OutputStreamWriter writer = new OutputStreamWriter(httpConnection.getOutputStream());
writer.write(wsRequestString);
writer.close();
System.out.println(httpConnection.getResponseCode());
if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
System.out.println(httpConnection.getInputStream());
}

When I am trying to execute httpConnection.getInputStream(), it throws java.io.FileNotFoundException. Also the URL I am sending as parameter is also a valid one. what could be the possible reason for this exception?

user207421
  • 305,947
  • 44
  • 307
  • 483
  • 1
    You can't print from an inputstream, try converting it to a String, http://stackoverflow.com/questions/309424/read-convert-an-inputstream-to-a-string – vikingsteve Jun 03 '16 at 07:07
  • even then I got the error as java.io.FileNotFoundException: "URL name" – Hifzur Rahman Jun 03 '16 at 07:21
  • 1
    You can't be getting a 404 and a 200 at the same time, and you're only calling `getInputStream()` if you got a 200. Is this the real code? – user207421 Jun 03 '16 at 07:24
  • Yes, as you said I am getting 404 code, which is why its not getting into the if condition. Then I added a line System.out.println(httpConnection.getInputStream()); after the if condition then i got FileNotFoundException – Hifzur Rahman Jun 03 '16 at 08:55
  • So why am I getting 404 response code? Any Idea on this? – Hifzur Rahman Jun 03 '16 at 08:56

1 Answers1

0

There is no wrong in the code, only thing was to checked was whether it was a Http or Https connection. Finally, I found it to be SAAJ Request, it worked with SAAJ Code