Skip to main content

@WebFault exception failing on throw

2 replies [Last post]
demichej
Offline
Joined: 2009-06-25
Points: 0

I've been scouring the internet for an answer to why my WebService in Jax-ws is giving me an error when I attempt to throw an Exception.

This is my Exception class:

@WebFault(name="PhotoServiceException", faultBean="PhotoServiceException", targetNamespace="http://photoService.uploader.redfin.com/")
@XmlAccessorType(XmlAccessType.FIELD)
public class PhotoServiceException extends Exception {
private static final long serialVersionUID = 1L;
private String details;
public PhotoServiceException(String reason, String details) {
super(reason);
setFaultInfo(details);
}
public void setFaultInfo(String details) {
this.details = details;
}
public String getFaultInfo() {
return details;
}
}

Here's what is generated in the XSD :

Now, when my web service throws this "PhotoServiceException", I am getting some odd error about a ClassCast Exception:

throw new PhotoServiceException("asdf","sdf");

Jun 25, 2009 11:37:43 AM com.sun.xml.internal.ws.server.sei.EndpointMethodHandler invoke
INFO: asdf
com.redfin.uploader.photoService.PhotoServiceException: asdf
at com.redfin.uploader.photoService.PhotoServiceImpl.uploadPhoto(PhotoServiceImpl.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.xml.internal.ws.api.server.InstanceResolver$1.invoke(InstanceResolver.java:210)
at com.sun.xml.internal.ws.server.InvokerTube$2.invoke(InvokerTube.java:132)
at com.sun.xml.internal.ws.server.sei.EndpointMethodHandler.invoke(EndpointMethodHandler.java:241)
at com.sun.xml.internal.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:74)
at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:581)
at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:540)
at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:525)
at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:422)
at com.sun.xml.internal.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:226)
at com.sun.xml.internal.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:375)
at com.sun.xml.internal.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:175)
at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handleExchange(WSHttpHandler.java:100)
at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler$HttpHandlerRunnable.run(WSHttpHandler.java:122)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)
java.lang.ExceptionInInitializerError
at com.sun.xml.internal.ws.server.sei.EndpointMethodHandler.invoke(EndpointMethodHandler.java:249)
at com.sun.xml.internal.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:74)
at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:581)
at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:540)
at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:525)
at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:422)
at com.sun.xml.internal.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:226)
at com.sun.xml.internal.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:375)
at com.sun.xml.internal.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:175)
at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handleExchange(WSHttpHandler.java:100)
at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler$HttpHandlerRunnable.run(WSHttpHandler.java:122)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassCastException: com.sun.xml.bind.v2.runtime.JAXBContextImpl cannot be cast to com.sun.xml.internal.bind.api.JAXBRIContext
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.(SOAPFaultBuilder.java:488)
... 14 more

What am I doing wrong? How come I can't send an Exception back to the client? Thanks.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ramapulavarthi
Offline
Joined: 2004-06-01
Points: 0

If you are attempting to throw an exception, you dont need to specify @WebFault(faultBean=".."). JAX-WS can generate the wrapper beans dynamically. All you need to make sure is that for all the info you want to be present in the fault there is a getter method.
If you already have the fault bean class coded and not want jax-ws to generate it on the fly, you can use faultBean in the annoation.

Otherwise you can create the exception that has the following methods
WrapperException(String message, FaultBean faultInfo)
FaultBean getFaultInfo()
Here instead of using the getters and setters on WrapperException class, it uses FaultBean to map to wsdl/messages.

See the samples in JAX-WS RI.

demichej
Offline
Joined: 2009-06-25
Points: 0

Thanks for the info, ramapulavarthi.

I see you mention that there are samples in JAX-WS RI. I can't seem to locate those samples at all, and would find them extremely helpful.

Is there any way you could add the link to this post?

Thanks.

P.S. I tried getting rid of the faultBean, but I still receive the same errors when I try to throw my Exception.