• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Soap Fault Implementation

 
Ranch Hand
Posts: 64
Oracle Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everybody, I'm new to this forum, and I start writing this post in order to get help with an issue that has been a pain for me:

Maybe, somebody have heard about Soap Fault? Well, I'm using an annotation called @Webfault to capture exceptions in a WebService.

I work with Eclipse, so I'm not sure if it's ok to do this, because these are the steps I followed:

Project -> New Dynamic Web Project -> Create Class...

And this is my class implementation:



Then I create the Exception Class and a FaultBean:

Exception Class:


And this is the fault bean:


I throw the Exception in the web method with the intention of getting my soap fault message, and I get this:

But what I really want to get is this:

Please I need your help to make this functionality, I will be very grateful if somebody can help me.

Thank you in advance...




 
Ranch Hand
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Marcelo,

I have not used Axis / eclipse combination in developing WS. But from the post, the one which you have is WSDL not the SOAP request/response. Once you have your service developed and deployed and when you run your test, you can capture SOAP request/response.

Have you deployed your service and executed any tests. You can use SOAPMonitor or SOAPUI to capture SOAP request/responses ?

Your statement "

I throw the Exception in the web method with the intention of getting my soap fault message, and I get this:



Can you elaborate a bit more on this ?
 
Marcelo Tataje
Ranch Hand
Posts: 64
Oracle Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for yout reply, I'm new to this dorum and to Webservices in Java, sorry if my post was not clear.

I was asked to do this:

Our teacher gives us a JAVA Application, which is a WebService developed in Eclipse, running with Apache Tomcat 6.0 no framework included.

So, the WebService process creation was like this:
New Dynamic Web Project -> new Java Class -> SumService.java

The code is like this:



To get the WebService, just click over the SumService.java in Project Explorer, WebService, create WebService.

Now, this is the tricky part for me, I have to manage Exceptions using SOAP 1.1 Standard with SOAP FAULTS and, in order to shoe that it really works, I have to force my application to throw that SoapFault.

I googled about the topic and many people recommended the following:
1. Use Spring
2. @WebFault annotation
3. SoapFaultException

My first option is discarded, 'cause we can't use frameworks. I tried with @Webfault annotation as I mentioned before and my process was like this:

1. Create a class that manage Exceptions with the annotation

@Webfault(name="SoapException" namespace="mynamespace.com")
public class ExceptionHandler extends Exception{

public ExceptionHandler(String message){super(message);}
public ExceptionHandler(String message,Throwable cause){super(message,cause);}

}
[/code]
2. In the class which is my web Service, I forced like this:


Then, I create the WebService again, based on that class. And when I go to the http://localhost.....?wsdl
I get what I show you previously.
I expected to receive the SOAP Fault, but as soon as you told me that I have to test with SOAPMonitor or with SOAPui, I did it with TCPMonitor and SOAPMonitor, but what I only get is the same that is in my wsdl, even when I forced my application.
Actually, I didn't even know that I was using AXIS.

3. I use the SoapFault class which is included in java.xml... library
And I added something like this:


And in my WebService class I throw that Exception

But neither of them seems to work.

There's a way in which I can receive this expected result when a Exception is launched?

1. <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
2. <SOAP-ENV:Header/>
3. <SOAP-ENV:Body>
4. <SOAP-ENV:Fault>
5. <faultcode>SOAP-ENV:Server</faultcode>
6. <faultstring xml:lang="en">FaultMsg</faultstring>
7. <detail>
8. <ServiceFault xmlns="http://stevideter.com/webservice">
9. <errorCode xmlns="">SERVICE-ERR</errorCode>
10. <errorDescription xmlns="">you can't do that!</errorDescription>
11. </ServiceFault>
12. </detail>
13. </SOAP-ENV:Fault>
14. </SOAP-ENV:Body>
15. </SOAP-ENV:Envelope>

I will be very grateful if you can help me or tell me how can I implement this functionality.

Thank you in advance
 
Kumar Raja
Ranch Hand
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Marcelo,

As I mentioned I have not worked on Axis before, but worked on sun's implementation of JAX-WS (It should not really matter). When you said that you used TCPMonitor and SOAP Monitor (Which I have not used personally), are you able to post any SOAP request? In order to get a SOAP Fault, your service should be able to throw an exception which is mapped to SOAPFault by run time. Now for that, considering a simple request/response scenario, we need to post a SOAP request.

Since you are using eclipse, if you go to Web perspective and launch "Webservices Explorer" from Run menu. Here you need to provide the URL of the WSDL in your case it would be something like http://localhost.....?wsdl, then it would allow you to invoke operations defined in WSDL and if you switch over to "Source" view, you can see both SOAP request and response. If you call your service and if the service throws the exception, you can see the Fault element in SOAP body of the response.

Alternatively, you can use SOAPUI, which is really cool in testing SOAP based WS.





 
Kumar Raja
Ranch Hand
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And I'm not sure, how a webservice can be developed with out using any specific framework. Not necessarily Axis, but some implementation of JAX-RPC or JAX-WS is needed.
 
Marcelo Tataje
Ranch Hand
Posts: 64
Oracle Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your answer!

After some tests, I could manage to find a Webservice sample which is developed with METRO and TOMCAT

This is part of the WebServiceCode, there's no use of WebFault annotations, just throw SoapFaultException:


I get what I expected:



Now, what I want to do is how to get something like this, and change the <wsa:Action> value, for example, instead of http://www.w3.org/2005/08/addressing/fault I want to set: http://www.test.com/fault
Maybe it's defined in some configuration file or something like that


There's something can I do to make possible what I want? I beg your help one more time please.

Thank you in advance.
 
Kumar Raja
Ranch Hand
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Marcello,

I'm very sorry that I was not able to help you much. I think, there is something which I do not understand in your question. However, when you said that you received what you expected from the sample, what does it mean. From your code, I see that you are building a SOAPFault element using SAAJ and returning it as a response. SAAJ is a way of doing things really at a very core level. Where you build your SOAP request/response etc using SAAJ API. Getting SOAP fault element in your response, does not necessarily require to use SAAJ. I'm not sure, if we both are talking about two different things, I'm providing you some steps you can use in java first approach using Metro and Glassfish (you can use Tomcat, if you want)

1) In eclipse, I start with a Dynamic Web Project.
2) Write my service, annotate with @WebService like something below


As you see, I just use a simple service which adds two numbers and throws CustomException if j = 0. You can write a CustomException class as you wrote and you can annotate it with @WebFault. Well for our testing at this point, I do not add any WebFault annotation and leave it as above

Now, if you are using Glassfish, no further change is needed, but if you are using Tomcat, may be you need to add Servlet in web.xml (not sure about this, please refer documentation).

2) I right click on the project and run on server. If you notice, I have not written WSDL.
3) Assume that my service is deployed at http://localhost:8080/CustomWS
4) Now if I browse to http://localhost:8080/CustomWS/CustomWSService?wsdl (I have not written any WSDL before nor, generated one using wsgen), I can see WSDL displayed in my browser.
5) Now since we have our service running, we will test this. There are two ways you can do it in eclipse. If you point your URL to http://localhost:8080/CustomWS/CustomWSService?Tester, it would show you another page, where you can enter values for i and j and submit. If you enter 0 for j, you will get Exception.

6) If you want to see the SOAP Request/respons, you can use SOAPUi, but let us not use any other tools. Go to run ->Webservices Explorer, select WSDL mode and paste http://localhost:8080/CustomWS/CustomWSService?wsdl in the text box for wsdl and click go.

7) Then click on operation "add" and you will see two text boxes for entering i, j. But instead of entering values, click on "Source" hyperlink, there form mode is switched over to Source mode and you can see SOAP request and response xmls. Here you can enter your values, say something like below



and when you submit, you will SOAP response with SOAP Fault.

Hope this would help you and get you started.
 
Marcelo Tataje
Ranch Hand
Posts: 64
Oracle Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much for this explanation, now I already know how to create my WS correctly. I implemented it and it works fine.
In a project I downloaded I'm using metro with tomcat 6. Everything seems tu run fine, but what I want to do now is to change the <wsa:Action> from the soap faut. I get:

<wsa:Action>http://www.w3.org/2005/08/addressing/fault</wsa:Action>;

and I want to change that value: http://www.w3.org/2005/08/addressing/fault
for my own customized.

Maybe somebody can help me in this part, but anyway, thanks for the explanation, I reached my first goal creating the webservice and its fault.

Thanks
reply
    Bookmark Topic Watch Topic
  • New Topic