aspose file tools*
The moose likes Web Services and the fly likes JAX Custom Exception Mapping to SOAP Fault Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "JAX Custom Exception Mapping to SOAP Fault" Watch "JAX Custom Exception Mapping to SOAP Fault" New topic
Author

JAX Custom Exception Mapping to SOAP Fault

Evan Ruff
Greenhorn

Joined: Jan 03, 2010
Posts: 6
Hey Guys,

I'm working on building a web services framework and I'm having some trouble getting javax.ws.Service stuff to handle my faults correctly. I've got everything else working, but I just can't seem to get the faults to do anything other than be returned as SOAPFaultException. The generated exception seems to have my faultstring mapped to the "detailMessage" field and everything else is null. I know it sounds silly to make something from scratch, but I just wanted something very bare bones and had some additional business requirements to work through, so... with that being said... here we are :-)

The WSDL is generated from the Server side service with Exceptions being mapped to various types and such. The "MerchantNotFoundException" looks like this:


with the message being:


Port:


and finally, the binding:


So, the server generates the following SOAP response when a MerchantNotFoundException is thrown:


I was under the impression that the javax.ws packages would automatically map to the MerchantNotFoundException based on the content of the detail portion of the SOAP fault. Unfortunately, I simply can not get it to behave that way, and always get a SOAPFaultException with very limited details. I have used CXF 2.2.5 wsdl2java to make my client and everything there looks like it has been generated nicely, but it just won't map that darn exception correctly! I'm
sure that I'm missing something in the generation, but I cannot find it for the life of me. Is there anything that is very obviously wrong?

I know that this is a complex mess of code but I really appreciate any light you can shine on this for me!

Thanks!

Evan
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
I get a little curious to what exactly you are trying to do. First you say that you cannot get javax.ws.Service (by the way, if this is the JAX-WS Service class, then it is located in the javax.xml.ws package) to correctly translate your faults to the appropriate exceptions. Then you say that you have used a CXF utility to generate client artifacts. Have you tried to use wsimport to generate the client artifacts and then trying that client with your web service and the exceptions?
Best wishes!
Evan Ruff
Greenhorn

Joined: Jan 03, 2010
Posts: 6
Ivan,

Thanks for your fast response. Basically, because of the specific architecture that has been implemented in our system, using any of the traditional service mapping tools was going to be a real pain. The decision was made to build a little service mapper from scratch that output the WSDL and handled the SOAP stuff. Everything is working beautifully except for this little Fault mapping issue.

From the WSDL that is generated, I used wsdl2java in the CXF package to create my client. It output all the types, ports and sample client. The sample client LOOKS fantastic. It has the functions throwing the expected exceptions, but when I actually run the test client, I only get the generic exception, not the specific mapped exception. That's my problem.

Also, from your post, I'm under the impression that I'm using the incorrect terminology of what I'm using. In the sample client, I'm importing these classes:


You say use WSImport to generate the client from the WSDL. What package does that tool belong to?

Thanks for all your help! I really appreciate it!
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Well, so far I have not contributed any help, so you may want to postpone any thanking.
Now I understand the situation better and am clear that you are only using CXF tools and classes for the client.
I recommend taking a look in the samples/wsdl_first directory of the CXF binary distribution. There is a client that catches a custom exception (a NoSuchCustomerException) and the corresponding service.

By the way, wsimport is a tool similar to wsdl2java, but for JAX-WS. It is part of the Java SE 6 distribution.
Best wishes!
Evan Ruff
Greenhorn

Joined: Jan 03, 2010
Posts: 6
Ivan,

Thanks for the tip. I plan on spending some more time working on it. My initial thought is that I might be forgetting a namespace or something, so we'll check that out. Certainly will check out the samples as well!

E
Evan Ruff
Greenhorn

Joined: Jan 03, 2010
Posts: 6
Ivan,

I've patterned my WSDL and Fault after everything in the sample, but I still can't seem to get the fault to map correctly. Futhermore, I can't seem to figure out a way to get the raw SOAP message that the sample message is returning. Is there an easy way to do that? I think the error must be in my generated Fault:



I think that the parser/mapper in the javax.jws packages just can't interpret my output.

Any ideas/help? I think that without that raw SOAP Message I might be stuck.

Thanks!

E
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi again!
I've ran the CXF WSDLFirst example through a TCP packet monitor and out came a SOAP Fault that looks like the one you have.
At this stage, I can only suggest a slightly time-consuming approach to solving your problem:
Start with the WSDLFirst example from the Apache CXF binary distribution and change it step-by-step until it becomes what you want.
After each step, run the tests (or create some test of your own) to make sure you haven't broken the server or client.
If you do find the problem, I wouldn't mind learning about it.
Best wishes!
Evan Ruff
Greenhorn

Joined: Jan 03, 2010
Posts: 6
Ivan,

Thanks a ton for that man. I think that for now I'm just going to insure that all the other services work and circle back around to this.

Could it be that my client is just plain wrong?

E
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Having had yet another look at your WSDL, or at least the parts which you have posted, I do find some differences between it and the one in the CXF sample:
Below is a <binding> element from the sample WSDL:

Differences I notice are:
- You use the encodingStyle attribute, which I know is not recommended by the WS-I BP. This also clashes with the use of use="literal", which you sometimes specifies on the same element as the encodingStyle attribute is specified on.
- You do not use the <soap:fault> element in your <wsdl:fault> element.

I don't know if the above causes the problem that you have, but I guess it is worth a try.
Best wishes!
Evan Ruff
Greenhorn

Joined: Jan 03, 2010
Posts: 6
SUCCESS!

After making the changes you suggested to the WSDL, I can get the exception. For posterity, here's what I'm working with:

Add a Type for the Exception Details:


Add a Message to define the Exception:


Add the exception message to the port:


And then, add to the binding:


Then the actual fault output of the exception looks like this:


It's interesting that the detail block is not MerchantNotFoundExceptionMessage, but just MerchantNotFound. I'm not sure exactly why this works without the actual type name in there, but it works without issue.

Thanks for all your help. Hopefully this post can help out someone else!

Thanks!

E
 
Don't get me started about those stupid light bulbs.
 
subject: JAX Custom Exception Mapping to SOAP Fault