简体   繁体   English

将JAXB注释类用于JAXWS服务

[英]Using JAXB annotated class for a JAXWS service

i have a web service working like this: 我有一个像这样工作的网络服务:

@WebService(serviceName = "TempService")
public class TempService {
  @WebMethod(operationName = "addBarkod")
  public Boolean addBarkod(@WebParam(name = "barkod") Barkod barkod) {
    System.out.println(barkod.getBarkodNo());
  }
}

and the Barkod class as: 和Barkod课程:

public class Barkod {
  private String barkodNo;
// there are constructors and getters, setters etc. nothing fancy //
}

with this structure my web service can be called with soapUI wtihout a problem. 使用这种结构,我可以使用soapUI调用我的Web服务,而不会出现问题。 the problem is when i want to annotate my model class with JAXB annotations like: 问题是当我想用JAXB注释注释我的模型类时:

@XmlType(name="barkod")
@XmlRootElement(name="barkod")
@XmlAccessorType(XmlAccessType.FIELD)

i can deploy this to glassfish 3.1 and soapUI generates new client request with new structure but when it comes to do "barkod.getBarkodNo();" 我可以将它部署到glassfish 3.1并且soapUI使用新结构生成新的客户端请求但是当涉及到“barkod.getBarkodNo();”时 at addBarkod operation it throws a NullPointerException. 在addBarkod操作中,它抛出一个NullPointerException。 i looks like the XML i sent to the web service does not create a proper Barkod object. 我看起来像我发送到Web服务的XML不会创建一个适当的Barkod对象。

do i have to do with web service class or something? 我是否需要使用Web服务类或其他什么?

i think problem caused because soapUI generates the request automatically from my WSDL. 我认为问题是因为s​​oapUI从我的WSDL自动生成请求。 when i annotate my class with @XmlRootElement without the namespace clause it does not map given XML to may object. 当我使用没有namespace子句的@XmlRootElement注释我的类时,它不会将给定的XML映射到may对象。 i assign @XmlRootElemen(namespace="") and my problem goes away. 我分配@XmlRootElemen(namespace =“”),我的问题就消失了。

thanks for responses anyway. 无论如何,谢谢你的回应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM