Is it possible to handle User Defined Exception using JAX WS Dispatch API ?
Posted
by snowflake
on Stack Overflow
See other posts from Stack Overflow
or by snowflake
Published on 2009-12-28T17:09:21Z
Indexed on
2010/05/16
2:00 UTC
Read the original article
Hit count: 496
Hello,
I'm performing dynamic webservices call using following code snippet:
JAXBContext jc = getJAXBContext(requestClass, responseClass, jaxbContextExtraClasses);
Dispatch<Object> dispatch = service.createDispatch(portQName, jc, Service.Mode.PAYLOAD);
Object requestValue = getRequestValue(requestClass, pOrderedParameters);
JAXBElement<?> request =
new JAXBElement(new QName(serviceQNameStr, pOperationName), requestValue.getClass(), null, requestValue);
Object tmpResponse = dispatch.invoke(request);
Invocation works perfectly, except if I add a user defined exception on the service (a basic UserException extends java.lang.Exception).
First I get:
javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schemas.xmlsoap.org/soap/envelope/", local:"Fault"). Expected elements are <{http://my.namespace/}myMethod>,<{http://my.namespace/}myResponse>
Then I added the UserException_Exception JAX-WS generated type to my JAXB Context, and then get:
Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions java.lang.StackTraceElement does not have a no-arg default constructor. this problem is related to the following location: at java.lang.StackTraceElement at public java.lang.StackTraceElement[] java.lang.Throwable.getStackTrace() at java.lang.Throwable at java.lang.Exception
Only solution available I found are:
- dispatch directly a Soap message and handle Soap fault directly (this is the way Jboss JAX-WS implementation performs a standard JAX-WS call using services interfaces). This is not an available solution for me, I want to use a high level implementation (the more I get close to Soap message the less dynamic my code can be)
- usage of JAXBRIContext.ANNOTATION_READER, which is implementation specific and not an available solution for me, in order to annotate annotates java.lang.Exception as @XmlTransient
The service with a user defined exception performs well using the JAX-WS generated standard client stubs and using a tool such Soap UI. Problem occurs in deserialization of the message when I have no user defined exception artifact in the JAXB context, and during invocation when I add those non JAXB compatible artifacts in the JAXB context.
I'm usign Jboss WS webservice stack within Jboss 4.2.3.GA
Any elegant solution to this problem is welcomed !
© Stack Overflow or respective owner