java JAX-WS 异常 - “返回不是有效的属性”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13782797/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JAX-WS Exception - "return is not a valid property"
提问by philomatic
I am new to JAX-WS, when I try to start this simple Web Service:
我是 JAX-WS 的新手,当我尝试启动这个简单的 Web 服务时:
Interface:
界面:
package ws;
import java.util.HashMap;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService
public interface IBasket {
@WebMethod public abstract void addItem(int productId, int count);
@WebMethod public abstract HashMap<Integer, Integer> getBasketMap();
}
Implementing Class:
实现类:
package model;
import java.util.HashMap;
import javax.jws.WebService;
import ws.IBasket;
@WebService(endpointInterface = "ws.IBasket")
public class Basket implements IBasket {
private HashMap<Integer, Integer> basket;
public Basket() {
this.basket = new HashMap<Integer, Integer>();
}
@Override
public void addItem(int productId, int count) {
int currentCount = 0;
if (basket.containsKey(productId)) {
currentCount = basket.get(productId);
}
basket.put(productId, currentCount + count);
}
@Override
public HashMap<Integer, Integer> getBasketMap() {
return basket;
}
}
Publisher:
出版商:
package endpoint;
import javax.xml.ws.Endpoint;
import model.Basket;
public class WSPublisher {
public static void main(String[] args) {
Endpoint.publish("http://localhost:8080/WS/Basket",new Basket());
}
}
I'm getting the following stacktrace:
我得到以下堆栈跟踪:
Exception in thread "main" javax.xml.ws.WebServiceException: class ws.jaxws.GetBasketMapResponse do not have a property of the name return
at com.sun.xml.internal.ws.server.sei.EndpointResponseMessageBuilder$DocLit.<init>(EndpointResponseMessageBuilder.java:196)
at com.sun.xml.internal.ws.server.sei.EndpointMethodHandler.createResponseMessageBuilder(EndpointMethodHandler.java:191)
at com.sun.xml.internal.ws.server.sei.EndpointMethodHandler.<init>(EndpointMethodHandler.java:97)
at com.sun.xml.internal.ws.server.sei.SEIInvokerTube.<init>(SEIInvokerTube.java:72)
at com.sun.xml.internal.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:208)
at com.sun.xml.internal.ws.api.server.WSEndpoint.create(WSEndpoint.java:498)
at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.createEndpoint(EndpointImpl.java:246)
at com.sun.xml.internal.ws.transport.http.server.EndpointImpl.publish(EndpointImpl.java:170)
at com.sun.xml.internal.ws.spi.ProviderImpl.createAndPublishEndpoint(ProviderImpl.java:113)
at javax.xml.ws.Endpoint.publish(Endpoint.java:240)
at endpoint.WSPublisher.main(WSPublisher.java:14)
Caused by: javax.xml.bind.JAXBException: return is not a valid property on class ws.jaxws.GetBasketMapResponse
at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getElementPropertyAccessor(JAXBContextImpl.java:966)
at com.sun.xml.internal.ws.server.sei.EndpointResponseMessageBuilder$DocLit.<init>(EndpointResponseMessageBuilder.java:193)
... 10 more
Any ideas how to solve this?
任何想法如何解决这个问题?
回答by philomatic
Ok, I've the solution for this Problem, see:
好的,我有这个问题的解决方案,请参阅:
How can I pass in an array as a value into a PHP soapclient request?
如何将数组作为值传递给 PHP soapclient 请求?
Its the same for HashMap return values. JAXB can't handle HashMaps as parameters/return values, maybe because they're generic.
HashMap 返回值也是如此。JAXB 无法将 HashMap 作为参数/返回值处理,可能是因为它们是通用的。
So instead, we need a wrapper class for the HashMap
所以相反,我们需要一个 HashMap 的包装类
public class HashMapWrapper {
private HashMap<Integer, Integer> basketMap;
public HashMapWrapper(HashMap<Integer, Integer> basketMap) {
this.setBasketMap(basketMap);
}
and use this one as return value.
并将其用作返回值。
回答by dinukadev
Are you using Metro as your JAX-WS provider? If so try setting the Document style as follows to RPC. This annotation should come after the @WebService annotation.;
您是否使用 Metro 作为您的 JAX-WS 提供程序?如果是这样,请尝试将文档样式设置为 RPC。这个注释应该在@WebService 注释之后。
@SOAPBinding(style = Style.RPC)