Reputation: 3775
I develop Restful web service. I want output as XML type(VXML). I try like this. I use Java 8, Maven, Jersey and same as new technology. I get details from that web address link.
this my example code for request catch
@Path("/custemerservice")
public interface CustemerService {
@GET
@Path("no/123")
@Consumes({ MediaType.APPLICATION_FORM_URLENCODED })
@Produces("text/html")
public Response getWelcomeInfo();
}
and below this is development code
@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();
}
}
this is my 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>
and I edit pom.xml for that part development
<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>
I try to run project using tomcat 8 in eclipse. I got error like this how to solve it.
HTTP Status 500 - Servlet execution threw an exception
type Exception report
message Servlet execution threw an exception
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Servlet execution threw an exception org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.NoSuchMethodError: org.jboss.resteasy.specimpl.BuiltResponse.getHeaders()Ljavax/ws/rs/core/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)
note The full stack trace of the root cause is available in the Apache Tomcat/8.0.23 logs. Apache Tomcat/8.0.23
this is eclipse log .
Thanks.
Upvotes: 3
Views: 7783
Reputation: 1
It didn´t recognize the annotation @Produces("text/html").
Use Response.status(Response.Status.OK).type(MediaType.TEXT_HTML)
Upvotes: 0
Reputation: 69450
Looks like you use a version 1 of resteasy-jaxrs.jar
. The Method getHeaders()Ljavax/ws/rs/core/MultivaluedMap;
was introduced in version 2.
So you have to change to version 2 of the resteasy-jaxrs.jar
which contains the class org.jboss.resteasy.specimpl.BuiltResponse
Upvotes: 6