Running RestEasy 2.3.5
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
@Produces({"application/json", "application/xml"})
public RestfulResponse findAll(@QueryParam(BaseResource.OFFSET)
@DefaultValue("0") String offset, @QueryParam(BaseResource.LIMIT)
@DefaultValue("10") String limit)
{
List<EnvironmentBean> list = null;
EnvironmentServiceLocal envSvc =
Services.get(EnvironmentServiceLocal.class);
RestfulResponse response = new RestfulResponse();
try {
if (isRetrieveAllAllowed()) {
list = envSvc.findAll();
} else {
validatePaginationParms(offset, limit);
list =
envSvc.find(paginationParms.get(BaseResource.OFFSET),
paginationParms.get(BaseResource.LIMIT));
}
} catch (FinderException e) {
response.setStatusCode(404);
return response;
}
response.setStatusCode(200);
GenericEntity<List<EnvironmentBean>> entity = new
GenericEntity<List<EnvironmentBean>>(list) {};
response.setMessageObject(entity);
//response.setMessageObject(list);
return response;
}
org.jboss.resteasy.plugins.providers.jaxb.JAXBMarshalException:
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:148)
at
org.jboss.resteasy.core.interception.MessageBodyWriterContextImpl.proceed(MessageBodyWriterContextImpl.java:117)
at
org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor.write(GZIPEncodingInterceptor.java:104)
at
org.jboss.resteasy.core.interception.MessageBodyWriterContextImpl.proceed(MessageBodyWriterContextImpl.java:123)
. . .
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?
Just setting the messageObject to the list reference gives exception:
JAXBException: java.util.ArrayList nor any of its super class is known to this
context.
------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. A cloud service to automate IT design, transition and operations
2. Dashboards that offer high-level views of enterprise services
3. A single system of record for all IT processes
http://p.sf.net/sfu/servicenow-d2d-j
_______________________________________________
Resteasy-users mailing list
Resteasy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/resteasy-users