1 Reply Latest reply: Mar 7, 2013 9:30 AM by 995476 RSS

    jwsc and map interface

    995476
      Hi All,

      I would like to expose java.util.Map as a parameter using JAX-WS web service generated using jwsc. I am getting the following error while executing jwsc ant task,

      *JWS Validation failed: [Type java.util.Map on JWS is not supported., Type java.util.Map on JWS is not supported.]*

      Here's what I have,

      Complex.java

      @WebService(name="complex", targetNamespace="http://abcd.org.jaxws")
      @SOAPBinding(style=SOAPBinding.Style.DOCUMENT, parameterStyle=SOAPBinding.ParameterStyle.WRAPPED, use=SOAPBinding.Use.LITERAL)
      @WLHttpTransport(contextPath="jaxws_complex", serviceUri="ComplexService")
      public class Complex {
           
           @WebMethod
           @XmlJavaTypeAdapter(MyMapAdapter.class)
           public Map<Integer, String> processHashMap(Map<Integer, String> hashMap) {
                
                hashMap.put(1, "2");
                return hashMap;
           }
      }

      I have written a custom MapAdapter to map the java.util.Map to a simple name/value string, but I think jwsc is not considering it while generating the web service.

      MyMapAdapter.java

      public class MyMapAdapter extends XmlAdapter<MyMapType, Map<Integer, String>> {

           @Override
           public MyMapType marshal(Map<Integer, String> v) throws Exception {
                // TODO Auto-generated method stub
                MyMapType myMapType = new MyMapType();
                
                List<MyMapEntryType> entries = new ArrayList<MyMapEntryType>();

                for(Map.Entry<Integer, String> entry : v.entrySet()){
                     entries.add(new MyMapEntryType(entry.getKey(), entry.getValue()));
                }
                
                myMapType.setEntry(entries);
                
                return myMapType;
                
           }
           
           @Override
           public Map<Integer, String> unmarshal(MyMapType v) throws Exception {
                Map<Integer, String> Map = new HashMap<Integer, String>(v.getEntry().size());
                for (MyMapEntryType entry : v.getEntry())
                     Map.put(entry.key, entry.value);
                return Map;
           }

           
      }

      MyMapEntryType.java

      public class MyMapEntryType {
           
           @XmlAttribute
      public Integer key;

      @XmlValue
      public String value;

      public MyMapEntryType() {
                super();
           }

           public MyMapEntryType(Integer key, String value) {
                super();
                this.key = key;
                this.value = value;
           }

           public Integer getKey() {
                return key;
           }

           public void setKey(Integer key) {
                this.key = key;
           }

           public String getValue() {
                return value;
           }

           public void setValue(String value) {
                this.value = value;
           }


      }

      MyMapType.java

      public class MyMapType {
           List<MyMapEntryType> entry;

           public List<MyMapEntryType> getEntry() {
                return entry;
           }

           public void setEntry(List<MyMapEntryType> entry) {
                this.entry = entry;
           }
      }

      build.xml
      <project name="webservices-jws_basic-complex" default="all"
           basedir=".">
      <property name="complex.ear.dir" value="output/complex/complexEAR" />
           <property name="complex.war" value="complex" />
           <property name="complex.ws.file" value="org\abcd\jaxws\complex\Complex" />
                
           <target name="all" depends="build-complex-service" />

           <target name="build-complex-service">
                
                <jwsc verbose="on" debug="on" srcdir="src" destdir="${complex.ear.dir}" >
                          <jws file="${complex.ws.file}.java" explode="true"/>
                          
                </jwsc>
           </target>
      </project>

      Exception stack trace:

      [jwsc] 1 JWS files being processed for module /org/syed/jaxws/complex/Complex
      [jwsc] C:\workspace\JAAS\JAXWS\src\org\syed\jaxws\complex\Complex.java 27:37
      [jwsc] [ERROR] - Type java.util.Map on JWS is not supported.
      [jwsc] C:\workspace\JAAS\JAXWS\src\org\syed\jaxws\complex\Complex.java 27:37
      [jwsc] [ERROR] - Type java.util.Map on JWS is not supported.
      [AntUtil.deleteDir] Deleting directory C:\DOCUME~1\p2085712\LOCALS~1\Temp\1\_i2m6up1
      [AntUtil.deleteDir] Deleting directory C:\DOCUME~1\p2085712\LOCALS~1\Temp\1\_i2m6up1

      BUILD FAILED
      C:\workspace\JAAS\JAXWS\ComplexBuild.xml:22: weblogic.wsee.tools.WsBuildException: JWS Validation failed: [Type java.util.Map on JWS is not supported., Type java.util.Map on JWS is not supported.]
           at weblogic.wsee.tools.anttasks.JwscTask.execute(JwscTask.java:236)
           at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:597)
           at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
           at org.apache.tools.ant.Task.perform(Task.java:348)
           at org.apache.tools.ant.Target.execute(Target.java:390)
           at org.apache.tools.ant.Target.performTasks(Target.java:411)
           at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
           at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
           at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
           at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
           at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
           at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424)
           at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)
      Caused by: weblogic.wsee.tools.WsBuildException: JWS Validation failed: [Type java.util.Map on JWS is not supported., Type java.util.Map on JWS is not supported.]
           at weblogic.wsee.tools.anttasks.JwsModule.buildAndValidate(JwsModule.java:589)
           at weblogic.wsee.tools.anttasks.JwsModule.loadWebServices(JwsModule.java:576)
           at weblogic.wsee.tools.anttasks.JwsModule.generate(JwsModule.java:369)
           at weblogic.wsee.tools.anttasks.JwsModule.build(JwsModule.java:256)
           at weblogic.wsee.tools.anttasks.JwscTask.execute(JwscTask.java:229)
           ... 16 more

      Any idea on how to enforce jwsc to understand the adapter I have written? Many thanks for your help.

      Regards
      Syed

      Edited by: 992473 on 07-Mar-2013 07:17
        • 1. Re: jwsc and map interface
          995476
          Just found the solution after posting the question, it is related to build.xml, have updated with type="JAXWS" as below:

          <target name="build-complex-service">
                    
                    <jwsc verbose="on" debug="on" srcdir="src" destdir="${complex.ear.dir}" >
                              <jws file="${complex.ws.file}.java" explode="true" type="JAXWS"/>
                              <binding dir="${binding.dir}" casesensitive="yes">
                                   <include name="**/*.xml"/>
                              </binding>
                    </jwsc>
               </target>