如何在JBossWS 3.1.2中将HashMap用作@WebParam [英] How to have a HashMap as @WebParam with JBossWS 3.1.2

查看:174
本文介绍了如何在JBossWS 3.1.2中将HashMap用作@WebParam的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用JBossWS 3.1.2开发一个Web服务,该服务将HashMap作为其参数之一.我正在使用此版本的JBossWS,因为这是随我所使用的JBoss版本一起分发的版本.我正在使用wsprovide生成WSDL,并使用wsconsume创建WS客户端存根.

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.

我的WebService的简化版本是:

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";
    }
}

wsprovide创建的WSDL包含:

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>

生成的客户端代码包含一个空的抽象类AbstractMap.java和一个空的HashMap类.

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

我希望已生成类似于以下内容的WSDL:

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>

我也尝试用自定义类(ParameterMap)包装HashMap,但是得到了更多相同的东西.

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

还有我没看到的下一步吗?我是否缺少某些东西,或者这是对使用JBossWS开发Web服务的自底向上方法的限制吗?

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?

推荐答案

答案在另一篇帖子中我从没想过要为JAX-WS解决方案研究PHP问题...

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

HashMap需要包装在另一个Java类HashMapWrapper.java(或其他任何类)中.

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

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

需要修改ping方法调用以使用包装器类而不是HashMap:

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

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

这会生成适当的WSDL,而WSDL又会生成有用的Java存根.

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

这篇关于如何在JBossWS 3.1.2中将HashMap用作@WebParam的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆