wood burning stoves*
The moose likes Web Services and the fly likes Web Service Client: Can't read fault instead an IOException is read. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Web Service Client: Can Watch "Web Service Client: Can New topic
Author

Web Service Client: Can't read fault instead an IOException is read.

Kelly Powell
Ranch Hand

Joined: Oct 29, 2010
Posts: 56
Hi. I have an Axis2 web service and a web service client which is not based on Axis2. I wrote the client from scratch without using any 3rd party API (I'm using URLConnection). I have a login method in my web service which returns the user information if login is successful and an AxisFault containing a message if login failed. When I try to connect in my web service using the client I made, I was able to get the XML response of my web service if my login is successful. However, if my login failed, I am only able to receive IOException.

Here are my questions:
1. Does Java treat AxisFault as SOAPFault? I included SOAPFaultException in my try catch statement before the IOException but the exception still goes to IOException.
2. When I try to invoke exception.getMessage(), I only get a "Server returned HTTP response code: 500 for URL: ..." error message instead of the "Login failed. The username and password does not match." which is the message I set on my AxisFault. How do I get the error message I set on the server?

Some facts:
1. I am using Java both for my web service and web service client.
2. I am not using Axis2 API for my client. I'm writing it from scratch.
3. I am calling the web service in my client in REST style. (http://ip:port/services/webService/login?username=value1&password=value2)
4. I am able to view the AxisFault if I call my web service using my browser (Firefox and Chrome). Browser displays an XML:

5. If login fails and I'm using Internet Explorer to call the web service, I only get an HTTP 500 error message without the XML.
6. The TCP/IP Monitor of Eclipse shows that my web service was able to return a response containing a soap envelope of the fault. Below is the response displayed in TCP/IP Monitor:
Below is a code snippet from the client:
Kelly Powell
Ranch Hand

Joined: Oct 29, 2010
Posts: 56
I found the solution to it. Instead of using URLConnection, I used HttpURLConnection. It allows me to get the status code of the response and then getErrorStream instead of getInputStream if the response is not OK. I found the solution at: http://www.coderanch.com/t/433447/Streams/java/HttpsURLConnection-Reading-Body-Response-when . I was searching for the wrong keyword before and is not yet sure regarding the cause of my problem.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Web Service Client: Can't read fault instead an IOException is read.