开发者

How to run a Rest WS?

开发者 https://www.devze.com 2023-03-18 19:04 出处:网络
I am getting the following error when i tried to run my Java REST WS on browser: HTTP Status 500 - type Exception report

I am getting the following error when i tried to run my Java REST WS on browser:

HTTP Status 500 -


type Exception report

message

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.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)  
   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)  
   org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)  
   org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)  
   org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)  
jav开发者_开发问答a.lang.Thread.run(Unknown Source)  

root cause

com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.  
com.sun.jersey.server.impl.application.RootResourceUriRules.<init>(RootResourceUriRules.java:99)  
com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1298)  
com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:169)  
com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:775)  
com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:771)  
com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
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:212)  
   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)  
   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)  
   org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)  
   org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)  
   org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)  
java.lang.Thread.run(Unknown Source)  

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.


Apache Tomcat/6.0.20

Let me please know what is the problem?

Do i have to create any servlet for the same??

My java class is as follows:

import javax.ws.rs.GET;  
import javax.ws.rs.Path;  
import javax.ws.rs.Produces;  
import javax.ws.rs.core.MediaType;  


//POJO, no interface no extends  

//The class registers its methods for the HTTP GET request using the @GET annotation.   
//Using the @Produces annotation, it defines that it can deliver several MIME types,  
//text, XML and HTML.   

//The browser requests per default the HTML MIME type.  

//Sets the path to base URL + /hello  
@Path("/hello")  

public class Welcome {  
    // This method is called if TEXT_PLAIN is request  
    @GET  
    @Produces(MediaType.TEXT_PLAIN)  
    public String sayPlainTextHello() {  
        return "Hello Jersey";  
    }  

    // This method is called if XML is request  
    @GET  
    @Produces(MediaType.TEXT_XML)  
    public String sayXMLHello() {  
        return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>";  
     }  

    // This method is called if HTML is request  
    @GET  
    @Produces(MediaType.TEXT_HTML)  
    public String sayHtmlHello() {  
        return "<html> " + "<title>" + "Hello Jersey" + "</title>"  
            + "<body><h1>" + "Hello Jersey" + "</body></h1>"   + "</html> ";  
    }  

 }

and web.xml :

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">

Hello

index.html

Jersey REST Service

com.sun.jersey.spi.container.servlet.ServletContainer

<init-param>  
  <param-name>com.sun.jersey.config.property.packages</param-name>  
  <param-value>Hello</param-value>  
</init-param>  

<load-on-startup>1</load-on-startup>  

Jersey REST Service

/rest/*


I made the following change in my web.xml and the problem got resolved:

 <init-param>  
      <param-name>com.sun.jersey.config.property.packages</param-name>  
      <param-value>**myPkgName**</param-value>  
    </init-param>  

Regards,
Sneha

0

精彩评论

暂无评论...
验证码 换一张
取 消