Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

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

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: https://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.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic