• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

JAX Custom Exception Mapping to SOAP Fault

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
He got surgery to replace his foot with a pig. He said it was because of this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic