我正在尝试在 JBoss 7.2 Rest Easy 中开发 JAX-RS 示例。我收到如下错误消息。
严重 [org.jboss.resteasy.core.SynchronousDispatcher] (http-/0.0.0.0:80-2) 执行 GET /test/resources/1 失败:org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure:找不到 MessageBodyWriter 以进行响应对象类型:vsample.Image 媒体类型:org.jboss.resteasy.core.ServerResponse.writeTo(ServerResponse.java:216) [resteasy-jaxrs-2.3.5.Final.jar:] 上的 image/jpeg。 jboss.resteasy.core.SynchronousDispatcher.writeJaxrsResponse(SynchronousDispatcher.java:602) [resteasy-jaxrs-2.3.5.Final.jar:] at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:528) [ resteasy-jaxrs-2.3.5.Final.jar:] at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:126) [resteasy-jaxrs-2.3.5.Final.jar:] at org.jboss .resteasy.plugins.server.servlet。ServletContainerDispatcher.service(ServletContainerDispatcher.java:208) [resteasy-jaxrs-2.3.5.Final.jar:] at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55) [resteasy- jaxrs-2.3.5.Final.jar:] 在 org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50) [resteasy-jaxrs-2.3.5.Final.jar:] 在 javax .servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.2.Final.jar:1.0.2.Final] 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:295) [jbossweb-7.2.0.Final.jar:7.2.0.Final] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.2.0. Final.jar:7.2.0.Final] 在 org.apache.catalina.core。StandardWrapperValve.invoke(StandardWrapperValve.java:230) [jbossweb-7.2.0.Final.jar:7.2.0.Final] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149) [jbossweb-7.2 .0.Final.jar:7.2.0.Final] 在 org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169) [jboss-as-web-7.2.0.Final.jar:7.2 .0.Final] 在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:145) [jbossweb-7.2.0.Final.jar:7.2.0.Final] 在 org.apache.catalina.valves。 ErrorReportValve.invoke(ErrorReportValve.java:97) [jbossweb-7.2.0.Final.jar:7.2.0.Final] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102) [jbossweb-7.2 .0.Final.jar:7.2.0.Final] 在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:336)[jbossweb-7.2.0.Final.jar:7.2.0.Final] 在 org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)[jbossweb-7.2.0.Final.jar:7.2 .0.Final] 在 org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653) [jbossweb-7.2.0.Final.jar:7.2.0.Final] 在 org.apache.tomcat。 util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:920) [jbossweb-7.2.0.Final.jar:7.2.0.Final] 在 java.lang.Thread.run(Thread.java:722) [rt .jar:1.7.0_17]JioEndpoint$Worker.run(JIoEndpoint.java:920) [jbossweb-7.2.0.Final.jar:7.2.0.Final] 在 java.lang.Thread.run(Thread.java:722) [rt.jar:1.7 .0_17]JioEndpoint$Worker.run(JIoEndpoint.java:920) [jbossweb-7.2.0.Final.jar:7.2.0.Final] 在 java.lang.Thread.run(Thread.java:722) [rt.jar:1.7 .0_17]
我的代码是,
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Application;
@ApplicationPath("/rest")
public class Etag extends Application {
}
和,
import java.util.Date;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.CacheControl;
import javax.ws.rs.core.EntityTag;
import javax.ws.rs.core.Response.ResponseBuilder;
@Path( "/test" )
public class EtagImpl {
@GET
@Produces("image/jpeg")
@Path("resources/{id}")
public Response getImage(@PathParam("id") String id, @Context Request request) {
ImageDAOImpl imageDAO = new ImageDAOImpl();
Image image = imageDAO.getImage(id);
CacheControl cc = new CacheControl();
cc.setMaxAge(172800); // 2 days
Response.ResponseBuilder rb = null;
String lastModified = image.getDateModified().toString();
// EntityTag etag = new EntityTag(imageDAO.getImage(id).hashCode()+"");
EntityTag etag = new EntityTag(lastModified.hashCode()+"");
System.out.println("Writing Response:" + etag);
rb = request.evaluatePreconditions(etag);
if (rb != null)
{
return rb.cacheControl(cc).tag(etag).build();
}
//If rb is null then either it is first time request; or resource is modified
//Get the updated representation and return with Etag attached to it
rb = Response.ok(imageDAO.getImage(id)).cacheControl(cc).tag(etag);
return rb.build();
}
由于我是 RestEasy 的新手,因此让想法朝着正确的方向前进会很有帮助
谢谢和问候,拉姆。