axis 2 Web 服务:http 绑定的空参数问题

发布于 2024-09-19 04:57:25 字数 3364 浏览 4 评论 0原文

我正在尝试使用 axis2 开发一个网络服务。问题是我没有获取 http 绑定的 url 中传递的参数。

这是我的 service.xml :

<parameter name="ServiceClass">my.package.MyClass
    </parameter>
    <operation name="getUser">
        <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
    </operation>
    <parameter name="useOriginalwsdl">true</parameter>

这是我的简化 wsdl :

<definitions ...>
        <types>
            <schema ...>
                <complexType name="User">
                    <sequence>
                        <element name="id" type="string"/>
                        <element name="age" type="int"/>
                    </sequence>
                </complexType>
                <element name="getUser">
                    <complexType>
                        <sequence>
                            <element name="id" type="xs:string" form="unqualified" />
                        </sequence>
                    </complexType>
                </element>
                <element name="getUserResponse">
                    <complexType>
                        <sequence>
                            <element name="user" nillable="true"
                                type="user" />
                        </sequence>
                    </complexType>
                </element>
            </schema>
        </types>


        <message name="getUserRequest">
            <part name="parameters" element="getUser" />
        </message>
        <message name="getUserResponse">
            <part name="parameters" element="getUserResponse" />
        </message>

        <portType name="testPortType">
            <operation name="getUser">
                <input message="getUserRequest"
                    Action="urn:getUser" />
                <output message="getUserResponse"
                    Action="urn:getUserResponse" />
            </operation>
        </portType>

        <binding name="testHttpBinding" type="testPortType">
            <binding verb="GET" />
            <operation name="getUser">
                <http:operation location="getUser" />
                <input>
                    <http:urlEncoded />
                <input>
                <output>
                    <mime:content type="text/xml" />
                </output>
            </operation>
        </binding>
        <service name="test">
            <port name="testHttpEndpoint" binding="testHttpBinding">
                <address
                    location="http://localhost:8080/axis2/services/test.testHttpEndpoint/" />
            </port>
        </service>
    </definitions>

最后是 my.package.MyClass :

public final class MyClass {

 public User getUser(String id) {
  //Do something
 }
}

当我使用请求 http://urlToService/getUser?id=test,我输入getUser(String id)但id为空。

有人知道我该如何解决这个问题吗?

谢谢

I am trying to develop a web service with axis2. The problem is that I don't get the parameters passed in the url for an http Binding.

Here is my service.xml :

<parameter name="ServiceClass">my.package.MyClass
    </parameter>
    <operation name="getUser">
        <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
    </operation>
    <parameter name="useOriginalwsdl">true</parameter>

Here is my simplified wsdl :

<definitions ...>
        <types>
            <schema ...>
                <complexType name="User">
                    <sequence>
                        <element name="id" type="string"/>
                        <element name="age" type="int"/>
                    </sequence>
                </complexType>
                <element name="getUser">
                    <complexType>
                        <sequence>
                            <element name="id" type="xs:string" form="unqualified" />
                        </sequence>
                    </complexType>
                </element>
                <element name="getUserResponse">
                    <complexType>
                        <sequence>
                            <element name="user" nillable="true"
                                type="user" />
                        </sequence>
                    </complexType>
                </element>
            </schema>
        </types>


        <message name="getUserRequest">
            <part name="parameters" element="getUser" />
        </message>
        <message name="getUserResponse">
            <part name="parameters" element="getUserResponse" />
        </message>

        <portType name="testPortType">
            <operation name="getUser">
                <input message="getUserRequest"
                    Action="urn:getUser" />
                <output message="getUserResponse"
                    Action="urn:getUserResponse" />
            </operation>
        </portType>

        <binding name="testHttpBinding" type="testPortType">
            <binding verb="GET" />
            <operation name="getUser">
                <http:operation location="getUser" />
                <input>
                    <http:urlEncoded />
                <input>
                <output>
                    <mime:content type="text/xml" />
                </output>
            </operation>
        </binding>
        <service name="test">
            <port name="testHttpEndpoint" binding="testHttpBinding">
                <address
                    location="http://localhost:8080/axis2/services/test.testHttpEndpoint/" />
            </port>
        </service>
    </definitions>

and finally my.package.MyClass :

public final class MyClass {

 public User getUser(String id) {
  //Do something
 }
}

When I call the service with the request http://urlToService/getUser?id=test, I enter in getUser(String id) but the id is null.

Does someone know how am I supposed to fix that?

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

傲性难收 2024-09-26 04:57:25

事实上我做错了什么。

在 MyClass 中,我不应该这样做 :

public User getUser(String id){
}

,而是

public User getUser(GetUser getUser){
}

按照 wsdl 文件中所写的那样。

In fact I was doing something wrong.

In MyClass, I am not supposed to do :

public User getUser(String id){
}

but

public User getUser(GetUser getUser){
}

as written in the wsdl file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文