Jersey 500 Error NoClassDefFoundError: org/json/JSONException - java

Before you mark it as DUPLICATE please understand I've checked all the relevant links but to no avail.
I'm calling the following Service.
#Path("/courses")
public class CourseService {
// #GET
// #Produces(MediaType.TEXT_PLAIN)
// public String hello(){
// return "Hello World !!!";
// }
private DataService _service;
public CourseService(String jsonData) throws ParseException, IOException, JSONException {
_service = new DataService(jsonData);
}
#GET
#Produces(MediaType.APPLICATION_XML)
public ArrayList<Course> getAllCourses(){
return _service.get_handler().getAllCourses();
}
}
If I just run the commented portion of the code my application runs fine and produces "Hello World"
But then when I run my actual service it gives me the following error.
type Exception report
message Servlet.init() for servlet Jersey Web Application threw exception
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Servlet.init() for servlet Jersey Web Application threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1502)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1458)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)
root cause
java.lang.NoClassDefFoundError: org/json/JSONException
java.lang.Class.getDeclaredConstructors0(Native Method)
java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
java.lang.Class.getConstructors(Class.java:1651)
org.glassfish.jersey.server.model.MethodHandler$ClassBasedMethodHandler.<init>(MethodHandler.java:265)
org.glassfish.jersey.server.model.MethodHandler.create(MethodHandler.java:155)
org.glassfish.jersey.server.model.ResourceMethod$Builder.createInvocable(ResourceMethod.java:550)
org.glassfish.jersey.server.model.ResourceMethod$Builder.build(ResourceMethod.java:536)
org.glassfish.jersey.server.model.Resource$Builder.processMethodBuilders(Resource.java:663)
org.glassfish.jersey.server.model.Resource$Builder.buildResourceData(Resource.java:599)
org.glassfish.jersey.server.model.Resource$Builder.build(Resource.java:655)
org.glassfish.jersey.server.model.Resource.from(Resource.java:798)
org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:465)
org.glassfish.jersey.server.ApplicationHandler.access$500(ApplicationHandler.java:184)
org.glassfish.jersey.server.ApplicationHandler$3.call(ApplicationHandler.java:350)
org.glassfish.jersey.server.ApplicationHandler$3.call(ApplicationHandler.java:347)
org.glassfish.jersey.internal.Errors.process(Errors.java:315)
org.glassfish.jersey.internal.Errors.process(Errors.java:297)
org.glassfish.jersey.internal.Errors.processWithException(Errors.java:255)
org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:347)
org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:392)
org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:177)
org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:369)
javax.servlet.GenericServlet.init(GenericServlet.java:158)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1502)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1458)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)
This is the structure of my Project Directory
I've tested my CourseService using a TestClient and it works fine. What am I doing wrong.

You shouldn't be defining dependencies like that. All your dependencies should be managed with something like maven or gradle. That being said, did you add it the jar to the class path?
Since your using maven, you would want to add this to your <dependencies> section. For example:
<dependencies>
<!-- other dependencies -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<!-- or w.e. version you wanted to use. -->
<!-- See http://mvnrepository.com/artifact/org.json/json-->
<version>20160212</version>
</dependency>
<!-- other dependencies -->
</dependencies>
Eclipse should automatically add dependencies like the one above to your class path.
Check out one of the official tutorials on maven: https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

java.lang.NoClassDefFoundError: org/json/JSONException
Please make sure JSONException is defined and accessible.

Related

Setting up JAX RS in an existing non maven web application

I'm trying to add jax rs with jersey to my webapplication, which already uses jax ws. It worked with plain text get and put but not with multipart form data.
I'm using
NetBeans 8.2
JDK 8
JAX WS 2.2.6
Metro 2.0
And following libraries for rest/jersey which I took from jersey homepage non maven user zip file:
aopalliance-repackaged-2.5.0-b32.jar
hk2-api-2.5.0-b32.jar
hk2-locator-2.5.0-b32.jar
hk2-utils-2.5.0-b32.jar
javassist-3.20.0-GA.jar
javax.annotation-api-1.2.jar
javax.inject-2.5.0-b32.jar
javax.servlet-api-3.0.1.jar
javax.ws.rs-api-2.0.1.jar
jersey-client-2.25.1.jar
jersey-common-2.25.1.jar
jersey-container-grizzly2-http-2.25.1.jar
jersey-container-grizzly2-servlet-2.25.1.jar
jersey-container-jdk-http-2.25.1.jar
jersey-container-jetty-http-2.25.1.jar
jersey-container-netty-http-2.25.1.jar
jersey-container-servlet-2.25.1.jar
jersey-container-servlet-core-2.25.1.jar
jersey-container-simple-http-2.25.1.jar
jersey-guava-2.25.1.jar
jersey-media-jaxb-2.25.1.jar
jersey-media-multipart-2.25.1.jar
jersey-netty-connector-2.25.1.jar
jersey-server-2.25.1.jar
jetty-continuation-9.2.14.v20151106.jar
jetty-http-9.2.14.v20151106.jar
jetty-io-9.2.14.v20151106.jar
jetty-server-9.2.14.v20151106.jar
jetty-util-9.2.14.v20151106.jar
mimepull-1.9.6.jar
oro-2.0.8.jar
osgi-resource-locator-1.0.1.jar
validation-api-1.1.0.Final.jar
I added a ServiceResource class via the netbeans rest wizard. Which did not work properly i had to add a config class and manually added the service class to the config resources
#javax.ws.rs.ApplicationPath("api")
public class RestConfig extends Application{
#Override
public Set<Class<?>> getClasses() {
Set<Class<?>> resources = new java.util.HashSet<>();
addRestResourceClasses(resources);
return resources;
}
private void addRestResourceClasses(Set<Class<?>> resources) {
resources.add(ws.rest.UploadResource.class);
}
}
So i could use the simple code generated from the wizard and received a text via get after i additionally added the servlet in the web.xml which looks like this:
<servlet>
<servlet-name>rest_let</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>ws.rest.RestConfig</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>rest_let</servlet-name>
<url-pattern>/api/</url-pattern>
</servlet-mapping>
So I was able to access the service. But after adding another method to my resource:
#Path("upload")
public class UploadResource {
#Context
private UriInfo context;
public UploadResource() {
}
#GET
#Produces(MediaType.TEXT_PLAIN)
public String getText() {
return "test";
}
#PUT
#Consumes(MediaType.TEXT_PLAIN)
public void putText(String content) {
}
#POST
#Consumes(MediaType.MULTIPART_FORM_DATA)
#Path("fup")
public Response uploadFile(#FormDataParam("file") InputStream uploadInputStream, #FormDataParam("file") FormDataContentDisposition fileDetail)
{
return Response.status(Response.Status.OK).entity("as expected").build();
}
}
I always get this exception stack:
05-Jul-2017 09:35:23.059 SEVERE [http-nio-8084-exec-22] org.apache.catalina.core.ApplicationContext.log StandardWrapper.Throwable
java.lang.IllegalStateException: The resource configuration is not modifiable in this context.
at org.glassfish.jersey.server.ResourceConfig$ImmutableState.register(ResourceConfig.java:274)
at org.glassfish.jersey.server.ResourceConfig$ImmutableState.register(ResourceConfig.java:221)
at org.glassfish.jersey.server.ResourceConfig.register(ResourceConfig.java:453)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:387)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:177)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:369)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1231)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:837)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
05-Jul-2017 09:35:23.059 SEVERE [http-nio-8084-exec-22] org.apache.catalina.core.StandardWrapperValve.invoke Allocate exception for servlet ws.rest.RestConfig
java.lang.IllegalStateException: The resource configuration is not modifiable in this context.
at org.glassfish.jersey.server.ResourceConfig$ImmutableState.register(ResourceConfig.java:274)
at org.glassfish.jersey.server.ResourceConfig$ImmutableState.register(ResourceConfig.java:221)
at org.glassfish.jersey.server.ResourceConfig.register(ResourceConfig.java:453)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:387)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:177)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:369)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1231)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:837)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Is there something wrong in the configuration? I didn't find a good tutorial for setting up rest without Maven so I tried on my own with lots of search on the net, which quite helped but now I'm stuck. It also vexes me because I already tried the same in a Maven project where it worked without a problem.

Servlet error when changing JAR from compile to provided

I am currently trying to move a JAR from a deployed WAR to just being included in the Tomcat library. Here's the dependency in my pom.xml
<dependency>
<groupId>psft.pt8</groupId>
<artifactId>psjoa</artifactId>
<version>8.54.22</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
When scope is <scope>compile</scope> everything works fine. I build the artifact, deploy it in Tomcat, and can access the WSDL. When I change scope to provided, I can still build the artifact, deploy it in Tomcat, it LOOKS like it's fine, but then when attempting to go to the WSDL I reach this error.
The server encountered an internal error that prevented it from fulfilling this request: Servlet.init() for servlet spring-ws threw exception
javax.servlet.ServletException: Servlet.init() for servlet spring-ws threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
psiprobe.Tomcat80AgentValve.invoke(Tomcat80AgentValve.java:45)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:676)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:670)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)
Not sure where to begin.
Solution 1.
If you don't want including artifact psft.pt8:psjoa:8.54.22 inside WAR generated artifact
use <scope>provided</scope> in pom.xml
put psft.pt8:psjoa:8.54.22 JAR file inside $CATALINA_HOME\lib (on macOS, Linux) or %CATALINA_HOME%\lib (on Windows operating system).
Solution 2.
If you want including artifact psft.pt8:psjoa:8.54.22 inside WAR generated artifact, use <scope>compile</scope> in pom.xml.

HTTP Status 500 - Servlet.init() for servlet Jersey Web Application threw exception

index.html
<html>
<body>
<h2>Jersey RESTful Web Application!</h2>
<p>Jersey resource
<p>Visit the Project Jersey website
for more information on Jersey!
</body>
</html>
MyResource.java
#Path("/myresource")
public class MyResource {
/** Method processing HTTP GET requests, producing "text/plain" MIME media
* type.
* #return String that will be send back as a response of type "text/plain".
*/
#GET
#Produces("text/plain")
public String getIt() {
return "Hi there!";
}
}
Error is Comming
HTTP Status 500 - Servlet.init() for servlet Jersey Web Application threw exception
--------------------------------------------------------------------------------
type Exception report
message Servlet.init() for servlet Jersey Web Application threw exception
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Servlet.init() for servlet Jersey Web Application threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)
root cause
java.lang.NoSuchMethodError: com.sun.jersey.core.reflection.ReflectionHelper.getContextClassLoaderPA()Ljava/security/PrivilegedAction;
com.sun.jersey.spi.scanning.AnnotationScannerListener.<init>(AnnotationScannerListener.java:94)
com.sun.jersey.spi.scanning.PathProviderScannerListener.<init>(PathProviderScannerListener.java:59)
com.sun.jersey.api.core.ScanningResourceConfig.init(ScanningResourceConfig.java:79)
com.sun.jersey.api.core.PackagesResourceConfig.init(PackagesResourceConfig.java:104)
com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:78)
com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:89)
com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:696)
com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:674)
com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:205)
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:158)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.67 logs.
you would have use correct version if you want proper output latest version number is 1.19.1 use this try onee
May be problem with servelet api dependcy :
use this in your maven pom for exemple:
<!-- servlet api 3 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
Its seems a java version issue. compile the code with supporting jar(java version) only

Jersey errors after deploying to tomcat, works fine in Eclipse

I've lost hours trying to pinpoint this annoying issue. I've created a simple Java app that exposes a few REST services using Jersey.
When debugging the application in Eclipse, using a Tomcat 8 server, everything works fine. I then export the project to a WAR file, deploy it to a real Tomcat 8 server, and when I try to call the REST services, I get the below error. I've checked the obvious things: making sure I'm using the correct Java version on the server, making sure the libraries are included, ... But alas, I'm stuck.
type Exception report
message Servlet.init() for servlet Jersey REST Service threw exception
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Servlet.init() for servlet Jersey REST Service threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1521)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1478)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)
root cause
java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;
org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:309)
org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:338)
org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:171)
org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:363)
javax.servlet.GenericServlet.init(GenericServlet.java:158)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1521)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1478)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)
All important libraries for the project are added in the WEB-INF, which are the following:
aopalliance-repackaged-2.4.0-b10.jar
asm-debug-all-5.0.2.jar
commons-beanutils-1.9.2.jar
commons-collections-3.2.1.jar
commons-collections4-4.0.jar
commons-logging-1.2.jar
gson-2.3.1.jar
hk2-api-2.4.0-b10.jar
hk2-locator-2.4.0-b10.jar
hk2-utils-2.4.0-b10.jar
httpclient-4.4.1.jar
httpcore-4.4.1.jar
java-json.jar
javassist-3.18.1-GA.jar
javax.annotation-api-1.2.jar
javax.inject-2.4.0-b10.jar
javax.json-1.0.2.jar
javax.servlet-api-3.0.1.jar
javax.ws.rs-api-2.0.1.jar
jaxb-api-2.2.7.jar
jersey-client-1.7.jar
jersey-client.jar
jersey-common.jar
jersey-container-servlet-core.jar
jersey-container-servlet.jar
jersey-core-1.7.jar
jersey-guava-2.17.jar
jersey-json-1.7.jar
jersey-media-jaxb.jar
jersey-server.jar
joda-time-2.3.jar
log4j-1.2.17.jar
org.osgi.core-4.2.0.jar
org.restlet.ext.gson-2.3.1.jar
org.restlet.ext.json.jar
org.restlet.jar
osgi-resource-locator-1.0.1.jar
persistence-api-1.0.jar
unboundid-ldapsdk-se.jar
validation-api-1.1.0.Final.jar
I believe this is not because of missing jar.. I believe it is class loading issue. The jersey jars are not being loaded (or) might have been loaded the wrong version. Could you please check the dependencies properly and check for duplicate jars for jersey in your application.
Also Please try by undeploying appliation and deploying again.. This might remove all the classes that were already loaded for taht application and Tomcat might intialize class loading again..
Hope this works...

Exception while trying to use jersey and jaxb

The following code:
#POST
#Path("/previous-status/{current}")
#Consumes(MediaType.APPLICATION_XML)
#Produces(MediaType.TEXT_PLAIN)
public String getPreviousStepStatus(#PathParam("current") JAXBElement<WorkflowStep> step) {
WorkflowStep wfStep = step.getValue();
return DBAccessor.getPrevStepStatus(wfStep);
}
Produces the following exception:
javax.servlet.ServletException: Servlet.init() for servlet Jersey Rest Service threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:498)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:394)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
java.lang.Thread.run(Thread.java:662)
root cause
com.sun.jersey.spi.inject.Errors$ErrorMessagesException
com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)
com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)
com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:771)
com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:766)
com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:488)
com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:318)
com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:609)
com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373)
com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556)
javax.servlet.GenericServlet.init(GenericServlet.java:160)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:498)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:394)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
java.lang.Thread.run(Thread.java:662)
If it is commented I don't get the exception. The currently used libraries in the web application are:
asm-3.1.jar
jersey-core-1.11.jar
jersey-server-1.11.jar
jsr311-api-1.1.1.jar
jersey-servlet-1.11.jar
activation.jar (part of jaxb distribution)
jaxb-api.jar
jaxb-impl.jar
stax-api-1.0.1.jar
woodstox-core-asl-4.1.2.jar
The reason I have included the last 5 libraries in the list is this article from developer works
Furthermore from the tomcat start up log I see the following:
SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
SEVERE: Missing dependency for method public java.lang.String restful.SilverLine.getPreviousStepStatus(javax.xml.bind.JAXBElement) at parameter at index 0
SEVERE: Method, public java.lang.String restful.SilverLine.getPreviousStepStatus(javax.xml.bind.JAXBElement), annotated with POST of resource, class restful.SilverLine, is not recognized as valid resource method.
Any ideas will be appreciated?
PathParameter and entity is something different, try following:
#POST
#Path("/previous-status/{order}")
#Consumes(MediaType.APPLICATION_XML)
#Produces(MediaType.TEXT_PLAIN)
public String getPreviousStepStatus(#PathParam("order") int order, JAXBElement<WorkflowStep> step) {
...
WorkflowStep wfStep = step.getValue();
return DBAccessor.getPrevStepStatus(wfStep);
}
in this case, you can do requests like POST http://host/previous-status/10 and put whatever you want into entity.
You had xml in path param (which is part of URL), which is not possible to use. Your request would look like POST http://host/previous-status/<some-xml><foo>bar</foo></some-xml > , which is .. not good idea and not supported.
You should take a look at Jersey user guide: http://jersey.java.net/nonav/documentation/latest/ , topics like path param injection, accessing entity and working with XML are well covered there.

Categories

Resources