axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ingo Fleer (JIRA)" <j...@apache.org>
Subject [jira] Commented: (AXIS2-3262) WSDL2Java generates incorrect Exception stubs
Date Thu, 06 Dec 2007 10:19:44 GMT

    [ https://issues.apache.org/jira/browse/AXIS2-3262?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12548980
] 

Ingo Fleer commented on AXIS2-3262:
-----------------------------------

I do have a solution for my special problem. But therefor I had to change the generated WSDL
by hand.

First I can tell you how I understood the code generation and usage of the stubs/skeletons
Understanding code generation:
1) The WSDL generation constructs some fault messages named "RemoteException"
2) The Java-code generation by WSDL generates a class that represents the fault message and
an Exception to transport the fault message.
(for your example:If you would rename your "RemoteException" to "RemoteFault" it would be
more obvious)

What I did:
I wrote an interface with no Exceptions to generate the WSDL (and removed all "/xsd" extension
of all namespaces). Then I did ad the fault messages named xxFault  (for your example: it
should  have a name like "RemoteFault")
>From the WSDL I generated the client stub and the server skeleton - so both of them handle
faults (with Exceptions).

IMPORTANT:
* Client stub methods throw an Exception named like xxFaultMessage (defined by the name of
the fault message in the WSDL)
* Server skeleton methods also throw an Exception named like xxFaultMessage, but to recieve
this at client side you have to create new instance of xxFault class and give it to the xxFaultMessage
before throwing it: Example for the server code:
public void test() throws xxFaultMessage{
  final xxFault fault = new xxFault();
  xxFaultMessage msg = new xxFaultMessage();
  msg.setFaultMessage(fault );
  throw msg;
}
If this method is called by client the proper Exception named xxFaultMessage can be caught
there.
Be advised to declare the fault variable final - without that it never worked for me. That
brought plenty of grey hair ;o)

I think in Axis2 the code generation and especially the naming of faults is not very (or too)
straight forward (or only intransparent for me). But with a little hand work you can get satisfying
solutions

Good luck for your project.



> WSDL2Java generates incorrect Exception stubs
> ---------------------------------------------
>
>                 Key: AXIS2-3262
>                 URL: https://issues.apache.org/jira/browse/AXIS2-3262
>             Project: Axis 2.0 (Axis2)
>          Issue Type: Bug
>          Components: wsdl
>    Affects Versions: 1.3
>            Reporter: Oleg Efimov
>            Assignee: Amila Chinthaka Suriarachchi
>            Priority: Critical
>
> I'm going to show simple example of the problem.
> First, I create a test service:
> -------------------------------------------------------------- test.axis.SoapService

> package test.axis;
> public class SoapService {
>     public void test() throws RemoteException {
>     }
> }
> --------------------------------------------------------------- test.axis.RemoteException
> package test.axis;
> public class RemoteException extends Exception{
>     public RemoteException() {
>     }
>     public RemoteException(Throwable cause) {
>         super(cause);
>     }
>     public RemoteException(String message) {
>         super(message);
>     }
>     public RemoteException(String message, Throwable cause) {
>         super(message, cause);
>     }
> }
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------
> I deploy it on tomcat5.5 on context /axis, web.xml is:
> ---------------------------------------------------------------- web.xml
> <?xml version="1.0" encoding="UTF-8"?>
> <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
>          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>          xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
>          version="2.4">
>     <servlet>
>         <servlet-name>Axis2Servlet</servlet-name>
>         <servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
>     </servlet>
>     <servlet-mapping>
>         <servlet-name>Axis2Servlet</servlet-name>
>         <url-pattern>/axis2/*</url-pattern>
>     </servlet-mapping>
> </web-app>
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------
> Service description:
> ----------------------------------------------------------------- services.xml
> <service name="soapservice" scope="application">
>     <messageReceivers>
>         <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
>                          class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/>
>         <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
>                          class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
>     </messageReceivers>
>     <parameter name="ServiceClass">test.axis.SoapService</parameter>
> </service>
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------
> I use default axis2.xml with only one change:
> ------------------------------------------------------------------------ change in axis2.xml
> <parameter name="servicePath">axis2</parameter>
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------
> WSDL, generated by ?wsdl request, is:
> ------------------------------------------------------------------------ wsdl
> <?xml version="1.0" encoding="UTF-8"?>
> <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:ns0="http://axis.test/xsd" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:ns1="http://axis.test" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" targetNamespace="http://axis.test">
>     <wsdl:documentation>soapservice</wsdl:documentation>
>     <wsdl:types>
>         <xs:schema xmlns:ax21="http://axis.test/xsd" attributeFormDefault="qualified"
elementFormDefault="qualified" targetNamespace="http://axis.test/xsd">
>     <xs:complexType name="RemoteException">
>         <xs:complexContent>
>             <xs:extension base="ns1:Exception">
>                 <xs:sequence/>
>             </xs:extension>
>         </xs:complexContent>
>     </xs:complexType>
> </xs:schema>
>         <xs:schema xmlns:ns="http://axis.test" attributeFormDefault="qualified" elementFormDefault="qualified"
targetNamespace="http://axis.test">
>     <xs:complexType name="Exception">
>         <xs:sequence>
>             <xs:element minOccurs="0" name="Exception" nillable="true" type="xs:anyType"/>
>         </xs:sequence>
>     </xs:complexType>
>     <xs:element name="RemoteException">
>         <xs:complexType>
>             <xs:sequence>
>                 <xs:element minOccurs="0" name="RemoteException" nillable="true" type="ns0:RemoteException"/>
>             </xs:sequence>
>         </xs:complexType>
>     </xs:element>
> </xs:schema>
>     </wsdl:types>
>     <wsdl:message name="testRequest"/>
>     <wsdl:message name="testResponse"/>
>     <wsdl:message name="RemoteException">
>         <wsdl:part name="parameters" element="ns1:RemoteException"/>
>     </wsdl:message>
>     <wsdl:portType name="soapservicePortType">
>         <wsdl:operation name="test">
>             <wsdl:input message="ns1:testRequest" wsaw:Action="urn:test"/>
>             <wsdl:output message="ns1:testResponse" wsaw:Action="urn:testResponse"/>
>             <wsdl:fault message="ns1:RemoteException" name="RemoteException" wsaw:Action="urn:testRemoteException"/>
>         </wsdl:operation>
>     </wsdl:portType>
>     <wsdl:binding name="soapserviceSOAP11Binding" type="ns1:soapservicePortType">
>         <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
>         <wsdl:operation name="test">
>             <soap:operation soapAction="urn:test" style="document"/>
>             <wsdl:input>
>                 <soap:body use="literal"/>
>             </wsdl:input>
>             <wsdl:output>
>                 <soap:body use="literal"/>
>             </wsdl:output>
>             <wsdl:fault name="RemoteException">
>                 <soap:fault use="literal" name="RemoteException"/>
>             </wsdl:fault>
>         </wsdl:operation>
>     </wsdl:binding>
>     <wsdl:binding name="soapserviceSOAP12Binding" type="ns1:soapservicePortType">
>         <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
>         <wsdl:operation name="test">
>             <soap12:operation soapAction="urn:test" style="document"/>
>             <wsdl:input>
>                 <soap12:body use="literal"/>
>             </wsdl:input>
>             <wsdl:output>
>                 <soap12:body use="literal"/>
>             </wsdl:output>
>             <wsdl:fault name="RemoteException">
>                 <soap12:fault use="literal" name="RemoteException"/>
>             </wsdl:fault>
>         </wsdl:operation>
>     </wsdl:binding>
>     <wsdl:binding name="soapserviceHttpBinding" type="ns1:soapservicePortType">
>         <http:binding verb="POST"/>
>         <wsdl:operation name="test">
>             <http:operation location="soapservice/test"/>
>             <wsdl:input>
>                 <mime:content type="text/xml" part="test"/>
>             </wsdl:input>
>         </wsdl:operation>
>     </wsdl:binding>
>     <wsdl:service name="soapservice">
>         <wsdl:port name="soapserviceSOAP11port_http" binding="ns1:soapserviceSOAP11Binding">
>             <soap:address location="http://localhost:8081/axis/axis2/soapservice"/>
>         </wsdl:port>
>         <wsdl:port name="soapserviceSOAP12port_http" binding="ns1:soapserviceSOAP12Binding">
>             <soap12:address location="http://localhost:8081/axis/axis2/soapservice"/>
>         </wsdl:port>
>         <wsdl:port name="soapserviceHttpport" binding="ns1:soapserviceHttpBinding">
>             <http:address location="http://localhost:8081/axis/axis2/soapservice"/>
>         </wsdl:port>
>     </wsdl:service>
> </wsdl:definitions>
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------
> Then I use wsdl2java task to create client stubs:
> ------------------------------------------------------------------------- build.xml
> <?xml version="1.0" encoding="UTF-8"?>
> <project name="testaxis2" basedir=".">
>     <path id="build.classpath">
>         <fileset dir="C:/axis2lib" includes="*.jar"/>
>     </path>
>     <macrodef name="wsdl2java">
>         <attribute name="url"/>
>         <attribute name="targetdir"/>
>         <attribute name="package"/>
>         <sequential>
>             <java classname="org.apache.axis2.wsdl.WSDL2Java" fork="yes" classpathref="build.classpath">
>                 <arg value="-or"/>
>                 <arg value="-u"/>
>                 <arg value="-uw"/>
>                 <arg value="-sp"/>
>                 <arg value="-p"/>
>                 <arg value="@{package}"/>
>                 <arg value="-o"/>
>                 <arg value="@{targetdir}"/>
>                 <arg value="-uri"/>
>                 <arg value="@{url}"/>
>             </java>
>         </sequential>
>     </macrodef>
>     <target name="test-wsdl">
>         <wsdl2java targetdir="c:/testaxis" url="http://localhost:8081/axis/axis2/soapservice?wsdl"
package="test.axis.stub"/>
>     </target>
> </project>
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------
> This task generates the following file tree inside testaxis/src/test/axis folder:
> ----------------------------------------------------------
> /stub
>      RemoteExceptionException0.java
>      Soapservice.java
>      SoapserviceCallbackHandler.java
>      SoapserviceStub.java
> /xsd
>      ExtensionMapper.java
>      RemoteException.java
> Exception.java
> RemoteException0.java
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------
> So, we've got plenty of exception classes here. To briefly describe their relations in
UML-like style, I can say:
> test.axis.stub.RemoteExceptionException0 HAS test.axis.RemoteException0 IS java.lang.Exception
> test.axis.RemoteException0 HAS test.axis.xsd.RemoteException
> test.axis.xsd.RemoteException IS test.axis.Exception
> Stub method test() is reported to throw test.axis.stub.RemoteExceptionException0, which
is simply java.lang.Exception, not an AxisFault, so really in case of RemoteException on server
I'll get just AxisFault with message preserved, not any specific RemoteException I've wanted.
> I believe, only one exception stub should be generated, called RemoteException, and it
should subclass AxisFault.
> PS Damn, I really hope someone will read it :)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-dev-help@ws.apache.org


Mime
View raw message