JAX-RS (RestEasy) and EJB3 integration in JBoss - web-services

I have build a maven project(packaging:war) for learning jax-rs and ejb integration. It has mainly following files:
Stateless Bean
package org.eb.stateless;
import javax.annotation.PostConstruct;
import javax.ejb.Stateless;
#Stateless
public class StatelessBeanDemo
{
#PostConstruct
public void init()
{
System.out.println("I M POST-CONSTRUCT");
}
public void printData()
{
System.out.println("I M Stateless");
}
}
Resource Interface
package org.webservice.rs;
import javax.ejb.Local;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
#Local
#Path("/home")
public interface IHelloWorldService
{
#GET
#Path("/eb/s1")
Response callSL1();
#GET
#Path("/eb/s2")
Response callSL2();
}
Resource
package org.webservice.rs;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.ws.rs.core.Response;
import org.eb.stateless.StatelessBeanDemo;
#Stateless
public class HelloWorldService implements IHelloWorldService
{
#Inject // Use of "Inject"
private StatelessBeanDemo sl; // Always Null
#EJB // Use of "EJB"
private StatelessBeanDemo s2; // Sometime Null, Sometime Not
public Response callSL1()
{
sl.printData();
return Response.status(201).entity("DONE").build();
}
public Response callSL2()
{
s2.printData();
return Response.status(201).entity("DONE").build();
}
}
Web Service Application Path Class
package org.webservice.rs;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;
public class RestServiceLocator extends Application
{
public Set<Class<?>> getClasses()
{
Set<Class<?>> s = new HashSet<Class<?>>();
s.add(HelloWorldService.class);
return s;
}
}
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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>J2EEDemo</display-name>
<context-param>
<param-name>resteasy.jndi.resources</param-name>
<param-value>java:module/HelloWorldService</param-value>
</context-param>
<listener>
<listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
<servlet>
<servlet-name>Resteasy</servlet-name>
<servlet-class>
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>org.webservice.rs.RestServiceLocator</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Resteasy</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
Now when I am hitting url "http://127.0.0.1:8080/J2EEDemo/home/eb/s1", it is ALWAYS throwing following null pointer exception:
13:59:08,695 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/J2EEDemo].[Resteasy]] (http-0.0.0.0-0.0.0.0-8080-2) Servlet.service() for servlet Resteasy threw exception: org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException
at org.jboss.resteasy.core.SynchronousDispatcher.handleApplicationException(SynchronousDispatcher.java:340) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.handleException(SynchronousDispatcher.java:214) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.handleInvokerException(SynchronousDispatcher.java:190) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:540) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:502) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50) [resteasy-jaxrs-2.3.2.Final.jar:]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:897) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:626) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:2039) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_51]
Caused by: java.lang.NullPointerException
at org.webservice.rs.HelloWorldService.callSL1(HelloWorldService.java:26) [classes:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_51]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_51]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_51]
at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_51]
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:155) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:257) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:222) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:211) [resteasy-jaxrs-2.3.2.Final.jar:]
at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:525) [resteasy-jaxrs-2.3.2.Final.jar:]
...
What more awkward is when I am hitting "http://127.0.0.1:8080/J2EEDemo/home/eb/s2", It is SOMETIMES working as per my wish (printing "DONE" and executing injected bean method) and sometimes throwing same null pointer exception. I am not able to understand what is happening.

I have solved the problem by adding 'beans.xml' dummy file in WEB-INF (Configuring CDI Application). (Enabling CDI)
But the question is still open. Why http://127.0.0.1:8080/J2EEDemo/home/eb/s2 working occasionally, before adding beans.xml ?

Related

File upload with Jersey using POSTMAN extension : FormDataContentDisposition is NULL

I am getting FormDataContentDisposition object as NULL while implementing jersey file upload example as mentioned in below URL :
http://www.mkyong.com/webservices/jax-rs/file-upload-example-in-jersey/
Here is my sample code,
IMPORTS
import java.io.InputStream;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import com.sun.jersey.core.header.FormDataContentDisposition;
import com.sun.jersey.multipart.FormDataParam;
Rest API code,
#POST
#Path("/uploadFiles")
#Produces({ MediaType.APPLICATION_JSON})
#Consumes({ MediaType.MULTIPART_FORM_DATA })
public Response uploadFiles(#FormDataParam("file") InputStream uploadedInputStream,
#FormDataParam("file") FormDataContentDisposition fileDetail)
throws IOException{
I am getting fileDetail object null in above code.
JAR versions used,
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.11</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
<version>1.19</version>
</dependency>
I am hitting my request from Chrome POSTMAN Client,
Here is the snapshot of my request from POSTMAN client...
I already gone through the link : File upload with Jersey : FormDataContentDisposition is null having same problem but the difference is that I am using REST Client instead of HTML/JSP to submit my request.
Can any one please help me to know why I am getting NULL object of FormDataContentDisposition,
Thanks in advance!
Edit:
I found the difference between example and my application implementation is that they have below configuration in web.xml
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.mkyong.rest</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
and My Application configuration is,
#javax.ws.rs.ApplicationPath("/rest")
#javax.ws.rs.Path("application")
public class RestServices extends Application {
#Override
public Set<Class<?>> getClasses() {
HashSet<Class<?>> classes = new HashSet<Class<?>>();
classes.add(this.getClass());
classes.add(RestAPI.class);
return classes;
}
Can anybody tell me what is the exact difference between these two
configurations. Can Above both implementation will changes the way
things working?
Remove #javax.ws.rs.Path("application").
You don't need two kinds of Deployment Descriptor, use either Programmatic approach or web.xml;
My approach:
empty web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
</web-app>
and config class:
#ApplicationPath("/rootpath")
public class YourApplication extends ResourceConfig {
// Constructor
public YourApplication() {
super (
//YOUR JAX-RS Service Classes
MyJaxRSService.class,
// This one corresponds to jersey-media-json-jackson in dependencies
JacksonFeature.class,
// This is one to : jersey-media-multipart
MultiPartFeature.class
);
}
}
update dependencies
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.22.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.22.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.22.1</version>
</dependency>
Last and most important: forget such tutorials, it helps you start instantly but when you encounter problem you're stuck, and you'll just waste your time. Instead read official documentation and their real world examples, get some real insight into technology how and why it works.
Jersey Documentation: https://jersey.java.net/documentation/latest/index.html
In addition: I'd recommend this book by Bill Burke - RESTful Java with JAX-RS 2.0.
Good luck.
Though I am using Jersey 2.22.1, my web.xml has provided configuration for multipart data.
web.xml
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.xyz.rest.controller;com.xyz.rest.filters</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>org.glassfish.jersey.media.multipart.MultiPartFeature</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
</web-app>
Reply back if still problem persist

Deploying Jersey web service application in Jboss as 7.1.1 shows webservices in package ws is not supported

I have an issue on deploying my war file ,everything expect the web services are working fine The error log is given below
16:14:08,866 INFO [com.sun.jersey.api.core.PackagesResourceConfig] (MSC service thread 1-1) Scanning for root resource and provider classes in the packages:com.fut.ws
16:14:08,920 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/fut-wager]] (MSC service thread 1-1) StandardWrapper.Throwable:com.sun.jersey.core.spi.scanning.ScannerException: The URI scheme vfs of the URI vfs:/content/fut-wager.war/WEB-INF/classes/com/fut/ws/ is not supported. Package scanning deployment is not supported for such URIs.
Try using a different deployment mechanism such as explicitly declaring root resource and provider classes using an extension of javax.ws.rs.core.Application at com.sun.jersey.core.spi.scanning.PackageNamesScanner.scan(PackageNamesScanner.java:225) [jersey-bundle-1.9.1.jar:1.9.1] at com.sun.jersey.core.spi.scanning.PackageNamesScanner.scan(PackageNamesScanner.java:139) [jersey-bundle-1.9.1.jar:1.9.1] at com.sun.jersey.api.core.ScanningResourceConfig.init(ScanningResourceConfig.java:80) [jersey-bundle-1.9.1.jar:1.9.1] at com.sun.jersey.api.core.PackagesResourceConfig.init(PackagesResourceConfig.java:104) [jersey-bundle-1.9.1.jar:1.9.1] at com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:78) [jersey-bundle-1.9.1.jar:1.9.1]
at com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:89) [jersey-bundle-1.9.1.jar:1.9.1] at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:700) [jersey-bundle-1.9.1.jar:1.9.1] at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:678) [jersey-bundle-1.9.1.jar:1.9.1] at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:203) [jersey-bundle-1.9.1.jar:1.9.1] at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373) [jersey-bundle-1.9.1.jar:1.9.1] at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556) [jersey-bundle-1.9.1.jar:1.9.1]
at javax.servlet.GenericServlet.init(GenericServlet.java:242) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final] at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1202) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3655) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3873) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_11]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_11]
at java.lang.Thread.run(Thread.java:619) [rt.jar:1.6.0_11]
16:14:08,974 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/fut-wager]] (MSC service thread 1-1) Servlet /fut-wager threw load() exception: com.sun.jersey.core.spi.scanning.ScannerException: The URI scheme vfs of the URI vfs:/content/fut-wager.war/WEB-INF/classes/com/fut/ws/ is not supported. Package scanning deployment is not supported for such URIs.
Try using a different deployment mechanism such as explicitly declaring root resource and provider classes using an extension of javax.ws.rs.core.Application
at com.sun.jersey.core.spi.scanning.PackageNamesScanner.scan(PackageNamesScanner.java:225) [jersey-bundle-1.9.1.jar:1.9.1]
at com.sun.jersey.core.spi.scanning.PackageNamesScanner.scan(PackageNamesScanner.java:139) [jersey-bundle-1.9.1.jar:1.9.1]
at com.sun.jersey.api.core.ScanningResourceConfig.init(ScanningResourceConfig.java:80) [jersey-bundle-1.9.1.jar:1.9.1]
at com.sun.jersey.api.core.PackagesResourceConfig.init(PackagesResourceConfig.java:104) [jersey-bundle-1.9.1.jar:1.9.1]
at com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:78) [jersey-bundle-1.9.1.jar:1.9.1]
at com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:89) [jersey-bundle-1.9.1.jar:1.9.1]
at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:700) [jersey-bundle-1.9.1.jar:1.9.1]
at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:678) [jersey-bundle-1.9.1.jar:1.9.1]
at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:203) [jersey-bundle-1.9.1.jar:1.9.1]
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373) [jersey-bundle-1.9.1.jar:1.9.1]
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556) [jersey-bundle-1.9.1.jar:1.9.1]
at javax.servlet.GenericServlet.init(GenericServlet.java:242) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1202) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3655) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3873) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_11]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_11]
at java.lang.Thread.run(Thread.java:619) [rt.jar:1.6.0_11]
16:14:09,038 INFO [org.jboss.web] (MSC service thread 1-1) JBAS018210: Registering web context: /fut-wager
16:14:09,155 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "fut-wager.war"
16:15:00,034 INFO [com.fut.scheduler.MatchScheduler] (org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-9) -- Match expiring scheduler execution started --
16:15:00,037 INFO [com.fut.ws.user.handler.MatchHandlerImpl] (org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-9) --Inside match expiring service--
16:15:00,039 INFO [com.fut.dao.user.MatchDao] (org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-9) --Inside match expiring dao--
16:15:00,313 INFO [com.fut.scheduler.MatchScheduler] (org.springframework.scheduling.quartz.SchedulerFactoryBean#0_Worker-9) -- Match expiring scheduler execution completed --
I got same error and solved using link provided by peeskillet. Here is example :
Web Service Application
package org.webservice.application;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;
import org.webservice.rs.HelloWorldService;
public class RSApplication extends Application
{
public Set<Class<?>> getClasses()
{
Set<Class<?>> s = new HashSet<Class<?>>();
s.add(HelloWorldService.class);
return s;
}
}
Resource
package org.webservice.rs;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
#Path("/hello")
public class HelloWorldService
{
#GET
public Response getMsg()
{
String output = "I M Jersey";
return Response.status(200).entity(output).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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>J2EEDemo</display-name>
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>org.webservice.application.RSApplication</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
pom.xml entry for dependency
<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.8</version>
</dependency>
</dependencies>
Hit url : http://<HOST>:<PORT>/<CONTEXT>/rest/hello
I also got the same problem. below works for me try it.
Problem: com.sun.jersey.core.spi.scanning.ScannerException: The URI scheme vfs of the URI vfs
`
Solution: Need to change web.xml file
I have created
- package : com.rest.spring
- class : PaymentService
and I have provided those values inside <init-Parm> in the web.xml file. See below:
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet
</servlet-class>
<init-param>
**<param-name>
com.sun.jersey.config.property.packages
</param-name>
<param-value>com.rest.spring</param-value>**
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
After deploying, I got above error. So the only thing we need to change that is <init param> see below:
**<param-name>
javax.ws.rs.core.Application
</param-name>
<param-value>com.rest.spring</param-value>**
enjoy...

Facing java.lang.IncompatibleClassChangeError

Trying to make a simple Restful service.
i used this tutorial to do it link
here is the link of jar using in this program
After follow each and every step ..... i face this error.
Please help ...
Pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.javacodegeeks.enterprise.rest.jersey</groupId>
<artifactId>JAXRS-HelloWorld</artifactId>
<version>0.0.1-SNAPSHOT</version>
<repositories>
<repository>
<id>maven2-repository.java.net</id>
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/2/</url>
<layout>default</layout>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.9</version>
</dependency>
</dependencies>
</project>
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" id="WebApp_ID" version="3.0">
<display-name>Restful Web Application</display-name>
<servlet>
<servlet-name>jersey-helloworld-serlvet</servlet-name>
<servlet-class>
com.sun.jersey.spi.container.servlet.ServletContainer
</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.javacodegeeks.enterprise.rest.jersey</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-helloworld-serlvet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
java file
package com.javacodegeeks.enterprise.rest.jersey;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
#Path("/helloWorldREST")
public class HelloWorldREST {
#GET
#Path("/{parameter}")
public Response responseMsg( #PathParam("parameter") String parameter,
#DefaultValue("Nothing to say") #QueryParam("value") String value) {
String output = "Hello from: " + parameter + " : " + value;
return Response.status(200).entity(output).build();
}
}
Error
Mar 28, 2015 6:51:17 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jersey-helloworld-serlvet] in context with path [/JAXRS-HelloWorld] threw exception [Servlet execution threw an exception] with root cause
java.lang.IncompatibleClassChangeError: Class javax.ws.rs.core.Response$Status does not implement the requested interface javax.ws.rs.core.Response$StatusType
at com.sun.jersey.spi.container.ContainerResponse.getStatus(ContainerResponse.java:599)
at com.sun.jersey.spi.container.ContainerResponse$CommittingOutputStream.commitWrite(ContainerResponse.java:157)
at com.sun.jersey.spi.container.ContainerResponse$CommittingOutputStream.write(ContainerResponse.java:134)
at sun.nio.cs.StreamEncoder.writeBytes(Unknown Source)
at sun.nio.cs.StreamEncoder.implFlushBuffer(Unknown Source)
at sun.nio.cs.StreamEncoder.implFlush(Unknown Source)
at sun.nio.cs.StreamEncoder.flush(Unknown Source)
at java.io.OutputStreamWriter.flush(Unknown Source)
at java.io.BufferedWriter.flush(Unknown Source)
at com.sun.jersey.core.util.ReaderWriter.writeToAsString(ReaderWriter.java:191)
at com.sun.jersey.core.provider.AbstractMessageReaderWriterProvider.writeToAsString(AbstractMessageReaderWriterProvider.java:128)
at com.sun.jersey.core.impl.provider.entity.StringProvider.writeTo(StringProvider.java:88)
at com.sun.jersey.core.impl.provider.entity.StringProvider.writeTo(StringProvider.java:58)
at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:302)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1510)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:947)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Asynchronous Jersey 2 REST in liferay vaadin portlet

Currently I have a standalone Jersey 2.x web app in my liferay tomcat container, set to run asynchronously. I also have my main portlet in Liferay built with Vaadin.
I want to move my REST service to my vaadin project, so that I can leverage hibernate and caching from my main app.
However, when I move all the code over, and the servlet entry in the web.xml file, it throws the exception below when I make a GET call to the service.
Has anybody accomplished this? I am thinking it has something to with the asynchronous functionality, or maybe spring? I am running Liferay 6.1.1 GA2.
`SEVERE: Servlet.service() for servlet [TEKControl RESTFul API] in context with path [/tekwave-portlet] threw exception [javax.ws.rs.ProcessingExceptio`
`n: Attempt to suspend a connection of an asynchronous request failed in the underlying container.] with root cause`
`javax.ws.rs.ProcessingException: Attempt to suspend a connection of an asynchronous request failed in the underlying container.`
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:331)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:106)
at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:259)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:318)
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:236)
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1010)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:373)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:382)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:345)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:220)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:116)
at sun.reflect.GeneratedMethodAccessor386.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.liferay.portal.kernel.bean.ClassLoaderBeanHandler.invoke(ClassLoaderBeanHandler.java:67)
at $Proxy526.doFilter(Unknown Source)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:72)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDirectCallFilter(InvokerFilterChain.java:167)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:95)
at com.liferay.portal.kernel.servlet.PortalClassLoaderFilter.doFilter(PortalClassLoaderFilter.java:70)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.processDoFilter(InvokerFilterChain.java:206)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:108)
at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:73)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1813)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
UPDATE
When I debug this, it reaches the class I'm calling with a GET request, but it throws the error after declaring some things and before going into the GET method. Below is my GET method declaration:
#GET
#Produces("application/xml")
public void AnswerPhoneCall(#Suspended final AsyncResponse asyncResponse, #Context UriInfo ui) {
final MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
new Thread(new Runnable() {
#Override
public void run() {
String ret = "Testing";
asyncResponse.resume(ret);
}
}).start();
}
----WORKING SOLUTION---
Since the liferay invoker filter was causing the issue, and I also don't think Liferay fully supports Servlet 3.0 yet, below is what we came up with to solve this problem.
Add a class that implements "org.glassfish.jersey.servlet.ServletContainer"
import org.apache.catalina.Globals;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;
public class ServletContainer extends org.glassfish.jersey.servlet.ServletContainer {
#Override
public void service(ServletRequest request, ServletResponse response)
throws ServletException, IOException {
request.setAttribute(Globals.ASYNC_SUPPORTED_ATTR, true);
super.service(request, response);
}
}
Change your servlet entry in the portlet web.xml to the above class:
<servlet>
<servlet-name>RESTFul API</servlet-name>
<servlet-class>com.myportlet.api.jersey.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.myportlet.api</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>RESTFul API</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
Add the following dependency in maven, if that is what you use
<dependency>
<groupId>org.apache.geronimo.ext.tomcat</groupId>
<artifactId>catalina</artifactId>
<version>7.0.39.1</version>
<scope>provided</scope>
</dependency>
can you please check connector property in server.xml
<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"
connectionTimeout="20000"
redirectPort="8443" />
AFAIU, it has Nothing to do with connector property. Basically what is happening is Liferay's filter is trying to intercept the request to the Jersey REST Webservice servlets. You may need to change Filter mappings of Liferay's filters in web.xml to exclude Jersey's servlets.
Another, possibly cleaner approach is that you may want to develop a "Web" plugin to host your REST services project. I haven't tried this, but you may want to explore possibilities in this direction.

Tomcat error 500 when using JAXB

I used a rest web service using jersey (followed this tutorial http://www.youtube.com/watch?v=4DY46f-LZ0M) and everything works fine.
Now I am trying to use a WS which returns a basic JSON.
When I try and use it via browser I get this error
HTTP Status 500 - Servlet.init() for servlet Jersey REST Service threw exception
Question:
Where should I investigate further?
I am using: Eclipse JEE, jersey-archive-1.18, Tomcat 7
THis is my class:
package com.name.rest.status;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
#Path("/v1/status")
public class V1_status {
private static final String api_version = "1.00.1";
#GET
#Produces(MediaType.TEXT_HTML)
public String returnTitle() {
return "<p> Java Web Service </p>";
}
#Path("/version")
#GET
#Produces(MediaType.TEXT_HTML)
public String returnVersion() {
return "<p> version is: <p>" + api_version;
}
#GET
#Produces("/application/json")
public MyJaxbBean getMyBean() {
return new MyJaxbBean("Agamemnon", 32);
}
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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>com.name.rest</display-name>
<welcome-file-list>
<welcome-file>readme.html</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.property.packages</param-name>
<param-value>com.name.rest</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>com.name.rest</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
</web-app>
Here my exception:
mensaje Servlet.init() for servlet Jersey REST Service threw exception
javax.servlet.ServletException: Servlet.init() for servlet Jersey REST Service threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:50 2)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:409)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1044)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:744)
java.lang.IllegalArgumentException: java.text.ParseException: Next event is not a Token
com.sun.jersey.core.header.MediaTypes.createQualitySourceMediaTypes(MediaTypes.java:289)
com.sun.jersey.core.header.MediaTypes.createQualitySourceMediaTypes(MediaTypes.java:274)
com.sun.jersey.server.impl.modelapi.annotation.IntrospectionModeller.addProduces(IntrospectionModeller.java:173)
com.sun.jersey.server.impl.modelapi.annotation.IntrospectionModeller.workOutResourceMethodsList(IntrospectionModeller.java:303)
com.sun.jersey.server.impl.modelapi.annotation.IntrospectionModeller.createResource(IntrospectionModeller.java:126)
com.sun.jersey.server.impl.application.WebApplicationImpl.getAbstractResource(WebApplicationImpl.java:769)
com.sun.jersey.server.impl.application.WebApplicationImpl.createAbstractResourceModelStructures(WebApplicationImpl.java:1595)
com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1356)
com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:180)
com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:799)
com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:795)
com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:795)
com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:790)
com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:491)
com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:321)
com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605)
com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:207)
com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:376)
com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:559)
javax.servlet.GenericServlet.init(GenericServlet.java:160)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:409)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1044)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:744)
java.text.ParseException: Next event is not a Token
com.sun.jersey.core.header.reader.HttpHeaderReader.nextToken(HttpHeaderReader.java:102)
com.sun.jersey.core.header.QualitySourceMediaType.valueOf(QualitySourceMediaType.java:84)
com.sun.jersey.core.header.reader.HttpHeaderReader$5.create(HttpHeaderReader.java:360)
com.sun.jersey.core.header.reader.HttpHeaderReader$5.create(HttpHeaderReader.java:358)
com.sun.jersey.core.header.reader.HttpHeaderReader.readList(HttpHeaderReader.java:481)
com.sun.jersey.core.header.reader.HttpHeaderReader.readList(HttpHeaderReader.java:473)
com.sun.jersey.core.header.reader.HttpHeaderReader.readAcceptableList(HttpHeaderReader.java:461)
com.sun.jersey.core.header.reader.HttpHeaderReader.readQualitySourceMediaType(HttpHeaderReader.java:365)
com.sun.jersey.core.header.reader.HttpHeaderReader.readQualitySourceMediaType(HttpHeaderReader.java:373)
com.sun.jersey.core.header.MediaTypes.createQualitySourceMediaTypes(MediaTypes.java:287)
com.sun.jersey.core.header.MediaTypes.createQualitySourceMediaTypes(MediaTypes.java:274)
com.sun.jersey.server.impl.modelapi.annotation.IntrospectionModeller.addProduces(IntrospectionModeller.java:173)
com.sun.jersey.server.impl.modelapi.annotation.IntrospectionModeller.workOutResourceMethodsList(IntrospectionModeller.java:303)
com.sun.jersey.server.impl.modelapi.annotation.IntrospectionModeller.createResource(IntrospectionModeller.java:126)
com.sun.jersey.server.impl.application.WebApplicationImpl.getAbstractResource(WebApplicationImpl.java:769)
com.sun.jersey.server.impl.application.WebApplicationImpl.createAbstractResourceModelStructures(WebApplicationImpl.java:1595)
com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1356)
com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:180)
com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:799)
com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:795)
com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:795)
com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:790)
com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:491)
com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:321)
com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605)
com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:207)
com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:376)
com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:559)
javax.servlet.GenericServlet.init(GenericServlet.java:160)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:409)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1044)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:744)
The #Produces annotation on getMyBean() method should be
#Produces("application/json")
instead of
#Produces("/application/json")
(remove the leading /)
Alternatively, you can use the constants defined injavax.ws.rs.core.MediaType. That way you'll be aware of mistakes at compile time. For example:
#Produces(MediaType.APPLICATION_JSON)