• Post Reply Bookmark Topic Watch Topic
  • New Topic

My Webservice doesnt work.Any advice its urgent for my school project.

 
dylan payne
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys.I will create webservice for my application project.But firstly I need to know its working or not, so I applied basic webservice.But when I run it.I get http 404 error page.

Here my what I did on webservice.

server --> Tomcat 8
dynamic project name-->project name is MovieWebService
WEB-INF/lib--> uploaded all jersey files
Built package and java class into the src file
and I set the xml file

those are my basic codes.I want to see hello word on tomcat What is my fault, anyone can help me? By the way sorry my language.

web.xml file=

<?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>MovieWebService</display-name>
<servlet>
<servlet-name>MovieWebService REST Service</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>sample.movie.webservices</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MovieWebService REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>



MovieWebService.java=

package sample.movie.webservices;

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

@Path("/hello")
public class movieWebService {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayHello() {
return "Hello Jersey";
}
}

 
Tim Moores
Saloon Keeper
Posts: 3263
54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which URL are you trying to access?
 
dylan payne
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:Which URL are you trying to access?


here my path =

http://localhost:8080/MovieWebService/WEB-INF/classes/sample/movie/webservices/movieWebService.java
 
Tim Moores
Saloon Keeper
Posts: 3263
54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing inside of WEB-INF will ever be served, so the 404 is to be expected.

The WS URL should be something like http://localhost:8080/MovieWebService/rest/hello

As an aside, don't keep source files inside of your webapps folder - it's all too easy to undeploy a web app and have it thereby deleted.
 
dylan payne
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:Nothing inside of WEB-INF will ever be served, so the 404 is to be expected.

The WS URL should be something like http://localhost:8080/MovieWebService/rest/hello

As an aside, don't keep source files inside of your webapps folder - it's all too easy to undeploy a web app and have it thereby deleted.


I also wrote this http://localhost:8080/MovieWebService/rest/hello path on the browser but still doenst change.I just create basic this document nothing more(dont have webapp recently), I follow this document step by step until listing 3 http://www.ibm.com/developerworks/library/wa-aj-tomcat/

I think I have to change somethings in path directory or sth.Because when I try to run it always coming same default path
 
Tim Moores
Saloon Keeper
Posts: 3263
54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What version of Jersey are you using? The "com.jersey..." stuff indicates a rather old version. I recommend to obtain the latest 2.x version, and to check out its "helloworld-webapp" example code.
 
dylan payne
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:What version of Jersey are you using? The "com.jersey..." stuff indicates a rather old version. I recommend to obtain the latest 2.x version, and to check out its "helloworld-webapp" example code.


I used 2.22 version.I thnk its okey.Now I investigating apache or wrong file destionation because when I wrote to default localhost:8080, apache page doesnt come.

and also found this topic he used it same document like me and he got same error. http://www.coderanch.com/t/570630/Web-Services/java/Run-Simple-Jersey-REST-Webservice

Im still tryng it.Ty for your patience
 
Tim Moores
Saloon Keeper
Posts: 3263
54
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That thread seems to discuss a different problem (missing jar files).

Jersey 2.22 is OK. Jersey 2 doesn't use "com.jersey" identifiers, so that's at least part of the problem. I once again advise to start with the "helloworld-webapp" example, it has everything you need to get started. You can ignore the App class, it is used for starting the container (you would use Tomcat instead).
 
dylan payne
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:That thread seems to discuss a different problem (missing jar files).

Jersey 2.22 is OK. Jersey 2 doesn't use "com.jersey" identifiers, so that's at least part of the problem. I once again advise to start with the "helloworld-webapp" example, it has everything you need to get started. You can ignore the App class, it is used for starting the container (you would use Tomcat instead).


I deleted "com" side and it works ty so much Tim
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!