1 Reply Latest reply on Apr 19, 2006 6:02 AM by Heiko Braun

    Serialize EJB3 collections

    Pablo Gomez Newbie

      Hello,

      I have written a test stateless EJB3 session bean. I'd like to publish it as a web service by using @WebService and @WebMethod annotations.

      I'd like some web methods to return complex types and arrays of complex types. These complex types would be tipically EJB3 entity beans.

      Basic types, complex types and array complex types returning from web methods are working in the sample.

      Collections of complex types DON'T WORK: I get a stack trace. I'm particularly interested in these return values, because @OneToMany relationships between EJB3 entities are tipically implemented as Java collections.

      I'm using latest JBoss 4.0.4 CR2.

      Web service calls are made from a .Net 1.1 client.

      I'm not sure if this code can be fixed and run on this JBoss release, or maybe if it could work in final 4.0.4 or further releases of JBoss.

      Thanks in advance,

      Pablo


      PS:
      This is the code I've used:

      package com.ejb3ws.entities;
      
      import .......... ;
      
      @Entity
      @Table(name="TEAMS")
      public class Team implements Serializable
      {
       private static final long serialVersionUID = 632767246967006316L;
      
       private Integer id;
       private String teamName;
      
       @Id @Column(name="ID") public Integer getId() { return id; }
       @Column(name="TEAM_NAME") public String getTeamName() { return teamName; }
      
       public void setId(Integer id) { this.id = id; }
       public void setTeamName(String teamName) { this.teamName = teamName; }
      }
      /**********************************************************/
      package com.ejb3ws.services;
      
      import ............. ;
      
      @WebService
      public interface TeamService {
      
       @WebMethod String helloWorld(); // OK
       @WebMethod Team getTeam (Integer id); // OK
       @WebMethod Team[] getAllTeamsArray(); // OK
       @WebMethod List <Team> getAllTeamsCollection(); // ERROR
      }
      
      /**********************************************************/
      package com.ejb3ws.services;
      
      import ............ ;
      
      @WebService(endpointInterface = "com.ejb3ws.services.TeamService")
      @Stateless
      public class TeamServiceBean implements TeamService {
      
       @PersistenceContext(unitName = "DESAADM")
       private EntityManager em;
      
       public String helloWorld() {
       return "helloWorld: " + Math.random();
       }
      
       public Team getTeam(Integer id) {
       Team e = (Team) em.createQuery("SELECT e FROM Team e WHERE id = :teamId")
       .setParameter("teamId", id)
       .getSingleResult();
      
       return e;
       }
      
       public Team[] getAllTeamsArray() {
      
       List<Team> teams = em.createQuery("SELECT e FROM Team e").getResultList();
      
       Team[] teamArray = new Team[teams.size()];
       int i = 0;
       for (Team e: teams) {
       teamArray [ i ] = e;
       i++;
       }
      
       return teamArray;
       }
      
       public List<Team> getAllTeamsCollection() {
       List teams = em.createQuery("SELECT e FROM Team e").getResultList();
      
       return teams;
       }
      
      }
      
      


      This is the stack trace I get when I invoke getAllTeamsCollection() web method:

      10:19:02,453 ERROR [SOAPFaultExceptionHelper] SOAP request exception
      javax.xml.rpc.JAXRPCException: Cannot create or send response message
       at org.jboss.ws.server.ServiceEndpoint.postProcessResponse(ServiceEndpoint.java:312)
       at org.jboss.ws.server.ServiceEndpoint.handleRequest(ServiceEndpoint.java:238)
       at org.jboss.ws.server.ServiceEndpointServlet.doPost(ServiceEndpointServlet.java:113)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
       at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:54)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:174)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
       at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java
      :664)
       at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
       at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
       at java.lang.Thread.run(Thread.java:595)
      
      
      Caused by: org.jboss.xb.binding.JBossXBValueFormatException: Java value for XSD boolean type expected to be an instance
      of java.lang.Boolean or java.lang.Number. But the value is of type java.util.ArrayList
       at org.jboss.xb.binding.SimpleTypeBindings.marshal(SimpleTypeBindings.java:1120)
       at org.jboss.xb.binding.XercesXsMarshaller.marshalCharacters(XercesXsMarshaller.java:1169)
       at org.jboss.xb.binding.XercesXsMarshaller.marshalSimpleType(XercesXsMarshaller.java:451)
       at org.jboss.xb.binding.XercesXsMarshaller.marshalElementType(XercesXsMarshaller.java:405)
       at org.jboss.xb.binding.XercesXsMarshaller.marshalElement(XercesXsMarshaller.java:380)
       at org.jboss.xb.binding.XercesXsMarshaller.marshalElementOccurence(XercesXsMarshaller.java:886)
       at org.jboss.xb.binding.XercesXsMarshaller.marshalParticle(XercesXsMarshaller.java:823)
       at org.jboss.xb.binding.XercesXsMarshaller.marshalModelGroupSequence(XercesXsMarshaller.java:1102)
       at org.jboss.xb.binding.XercesXsMarshaller.marshalModelGroup(XercesXsMarshaller.java:1057)
       at org.jboss.xb.binding.XercesXsMarshaller.marshalParticle(XercesXsMarshaller.java:729)
       at org.jboss.xb.binding.XercesXsMarshaller.marshalComplexType(XercesXsMarshaller.java:685)
       at org.jboss.xb.binding.XercesXsMarshaller.marshalElementType(XercesXsMarshaller.java:414)
       at org.jboss.xb.binding.XercesXsMarshaller.marshalElement(XercesXsMarshaller.java:380)
       at org.jboss.xb.binding.XercesXsMarshaller.marshalElementOccurence(XercesXsMarshaller.java:886)
       at org.jboss.xb.binding.XercesXsMarshaller.marshalParticle(XercesXsMarshaller.java:823)
       at org.jboss.xb.binding.XercesXsMarshaller.marshalModelGroupSequence(XercesXsMarshaller.java:1102)
       at org.jboss.xb.binding.XercesXsMarshaller.marshalModelGroup(XercesXsMarshaller.java:1057)
       at org.jboss.xb.binding.XercesXsMarshaller.marshalParticle(XercesXsMarshaller.java:729)
       at org.jboss.xb.binding.XercesXsMarshaller.marshalComplexType(XercesXsMarshaller.java:685)
       at org.jboss.xb.binding.XercesXsMarshaller.marshalElementType(XercesXsMarshaller.java:414)
       at org.jboss.xb.binding.XercesXsMarshaller.marshalElement(XercesXsMarshaller.java:380)
       at org.jboss.xb.binding.XercesXsMarshaller.marshalElementOccurence(XercesXsMarshaller.java:886)
       at org.jboss.xb.binding.XercesXsMarshaller.marshallInternal(XercesXsMarshaller.java:275)
       at org.jboss.xb.binding.XercesXsMarshaller.marshal(XercesXsMarshaller.java:222)
       at org.jboss.ws.jaxb.JAXBMarshallerImpl.marshal(JAXBMarshallerImpl.java:172)
       at org.jboss.ws.jaxrpc.encoding.JAXBSerializer.serialize(JAXBSerializer.java:100)
       at org.jboss.ws.soap.SOAPContentElement.getXMLFragment(SOAPContentElement.java:172)
       at org.jboss.ws.soap.SOAPContentElement.expandToDOM(SOAPContentElement.java:844)
       at org.jboss.ws.soap.SOAPContentElement.getChildNodes(SOAPContentElement.java:761)
       at org.jboss.util.xml.DOMWriter.printInternal(DOMWriter.java:201)
       at org.jboss.util.xml.DOMWriter.printInternal(DOMWriter.java:260)
       at org.jboss.util.xml.DOMWriter.printInternal(DOMWriter.java:260)
       at org.jboss.util.xml.DOMWriter.print(DOMWriter.java:177)
       at org.jboss.util.xml.DOMWriter.printNode(DOMWriter.java:126)
       at org.jboss.ws.server.ServiceEndpoint.postProcessResponse(ServiceEndpoint.java:306)
       ... 23 more