Simon Nash wrote:
Millies, Sebastian wrote:
Hello Gaetan,

I asked this same question in September, and Simon Nash all explained it to me.

I attach Simon’s responses to this mail.

n  Sebastian

*From:* Ruault Gaetan [mailto:[email protected]]
*Sent:* Tuesday, October 26, 2010 6:07 PM
*To:* [email protected]
*Subject:* fault extends with binding.ws

Hi,

I have a problem with exception inheritance

I have two exceptions like this

public AbstractException extends Exception;

public BusinessException extends AbstractException;

and my service like this

public  method(param1,param2) throws AbstractException

but when my service throw an BusinessException i receive an AbstractException.

Could you help me for receive the good Exception Type.

i join my wsdl.

thank

Gaëtan RUAULT

Consultant - Business Consulting Atlantique

Sopra group.

28, rue Léo Lagrange 79000 Niort

Phone : +33 (0)5 49 77 38 20

[email protected] - www.sopragroup.com

Ce message peut contenir des informations confidentielles dont la divulgation est à ce titre rigoureusement interdite en l'absence d'autorisation explicite de l'émetteur. Dans l'hypothèse où vous auriez reçu par erreur ce message, merci de le renvoyer à l'émetteur et de détruire toute copie.

P Pensez à l'environnement avant d'imprimer.


------------------------------------------------------------------------

Subject:
Re: Abstract exception classes and web services
From:
"Simon Nash" <[email protected]>
Date:
Thu, 9 Sep 2010 14:12:59 +0200
To:
<[email protected]>

To:
<[email protected]>


I think it's important to establish general principles for these
interoperability cases, and then look at specific cases to see
how the general principles are applied.

The general principle for SCA components communicating over the
Web Service binding is:

1. The service interface is mapped to WSDL (if not already WSDL).
2. The client interface is mapped to WSDL (if not already WSDL).
3. If either interface can't be mapped to WSDL, interoperability
    isn't possible and an error should be reported.
4. The SCA compatibility rules are applied to the mapped WSDL
    interfaces.  If the mapped WSDL interfaces don't pass the
    compatibility test, interoperability isn't possible and an
    error should be reported.
5. If no errors were reported by steps 3 and 4, the client and
    service should interoperate correctly at runtime.

The implication here is that every Java interface and implementation
that passes steps 3 and 4 will also pass step 5.  However this isn't
always the case for JAX-WS and JAXB.  In some cases it's necessary to
add custom marshalling/unmarshalling code using the @XmlJavaTypeAdapter
annotation to enable the JAXB runtime to successfully marshal and
unmarshal certain object types.  In some cases (e.g., interface types)
the need for such customization is detected by the Java-WSDL mapping.
In other cases (e.g., abstract class types), the Java-WSDL mapping
doesn't produce any error message, but it's still necessary to add
custom unmarshalling code to get things to work.

I don't think there's anything special about using an abstract class
as a thrown exception rather than using an abstract class as a passed
or returned parameter.  In all these cases the Java-WSDL mapping
works OK without errors, but runtime unmarshalling doesn't work
unless @XmlJavaTypeAdapter is used.

If you want to be able to throw and catch any of a number of concrete
exception classes when using an abstract exception class on the
service interface, you'll need to write a JAXB custom marshalling/
unmarshalling adapter that stores the desired concrete class name
in the XML data passed across the wire for the WSDL fault and uses
this information on the client side to create the correct concrete
subclass.  This is effectively what the RMI runtime is doing
automatically for you.

The bottom line is that if using abstract exception classes you need
to write some extra marshalling/unmarshalling adapter code and you
need to design your abstract exception classes to hold the necessary
information to enable custom unmarshalling.  If you do this, the same
business exception logic will work over both Web Services and RMI.

   Simon

Millies, Sebastian wrote:
 > Hello there,
 >
 >  >
> in Tuscany SCA 1.6, it seems not to be possible to have a remote method
 > that declares
 >
 > an abstract exception class in its interface, and access that method
 > from a remote node
 >
 > over a webservice binding.
 >
 >  >
 > For example, say CurrencyConverterException is an abstract base class
 > for my checked
 >
> exceptions, and it has UnknownCurrencyException as an immediate concrete
 > subclass.
 >
 > Then my service interface and implementation may look like this.
 >
 >  >
 > @Remotable
 >
 > *public* *interface* CurrencyConverter
 >
 > {
 >
 >   *double* getExchangeRate( String fromCurrencyCode, String
 > toCurrencyCode ) *throws* CurrencyConverterException;
 >
 > }
 >
 >  >
 > @Service(interfaces =
 >
 >   { CurrencyConverter.*class* })
 >
 > *public* *class* CurrencyConverterImpl *implements* CurrencyConverter
 >
 > {
 >
 >  >
 >   *public* *double* getExchangeRate( String fromCurrencyCode, String
 > toCurrencyCode ) *throws* CurrencyConverterException
 >
 >   {
 >
 >     *if*( true )
 >
 >     {
 >
> *throw* *new* UnknownCurrencyException( "Unknown source currency:
 > " + fromCurrencyCode );
 >
 >     }
 >
 >   }
 >
 > }
 >
 >  >
 > The client component has a reference to the CurrencyConverter service:
 >
 > <sca:component name=/"ClientComponent"/>
 >
 >     <sca:reference name=/"converter"/>
 >
> <sca:binding.ws uri=/"http://localhost:8080/CurrencyConverter"//>
 >
 >     </sca:reference>
 >
 >   </sca:component>
 >
 >  >
> When running the client in its own node, calling getExchangeRate on the
 > injected CurrencyConverter reference,
 >
 >  I will get a  _java.lang.InstantiationException _in the class
> org.apache.tuscany.sca.interfacedef.java.jaxws.JAXWSFaultExceptionMapper
 >
 >  >
 > Of course, the wsdl didn’t change a bit when I changed my service
 > implementation and made CurrencyConverterException abstract.
 >
> A normal JAX-WS Java client can continue to use the JAX-WS artefacts as
 > it always did and will not encounter this InstantiationException,
 >
 > because it doesn’t even try to reconstruct a server side exception.
 >
 >  >
> And of course, when using the webservice binding, the client should not
 > have to rely on technical
 >
> implementation details of the server (after all, the whole idea is they
 > may be implemented in different technologies). So
 >
 > Tuscany shouldn’t try to give me the original exception, but the
 > corresponding web fault. Which would force the client
 >
 > to use different exception handling code for a webservice than say for
 > an RMI binding. The technologies are just too different
 >
 > to be handled in a uniform fashion.
 >
 >  >
 > We had this point before. I find it interesting that I keep running up
 > against it in the context of exceptions.
 >
 >  >
 > -- Sebastian
 >
 >  >


------------------------------------------------------------------------

Subject:
Re: Abstract exception classes and web services
From:
"Simon Nash" <[email protected]>
Date:
Sun, 12 Sep 2010 16:38:28 +0200
To:
<[email protected]>

To:
<[email protected]>


Simon Laws wrote:
 > On Thu, Sep 9, 2010 at 3:35 PM, Millies, Sebastian
 > <[email protected]> wrote:
>> thanks for the explanation. However, when I tested this just now, it didn't
 >> work. Perhaps I misunderstood, or there's a bug in Tuscany.
 >>
 >> What I did was annotate the abstract exception class as follows
 >>
 >> @XmlJavaTypeAdapter(CurrencyConverterExceptionAdapter.class)
 >> public abstract class CurrencyConverterException extends Exception
 >>
>> and implement the adapter class in the same server-side package, so it can >> get imported by the client together with the exception. The adapter simply
 >> serializes the exception to and from a string in the format
 >> "concreteClassName#message".
 >>
>> On the client side I changed nothing. When I ran this code in Tuscany 1.6 >> (calling the server from a different node to make sure the ws-binding is used), >> the unmarshal/marshal methods in the adapter do not even get called. Is there >> anything more I have to do except implement the adapter class? I'm sorry if >> this is a naive question, but it really sounded so simple in your post.
 >>
 >> -- Sebastian
 >
 > Hi Sebastien
 >
 > Unfortunately I don't think the @XmlJavaTypeAdapter JAXB annotation is
 > supported in the 1.x code base. If was added to the 2.x code base at
 > r743192 if you want to look it up. The interface test was extended
 > here [1]
 >
> [1] http://svn.apache.org/repos/asf/tuscany/sca-java-2.x/trunk/modules/interface-java-jaxws/src/test/java/org/apache/tuscany/sca/interfacedef/java/jaxws/TestInterface.java

 >
 > Regards
 >
 > Simon
 >
It looks like this code change (but not the test case?) was added to the
Tuscany 1.x codebase under r744091. This was marked as a fix for TUSCANY-2840,
and there were additional commits to 1.x for this JIRA under r745778 and
r745779. I'll do some investigation to try to find out why this annotation
isn't working with 1.x.

   Simon

I'm looking at this 1.x problem with @XmlJavaTypeAdapter now and I will
post an update when I have more information.

  Simon



I wrote a simple itest for @XmlJavaTypeAdapter and checked it into the 1.x
trunk under revision r1028105.  This revision also contains the remaining
test code from revision r743192 that was previously only in 2.x.  The runtime
code from revision r743192 to support this was added to 1.x some time ago.

The itest that I added works as expected.  It passes a simple abstract class
as a method parameter across the Web Service binding using @XmlJavaTypeAdapter
to marshal the abstract class as a string.  The @XmlJavaTypeAdapter annotation
is applied to the declaration of the abstract class.

Encouraged by this success, I tried extending the itest to include an abstract
exception class annotated with @XmlJavaTypeAdapter.  Unfortunately this isn't
working as I expected.  I'm getting an InstantiationException which suggests
that the @XmlJavaTypeAdapter annotation is being ignored.  I'll continue to
investigate this.

 Simon

Reply via email to