我开发了Restful Web服务。我希望输出为XML类型(VXML)。我试着这样。我使用Java 8,Maven,Jersey和新技术一样。我从该网址link获取详细信息。
这是我的请求捕获示例代码
@Path("/custemerservice")
public interface CustemerService {
@GET
@Path("no/123")
@Consumes({ MediaType.APPLICATION_FORM_URLENCODED })
@Produces("text/html")
public Response getWelcomeInfo();
}
以下是开发代码
@Service
public class CustemerServiceImpl implements CustemerService {
@Override
public Response getWelcomeInfo() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("user", "usul");
List<String> l = new ArrayList<String>();
l.add("light saber");
l.add("fremen clothes");
map.put("items", l);
return Response.ok(new Viewable("/cart.jsp", map)).build();
}
}
这是我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>MyApp</display-name>
<listener>
<listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
<listener>
<listener-class>org.jboss.resteasy.plugins.spring.SpringContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>com.sun.jersey.spi.container.servlet.ServletContainer</listener-class>
</listener>
<servlet>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/resteasy/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/spring-hibernate-resteasy.xml</param-value>
</context-param>
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/resteasy</param-value>
</context-param>
<context-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.ezakus.web</param-value>
</context-param>
<context-param>
<param-name>com.sun.jersey.config.property.JSPTemplatesBasePath</param-name>
<param-value>/WEB-INF/jsp</param-value>
</context-param>
<context-param>
<param-name>com.sun.jersey.config.property.WebPageContentRegex</param-name>
<param-value>/(resources|(WEB-INF/jsp))/.*</param-value>
</context-param>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
我为该部分开发编辑pom.xml
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-json-provider</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
<scope>compile</scope>
</dependency>
我尝试在eclipse中使用tomcat 8运行项目。我得到了这样的错误如何解决它。
HTTP状态500 - Servlet执行引发异常
输入例外报告
消息Servlet执行引发异常
description服务器遇到阻止它的内部错误 完成此请求。
例外
javax.servlet.ServletException:Servlet执行引发异常 org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
根本原因
java.lang.NoSuchMethodError: org.jboss.resteasy.specimpl.BuiltResponse.getHeaders()Ljavax / WS / RS /型芯/ MultivaluedMap; org.jboss.resteasy.core.ServerResponseWriter.setDefaultContentType(ServerResponseWriter.java:186) org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:46) org.jboss.resteasy.core.SynchronousDispatcher.writeResponse(SynchronousDispatcher.java:427) org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:376) org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179) org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220) org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) javax.servlet.http.HttpServlet.service(HttpServlet.java:729) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
注意Apache中提供了根本原因的完整堆栈跟踪 Tomcat / 8。0。2。3日志。 Apache Tomcat / 8.0.23
这是日食日志。
感谢。
答案 0 :(得分:6)
您似乎使用resteasy-jaxrs.jar
的版本1。方法getHeaders()Ljavax/ws/rs/core/MultivaluedMap;
在版本2中引入。
因此,您必须更改为resteasy-jaxrs.jar
的第2版,其中包含类org.jboss.resteasy.specimpl.BuiltResponse
答案 1 :(得分:0)
它无法识别 @Produces("text/html") 注释。
使用 Response.status(Response.Status.OK).type(MediaType.TEXT_HTML)