Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Rest API - 404 not found

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

This is my first REST Api in java for which I followed the tutorial on youtube: (https://www.youtube.com/watch?v=5jQSat1cKMo) exactly. However I cannot get the url to work in eclipse and get the following error message: (see attached image also)

HTTP Status 404 – Not Found
Type Status Report
Message Not Found
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Apache Tomcat/8.5.13

I have uploaded my src and web xml files.

Can you help me discover what I am doing incorrectly.

Things I have tried already using google blogs:
- checked tomcat server is running independently - yes this is ok as it displays the tomcat home page when I enter the url: http://localhost:8080
- changed the url to many variations i.e.
http://localhost:8080/JavaAPI/rest/hello
http://localhost:8080/rest/hello
http://localhost:8080/JavaAPI/test/rest/hello
...etc none have worked.

Any help in this matter is appreciated.

Kind Regards

Sakir


"
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
 <display-name>JavaAPI</display-name>
 <servlet>
   <servlet-name>JavaAPI</servlet-name>
   <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
   <init-param>
     <param-name>jersey.config.server.provider.packages</param-name>
     <param-value>test</param-value>
   </init-param>
   <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
   <servlet-name>JavaAPI</servlet-name>
   <url-pattern>/rest/*</url-pattern>
 </servlet-mapping>
</web-app>

"

"
package test;

//import java.awt.PageAttributes.MediaType;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;



@Path("/hello")
//@ApplicationPath("hello")
public class Hello extends Application {
@GET
@Produces(MediaType.TEXT_XML)
public String sayHello(){
String resource = "<? xml version='1.0' ?>" +
   "<hello> Hi Shakir, This is is Hello from XML</hello>";
return resource;
}

@GET
@Produces(MediaType.APPLICATION_JSON)
public String sayHelloJason(){
String resource = null;
return resource;
}

@GET
@Produces(MediaType.TEXT_HTML)
public String sayHelloHTML(){
String resource = "<h1> Hi Shakir, This is is Hello from HTML</h>";;
return resource;
}


}

"
Screenshot-2020-09-14-102804.png
[Thumbnail for Screenshot-2020-09-14-102804.png]
 
Master Rancher
Posts: 4710
49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How did you deploy the web app onto Tomvcat?
What is the directory structure under the tomcat webapps directory?
 
sakir syed
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dave,

Thank for replying to my post...

I followed the tutorial which specifies that the service can be run by 'Run on server' in Eclipse. I did not deply anything to the tomcat webapps directory. Attached you will find the tomcat directory structure image. Let me know how to proceed.

Kind regards

Sakir
Screenshot-2020-09-14-112048.png
[Thumbnail for Screenshot-2020-09-14-112048.png]
 
Dave Tolls
Master Rancher
Posts: 4710
49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, looks to me like that's not deployed anything to that tomcat server.

I don't rely on an IDE to do any deployments, as I have always found them to be a little flaky.
So I can't help with that.
If you want to run it up outside of Eclipse then you need to place a WAR file into the webapps directory.
 
Saloon Keeper
Posts: 22679
153
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eclipse is not a webapp server. To serve webapps you have to install a separate webapp server, construct an actual web application in WAR format, and deploy the WAR to the webapp server. Eclipse can control webapp servers and provide debugging, but it doesn't actually run the webapps themselves.

Historically, there have been 2 ways of running webapps in Eclipse. One came with the JEE spin of Eclipse and it was abominable. The other was a third-party plugin most recently known as "mongrel", although I haven't looked lately. I preferred mongrel because it allowed a cleaner mode of operation. The JEE builtin did rather horrible things to the WAR when it deployed.

Regardless, the key in either case is that your application be properly structured and properly made known to Tomcat, since Tomcat does the actual deployment regardless. The simplest and most popular way to publiish a webapp to Tomcat is to simply copy a WAR file into the TOMCAT_HOME/webapps directory.
 
sakir syed
Greenhorn
Posts: 9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,

Thanks for your help. I deployed to the webapps folder for Tomcat having changed the webxml to correct the url, and it worked I got my first resource message. I will continue with the example.

thanks to Dave as well.


Kind Regards

Sakir

 
Can you hear that? That's my theme music. I don't know where it comes from. Check under this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic