Newbie in trying to set up a REST service in Java. I created a simple java program and deployed the war file in apache-tomcat-8.5.5 (under the apache-tomcat-8.5.5\webapps dir). But when I try to access the REST service (http://localhost:8081/SampleRS/rest/sampproj/uservalue), get a 404 error. (Starting the tomcat on port 8081 {Had wanted to do a POST - using Postman,but was getting error, then added a GET method to verify, but still got error)
The Java file:
package sampproj;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.PathParam;
@Path("sampproj")
public class WSPostSer {
public WSPostSer() {
super();
}
@POST
@Consumes("application/json")
@Path("devpost")
public String createTemp (String devName){
System.out.println (" in reate");
return "heloo" + devName;
}
@GET
@Produces("text/plain")
@Path("/uservalue")
public String welcomeResource (@PathParam("uservalue") String username){
System.out.println(" welcomeResource ");
return "heloo Get " + username;
}
}
The 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_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>SampleRS</display-name>
<servlet>
<servlet-name>Jersey RESTful 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>sampproj</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Jersey RESTful Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
The lib (jars) that are:
Log file localhost_access_log.2016-09-10: 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:16:56 +0530] "POST /SampleRS/rest/sampproj/devpost HTTP/1.1" 404 1052 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:18:46 +0530] "POST /SampleRS/rest/sampproj/devpost HTTP/1.1" 404 1052 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:24:57 +0530] "GET /SampleRS/rest/sampproj/uservalue HTTP/1.1" 404 1056 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:25:04 +0530] "GET /SampleRS/rest/sampproj/hell HTTP/1.1" 404 1046 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:29:25 +0530] "GET / HTTP/1.1" 200 11450 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:29:26 +0530] "GET /tomcat.css HTTP/1.1" 200 5926 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:29:26 +0530] "GET /tomcat.png HTTP/1.1" 200 5103 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:29:26 +0530] "GET /favicon.ico HTTP/1.1" 200 21630 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:29:27 +0530] "GET /bg-nav.png HTTP/1.1" 200 1401 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:29:27 +0530] "GET /asf-logo.png HTTP/1.1" 200 17811 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:29:27 +0530] "GET /bg-upper.png HTTP/1.1" 200 3103 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:29:27 +0530] "GET /bg-button.png HTTP/1.1" 200 713 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:29:27 +0530] "GET /bg-middle.png HTTP/1.1" 200 1918 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:29:42 +0530] "GET /SampleRS HTTP/1.1" 404 1008 0:0:0:0:0:0:0:1 - - [10/Sep/2016:08:30:02 +0530] "GET /SampleRS HTTP/1.1" 404 1008 0:0:0:0:0:0:0:1 - - [10/Sep/2016:15:49:20 +0530] "GET /SampleRS/rest/sampproj/uservalue HTTP/1.1" 404 1056 0:0:0:0:0:0:0:1 - - [10/Sep/2016:15:49:20 +0530] "GET /favicon.ico HTTP/1.1" 200 21630 0:0:0:0:0:0:0:1 - - [10/Sep/2016:16:07:42 +0530] "GET /SampleRS/rest/sampproj/uservalue/df HTTP/1.1" 404 1062 0:0:0:0:0:0:0:1 - - [10/Sep/2016:16:07:49 +0530] "GET /SampleRS/rest/sampproj/uservalue=df HTTP/1.1" 404 1062 0:0:0:0:0:0:0:1 - - [10/Sep/2016:16:22:41 +0530] "GET /SampleRS/rest/sampproj/user HTTP/1.1" 404 1046 0:0:0:0:0:0:0:1 - - [10/Sep/2016:17:40:07 +0530] "GET /SampleRS/rest/sampproj/uservalue/me HTTP/1.1" 404 1062 0:0:0:0:0:0:0:1 - - [10/Sep/2016:17:43:08 +0530] "GET /SampleRS/rest/sampproj/uservalue/me HTTP/1.1" 404 1062 0:0:0:0:0:0:0:1 - - [10/Sep/2016:18:04:23 +0530] "GET /SampleRS/rest/sampproj/uservalue/me HTTP/1.1" 404 1062 0:0:0:0:0:0:0:1 - - [10/Sep/2016:18:04:31 +0530] "GET /WSwebapp/SampleRS/rest/sampproj/uservalue/me HTTP/1.1" 404 1080 0:0:0:0:0:0:0:1 - - [10/Sep/2016:18:04:40 +0530] "GET /WSwebapp/rest/sampproj/uservalue/me HTTP/1.1" 404 1008 0:0:0:0:0:0:0:1 - - [10/Sep/2016:18:09:10 +0530] "GET /WSwebapp/rest/sampproj/uservalue/me HTTP/1.1" 404 1008 0:0:0:0:0:0:0:1 - - [10/Sep/2016:18:20:25 +0530] "GET /WSwebapp/rest/sampproj/uservalue/me HTTP/1.1" 404 1008 0:0:0:0:0:0:0:1 - - [10/Sep/2016:18:21:04 +0530] "GET /WSwebapp/rest/sampproj/uservalue/me HTTP/1.1" 404 1008
catalina.2016-09-10: 10-Sep-2016 17:45:33.158 INFO [localhost-startStop-2] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive C:\apache-tomcat-8.5.5\webapps\WSwebapp.war has finished in 2,632 ms 10-Sep-2016 17:45:33.235 INFO [Thread-5] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-nio-8081"] 10-Sep-2016 17:45:33.248 INFO [Thread-5] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["ajp-nio-8009"] 10-Sep-2016 17:45:33.259 INFO [Thread-5] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["http-nio-8081"] 10-Sep-2016 17:45:33.267 INFO [Thread-5] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["ajp-nio-8009"] 10-Sep-2016 17:57:11.249 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.5.5 10-Sep-2016 17:57:11.253 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:
Aug 31 2016 19:51:16 UTC 10-Sep-2016 17:57:11.253 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:
8.5.5.0 10-Sep-2016 17:57:11.254 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:
Windows 7 10-Sep-2016 17:57:11.254 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:
6.1 10-Sep-2016 17:57:11.255 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:
amd64 10-Sep-2016 17:57:11.255 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:
C:\Program Files\Java\jdk1.8.0_91\jre 10-Sep-2016 17:57:11.256 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_91-b15 10-Sep-2016 17:57:11.256 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:
Oracle Corporation 10-Sep-2016 17:57:11.256 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:
C:\apache-tomcat-8.5.5 10-Sep-2016 17:57:11.257 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:
C:\apache-tomcat-8.5.5 10-Sep-2016 17:57:11.260 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048 10-Sep-2016 17:57:11.262 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=C:\apache-tomcat-8.5.5\conf\logging.properties 10-Sep-2016 17:57:11.264 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager 10-Sep-2016 17:57:11.268 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=C:\apache-tomcat-8.5.5 10-Sep-2016 17:57:11.273 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=C:\apache-tomcat-8.5.5 10-Sep-2016 17:57:11.278 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=C:\apache-tomcat-8.5.5\temp 10-Sep-2016 17:57:11.283 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.8.0_91\bin;C:\windows\Sun\Java\bin;C:\windows\system32;C:\windows;C:\oraclexe\app\oracle\product\11.2.0\server\bin;;C:\Program Files\Broadcom\Broadcom 802.11;;;C:\ProgramData\Oracle\Java\javapath;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\syswow64;C:\Program Files\Java\jdk1.8.0_91\bin;. 10-Sep-2016 17:57:11.634 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8081"] 10-Sep-2016 17:57:11.950 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read 10-Sep-2016 17:57:11.957 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"] 10-Sep-2016 17:57:11.983 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read 10-Sep-2016 17:57:11.985 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 1694 ms 10-Sep-2016 17:57:12.061 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina 10-Sep-2016 17:57:12.065 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.5 10-Sep-2016 17:57:12.135 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive C:\apache-tomcat-8.5.5\webapps\WSwebapp.war 10-Sep-2016 17:57:15.713 INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 10-Sep-2016 17:57:16.210 INFO [localhost-startStop-1] org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [305] milliseconds. 10-Sep-2016 17:57:16.264 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive C:\apache-tomcat-8.5.5\webapps\WSwebapp.war has finished in 4,128 ms 10-Sep-2016 17:57:16.267 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\apache-tomcat-8.5.5\webapps\docs 10-Sep-2016 17:57:16.324 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory C:\apache-tomcat-8.5.5\webapps\docs has finished in 58 ms 10-Sep-2016 17:57:16.325 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\apache-tomcat-8.5.5\webapps\examples 10-Sep-2016 17:57:17.600 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory C:\apache-tomcat-8.5.5\webapps\examples has finished in 1,275 ms 10-Sep-2016 17:57:17.601 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\apache-tomcat-8.5.5\webapps\host-manager 10-Sep-2016 17:57:17.687 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory C:\apache-tomcat-8.5.5\webapps\host-manager has finished in 86 ms 10-Sep-2016 17:57:17.688 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\apache-tomcat-8.5.5\webapps\manager 10-Sep-2016 17:57:17.761 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory C:\apache-tomcat-8.5.5\webapps\manager has finished in 74 ms 10-Sep-2016 17:57:17.762 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\apache-tomcat-8.5.5\webapps\ROOT 10-Sep-2016 17:57:20.655 INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 10-Sep-2016 17:57:20.766 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory C:\apache-tomcat-8.5.5\webapps\ROOT has finished in 3,004 ms 10-Sep-2016 17:57:20.777 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [http-nio-8081] 10-Sep-2016 17:57:20.828 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler [ajp-nio-8009] 10-Sep-2016 17:57:20.864 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 8874 ms
@Path("/sampproj")
, i.e. you should add a forward slash – Ori Dar@PathParam("uservalue")
, change@Path("/uservalue")
to@Path("/uservalue/${uservalue}")
and invoke URL like this: localhost:8081/SampleRS/rest/sampproj/uservalue/me. Assuming the context is indeedSampleRS
. – Ori DarWSwebapp
dir underwebapps
, the URL should indeed belocalhost:8081/WSwebapp/rest/sampproj/uservalue/me
. Without any further info such as logs, it's hard to say what's going on wrong. – Ori Dar