I have a very simple Resource class that looks like below
package service;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
#Path("names")
public class NameService {
#Produces(MediaType.APPLICATION_XML)
#Path("name")
#GET
public String getName(#QueryParam(value="id")int id){
return "Nishanth";
}
}
I defined a custom application class ( extending ResourceConfig) to encapsulate this Resource class.
package application;
import javax.ws.rs.ApplicationPath;
import org.glassfish.jersey.server.ResourceConfig;
public class MyApp extends ResourceConfig{
public MyApp()
{
packages("service");
}
}
My web.xml looks like below. This is a servlet 3.0 web application in Eclipse meant to be deployed on Tomcat 7
<?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>RESTapp</display-name>
<servlet>
<servlet-name>application.MyApp</servlet-name>
</servlet>
<servlet-mapping>
<servlet-name>application.MyApp</servlet-name>
<url-pattern>/res/*</url-pattern>
</servlet-mapping>
</web-app>
My lib has the below jars added to application classpath.
I deploy the above application directly through Eclipse into a Tomcat 7.0 servlet container. I access the below URL
http://localhost:8080/RESTapp/res/names/name?id=2
and the browser shows the error below with response status 500
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
java.util.concurrent.ConcurrentHashMap.putVal(Unknown Source)
java.util.concurrent.ConcurrentHashMap.putIfAbsent(Unknown Source)
java.lang.ClassLoader.getClassLoadingLock(Unknown Source)
java.lang.ClassLoader.loadClass(Unknown Source)
java.lang.ClassLoader.loadClass(Unknown Source)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1641)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Unknown Source)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.54 logs.
I know that the above error is thrown when the container is not able to find a servlet-class. I could be wrong.
Not sure what is going wrong here since as per Jersey API docs, Jersey container should add the servlet class when deployed this way in a Servlet 3.0 container.
I checked all over stack overflow and other forum posts but i could not find anything close to the issue i am facing now.
Any help is greatly appreciated.
Related
I am beginner to working with servlet.I am creating a servlet and but after running that i am getting error
Can anyone help me to resolve this.
Error
Type Exception Report
Message Class [com.practice.MyServlet] is not a Servlet
Description The server encountered an unexpected condition that
prevented it from fulfilling the request.
Exception
jakarta.servlet.ServletException: Class [com.practice.MyServlet] is
not a Servlet
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:682)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:332)
org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:859)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1568)
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:748) Root Cause
java.lang.ClassCastException: com.practice.MyServlet cannot be cast to
jakarta.servlet.Servlet
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:682)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:332)
org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:859)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1568)
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:748) Note The full stack trace of
the root cause is available in the server logs.
Click here to see the Project directory
MyServlet.java
package com.practice;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;
/**
*
* #author admin
*/
public class MyServlet extends HttpServlet {
#Override
public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException
{
PrintWriter out=response.getWriter();
response.setContentType("test/html");
out.print("<h1>This is get method of my servlet</h1>");
}
}
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>myservlet</servlet-name>
<servlet-class>com.practice.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>myservlet</servlet-name>
<url-pattern>/myservlet</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
You're basically physically including Tomcat 9.x (Servlet 4.0) specific JAR file in WAR and then writing/compiling code against Tomcat 9.x (Servlet 4.0) or older and then then deploying the WAR to Tomcat 10.x (Servlet 5.0) or newer. This is not the correct approach at all.
Since Tomcat 10.x (Servlet 5.0) the javax.* package has been renamed to jakarta.* package.
In other words, please make sure that you don't randomly put JAR files of a different server in your WAR such as tomcat-servlet-api-9.0.4.jar. This will only cause trouble. Remove it altogether and edit the imports of your servlet class from
import javax.servlet.*;
import javax.servlet.http.*;
to
import jakarta.servlet.*;
import jakarta.servlet.http.*;
While at it, please also make sure that the root element of the web.xml is declared conform the Servlet API version of the target server, which is in case of Tomcat 10.x thus Servlet 5.0 (and thus not Servlet 3.1 which basically matches Tomcat 8.0).
<web-app
xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"
version="5.0"
>
<!-- Config here. -->
</web-app>
See also:
Tomcat versions
Tomcat 9 casting servlets to javax.servlet.Servlet instead of jakarta.servlet.http.HttpServlet
I am making a simple RESTful API to my application. I've made another package in my project (other from one where is my main java class, servlet, and model). And then I've made my resource file, very simple which looks like this:
package com.java.api;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
#Path("webservice")
public class ZipcodeService {
#GET
#Path("/lookup")
public Response lookup() {
return Response.ok().entity("Los Angeles").build();
}
}
and this is my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" id="WebApp_ID"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<display-name>parking-space-booking-system</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<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.java.api</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/webservice/*</url-pattern>
</servlet-mapping>
</web-app>
I am not using Maven. I am using Netbeans IDE and Tomcat server. I uploaded Jersey 2.25 all jar files to WEB-INF/lib folder. I am experimenting with web.xml to fix it but I have no more ideas. Here is the structure of my project:
Here is also my error message I got:
HTTP Status 500 - Servlet.init() for servlet Jersey Web Application threw exception
type Exception report
message Servlet.init() for servlet Jersey Web Application threw an 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:518)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:748)
root cause
java.lang.NoSuchMethodError: org.glassfish.jersey.CommonProperties.getValue(Ljava/util/Map;Ljavax/ws/rs/RuntimeType;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
org.glassfish.jersey.jackson.JacksonFeature.configure(JacksonFeature.java:69)
org.glassfish.jersey.model.internal.CommonConfig.configureFeatures(CommonConfig.java:674)
org.glassfish.jersey.model.internal.CommonConfig.configureMetaProviders(CommonConfig.java:610)
org.glassfish.jersey.server.ResourceConfig.configureMetaProviders(ResourceConfig.java:800)
org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:367)
org.glassfish.jersey.server.ApplicationHandler.access$500(ApplicationHandler.java:162)
org.glassfish.jersey.server.ApplicationHandler$3.run(ApplicationHandler.java:304)
org.glassfish.jersey.internal.Errors$2.call(Errors.java:289)
org.glassfish.jersey.internal.Errors$2.call(Errors.java:286)
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:286)
org.glassfish.jersey.server.ApplicationHandler.(ApplicationHandler.java:301)
org.glassfish.jersey.servlet.WebComponent.(WebComponent.java:311)
org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:169)
org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:359)
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:518)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:748)
note The full stack trace of the root cause is available in the Apache Tomcat/8.0.27 logs.
Apache Tomcat/8.0.27
Perhaps you have problems with your libraries.
root cause
java.lang.NoSuchMethodError: org.glassfish.jersey.CommonProperties.getValue(..
by the server initialisation shows that you forgot to add some library (perhaps it's not in your Jersey 2.25, check for it). Your can also try to use another version of Jersey.
You need to look in (and post) your Tomcat logs. Look at catalina.out. It looks to me like your web.xml doesn't have a closing web-app tag, but that might just be because you didn't post the full web.xml.
Also, you need to package your application as a WAR file. Tomcat expects your web application WAR file to be located under the webapps directory.
edit:
the method wasn't found, therefore the appropriate JAR isn't actually on the classpath (lib folder).
org.glassfish.jersey.CommonProperties.getValue
This question already has answers here:
Servlet returns "HTTP Status 404 The requested resource (/servlet) is not available"
(19 answers)
Closed 6 years ago.
I am trying to execute a servlet program in eclipse, but i am getting an HTTP status 500 error.
Please find my directory structure:
Practice_servlet
|
Java Resources
|
src
|
javs.reg.pkg
|
Hello.java
My web.xml is:
<?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_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>Practice1_servlet</display-name>
<welcome-file-list>
<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>Hello1</servlet-name>
<servlet-class>java.reg.pkg.Hello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Hello1</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
</web-app>
My hello.java program is:
package java.reg.pkg;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class Hello
*/
public class Hello extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* #see HttpServlet#HttpServlet()
*/
public Hello() {
super();
// TODO Auto-generated constructor stub
}
/**
* #see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("type/html");
PrintWriter out = response.getWriter();
out.println("Hello World");
// TODO Auto-generated method stub
}
}
Any idea of what the problem could be ?
Stack trace for the above program:
HTTP Status 500 - Error instantiating servlet class java.reg.pkg.Hello
type Exception report
message Error instantiating servlet class java.reg.pkg.Hello
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Error instantiating servlet class
java.reg.pkg.Hello
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
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(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)
root cause
java.lang.ClassNotFoundException: java.reg.pkg.Hello
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1718)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1569)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
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(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.52 logs.
I am using Apache Tomcat/7.0.52.
Try cleaning the project and run. If you are using eclipse Project -> Clean
I think there is a wrong name there. Your servlet is called Hello and is in java.reg.pkg, while the stack trace says it is instructed to load a servlet called SampleHello within the java.sample.pkg package.
The web.xml you provided has no trace of the latter servlet, hence the ClassNotFoundException error...
I have an error trying to run simple JAX-RS example.
I'am using jaxrs-ri-2.4.1, and Jetty embedded server with "Run Jetty" plugin for eclipse.
Thank you.
web.xml
<servlet>
<servlet-name>restServlet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>path_to_class.FormsRestService</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>restServlet</servlet-name>
<url-pattern>/rest/</url-pattern>
</servlet-mapping>
FormsRestService.java
package path_to_class;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
#Path("/")
public class FormsRestService {
#GET
#Produces(MediaType.TEXT_PLAIN)
public String getStringHello(){
return "Hello Jersey!";
}
}
And exception briefly (or full text here http://pastebin.com/fFMb7Y2a)
Caused by:
java.lang.NoClassDefFoundError: org/glassfish/jersey/server/ContainerException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at org.mortbay.jetty.servlet.Holder.newInstance(Holder.java:153)
at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:428)
......
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
I'moved to jetty 7, now I have such exception: pastebin.com/ZdRXzeED
jaxrs-ri-2.4.1 expects that you run on Glassfish.
Look at this old question (and both answers) for some help.
Integrating Jetty with JAX-RS-Jersey
I am trying to create a hello example REST service and I am running into the following error:
SEVERE: Allocate exception for servlet jersey-serlvet
com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.
at com.sun.jersey.server.impl.application.RootResourceUriRules.<init>(RootResourceUriRules.java:99)
at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1298)
at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:169)
at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:775)
at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:771)
at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:771)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:766)
at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:488)
at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:318)
at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:609)
at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:373)
at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:556)
at javax.servlet.GenericServlet.init(GenericServlet.java:160)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1266)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1185)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:857)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
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:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
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:999)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
I looked into all related posts and also on other blogs/forums but couldnt resolve the issue.
Below is my servlet:
package com.mkyong.rest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
#Path("/hello")
public class HelloWorldService {
#GET
#Path("/{param}")
public Response getMsg(#PathParam("param") String msg) {
String output = "Jersey say : " + msg;
return Response.status(200).entity(output).build();
}
}
The web.xml file:
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
Restful Web Application
<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 the project structure:
I get the error when I try to access the url: http://localhost:8090/RESTfulExample/rest/hello/test
I ve been trying for hours to resolve the problem but without any luck. Does anyone see an error in my project?
Thank you
I had the same issue; in Eclipse try [Project > Clean ...] and restart the server.
Code seems to be fine.. Do not prefer tomcat in eclipse.. Deploy the project to WEB-APPS in tomcat installation folder & try. I am able to see the o/p for this project..
Have fun in solving these kind of issues....