You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Leon Hwang <hw...@mystrands.com> on 2007/08/29 23:25:41 UTC

[Axis2] Axis2 and Enum type

Hello there,

I created a simple function that returns an object type of enum.
It is very simple function:

public static Gender getGender() {
     return Gender.MALE;
}

but when I opened the page from a browser
http://localhost:8080/OpenApi/services/TestApi10/getGender

it generates an error like
<soapenv:Reason>
     <soapenv:Text xml:lang="en-US">
         java.lang.RuntimeException: org.apache.axis2.AxisFault: Mapping qname not fond for the package: org.apache.catalina.loader
     </soapenv:Text>
</soapenv:Reason>

If I return any other objects, it works fine.
Am I not supposed to Enum type?
I think this is an error in Axis2.
By the way, I would not like to use Type-safe enum.
It has its own problem.

I have attached a source code and services.xml (TestApi.xml) and wsdl (TestApi10.xml - created by Axis2 on the fly).


By the way, if I create a client using WSDL2Java
wsdl2java.bat -or -g -Eofv -uw -u -uri http://localhost:8080/OpenApi/services/UserApi10?wsdl

I get a warning like this:
[WARN] Type {http://www.w3.org/2001/XMLSchema}Enum missing!

How do I get rid of this?

Also WSDL2Java doesn't create a enum type for Gender. Rather it is a regular class.
Which I have to use it like

Gender g = new Gender();
g.getFEMALE();

This didn't make a sense to me.


As a comparison, .NET create an enum type correctly.
In WSDL that .NET create, it is a just simpleType with restrictions.
I don't know if that caused the problem or not.

I would appreciate if you could give any help on this.

Thank you,

- Leon

Re: [Axis2] Axis2 and Enum type

Posted by Leon Hwang <hw...@mystrands.com>.
They said the current Axis2 is based on Java 1.4 which doesn't have the enum type definition.
I was told that this will be fixed in the next release (I am not sure if that was an official answer or not).

For creating WSDL, look at the code (WSDLDataLocator.java) in Axis2 source.
Here is what I do.
Instead of inventing WSDL creator, create your own data locator "extended" from WSDLDataLocator.
In outputInlineForm, get the result (OMElemet) from the parent and make changes there.

  protected Data[] outputInlineForm(MessageContext msgContext, ServiceData[] dataList)
             throws DataRetrievalException {
     	Data[] result = super.outputInlineForm(msgContext, dataList);
     	
     	if (null != result && null != result[0]) {
     		OMElement wsdlElement = (OMElement)result[0].getData();
     		this.generateCustomWSDL(wsdlElement); // call your own function
     		result[0] = new Data(wsdlElement, null);    		
     	}
     	
     	return result;
     }


Then, add datalocator in service.xml

<service name="api">
		<description>Some API</description>
		
		<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" locked="false">
			YOUR_SERVICE_CLASS
		</parameter>
		
		<dataLocator>
			<dialectLocator dialect="http://schemas.xmlsoap.org/wsdl/"
				class="YOUR_DATA_LOCATOR_CLASS" />
		</dataLocator>
</service>

Hope this helps.

- Leon

Mathias P.W Nilsson wrote:
> I don't quit get the response. I don't generate the wsdl myself. Axis2
> servlet does that I suppose. 
> 
> In my method I should return int instead? 

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


Re: [Axis2] Axis2 and Enum type

Posted by "Mathias P.W Nilsson" <ma...@snyltarna.se>.
I don't quit get the response. I don't generate the wsdl myself. Axis2
servlet does that I suppose. 

In my method I should return int instead? 
-- 
View this message in context: http://www.nabble.com/-Axis2--Axis2-and-Enum-type-tf4350527.html#a12821870
Sent from the Axis - User mailing list archive at Nabble.com.


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


Re: [Axis2] Axis2 and Enum type

Posted by robert lazarski <ro...@gmail.com>.
This is an old problem. Until Axis2 gets code to support java 5 enums,
 I just do a
simple conversion. With this example in the wsdl:

<element minOccurs="1" maxOccurs="1" nillable="true"
name="TipoMibEnum" type="xsd:int"/>

You'd get that value in the Service with the idea of converting it to this:

public enum TipoMib implements Serializable{

       MIB2,
       MIB_GERENCIA,
       MIB_ESPECIFICA;
}

I do the conversion as:

private static TipoMib getTipoMib(Integer ordinal) {
      if (TipoMib.MIB2.ordinal() == ordinal) {
          return TipoMib.MIB2;
      } else if (TipoMib.MIB_ESPECIFICA.ordinal() == ordinal) {
          return TipoMib.MIB_ESPECIFICA;
      } else if (TipoMib.MIB_GERENCIA.ordinal() == ordinal) {
          return TipoMib.MIB_GERENCIA;
      } else
          return null;
}

To convert the other way I do tipoMib.ordinal() - see the javadoc of
Enum about ordinal() .

HTH,
Robert

On 9/21/07, Mathias P.W Nilsson <ma...@snyltarna.se> wrote:
>
> Did you find any solution to this? I'm having the same problem
> --
> View this message in context: http://www.nabble.com/-Axis2--Axis2-and-Enum-type-tf4350527.html#a12819819
> Sent from the Axis - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>

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


Re: [Axis2] Axis2 and Enum type

Posted by "Mathias P.W Nilsson" <ma...@snyltarna.se>.
Did you find any solution to this? I'm having the same problem
-- 
View this message in context: http://www.nabble.com/-Axis2--Axis2-and-Enum-type-tf4350527.html#a12819819
Sent from the Axis - User mailing list archive at Nabble.com.


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


Re: [Axis2] Axis2 and Enum type

Posted by Sanka Samaranayake <ss...@gmail.com>.
On 8/30/07, Leon Hwang <hw...@mystrands.com> wrote:
>
> Wow...
>
> Thank you, Keith.
>
> Then, I guess, returning enum type won't do any good. (like I can...)
>
> What does people do?
> Is there any alternative?
> Only way I can think of is to return a primitive type or String
> representation of the enum value,
> then communicate with developers wring client, "You have to use this EXACT
> string".
>
> Keith, do you happen to know when the enum feature will be supported by
> Axis2?



It is on the table for next Axis2 release version.

Best,
Sanka

Thank you, again.
>
> - Leon
>
> keith chapman wrote:
> > Axis2 is JDK 1.4 compatible. Hence it does not use JDK 1.5 features.
> > This is the reason you see code like the following.
> >
> > Gender g = new Gender();
> > g.getFEMALE();
> >
> > Thanks,
> > Keith.
> >
> > On 8/30/07, *Leon Hwang* <hwang@mystrands.com
> > <ma...@mystrands.com>> wrote:
> >
> >     Hello there,
> >
> >     I created a simple function that returns an object type of enum.
> >     It is very simple function:
> >
> >     public static Gender getGender() {
> >          return Gender.MALE;
> >     }
> >
> >     but when I opened the page from a browser
> >     http://localhost:8080/OpenApi/services/TestApi10/getGender
> >
> >     it generates an error like
> >     <soapenv:Reason>
> >          <soapenv:Text xml:lang="en-US">
> >              java.lang.RuntimeException: org.apache.axis2.AxisFault:
> >     Mapping qname not fond for the package: org.apache.catalina.loader
> >          </soapenv:Text>
> >     </soapenv:Reason>
> >
> >     If I return any other objects, it works fine.
> >     Am I not supposed to Enum type?
> >     I think this is an error in Axis2.
> >     By the way, I would not like to use Type-safe enum.
> >     It has its own problem.
> >
> >     I have attached a source code and services.xml (TestApi.xml ) and
> >     wsdl (TestApi10.xml - created by Axis2 on the fly).
> >
> >
> >     By the way, if I create a client using WSDL2Java
> >     wsdl2java.bat -or -g -Eofv -uw -u -uri
> >     http://localhost:8080/OpenApi/services/UserApi10?wsdl
> >
> >     I get a warning like this:
> >     [WARN] Type {http://www.w3.org/2001/XMLSchema}Enum missing!
> >
> >     How do I get rid of this?
> >
> >     Also WSDL2Java doesn't create a enum type for Gender. Rather it is a
> >     regular class.
> >     Which I have to use it like
> >
> >     Gender g = new Gender();
> >     g.getFEMALE();
> >
> >     This didn't make a sense to me.
> >
> >
> >     As a comparison, .NET create an enum type correctly.
> >     In WSDL that .NET create, it is a just simpleType with restrictions.
> >     I don't know if that caused the problem or not.
> >
> >     I would appreciate if you could give any help on this.
> >
> >     Thank you,
> >
> >     - Leon
> >
> >
> ---------------------------------------------------------------------
> >     To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
> >     <ma...@ws.apache.org>
> >     For additional commands, e-mail: axis-dev-help@ws.apache.org
> >     <ma...@ws.apache.org>
> >
> >
> >
> >
> > --
> > Keith Chapman
> > WSO2 Inc.
> > Oxygen for Web Services Developers.
> > http://wso2.org/
>
> --
> Leon Hwang
> Senior Tech Lead
> MyStrands Inc.
>
> work: 1.541.753.4426
> mobile: 1.541.740.7511
> fax: 1.541.754.6416
> email: hwang@mystrands.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-dev-help@ws.apache.org
>
>


-- 
Sanka Samaranayake
WSO2 Inc.

http://www.bloglines.com/blog/sanka
http://www.wso2.org/

Re: [Axis2] Axis2 and Enum type

Posted by keith chapman <ke...@gmail.com>.
On 8/30/07, Leon Hwang <hw...@mystrands.com> wrote:
>
> Wow...
>
> Thank you, Keith.
>
> Then, I guess, returning enum type won't do any good. (like I can...)
>
> What does people do?
> Is there any alternative?
> Only way I can think of is to return a primitive type or String
> representation of the enum value,
> then communicate with developers wring client, "You have to use this EXACT
> string".


You can communicate this via the WSDL for your service. The schema used to
define the input elements for your operations can use <xs:enumerations>. Any
client having this WSDL knows what the operation expects.

Thanks,
Keith.

Keith, do you happen to know when the enum feature will be supported by
> Axis2?
>
> Thank you, again.
>
> - Leon
>
> keith chapman wrote:
> > Axis2 is JDK 1.4 compatible. Hence it does not use JDK 1.5 features.
> > This is the reason you see code like the following.
> >
> > Gender g = new Gender();
> > g.getFEMALE();
> >
> > Thanks,
> > Keith.
> >
> > On 8/30/07, *Leon Hwang* <hwang@mystrands.com
> > <ma...@mystrands.com>> wrote:
> >
> >     Hello there,
> >
> >     I created a simple function that returns an object type of enum.
> >     It is very simple function:
> >
> >     public static Gender getGender() {
> >          return Gender.MALE;
> >     }
> >
> >     but when I opened the page from a browser
> >     http://localhost:8080/OpenApi/services/TestApi10/getGender
> >
> >     it generates an error like
> >     <soapenv:Reason>
> >          <soapenv:Text xml:lang="en-US">
> >              java.lang.RuntimeException: org.apache.axis2.AxisFault:
> >     Mapping qname not fond for the package: org.apache.catalina.loader
> >          </soapenv:Text>
> >     </soapenv:Reason>
> >
> >     If I return any other objects, it works fine.
> >     Am I not supposed to Enum type?
> >     I think this is an error in Axis2.
> >     By the way, I would not like to use Type-safe enum.
> >     It has its own problem.
> >
> >     I have attached a source code and services.xml (TestApi.xml ) and
> >     wsdl (TestApi10.xml - created by Axis2 on the fly).
> >
> >
> >     By the way, if I create a client using WSDL2Java
> >     wsdl2java.bat -or -g -Eofv -uw -u -uri
> >     http://localhost:8080/OpenApi/services/UserApi10?wsdl
> >
> >     I get a warning like this:
> >     [WARN] Type {http://www.w3.org/2001/XMLSchema}Enum missing!
> >
> >     How do I get rid of this?
> >
> >     Also WSDL2Java doesn't create a enum type for Gender. Rather it is a
> >     regular class.
> >     Which I have to use it like
> >
> >     Gender g = new Gender();
> >     g.getFEMALE();
> >
> >     This didn't make a sense to me.
> >
> >
> >     As a comparison, .NET create an enum type correctly.
> >     In WSDL that .NET create, it is a just simpleType with restrictions.
> >     I don't know if that caused the problem or not.
> >
> >     I would appreciate if you could give any help on this.
> >
> >     Thank you,
> >
> >     - Leon
> >
> >
> ---------------------------------------------------------------------
> >     To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
> >     <ma...@ws.apache.org>
> >     For additional commands, e-mail: axis-dev-help@ws.apache.org
> >     <ma...@ws.apache.org>
> >
> >
> >
> >
> > --
> > Keith Chapman
> > WSO2 Inc.
> > Oxygen for Web Services Developers.
> > http://wso2.org/
>
> --
> Leon Hwang
> Senior Tech Lead
> MyStrands Inc.
>
> work: 1.541.753.4426
> mobile: 1.541.740.7511
> fax: 1.541.754.6416
> email: hwang@mystrands.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-dev-help@ws.apache.org
>
>


-- 
Keith Chapman
WSO2 Inc.
Oxygen for Web Services Developers.
http://wso2.org/

Re: [Axis2] Axis2 and Enum type

Posted by Leon Hwang <hw...@mystrands.com>.
Wow...

Thank you, Keith.

Then, I guess, returning enum type won't do any good. (like I can...)

What does people do?
Is there any alternative?
Only way I can think of is to return a primitive type or String representation of the enum value,
then communicate with developers wring client, "You have to use this EXACT string".

Keith, do you happen to know when the enum feature will be supported by Axis2?

Thank you, again.

- Leon

keith chapman wrote:
> Axis2 is JDK 1.4 compatible. Hence it does not use JDK 1.5 features. 
> This is the reason you see code like the following.
> 
> Gender g = new Gender();
> g.getFEMALE();
> 
> Thanks,
> Keith.
> 
> On 8/30/07, *Leon Hwang* <hwang@mystrands.com 
> <ma...@mystrands.com>> wrote:
> 
>     Hello there,
> 
>     I created a simple function that returns an object type of enum.
>     It is very simple function:
> 
>     public static Gender getGender() {
>          return Gender.MALE;
>     }
> 
>     but when I opened the page from a browser
>     http://localhost:8080/OpenApi/services/TestApi10/getGender
> 
>     it generates an error like
>     <soapenv:Reason>
>          <soapenv:Text xml:lang="en-US">
>              java.lang.RuntimeException: org.apache.axis2.AxisFault:
>     Mapping qname not fond for the package: org.apache.catalina.loader
>          </soapenv:Text>
>     </soapenv:Reason>
> 
>     If I return any other objects, it works fine.
>     Am I not supposed to Enum type?
>     I think this is an error in Axis2.
>     By the way, I would not like to use Type-safe enum.
>     It has its own problem.
> 
>     I have attached a source code and services.xml (TestApi.xml ) and
>     wsdl (TestApi10.xml - created by Axis2 on the fly).
> 
> 
>     By the way, if I create a client using WSDL2Java
>     wsdl2java.bat -or -g -Eofv -uw -u -uri
>     http://localhost:8080/OpenApi/services/UserApi10?wsdl
> 
>     I get a warning like this:
>     [WARN] Type {http://www.w3.org/2001/XMLSchema}Enum missing!
> 
>     How do I get rid of this?
> 
>     Also WSDL2Java doesn't create a enum type for Gender. Rather it is a
>     regular class.
>     Which I have to use it like
> 
>     Gender g = new Gender();
>     g.getFEMALE();
> 
>     This didn't make a sense to me.
> 
> 
>     As a comparison, .NET create an enum type correctly.
>     In WSDL that .NET create, it is a just simpleType with restrictions.
>     I don't know if that caused the problem or not.
> 
>     I would appreciate if you could give any help on this.
> 
>     Thank you,
> 
>     - Leon
> 
>     ---------------------------------------------------------------------
>     To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
>     <ma...@ws.apache.org>
>     For additional commands, e-mail: axis-dev-help@ws.apache.org
>     <ma...@ws.apache.org>
> 
> 
> 
> 
> -- 
> Keith Chapman
> WSO2 Inc.
> Oxygen for Web Services Developers.
> http://wso2.org/

-- 
Leon Hwang
Senior Tech Lead
MyStrands Inc.

work: 1.541.753.4426
mobile: 1.541.740.7511
fax: 1.541.754.6416
email: hwang@mystrands.com

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


Re: [Axis2] Axis2 and Enum type

Posted by keith chapman <ke...@gmail.com>.
Axis2 is JDK 1.4 compatible. Hence it does not use JDK 1.5 features. This is
the reason you see code like the following.

Gender g = new Gender();
g.getFEMALE();

Thanks,
Keith.

On 8/30/07, Leon Hwang <hw...@mystrands.com> wrote:
>
> Hello there,
>
> I created a simple function that returns an object type of enum.
> It is very simple function:
>
> public static Gender getGender() {
>      return Gender.MALE;
> }
>
> but when I opened the page from a browser
> http://localhost:8080/OpenApi/services/TestApi10/getGender
>
> it generates an error like
> <soapenv:Reason>
>      <soapenv:Text xml:lang="en-US">
>          java.lang.RuntimeException: org.apache.axis2.AxisFault: Mapping
> qname not fond for the package: org.apache.catalina.loader
>      </soapenv:Text>
> </soapenv:Reason>
>
> If I return any other objects, it works fine.
> Am I not supposed to Enum type?
> I think this is an error in Axis2.
> By the way, I would not like to use Type-safe enum.
> It has its own problem.
>
> I have attached a source code and services.xml (TestApi.xml) and wsdl (
> TestApi10.xml - created by Axis2 on the fly).
>
>
> By the way, if I create a client using WSDL2Java
> wsdl2java.bat -or -g -Eofv -uw -u -uri
> http://localhost:8080/OpenApi/services/UserApi10?wsdl
>
> I get a warning like this:
> [WARN] Type {http://www.w3.org/2001/XMLSchema}Enum missing!
>
> How do I get rid of this?
>
> Also WSDL2Java doesn't create a enum type for Gender. Rather it is a
> regular class.
> Which I have to use it like
>
> Gender g = new Gender();
> g.getFEMALE();
>
> This didn't make a sense to me.
>
>
> As a comparison, .NET create an enum type correctly.
> In WSDL that .NET create, it is a just simpleType with restrictions.
> I don't know if that caused the problem or not.
>
> I would appreciate if you could give any help on this.
>
> Thank you,
>
> - Leon
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-dev-help@ws.apache.org
>
>


-- 
Keith Chapman
WSO2 Inc.
Oxygen for Web Services Developers.
http://wso2.org/