How to have a HashMap as @WebParam with JBossWS 3.

2019-04-02 02:12发布

问题:

I am trying to develop a web service with JBossWS 3.1.2 that has a HashMap as one of its arguments. I am using this version of JBossWS because that is what is distributed with the version of JBoss that I am using. I am using wsprovide to generate the WSDL and wsconsume to create WS client stubs.

A simplified version of my WebService is:

@WebService(targetNamespace = "http://localhost/ping", serviceName = "Ping")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public class Ping {
    @WebMethod
    @WebResult(name="result")
    public String ping(@WebParam(name="arguments") HashMap arguments) {
        return "pong";
    }
}

The WSDL created by wsprovide contains:

<types>
    <xs:schema targetNamespace='http://localhost/ping' version='1.0' xmlns:tns='http://localhost/ping' xmlns:xs='http://www.w3.org/2001/XMLSchema'>
        <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>

The generated client code contains an empty abstract class AbstractMap.java and an empty class HashMap.

I would have expected WSDL similar to the following to have been generated:

<complexType>
    <sequence>
        <element name="key" type="anyType" />
        <element name="value" type="anyType" />
    </sequence>
</complexType>

I also tried wrapping HashMap with a custom class (ParameterMap) but just got more of the same.

Is there a next step that I'm not seeing? Am I missing something or is this a limitation to the bottom up approach to developing Web Services with JBossWS?

回答1:

The answer was in another post How can I pass in an array as a value into a PHP soapclient request?

I would have never thought to look into a PHP question for a JAX-WS solution...

The HashMap needs to be wrapped in another Java class called HashMapWrapper.java (or whatever).

public class HashMapWrapper {
    public HashMap<String, Object> parameters;
}

The ping method call needs to be modified to use the wrapper class instead of HashMap:

public String ping(@WebParam(name="arguments") HashMapWrapper arguments) {

This generates appropriate WSDL which in turns generates useful Java stubs.