0

I am trying to make a dynamic Web Service in which i will be expecting a Java hash map or an Array list for the argument.

I am using the following code in Class Code:

package demo;

import java.util.ArrayList;

import javax.jws.WebService;

@WebService
public class HashMapTest {
    public HashMapTest() {
        super();
    }

    public int getResponse(ArrayList<String> hm) {
        return hm.size();
    }
}

I am using an IDE: Oracle Jdeveloper 11g. when i use the Wizard in the same, the output WSDL is as given below:

<?xml version="1.0" encoding="UTF-8" ?>
<wsdl:definitions
     name="HashMapTestService"
     targetNamespace="http://demo/"
     xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
     xmlns:tns="http://demo/"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
     xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
     xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
    >
    <wsdl:types>
    </wsdl:types>
    <wsdl:portType name="HashMapTest">
    </wsdl:portType>
    <wsdl:binding name="HashMapTestSoapHttp" type="tns:HashMapTest">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    </wsdl:binding>
    <wsdl:service name="HashMapTestService">
        <wsdl:port name="HashMapTestPort" binding="tns:HashMapTestSoapHttp">
            <soap:address location="http://localhost:7101/DemoServer-Demo-context-root/HashMapTestPort"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

As easily seen, the WSDL is corrupt and cannot be used.

Is it just a bug in Jdeveloper or can we simply not use Collections API in Web service as a parameter?

Please help

Fr_nkenstien
  • 1,923
  • 7
  • 33
  • 66
  • 1
    Hi, this answer might be useful to you: http://stackoverflow.com/questions/8254948/soap-response-wrongly-deserializing-as-null-in-cxf-simple-frontend-aegis-dat/9921501#9921501 – Anders R. Bystrup Nov 06 '12 at 11:41
  • @AndersRostgaardBystrup, Please post this as answer i would accept is as i tested the same and found it to be correct. – Fr_nkenstien Nov 06 '12 at 11:54

2 Answers2

5

this is caused by bug in JAXB . Use the following Code:

public class DTOObject
{ 
        HashMap hm = new HashMap();

    public void setHm(HashMap hm) {
        this.hm = hm;
    }

    public HashMap getHm() {
        return hm;
    }

    public int size() {
        return hm.size();
    }
}

and

public class HashMapTest {
    public HashMapTest() {
        super();
    }

    public int getResponse(Wrapped hm) {

        System.out.println(hm);
        return hm.size();
    }


}

It will solve the issue and create the wsdl correctly.

-2

You can not use the Technology dependent type in Web Service . You should use String or Byte . If you want to pass collection as a argument then serialize it and pass it as argument in the form of bytes. At the other end create the instance of collection form bytes.

Vijay
  • 1,024
  • 6
  • 18
  • Your are right that no concrete implementation should be used on a WS interface. But of course you can use map semantics in WS! –  Nov 06 '12 at 11:47
  • Dear Vijay, I found a solution and am going to answer the same. but the fact is that the Technology Specific libraries are converted to XML via marshalling using JAXB mapping. The answer from @Anders Rostgaard Bystrup is correct as it seems that there is an issue with JAXB. anyways. Please note that Complex objects are also used over the Web services. – Fr_nkenstien Nov 06 '12 at 11:54
  • Yeah, Right you can use technology specific type in web service , but it makes your web service technology dependent. – Vijay Nov 06 '12 at 11:58
  • not at all, if you use modern IDEs, they will create similar implementations of the same. and almost all technologies have the same collections classes implemented with a different or the same name so it should not be much of an issue. – Fr_nkenstien Nov 06 '12 at 12:01
  • 1
    ok got it , it means if there is any technology dependent type is there then it will be defined as complex type in wsdl and it definition will be there using simple type. That is what happens in XSD. – Vijay Nov 06 '12 at 12:07