Running JBoss 4.2.3.GA with RestEasy 1.0.0

We are looking at exposing many of our EJB services thru RestEasy.   One of our 
thoughts is to return a common object that contains a reference to the resource 
or list of resources.   The object would look like below, where the resource or 
list of resources would be saved in the messageObject field.   This fails when 
Resteasy tries to find the correct message writer.

package rest;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "RestfulResponse")
public class RestfulResponse {

        private long statusCode;
        private String statusDescription;
        private Object messageObject;
        private String excpDetails;

        @XmlElement(name="StatusCode")
        public long getStatusCode() {
                return statusCode;
        }
        public void setStatusCode(long statusCode) {
                this.statusCode = statusCode;
        }

        @XmlElement(name="StatusDescription")
        public String getStatusDescription() {
                return statusDescription;
        }
        public void setStatusDescription(String statusDescription) {
                this.statusDescription = statusDescription;
        }

        @XmlElement(name="ExceptionDetails")
        public String getExcpDetails() {
                return excpDetails;
        }
        public void setExcpDetails(String excpDetails) {
                this.excpDetails = excpDetails;
        }

        @XmlElement(name="Response")
        public Object getMessageObject() {
                return messageObject;
        }
        public void setMessageObject(Object messageObject) {
                this.messageObject = messageObject;
        }

}

I tried adjusting my resource method to use the GenericEntity class but must 
have gotten that wrong, see exception below.

        @GET
        @Path("/{id}")
        @Produces({"application/json", "application/xml"})
        public RestfulResponse findByPrimaryKey(@PathParam("id") long id )
        {
                RestfulResponse response = new RestfulResponse();
                EnvironmentServiceLocal envSvc = 
Services.get(EnvironmentServiceLocal.class);
                try {
                        EnvironmentBean envBean = envSvc.findByPrimaryKey(id);
                        GenericEntity<EnvironmentBean> entity = new 
GenericEntity<EnvironmentBean>(envBean) {};
                        response.setMessageObject(entity);
                        response.setStatusCode(200);
                } catch (FinderException e) {
                        Log.getInstance().error("Exception getting environment 
bean with id="+id, e);
                        response.setExcpDetails(e.getMessage());
                        response.setStatusCode(404);
                }
                return response;
        }


Exception thrown:

javax.ws.rs.WebApplicationException: javax.xml.bind.MarshalException
 - with linked exception:
[javax.xml.bind.JAXBException: rest.EnvironmentResource$1 nor any of its super 
class is known to this context]
        at 
org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBProvider.writeTo(AbstractJAXBProvider.java:113)
        at 
org.jboss.resteasy.core.interception.MessageBodyWriterContextImpl.proceed(MessageBodyWriterContextImpl.java:117)
        at 
org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor.write(GZIPEncodingInterceptor.java:48)
        at 
org.jboss.resteasy.core.interception.MessageBodyWriterContextImpl.proceed(MessageBodyWriterContextImpl.java:123)
        at 
org.jboss.resteasy.core.ServerResponse.writeTo(ServerResponse.java:184)
        at 
org.jboss.resteasy.core.SynchronousDispatcher.writeJaxrsResponse(SynchronousDispatcher.java:403)
        at 
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:340)
        at 
org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:103)
        at 
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:114)
        at 
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at 
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
        at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
        at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at 
org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
        at 
org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
        at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at 
org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
        at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
        at 
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
        at 
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
        at 
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
        at java.lang.Thread.run(Thread.java:722)
Caused by: javax.xml.bind.MarshalException
 - with linked exception:
[javax.xml.bind.JAXBException: rest.EnvironmentResource$1 nor any of its super 
class is known to thi
s context]
        at 
com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:295)
        at 
com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:148)
        at 
org.jboss.resteasy.plugins.providers.jaxb.json.JettisonMappedMarshaller.marshal(JettisonMappedMarshaller.java:71)
        at 
org.jboss.resteasy.plugins.providers.jaxb.BaseMarshaller.marshal(BaseMarshaller.java:24)
        at 
org.jboss.resteasy.plugins.providers.jaxb.AbstractJAXBProvider.writeTo(AbstractJAXBProvider.java:108)
        ... 28 more
Caused by: javax.xml.bind.JAXBException: rest.EnvironmentResource$1 nor any of 
its super class is known to this context


This seems to work okay if I use the javax.ws.rs.core.Response class and set 
the entities in there.  We wanted the option to return some additional 
'metadata' about the requests if appropriate, like a total count in a metadata 
field somewhere when getting a list of resources.   Is there a better way to do 
what we are trying to do?



------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite
It's a free troubleshooting tool designed for production
Get down to code-level detail for bottlenecks, with <2% overhead.
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap2
_______________________________________________
Resteasy-users mailing list
Resteasy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/resteasy-users

Reply via email to