[jbossws-users] [JBossWS] - Re: Newbee Q: Returning hashmaps

soch do-not-reply at jboss.com
Tue Apr 29 10:28:30 EDT 2008


"mikkus" wrote : toString() outputs the contents of the HashMap only if the class generated is actually a HashMap, otherwise it outputs the java class instance name.
  | 
  | Most probably, wsconsume generated a class named HashMap, instead of using java.util.HashMap. This class is not actually a hashmap but a representation of the web service return data. Most probably, you'll need to convert that data to an actual hashmap.
  | 
  | I notice you commented out the cast to java.util.HashMap, probably you got a ClassCastException here? Seeing the class generated by wsconsume and related wsdl would help.
  | 
  | Your web.xml file should not be the problem. It just exposes the webservice, and since you're able to invoke it, it is doing its job.

Thanks mikkus. Yes, wsconsume creates it's own HashMap which inherits from it's own AbstractMap. 

How do I convert the wsconsume generated HashMap to java.util.HashMap? I believe this needs to be done at the client side.

Data below:

C:\..\test\webservices> wsconsume -k http://localhost:8080/getpm/GetPM?wsdl
JBossWS-Native stack deployed
parsing WSDL...
generating code...
getpm\AbstractMap.java
getpm\GetPM.java
getpm\GetPMResponse.java
getpm\GetPMService.java
getpm\GetPM_Type.java
getpm\HashMap.java
getpm\ObjectFactory.java
getpm\package-info.java

HashMap.java:

  | package getpm;
  | 
  | import javax.xml.bind.annotation.XmlAccessType;
  | import javax.xml.bind.annotation.XmlAccessorType;
  | import javax.xml.bind.annotation.XmlType;
  | 
  | 
  | /**
  |  * <p>Java class for hashMap complex type.
  |  * 
  |  * <p>The following schema fragment specifies the expected content contained within this class.
  |  * 
  |  * <pre>
  |  * <complexType name="hashMap">
  |  *   <complexContent>
  |  *     <extension base="{http://getpm/}abstractMap">
  |  *       <sequence>
  |  *       </sequence>
  |  *     </extension>
  |  *   </complexContent>
  |  * </complexType>
  |  * </pre>
  |  * 
  |  * 
  |  */
  | @XmlAccessorType(XmlAccessType.FIELD)
  | @XmlType(name = "hashMap")
  | public class HashMap
  |     extends AbstractMap
  | {
  | 
  | 
  | }

AbstractMap.java:

package getpm;
  | 
  | import javax.xml.bind.annotation.XmlAccessType;
  | import javax.xml.bind.annotation.XmlAccessorType;
  | import javax.xml.bind.annotation.XmlType;
  | 
  | 
  | /**
  |  * <p>Java class for abstractMap complex type.
  |  * 
  |  * <p>The following schema fragment specifies the expected content contained within this class.
  |  * 
  |  * <pre>
  |  * <complexType name="abstractMap">
  |  *   <complexContent>
  |  *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
  |  *       <sequence>
  |  *       </sequence>
  |  *     </restriction>
  |  *   </complexContent>
  |  * </complexType>
  |  * </pre>
  |  * 
  |  * 
  |  */
  | @XmlAccessorType(XmlAccessType.FIELD)
  | @XmlType(name = "abstractMap")
  | public abstract class AbstractMap {
  | 
  | 
  | }

The generated service WSDL under C:\jboss-4.2.2.GA\server\default\data\wsdl\getpm.war

GetPMService31986.wsdl:
<?xml version="1.0" encoding="UTF-8"?>
  | <definitions name="GetPMService" targetNamespace="http://getpm/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://getpm/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
  |   <types>
  |     <xs:schema targetNamespace="http://getpm/" version="1.0" xmlns:tns="http://getpm/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  |    <xs:element name="getPM" type="tns:getPM"/>
  |    <xs:element name="getPMResponse" type="tns:getPMResponse"/>
  |    <xs:complexType name="getPM">
  |     <xs:sequence/>
  |    </xs:complexType>
  |    <xs:complexType name="getPMResponse">
  |     <xs:sequence>
  |      <xs:element minOccurs="0" name="return" type="tns:hashMap"/>
  |     </xs:sequence>
  |    </xs:complexType>
  |    <xs:complexType name="hashMap">
  |     <xs:complexContent>
  |      <xs:extension base="tns:abstractMap">
  |       <xs:sequence/>
  |      </xs:extension>
  |     </xs:complexContent>
  |    </xs:complexType>
  |    <xs:complexType abstract="true" name="abstractMap">
  |     <xs:sequence/>
  |    </xs:complexType>
  |   </xs:schema>
  |   </types>
  |   <message name="GetPM_getPMResponse">
  |     <part name="getPMResponse" element="tns:getPMResponse">
  |     </part>
  |   </message>
  |   <message name="GetPM_getPM">
  |     <part name="getPM" element="tns:getPM">
  |     </part>
  |   </message>
  |   <portType name="GetPM">
  |     <operation name="getPM" parameterOrder="getPM">
  |       <input message="tns:GetPM_getPM">
  |     </input>
  |       <output message="tns:GetPM_getPMResponse">
  |     </output>
  |     </operation>
  |   </portType>
  |   <binding name="GetPMBinding" type="tns:GetPM">
  |     <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
  |     <operation name="getPM">
  |       <soap:operation soapAction=""/>
  |       <input>
  |         <soap:body use="literal"/>
  |       </input>
  |       <output>
  |         <soap:body use="literal"/>
  |       </output>
  |     </operation>
  |   </binding>
  |   <service name="GetPMService">
  |     <port name="GetPMPort" binding="tns:GetPMBinding">
  |       <soap:address location="http://127.0.0.1:8080/getpm/GetPM"/>
  |     </port>
  |   </service>
  | </definitions>

I tried the convertion but got errors:

C:\Documents and Settings\jaina\My Documents\Work\CODE\test\webservices\getpm\output>wsrunclient GetPMclient
log4j:WARN No appenders could be found for logger (org.jboss.ws.metadata.builder.jaxws.JAXWSWebServiceMetaDataBuilder).
log4j:WARN Please initialize the log4j system properly.
getpm.HashMap at 1a0b53e
C:\Documents and Settings\jaina\My Documents\Work\CODE\test\webservices\getpm\output>javac GetPMclient.java
GetPMclient.java:13: inconvertible types
found   : getpm.HashMap
required: java.util.HashMap
      java.util.HashMap hm = (java.util.HashMap) pm.getPM();
                                                         ^
1 error

import getpm.*;
  | 
  | import java.util.HashMap;
  | 
  | public class GetPMclient
  | {
  |    public static void main(String args[])
  |    {
  |        
  |       GetPMService service = new GetPMService();
  |       GetPM pm = service.getGetPMPort();
  |       //System.out.println("Server said: " + pm.getPM());
  |       java.util.HashMap hm = (java.util.HashMap) pm.getPM();
  |       System.out.println(hm.toString());     
  |      
  | 
  | 
  |    } 
  | }


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4147520#4147520

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4147520



More information about the jbossws-users mailing list