java - error404 accessing Restful web service using jersey framework and tomcat server -
am facing problem accessing restful web service via url: localhost:8080/primnumbers/generator/strategy
i got error:
http status 404 - /primnumbers/generator/strategy
type status report
message /primnumbers/generator/strategy
description requested resource not available.
am using tomcat7.0.81 server , jersey1.17 framework (i have included jersey jar file under web-inf/lib in project). here web.xml file:
<?xml version="1.0" encoding="utf-8"?> <element> <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" version="3.0"> <display-name>primnumbers</display-name> <servlet> <servlet-name>jersey restful application</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.servletcontainer</servlet-class> <init-param> <param-name> jersey.config.server.provider.packages</param-name> <param-value>primenbs</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>jersey restful application</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> </web-app> </element
>
and service.java(am testing service):
package primenbs; import javax.ws.rs.path; import javax.ws.rs.get; import javax.ws.rs.produces; import javax.ws.rs.core.mediatype; //annotations @path("/generator") public class primenbsgeneratorservice { @get @path("/strategy") @produces(mediatype.text_html) public string strategy1(){ boolean prime=true; string rslt="<html><h1> prime numbers: "; return(rslt+" test...</h1></html>"); } }
while running server got these log msgs:
> ug 22, 2017 11:22:44 org.apache.tomcat.util.digester.setpropertiesrule begin warning: [setpropertiesrule]{server/service/engine/host/context} setting property 'source' 'org.eclipse.jst.jee.server:primnumbers' did not find matching property. aug 22, 2017 11:22:44 org.apache.catalina.startup.versionloggerlistener log info: server version: apache tomcat/7.0.81 aug 22, 2017 11:22:44 org.apache.catalina.startup.versionloggerlistener log info: server built: aug 11 2017 10:21:27 utc aug 22, 2017 11:22:44 org.apache.catalina.startup.versionloggerlistener log info: server number: 7.0.81.0 aug 22, 2017 11:22:44 org.apache.catalina.startup.versionloggerlistener log info: os name: linux aug 22, 2017 11:22:44 org.apache.catalina.startup.versionloggerlistener log info: os version: 4.4.0-21-generic aug 22, 2017 11:22:44 org.apache.catalina.startup.versionloggerlistener log info: architecture: amd64 aug 22, 2017 11:22:44 org.apache.catalina.startup.versionloggerlistener log info: java home: /home/elhem/java/jre1.8.0_121 aug 22, 2017 11:22:44 org.apache.catalina.startup.versionloggerlistener log info: jvm version: 1.8.0_121-b13 aug 22, 2017 11:22:44 org.apache.catalina.startup.versionloggerlistener log info: jvm vendor: oracle corporation aug 22, 2017 11:22:44 org.apache.catalina.startup.versionloggerlistener log info: catalina_base: /home/elhem/workspace/tomcat aug 22, 2017 11:22:44 org.apache.catalina.startup.versionloggerlistener log info: catalina_home: /home/elhem/workspace/tomcat aug 22, 2017 11:22:44 org.apache.catalina.startup.versionloggerlistener log info: command line argument: -dcatalina.base=/home/elhem/workspace/tomcat aug 22, 2017 11:22:44 org.apache.catalina.startup.versionloggerlistener log info: command line argument: -dcatalina.home=/home/elhem/workspace/tomcat aug 22, 2017 11:22:44 org.apache.catalina.startup.versionloggerlistener log info: command line argument: -dwtp.deploy=/home/elhem/workspace/tomcat/wtpwebapps aug 22, 2017 11:22:44 org.apache.catalina.startup.versionloggerlistener log info: command line argument: -djava.endorsed.dirs=/home/elhem/workspace/tomcat/endorsed aug 22, 2017 11:22:44 org.apache.catalina.startup.versionloggerlistener log info: command line argument: -dfile.encoding=utf-8 aug 22, 2017 11:22:44 org.apache.catalina.core.aprlifecyclelistener lifecycleevent info: apr based apache tomcat native library allows optimal performance in production environments not found on java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib aug 22, 2017 11:22:45 org.apache.coyote.abstractprotocol init info: initializing protocolhandler ["http-bio-8080"] aug 22, 2017 11:22:45 org.apache.coyote.abstractprotocol init info: initializing protocolhandler ["ajp-bio-8009"] aug 22, 2017 11:22:45 org.apache.catalina.startup.catalina load info: initialization processed in 865 ms aug 22, 2017 11:22:45 org.apache.catalina.core.standardservice startinternal info: starting service catalina aug 22, 2017 11:22:45 org.apache.catalina.core.standardengine startinternal info: starting servlet engine: apache tomcat/7.0.81 aug 22, 2017 11:22:45 org.apache.catalina.startup.tldconfig execute info: @ least 1 jar scanned tlds yet contained no tlds. enable debug logging logger complete list of jars scanned no tlds found in them. skipping unneeded jars during scanning can improve startup time , jsp compilation time. aug 22, 2017 11:22:45 org.apache.catalina.startup.hostconfig deploydirectory info: deploying web application directory /home/elhem/workspace/tomcat/webapps/host-manager aug 22, 2017 11:22:45 org.apache.catalina.startup.hostconfig deploydirectory info: deployment of web application directory /home/elhem/workspace/tomcat/webapps/host-manager has finished in 74 ms aug 22, 2017 11:22:46 org.apache.catalina.startup.hostconfig deploydirectory info: deploying web application directory /home/elhem/workspace/tomcat/webapps/manager aug 22, 2017 11:22:46 org.apache.catalina.startup.hostconfig deploydirectory info: deployment of web application directory /home/elhem/workspace/tomcat/webapps/manager has finished in 67 ms aug 22, 2017 11:22:46 org.apache.catalina.startup.hostconfig deploydirectory info: deploying web application directory /home/elhem/workspace/tomcat/webapps/root aug 22, 2017 11:22:46 org.apache.catalina.startup.hostconfig deploydirectory info: deployment of web application directory /home/elhem/workspace/tomcat/webapps/root has finished in 61 ms aug 22, 2017 11:22:46 org.apache.catalina.startup.hostconfig deploydirectory info: deploying web application directory /home/elhem/workspace/tomcat/webapps/docs aug 22, 2017 11:22:46 org.apache.catalina.startup.hostconfig deploydirectory info: deployment of web application directory /home/elhem/workspace/tomcat/webapps/docs has finished in 60 ms aug 22, 2017 11:22:46 org.apache.catalina.startup.hostconfig deploydirectory info: deploying web application directory /home/elhem/workspace/tomcat/webapps/examples aug 22, 2017 11:22:46 org.apache.catalina.core.applicationcontext log info: contextlistener: contextinitialized() aug 22, 2017 11:22:46 org.apache.catalina.core.applicationcontext log info: sessionlistener: contextinitialized() aug 22, 2017 11:22:46 org.apache.catalina.core.applicationcontext log info: contextlistener: attributeadded('org.apache.jasper.compiler.tldlocationscache', 'org.apache.jasper.compiler.tldlocationscache@51542878') aug 22, 2017 11:22:46 org.apache.catalina.startup.hostconfig deploydirectory info: deployment of web application directory /home/elhem/workspace/tomcat/webapps/examples has finished in 231 ms aug 22, 2017 11:22:46 org.apache.coyote.abstractprotocol start info: starting protocolhandler ["http-bio-8080"] aug 22, 2017 11:22:46 org.apache.coyote.abstractprotocol start info: starting protocolhandler ["ajp-bio-8009"] aug 22, 2017 11:22:46 org.apache.catalina.startup.catalina start info: server startup in 1397 ms
can help! appreciating.
you have problem web.xml.
you create servlet name jersey restful application
, mapping servlet name primnumbers
. servler primnumbers
not exists.
so need make servletand servlet-mapping use same name.
like this:
<servlet> <servlet-name>jersey restful application</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.servletcontainer</servlet-class> <init-param> <param-name> jersey.config.server.provider.packages</param-name> <param-value>primenbs</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>jersey restful application</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping>
wiki
Comments
Post a Comment