Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-2234

Unmarshalling with JAXB of a method that is defined in an inherited interface results in an NPE exception

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.2.2
    • 2.2.2
    • None
    • WindowsXP-SP3, Eclipse 3.4

    Description

      The UserService:

      @javax.jws.WebService
      public interface UserService extends AbstractService<User, Users>
      {
      }

      The AbstractService:

      @javax.jws.WebService
      public interface AbstractService<T, Ts>
      {
      public Ts list();
      }

      The UserServiceImpl:

      @javax.jws.WebService(endpointInterface = "nl.knowledgeplaza.profiler.services.UserService", serviceName = "users") // the "ws" prefix is handled by the container
      public class UserServiceImpl
      implements UserService
      {
      public Users list()
      {
      try
      {
      if (slf4j.isDebugEnabled()) slf4j.debug("list User");

      // find all
      List<User> lList = User.findAll();
      if (slf4j.isDebugEnabled()) slf4j.debug("list User size={}", lList.size());

      // create a collection so JAXB knows what to do
      Users lUsers= new Users(lList);

      // done
      return lUsers;
      }
      catch (RuntimeException e)

      { slf4j.error(ExceptionUtil.describe(e), e); throw e; }

      }
      }

      UnitTests start the SOAP end point as follows:

      javax.xml.ws.Endpoint.publish(cWSUserAddress, new UserServiceImpl());

      The unittest:

      @org.junit.Test
      public void listUsersSOAP()

      { // create a proxy to the service JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.getInInterceptors().add(new LoggingInInterceptor()); factory.getOutInterceptors().add(new LoggingOutInterceptor()); factory.setServiceClass(UserService.class); factory.setAddress(cWSUserAddress); UserService lUserService = (UserService)factory.create(); // make the call Users lUsers = lUserService.list(); // check it org.fest.assertions.Assertions.assertThat( lUsers.getUser().size() ).isGreaterThan(0); }

      The call arrives serverside, the code is correctly executed and 4 User entities have been fetched from the database. The JAXB marshalling then runs into problems, resulting in a value of null being returned on the clients side, and failing the unittest on a NPE.

      The trace:

      May 22, 2009 11:29:00 AM org.apache.cxf.interceptor.LoggingOutInterceptor$LoggingCallback onClose
      INFO: Outbound Message
      ---------------------------
      ID: 2
      Address: http://localhost:9000/ws/user
      Encoding: UTF-8
      Content-Type: text/xml
      Headers:

      {SOAPAction=[""], Accept=[*/*]}

      Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns1:list xmlns:ns1="http://services.profiler.knowledgeplaza.nl/" /></soap:Body></soap:Envelope>
      --------------------------------------
      [33299971@qtp-22864463-1] 2009-05-22 11:29:06,296 DEBUG nl.knowledgeplaza.profiler.services.UserServiceImpl.list(UserServiceImpl.java:48) list User
      [EL Fine]: 2009-05-22 11:29:07.093-ServerSession(15545028)Connection(13749345)Thread(Thread[33299971@qtp-22864463-1,5,main])-SELECT id, username, middlename, email, lastname, callname, firstname, version FROM KP_USER
      [33299971@qtp-22864463-1] 2009-05-22 11:29:08,750 DEBUG nl.knowledgeplaza.profiler.services.UserServiceImpl.list(UserServiceImpl.java:52) list User size=4
      May 22, 2009 11:29:11 AM org.apache.cxf.phase.PhaseInterceptorChain doIntercept
      INFO: Interceptor has thrown exception, unwinding now
      org.apache.cxf.interceptor.Fault: Marshalling Error: class nl.knowledgeplaza.profiler.services.support.Users nor any of its super class is known to this context.
      at org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:159)
      at org.apache.cxf.jaxb.io.DataWriterImpl.write(DataWriterImpl.java:169)
      at org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writeParts(AbstractOutDatabindingInterceptor.java:105)
      at org.apache.cxf.interceptor.BareOutInterceptor.handleMessage(BareOutInterceptor.java:68)
      at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236)
      at org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:74)
      at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236)
      at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:89)
      at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:302)
      at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:265)
      at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:70)
      at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
      at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
      at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
      at org.mortbay.jetty.Server.handle(Server.java:324)
      at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:535)
      at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:880)
      at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:747)
      at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
      at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
      at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
      at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:520)
      Caused by: javax.xml.bind.MarshalException

      • with linked exception:
        [javax.xml.bind.JAXBException: class nl.knowledgeplaza.profiler.services.support.Users nor any of its super class is known to this context.]
        at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:328)
        at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:254)
        at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:75)
        at org.apache.cxf.jaxb.JAXBEncoderDecoder.writeObject(JAXBEncoderDecoder.java:441)
        at org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:138)
        ... 21 more
        Caused by: javax.xml.bind.JAXBException: class nl.knowledgeplaza.profiler.services.support.Users nor any of its super class is known to this context.
        at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:242)
        at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:257)
        at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:649)
        at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:151)
        at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:185)
        at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeBody(ElementBeanInfoImpl.java:305)
        at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:312)
        at com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:71)
        at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:490)
        at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:325)
        ... 25 more
        Caused by: javax.xml.bind.JAXBException: class nl.knowledgeplaza.profiler.services.support.Users nor any of its super class is known to this context.
        at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getBeanInfo(JAXBContextImpl.java:566)
        at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:644)
        ... 32 more
        May 22, 2009 11:29:12 AM org.apache.cxf.interceptor.LoggingInInterceptor logging
        INFO: Inbound Message
        ----------------------------
        ID: 2
        Encoding: UTF-8
        Content-Type: text/xml; charset=utf-8
        Headers: {content-type=[text/xml; charset=utf-8], Content-Length=[415], Server=[Jetty(6.1.15)]}

        Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns1:listResponse xmlns:ns1="http://services.profiler.knowledgeplaza.nl/"><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Marshalling Error: class nl.knowledgeplaza.profiler.services.support.Users nor any of its super class is known to this context.</faultstring></soap:Fault></ns1:listResponse></soap:Body></soap:Envelope>
        --------------------------------------

      The Users class is just a collection workaround as suggested in CXF's documentation:

      @XmlRootElement(name = "users")
      public class Users
      implements Serializable
      {
      public Users()

      { setUser(new ArrayList<User>()); }

      // upon JAXB unmarshalling of an empty collection, the setUser is NOT called and the collection would be null instead of empty
      public Users(Collection<User> c)

      { setUser(c); }

      private Collection<User> iCollection;
      public Collection<User> getUser()

      { return iCollection; }

      public void setUser(Collection<User> c)

      { iCollection = c; }

      public List<User> asList()

      { return new ArrayList<User>(iCollection); }

      }

      Attachments

        1. services.rar
          5 kB
          Tom

        Activity

          People

            Unassigned Unassigned
            tbee Tom
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: