namespace issue on web service with Apache CXF

前端 未结 1 1317

I\'m using Apache CXF 2.7.3, and running into a namespace issue that I really don\'t understand. I\'ve tried extensively to search on this, but most of the results that I find a

1条回答
  •  鱼传尺愫
    2021-02-06 16:50

    The source of the problem is wsgen, and I think this is a bug. It does not make the wsdl and the jaxb generated classes compatible. In the jaxb generated classes, the elements are not default form qualified, which puts the parameter element into a null namespace. However in the WSDL, it IS default form qualified, and therein lies the problem. There are probably a number of ways to solve this, the most quick and dirty way I found is to set the targetNamespace on the @WebParam annotation. Here are code snippets to demonstrate what I mean, and I hope this helps someone else who runs into this.

    Here is what I had originally for the bottom-up implementation class:

    @WebService(serviceName="OrderService")
    public class OrderService {
    
        public OrderResponse getOrder(@WebParam(name="id", targetNamespace="http://www.example.org/order") String id)  {
    

    This will result in the following generated JAXB classes. As you can see it sets the namespace for the root but its not form qualified, and it does not generate a package-info file either.

    @XmlRootElement(name = "getOrder", namespace = "http://www.example.org/order")
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "getOrder", namespace = "http://www.example.org/order")
    
    public class GetOrder {
    
        @XmlElement(name = "id")
        private java.lang.String id;
    

    Then I changed the service implementation class, to add the namespace to the @WebParam:

    @WebService(serviceName="OrderService", targetNamespace="http://www.example.org/order")
    public class OrderService {
    
        public OrderResponse getOrder(@WebParam(name="id", targetNamespace="http://www.example.org/order") String id)  {
    

    While that doesn't make it default form qualified, it does add the namespace to the element in the generated JAXB class:

    @XmlRootElement(name = "getOrder", namespace = "http://www.example.org/order")
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "getOrder", namespace = "http://www.example.org/order")
    
    public class GetOrder {
    
        @XmlElement(name = "id", namespace = "http://www.example.org/order")
        private java.lang.String id;
    

    0 讨论(0)
提交回复
热议问题