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 Borislav Kirilov <bo...@bultreebank.org> on 2007/04/02 13:45:56 UTC

java.util.Map and more specifically HashMap

Hello! I'm trying to generate code for a method with the following 
signature :
public Map<String, String[]> listQueries()

I tried with the code generator plug-in for Eclipse available from 
http://ws.apache.org/axis2/tools/index.html
The first problem that I have is that for returning the Map type, the 
tool generates from the WSDL additional package which name is 
java.util.xsd that contains the Map type description, but this is a 
wrong class name, because java, sun and javax are reserved for the Java 
Virtual Machine!
The other problem is that this Map description has nothing in common 
with the original java.util.Map type and hence gives me the following 
exception:
org.apache.axis2.AxisFault: java.util.HashMap
    at 
org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:271)
    at 
org.apache.axis2.description.OutInAxisOperationClient.execute(OutInAxisOperation.java:202)
    at 
clark.webinterface.webadapter.ClarkWebServiceStub.listQueries(ClarkWebServiceStub.java:4413)

I have attached the generated classes from the java.util.xsd package.

Has anyone met the same problem? If you have please share your experience!


Re: java.util.Map and more specifically HashMap

Posted by Lahiru Sandakith <sa...@gmail.com>.
Hi Borislav,

I am  trying to understand the requirement. This is what I did,I just
include a method as yours in a pojo class and generated a wsdl from that
using the codegen tool. So as expectedly because you have used a collection
as the return type the wsdl include

<xs:element name="TestResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="return" nillable="true"
                            type="xs:anyType" />
                    </xs:sequence>
                </xs:complexType>
            </xs:element>

anyType as element type of the return values, so what that means the output
from the web service can contain any kind of valid xml. So from this service
you can generate the skeleton and include your logic inside that skeleton to
create the service and deploy that. AFAIK since messages passes are in xml
you have to implement the logic to according to that inside service
skeleton.

Thanks

Lahiru

On 4/2/07, Borislav Kirilov <bo...@bultreebank.org> wrote:
>
> Hello! I'm trying to generate code for a method with the following
> signature :
> public Map<String, String[]> listQueries()
>
> I tried with the code generator plug-in for Eclipse available from
> http://ws.apache.org/axis2/tools/index.html
> The first problem that I have is that for returning the Map type, the
> tool generates from the WSDL additional package which name is
> java.util.xsd that contains the Map type description, but this is a
> wrong class name, because java, sun and javax are reserved for the Java
> Virtual Machine!
> The other problem is that this Map description has nothing in common
> with the original java.util.Map type and hence gives me the following
> exception:
> org.apache.axis2.AxisFault: java.util.HashMap
>     at
> org.apache.axis2.description.OutInAxisOperationClient.send(
> OutInAxisOperation.java:271)
>     at
> org.apache.axis2.description.OutInAxisOperationClient.execute(
> OutInAxisOperation.java:202)
>     at
> clark.webinterface.webadapter.ClarkWebServiceStub.listQueries(
> ClarkWebServiceStub.java:4413)
>
> I have attached the generated classes from the java.util.xsd package.
>
> Has anyone met the same problem? If you have please share your experience!
>
>
>
>             /**
>             * ExtensionMapper.java
>             *
>             * This file was auto-generated from WSDL
>             * by the Apache Axis2 version: #axisVersion# #today#
>             */
>
>             package clark.webinterface.util.xsd;
>             /**
>             *  ExtensionMapper class
>             */
>
>         public  class ExtensionMapper{
>
>           public static java.lang.Object getTypeObject(java.lang.StringnamespaceURI,
>                                                        java.lang.StringtypeName,
>
> javax.xml.stream.XMLStreamReader reader) throws java.lang.Exception{
>
>
>                   if (
>                   "http://util.java/xsd".equals(namespaceURI) &&
>                   "Map".equals(typeName)){
>
>                             return
> clark.webinterface.util.xsd.Map.Factory.parse(reader);
>
>
>                   }
>
>
>              throw new java.lang.RuntimeException("Unsupported type " +
> namespaceURI + " " + typeName);
>           }
>
>         }
>
>
>             /**
>             * Map2.java
>             *
>             * This file was auto-generated from WSDL
>             * by the Apache Axis2 version: #axisVersion# #today#
>             */
>
>             package clark.webinterface.util.xsd;
>             /**
>             *  Map2 bean class
>             */
>
>         public  class Map2
>         implements org.apache.axis2.databinding.ADBBean{
>
>                 public static final javax.xml.namespace.QName MY_QNAME =
> new javax.xml.namespace.QName(
>                 "http://util.java/xsd",
>                 "Map",
>                 "ns1");
>
>
>
>                         /**
>                         * field for Map
>                         */
>
>                         protected clark.webinterface.util.xsd.Map localMap
> ;
>
>
>                            /**
>                            * Auto generated getter method
>                            * @return java.util.xsd.Map
>                            */
>                            public  clark.webinterface.util.xsd.MapgetMap(){
>                                return localMap;
>                            }
>
>
>
>                             /**
>                                * Auto generated setter method
>                                * @param param Map
>                                */
>                                public void setMap(
> clark.webinterface.util.xsd.Map param){
>
>                                     this.localMap=param;
>
>
>                                }
>
>
>      /**
>      * isReaderMTOMAware
>      * @return true if the reader supports MTOM
>      */
>    public static boolean isReaderMTOMAware(
> javax.xml.stream.XMLStreamReader reader) {
>         boolean isReaderMTOMAware = false;
>
>         try{
>           isReaderMTOMAware = java.lang.Boolean.TRUE.equals(
> reader.getProperty(org.apache.axiom.om.OMConstants.IS_DATA_HANDLERS_AWARE
> ));
>         }catch(java.lang.IllegalArgumentException e){
>           isReaderMTOMAware = false;
>         }
>         return isReaderMTOMAware;
>    }
>
>
>         /**
>         *
>         * @param parentQName
>         * @param factory
>         * @return org.apache.axiom.om.OMElement
>         */
>        public org.apache.axiom.om.OMElement getOMElement(
>                final javax.xml.namespace.QName parentQName,
>                final org.apache.axiom.om.OMFactory factory){
>
>         org.apache.axiom.om.OMDataSource dataSource =
> getOMDataSource(parentQName, factory);
>
>
>                return new
> org.apache.axiom.om.impl.llom.OMSourcedElementImpl(
>                MY_QNAME,factory,dataSource);
>
>        }
>
>      /**
>      *
>      * @param parentQName
>      * @param factory
>      * @return org.apache.axiom.om.OMElement
>      */
>     public org.apache.axiom.om.OMDataSource getOMDataSource(
>             final javax.xml.namespace.QName parentQName,
>             final org.apache.axiom.om.OMFactory factory){
>
>
>         org.apache.axiom.om.OMDataSource dataSource =
>                        new org.apache.axis2.databinding.ADBDataSource
> (this,parentQName){
>
>          public void serialize(
>                                   javax.xml.stream.XMLStreamWriterxmlWriter) throws
> javax.xml.stream.XMLStreamException {
>
>
>                 //We can safely assume an element has only one type
> associated with it
>
>                                  if (localMap==null){
>                                    throw new RuntimeException("Property
> cannot be null!");
>                                  }
>                                  localMap.getOMDataSource(
>                                          MY_QNAME,
>                                          factory).serialize(xmlWriter);
>
>
>         }
>
>          /**
>           * Util method to write an attribute with the ns prefix
>           */
>           private void writeAttribute(java.lang.String prefix,
> java.lang.String namespace,java.lang.String attName,
>                                       java.lang.String attValue,
> javax.xml.stream.XMLStreamWriter xmlWriter) throws
> javax.xml.stream.XMLStreamException{
>               if (xmlWriter.getPrefix(namespace) == null) {
>                        xmlWriter.writeNamespace(prefix, namespace);
>                        xmlWriter.setPrefix(prefix, namespace);
>
>               }
>
>               xmlWriter.writeAttribute(namespace,attName,attValue);
>
>          }
>
>          /**
>           * Util method to write an attribute without the ns prefix
>           */
>           private void writeAttribute(java.lang.String namespace,
> java.lang.String attName,
>                                       java.lang.String attValue,
> javax.xml.stream.XMLStreamWriter xmlWriter) throws
> javax.xml.stream.XMLStreamException{
>                   if (namespace.equals(""))
>                   {
>                           xmlWriter.writeAttribute(attName,attValue);
>                   }
>                   else
>                   {
>                   registerPrefix(xmlWriter, namespace);
>                   xmlWriter.writeAttribute(namespace,attName,attValue);
>               }
>           }
>
>          /**
>          * Register a namespace prefix
>          */
>          private java.lang.String registerPrefix(
> javax.xml.stream.XMLStreamWriter xmlWriter, java.lang.String namespace)
> throws javax.xml.stream.XMLStreamException {
>                 java.lang.String prefix = xmlWriter.getPrefix(namespace);
>
>                 if (prefix == null) {
>                     prefix = createPrefix();
>
>                     while (xmlWriter.getNamespaceContext().getNamespaceURI(prefix)
> != null) {
>                         prefix = createPrefix();
>                     }
>
>                     xmlWriter.writeNamespace(prefix, namespace);
>                     xmlWriter.setPrefix(prefix, namespace);
>                 }
>
>                 return prefix;
>             }
>
>          /**
>           * Create a prefix
>           */
>           private java.lang.String createPrefix() {
>                 return "ns" + (int)Math.random();
>           }
>         };
>
>         return dataSource;
>     }
>
>
>         /**
>         * databinding method to get an XML representation of this object
>         *
>         */
>         public javax.xml.stream.XMLStreamReader getPullParser(
> javax.xml.namespace.QName qName){
>
>
>
>
>                 //We can safely assume an element has only one type
> associated with it
>                 return localMap.getPullParser(MY_QNAME);
>
>         }
>
>
>
>      /**
>       *  Factory class that keeps the parse method
>       */
>     public static class Factory{
>
>
>         /**
>         * static method to create the object
>         * Precondition:  If this object is an element, the current or next
> start element starts this object and any intervening reader events are
> ignorable
>         *                If this object is not an element, it is a complex
> type and the reader is at the event just after the outer start element
>         * Postcondition: If this object is an element, the reader is
> positioned at its end element
>         *                If this object is a complex type, the reader is
> positioned at the end element of its outer element
>         */
>         public static Map2 parse(javax.xml.stream.XMLStreamReader reader)
> throws java.lang.Exception{
>             Map2 object = new Map2();
>             int event;
>             try {
>
>                 while (!reader.isStartElement() && !reader.isEndElement())
>                     reader.next();
>
>
>
>
>                 // Note all attributes that were handled. Used to differ
> normal attributes
>                 // from anyAttributes.
>                 java.util.Vector handledAttributes = new java.util.Vector
> ();
>
>                 while(!reader.isEndElement()) {
>                     if (reader.isStartElement() ){
>
>                                     if (reader.isStartElement() && new
> javax.xml.namespace.QName("http://util.java/xsd","Map").equals(
> reader.getName())){
>
>                                         object.setMap(
> clark.webinterface.util.xsd.Map.Factory.parse(reader));
>
>                               }  // End of if for expected property start
> element
>
>                              else{
>                                         // A start element we are not
> expecting indicates an invalid parameter was passed
>                                         throw new
> java.lang.RuntimeException("Unexpected subelement " + reader.getLocalName
> ());
>                              }
>
>                              } else reader.next();
>                             }  // end of while loop
>
>
>
>             } catch (javax.xml.stream.XMLStreamException e) {
>                 throw new java.lang.Exception(e);
>             }
>
>             return object;
>         }
>
>         }//end of factory class
>
>
>
>         }
>
>
>
>             /**
>             * Map.java
>             *
>             * This file was auto-generated from WSDL
>             * by the Apache Axis2 version: #axisVersion# #today#
>             */
>
>             package clark.webinterface.util.xsd;
>             /**
>             *  Map bean class
>             */
>
>         public  class Map
>         implements org.apache.axis2.databinding.ADBBean{
>         /* This type was generated from the piece of schema that had
>                 name = Map
>                 Namespace URI = http://util.java/xsd
>                 Namespace Prefix = ns1
>                 */
>
>
>                         /**
>                         * field for Empty
>                         */
>
>                         protected boolean localEmpty ;
>
>
>                            /**
>                            * Auto generated getter method
>                            * @return boolean
>                            */
>                            public  boolean getEmpty(){
>                                return localEmpty;
>                            }
>
>
>
>                             /**
>                                * Auto generated setter method
>                                * @param param Empty
>                                */
>                                public void setEmpty(boolean param){
>
>                                     this.localEmpty=param;
>
>
>                                }
>
>
>      /**
>      * isReaderMTOMAware
>      * @return true if the reader supports MTOM
>      */
>    public static boolean isReaderMTOMAware(
> javax.xml.stream.XMLStreamReader reader) {
>         boolean isReaderMTOMAware = false;
>
>         try{
>           isReaderMTOMAware = java.lang.Boolean.TRUE.equals(
> reader.getProperty(org.apache.axiom.om.OMConstants.IS_DATA_HANDLERS_AWARE
> ));
>         }catch(java.lang.IllegalArgumentException e){
>           isReaderMTOMAware = false;
>         }
>         return isReaderMTOMAware;
>    }
>
>
>         /**
>         *
>         * @param parentQName
>         * @param factory
>         * @return org.apache.axiom.om.OMElement
>         */
>        public org.apache.axiom.om.OMElement getOMElement(
>                final javax.xml.namespace.QName parentQName,
>                final org.apache.axiom.om.OMFactory factory){
>
>         org.apache.axiom.om.OMDataSource dataSource =
> getOMDataSource(parentQName, factory);
>
>
>                return new
> org.apache.axiom.om.impl.llom.OMSourcedElementImpl(
>                parentQName,factory,dataSource);
>
>        }
>
>      /**
>      *
>      * @param parentQName
>      * @param factory
>      * @return org.apache.axiom.om.OMElement
>      */
>     public org.apache.axiom.om.OMDataSource getOMDataSource(
>             final javax.xml.namespace.QName parentQName,
>             final org.apache.axiom.om.OMFactory factory){
>
>
>         org.apache.axiom.om.OMDataSource dataSource =
>                        new org.apache.axis2.databinding.ADBDataSource
> (this,parentQName){
>
>          public void serialize(
>                                   javax.xml.stream.XMLStreamWriterxmlWriter) throws
> javax.xml.stream.XMLStreamException {
>
>
>
>                 java.lang.String prefix = parentQName.getPrefix();
>                 java.lang.String namespace = parentQName.getNamespaceURI
> ();
>
>                 if (namespace != null) {
>                     java.lang.String writerPrefix = xmlWriter.getPrefix
> (namespace);
>                     if (writerPrefix != null) {
>                         xmlWriter.writeStartElement(namespace,
> parentQName.getLocalPart());
>                     } else {
>                         if (prefix == null) {
>                             prefix =
> org.apache.axis2.databinding.utils.BeanUtil.getUniquePrefix();
>                         }
>
>                         xmlWriter.writeStartElement(prefix,
> parentQName.getLocalPart(), namespace);
>                         xmlWriter.writeNamespace(prefix, namespace);
>                         xmlWriter.setPrefix(prefix, namespace);
>                     }
>                 } else {
>                     xmlWriter.writeStartElement(parentQName.getLocalPart
> ());
>                 }
>
>
>
>                                     namespace = "http://util.java/xsd";
>                                     if (! namespace.equals("")) {
>                                         prefix = xmlWriter.getPrefix
> (namespace);
>
>                                         if (prefix == null) {
>                                             prefix =
> org.apache.axis2.databinding.utils.BeanUtil.getUniquePrefix();
>
>                                             xmlWriter.writeStartElement(prefix,"empty",
> namespace);
>                                             xmlWriter.writeNamespace(prefix,
> namespace);
>                                             xmlWriter.setPrefix(prefix,
> namespace);
>
>                                         } else {
>                                             xmlWriter.writeStartElement
> (namespace,"empty");
>                                         }
>
>                                     } else {
>                                         xmlWriter.writeStartElement
> ("empty");
>                                     }
>
>                                        xmlWriter.writeCharacters(
> org.apache.axis2.databinding.utils.ConverterUtil.convertToString
> (localEmpty));
>
>                                    xmlWriter.writeEndElement();
>
>
>                xmlWriter.writeEndElement();
>
>
>
>         }
>
>          /**
>           * Util method to write an attribute with the ns prefix
>           */
>           private void writeAttribute(java.lang.String prefix,
> java.lang.String namespace,java.lang.String attName,
>                                       java.lang.String attValue,
> javax.xml.stream.XMLStreamWriter xmlWriter) throws
> javax.xml.stream.XMLStreamException{
>               if (xmlWriter.getPrefix(namespace) == null) {
>                        xmlWriter.writeNamespace(prefix, namespace);
>                        xmlWriter.setPrefix(prefix, namespace);
>
>               }
>
>               xmlWriter.writeAttribute(namespace,attName,attValue);
>
>          }
>
>          /**
>           * Util method to write an attribute without the ns prefix
>           */
>           private void writeAttribute(java.lang.String namespace,
> java.lang.String attName,
>                                       java.lang.String attValue,
> javax.xml.stream.XMLStreamWriter xmlWriter) throws
> javax.xml.stream.XMLStreamException{
>                   if (namespace.equals(""))
>                   {
>                           xmlWriter.writeAttribute(attName,attValue);
>                   }
>                   else
>                   {
>                   registerPrefix(xmlWriter, namespace);
>                   xmlWriter.writeAttribute(namespace,attName,attValue);
>               }
>           }
>
>          /**
>          * Register a namespace prefix
>          */
>          private java.lang.String registerPrefix(
> javax.xml.stream.XMLStreamWriter xmlWriter, java.lang.String namespace)
> throws javax.xml.stream.XMLStreamException {
>                 java.lang.String prefix = xmlWriter.getPrefix(namespace);
>
>                 if (prefix == null) {
>                     prefix = createPrefix();
>
>                     while (xmlWriter.getNamespaceContext().getNamespaceURI(prefix)
> != null) {
>                         prefix = createPrefix();
>                     }
>
>                     xmlWriter.writeNamespace(prefix, namespace);
>                     xmlWriter.setPrefix(prefix, namespace);
>                 }
>
>                 return prefix;
>             }
>
>          /**
>           * Create a prefix
>           */
>           private java.lang.String createPrefix() {
>                 return "ns" + (int)Math.random();
>           }
>         };
>
>         return dataSource;
>     }
>
>
>         /**
>         * databinding method to get an XML representation of this object
>         *
>         */
>         public javax.xml.stream.XMLStreamReader getPullParser(
> javax.xml.namespace.QName qName){
>
>
>
>                  java.util.ArrayList elementList = new java.util.ArrayList
> ();
>                  java.util.ArrayList attribList = new java.util.ArrayList
> ();
>
>
>                              elementList.add(new javax.xml.namespace.QName
> ("http://util.java/xsd",
>
>                                                                       "empty"));
>
>                                 elementList.add(
>
> org.apache.axis2.databinding.utils.ConverterUtil.convertToString
> (localEmpty));
>
>
>                 return new
> org.apache.axis2.databinding.utils.reader.ADBXMLStreamReaderImpl(qName,
> elementList.toArray(), attribList.toArray());
>
>
>
>         }
>
>
>
>      /**
>       *  Factory class that keeps the parse method
>       */
>     public static class Factory{
>
>
>         /**
>         * static method to create the object
>         * Precondition:  If this object is an element, the current or next
> start element starts this object and any intervening reader events are
> ignorable
>         *                If this object is not an element, it is a complex
> type and the reader is at the event just after the outer start element
>         * Postcondition: If this object is an element, the reader is
> positioned at its end element
>         *                If this object is a complex type, the reader is
> positioned at the end element of its outer element
>         */
>         public static Map parse(javax.xml.stream.XMLStreamReader reader)
> throws java.lang.Exception{
>             Map object = new Map();
>             int event;
>             try {
>
>                 while (!reader.isStartElement() && !reader.isEndElement())
>                     reader.next();
>
>
>                 if (reader.getAttributeValue("
> http://www.w3.org/2001/XMLSchema-instance","type")!=null){
>                   java.lang.String fullTypeName = reader.getAttributeValue
> ("http://www.w3.org/2001/XMLSchema-instance",
>                         "type");
>                   if (fullTypeName!=null){
>                     java.lang.String nsPrefix = fullTypeName.substring(0,
> fullTypeName.indexOf(":"));
>                     nsPrefix = nsPrefix==null?"":nsPrefix;
>
>                     java.lang.String type = fullTypeName.substring(
> fullTypeName.indexOf(":")+1);
>                     if (!"Map".equals(type)){
>                         //find namespace for the prefix
>                         java.lang.String nsUri =
> reader.getNamespaceContext().getNamespaceURI(nsPrefix);
>                         return
> (Map)clark.webinterface.util.xsd.ExtensionMapper.getTypeObject(
>                              nsUri,type,reader);
>                       }
>
>                   }
>
>                 }
>
>
>
>                 // Note all attributes that were handled. Used to differ
> normal attributes
>                 // from anyAttributes.
>                 java.util.Vector handledAttributes = new java.util.Vector
> ();
>
>
>                     reader.next();
>
>
>                                     while (!reader.isStartElement() &&
> !reader.isEndElement()) reader.next();
>
>                                     if (reader.isStartElement() && new
> javax.xml.namespace.QName("http://util.java/xsd","empty").equals(
> reader.getName())){
>
>                                     java.lang.String content =
> reader.getElementText();
>
>                                               object.setEmpty(
>
> org.apache.axis2.databinding.utils.ConverterUtil.convertToBoolean
> (content));
>
>                                         reader.next();
>
>                               }  // End of if for expected property start
> element
>
>                                 else{
>                                     // A start element we are not
> expecting indicates an invalid parameter was passed
>                                     throw new java.lang.RuntimeException("Unexpected
> subelement " + reader.getLocalName());
>                                 }
>
>                             while (!reader.isStartElement() &&
> !reader.isEndElement())
>                                 reader.next();
>                             if (reader.isStartElement())
>                                 // A start element we are not expecting
> indicates a trailing invalid property
>                                 throw new java.lang.RuntimeException("Unexpected
> subelement " + reader.getLocalName());
>
>
>
>             } catch (javax.xml.stream.XMLStreamException e) {
>                 throw new java.lang.Exception(e);
>             }
>
>             return object;
>         }
>
>         }//end of factory class
>
>
>
>         }
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>



-- 
Regards
Lahiru Sandakith