java - @WebParam 在 jetty 服务 SOAP 中始终为空

标签 java web-services soap jetty jax-ws

我有一个通过 Jetty 公开 SOAP API 的 Java 应用程序。我可以成功访问 WSDL 并伪造请求,但发送的 webparam 始终为空。我不知道如何调试这个问题。 这里我有一些请求中涉及的函数的片段。 如果您需要更多信息,我会编辑:

@WebMethod(
        operationName = "findEvent"
    )
    public ServiceEventDto findEvent(
            @WebParam(name = "eventId") Long eventId) throws InstanceNotFoundException {
        Event event
                = EventServiceFactory.getService().findEvent(eventId);
        return EventToEventDtoConversor.toEventDto(event);
    }

这是请求:

<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:eve="http://ws.udc.es/event">
<x:Header/>
<x:Body>
    <eve:findEvent>
        <eve:eventId>0</eve:eventId>
    </eve:findEvent>
</x:Body>

提前谢谢您。

最佳答案

我相信问题是您的 SOAP 输入使用 eve eventId 的命名空间前缀输入元素。

试试这个:

<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:eve="http://ws.udc.es/event">
<x:Header/>
<x:Body>
    <eve:findEvent>
        <eventId>0</eventId>
    </eve:findEvent>
</x:Body>

我能够在 Jetty 9.4 中使用以下服务提供程序重新创建:

服务端点接口(interface):

package org.example.sampleservice;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

@WebService(targetNamespace="http://ws.udc.es/event")
public interface SampleService {

    @WebMethod(operationName = "findEvent")
        public ServiceEventDto findEvent(@WebParam(name = "eventId") Long eventId) throws InstanceNotFoundException;

}

服务实现:

package org.example.sampleservice;

import javax.annotation.Resource;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.xml.ws.WebServiceContext;

@WebService(endpointInterface = "org.example.sampleservice.SampleService", targetNamespace="http://ws.udc.es/event")
public class SampleServiceImpl implements SampleService {

    @Resource
    private WebServiceContext ctx;

    @WebMethod(operationName = "findEvent")
    public ServiceEventDto findEvent(@WebParam(name = "eventId") Long eventId) throws InstanceNotFoundException {
        System.out.println("SampleServiceImpl: received eventId " + eventId);
        return new ServiceEventDto();
    }

}

当我使用您的原始输入 <eve:eventId>0</eve:eventId> 时我观察到以下输出:

SampleServiceImpl: received eventId null

当我使用<eventId>0</eventId>时我观察到预期的输出:

SampleServiceImpl: received eventId 0

但是,如果您需要接受 <eve:eventId> 您还可以调整 @WebParam添加targetNamespace如下:

 @WebParam(name = "eventId", targetNamespace="http://ws.udc.es/event") Long eventId

当我以这种方式更改服务提供商时,输出会反转并 <eve:eventId>不再是null .

关于java - @WebParam 在 jetty 服务 SOAP 中始终为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41155157/

相关文章:

java - 使用 GCM 发送推送消息时错误代码 "notRegistered"是什么意思?

eclipse - 如何使用 Eclipse 调试 SOAP UI 脚本

java - 实数矩阵与复数矩阵相乘

java - 为什么 Java 对每种颜色都有两个颜色值?

java - 混淆模块/库

jquery - 通过 jquery ajax 和 javax.ws Web 服务发送 json 作为值失败

javascript - 使用 googleVis 和 R 的基于订阅的网站的 Web 开发建议

python - 使用 SUDS 测试 WSDL

PHP + WSDL + SOAP - 如何在屏幕上显示网络服务结果

PHP-Soap 传递方法参数