2 Replies Latest reply on Feb 5, 2015 10:06 AM by Philipp Russ

    Issue in JBoss with @XmlElementWrapper in combination with @ResponseWrapper

    Philipp Russ Newbie

      I am currently migrating a web service from GlassFish to JBoss. While it works fine in GlassFish, I have an issue in JBoss. Here is the relevant code:

       

      @WebService

      @SOAPBinding( style = Style.DOCUMENT, use = Use.LITERAL, parameterStyle = ParameterStyle.WRAPPED )

      public class MyService {

          // ...


          @XmlAccessorType( XmlAccessType.PUBLIC_MEMBER )

          @XmlType( name = "getMyDatasResult", propOrder = { "myDatas" } )

          public static class GetMyDatasResult {

              @XmlElementWrapper( name = "myDatas", required = true, nillable = false )

              @XmlElement( name = "myData", required = false, nillable = false )

              public List<MyData> myDatas;

          }


          @WebMethod

          @WebResult( name = "myDatas" )

          @ResponseWrapper( className = "mypackage.MyService$GetMyDatasResult" )

          public List<MyData> getMyDatas() {

              // ...

          }


          // ...

      }

             

      According to JAXB, when the returned list is empty I expect to get something like

       

      <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">

         <soap:Body>

            <ns3:getMyDatasResponse xmlns:ns2="http://mypackage/" xmlns:ns3="http://mypackage/">

               <myDatas/>

            </ns3:getMyDatasResponse>

         </soap:Body>

      </soap:Envelope>

       

      Instead, I get the following:

       

      <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">

         <soap:Body>

            <ns3:getMyDatasResponse xmlns:ns2="http://mypackage/" xmlns:ns3="http://mypackage/"/>

         </soap:Body>

      </soap:Envelope>

       

      In other words: I expect to get an empty wrapped collection, instead I get an empty unwrapped collection.

       

      Furthermore - and what I cannot explain - I get the following warning:

       

      WARNING [org.apache.cxf.jaxb.JAXBDataBinding] (http-/127.0.0.1:8080-1) Could not create accessor for property myDatas of type mypackage.MyService$GetMyDatasResult as the @XmlElement defines the name as myData

       

      Did I overlook or miss something with the JAXB or JAX-WS spec ? Any help would highly be appreciated.

       

      BTW:

      I am running JBoss EAP 6.3.0.GA (AS 7.4.0.Final-redhat-19).

      Java SE build 1.7.0_01-b08

       

        • 1. Re: Issue in JBoss with @XmlElementWrapper in combination with @ResponseWrapper
          Rafael Chies Novice

          Hi Philipp,

           

          This is because you are using an inner class, and also no getter and setter to the myDatas List. Also, you don't need the XmlElement annotation if you are already annotating the field with RequestWrapper. Please, try this:

           

          @XmlAccessorType( XmlAccessType.FIELD )

          @XmlType( name = "getMyDatasResult", propOrder = { "myDatas" } )

          public static class GetMyDatasResult {

                

              @XmlElementWrapper( name = "myDatas", required = true, nillable = false )

              private List<MyData> myDatas;

           

           

              public List<MyData> getMyDatas() {

                 return myDatas;

              }

           

           

              public void setMyDatas(List<MyData> myDatas) {

                  this.myDatas = myDatas;

              }

          }

          • 2. Re: Issue in JBoss with @XmlElementWrapper in combination with @ResponseWrapper
            Philipp Russ Newbie

            Thanks for your reply !

             

            I tried it out and it works in JBoss. What makes me confusing is that the below does work in JBoss although it uses the same pattern as I used above (which doesn't work), i.e. the pattern uses a nested class, it uses both @XmlElementWrapper and @XmlElement, and XmlAccessType.PUBLIC_MEMBER.

             

            public class XmlElementWrapperTest {

                @XmlRootElement

                @XmlAccessorType( XmlAccessType.PUBLIC_MEMBER )

                public static class Customer {

                    @XmlElementWrapper( name="email-addresses", required = true, nillable = false )

                    @XmlElement( name="email-address", required = false, nillable = false )

                    public List<String> emailAddresses;

             

                    public Customer() {

                        emailAddresses = new ArrayList<String>();

                    }

                }

             

                public static void test() throws Exception {

                    JAXBContext jc = JAXBContext.newInstance( Customer.class );

                    Marshaller marshaller = jc.createMarshaller();

                    marshaller.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, true );

             

                    Customer customer1 = new Customer();

                    customer1.emailAddresses.add( "charliebrown@example.com" );

                    customer1.emailAddresses.add( "snoopy@example.org" );

                    marshaller.marshal( customer1, System.out );

                   

                    Customer customer2 = new Customer();

                    marshaller.marshal( customer2, System.out );

                }

            }

             

            Can you explain why this works in JBoss but my class GetMyDatasResult does not ?