Java Restful Web service 404 Error - java

I am trying to make a RESTFUL JAVA WEB SERVICE using eclipse and maven in Apache Tomcat. Everything seems fine to me and it is not showing any error but when open the URL it shows 404 Error.
I am trying to call it via this URL http://localhost:8080/first/rest
WEB.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>first</display-name>
<servlet>
<servlet-name>firstapp</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>com.first.pkg</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>firstapp</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>task</groupId>
<artifactId>first</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>first Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>maven2-repository.java.net</id>
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/2/</url>
<layout>default</layout>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.9</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
</build>
</project>
RestServ.java
package com.first.pkg;
import java.util.Date;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
#Path("/")
public class RestServ {
#GET
#Produces("text/html")
public Response getStartingPage()
{
String output = "<h1>Hello World!<h1>" +
"<p>RESTful Service is running ... <br>Ping # " + new Date().toString() + "</p<br>";
return Response.status(200).entity(output).build();
}
}

<display-name>first</display-name>
is a description part and I don't think you can call your web service via this name. Instead, try calling it like
http://localhost:8080/{nameOfYourWARFileHere}/rest
Also make sure to put rest into your #Path("/") annotation in RestServ.java right after the slash otherwise the request mapping won't work.

Related

Unable to run JaxRs web service using Wildfly web server

Hi I am trying to build a Simple JaxRs web service on JBoss developer studio and Wildfly 11 as application server but i am getting following error while i am trying to deploy my maven project :
Failed to start service
jboss.undertow.deployment.default-server.default-host."/JaxRsTest-0.0.1-SNAPSHOT":
org.jboss.msc.service.StartException in service
jboss.undertow.deployment.default-server.default-host."/JaxRsTest-0.0.1-SNAPSHOT":
java.lang.NoSuchMethodError:
org.apache.tomcat.util.descriptor.DigesterFactory.newDigester(ZZLorg/apache/tomcat/util/digester/RuleSet;Z)Lorg/apache/tomcat/util/digester/Digester;
Also i want to inform you that the project is working fine when i use apache tomcat 9 However it throws above mentioned error when I switch to wildfly 11. I am new to java and Specially web service and just started working for a company which uses Jboss eap server which is quite same as wildfly and unfortunately i am receiving same error there as well while working on a web service assignment.
For more reference below is my pom.xml file :
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>JaxRsServiceTest</groupId>
<artifactId>JaxRsServiceTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
<version>1.19</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
and my web.xml file content is :
<?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>JaxRsServiceTest</display-name>
<servlet>
<servlet-name>Jersey 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>com.test.jaxrs.service</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
and my java class within package com.test.jaxrs.service is
package com.test.jaxrs.service;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
#Path("/test")
public class JaxRsTest {
#GET
#Path("/hello/{msg}")
#Produces(MediaType.TEXT_PLAIN)
public String processRequest(#PathParam(value="msg")String message)
{
return "Hello : " + message;
}
}
Please let me know where i am going wrong with the wildfly.... and Thanks in advance
Wildfly and EAP are a full JEE servers - there is no need to include Jersey dependencies in your pom.xml. Tomcat required that because it is primarily a servlet/JSP engine. Your service looks good but your pom.xml and web.xml are the result using Tomcat. Additionally, you do not need a web.xml any longer if you don't want and you certainly don't need to use Jersey to map it.
You'll want one more file - the Application class that gets things started. It looks something like:
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
/**
* Used to bootstrap JAX-RS. Otherwise this class is
* not directly used.
*/
#ApplicationPath("/rest")
public class RestApplicationConfig extends Application {
// intentionally empty
}
It can go anywhere in your source tree. Note that it takes over the /rest path which is similar to what you had in your web.xml.
The pom.xml below will create a .war file that you can deploy to Wildfly. This is about as simple as it gets and again, remove your web.xml for now.
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>JaxRsServiceTest</groupId>
<artifactId>JaxRsServiceTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
<dependencies>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>jaxrs-api</artifactId>
<version>3.0.12.Final</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

Jersey Rest API Documentation using Swagger

I am trying to view the list of my jersey rest service methods in API Documentation using Swagger. Went through few examples/sample given in GitHub sites. But still I am not able to list out my service methods when I try to access the context-root link. Getting 404 service not found.
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.danfoss.des</groupId>
<artifactId>SampleRestProject</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>SampleRestProject Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jersey-jaxrs</artifactId>
<version>1.5.0</version>
</dependency>
<!-- <dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-jaxrs_2.9.1</artifactId>
<version>1.2.0</version>
<scope>compile</scope>
</dependency> -->
</dependencies>
<build>
<finalName>SampleRestProject</finalName>
</build>
web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>helloworld</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>io.swagger.jaxrs.listing,com.danfoss.des</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<!-- <init-param>
<param-name>api.version</param-name>
<param-value>1.0.0</param-value>
</init-param>
<init-param>
<param-name>swagger.api.basepath</param-name>
<param-value>http://localhost:8081/SampleRestProject/</param-value>
</init-param> -->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>JerseyJaxrsConfig</servlet-name>
<servlet-class>io.swagger.jersey.config.JerseyJaxrsConfig</servlet-class>
<init-param>
<param-name>api.version</param-name>
<param-value>1.0</param-value>
</init-param>
<init-param>
<param-name>swagger.api.basepath</param-name>
<param-value>http://localhost:8081/SampleRestProject/rest</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>helloworld</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<!-- <welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list> -->
</web-app>
Service java class:
package com.danfoss.des;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import com.danfoss.model.Track;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
#Path("/helloWorld")
#Api(value="helloWorld", description="Sample hello world swagger service")
public class RESTfulHelloWorld
{
#GET
#Produces("text/html")
#Path("/startingPage")
#ApiOperation(value="Starting of the swagger service")
public Response getStartingPage()
{
String output = "Staring method is invoked";
return Response.status(200).entity(output).build();
}
}
My Project structure
The link am trying to access to view the list: http://localhost:8081/SampleRestProject/api-docs
Can someone please help me find out where exactly am going wrong or if I am missing out anything.
The JerseyJaxrsConfig class is part of the swagger-jersey2-jaxrs library and hence is not available when deploying the webapp, because you're using swagger-jersey-jaxrs combined with Jersey 1.9 (which is good).
Simply replace
<servlet-class>io.swagger.jaxrs.config.JerseyJaxrsConfig</servlet-class>
with
<servlet-class>io.swagger.jaxrs.config.DefaultJaxrsConfig</servlet-class>
to use the correct configuration class and then try accessing http://localhost:8081/SampleRestProject/rest/swagger.json again.
Also while you're at it, consider defining Swagger's basepath as a relative path so you're able to deploy the webapp on different ports.
<init-param>
<param-name>swagger.api.basepath</param-name>
<param-value>/SampleRestProject/rest</param-value>
</init-param>

Apache Tomcat 9 - HTTP Status 404 on browser

I'm trying to create a simple web service, but I'm getting 404 when I try to go to the URL.
Here's the web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>Test</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>Test</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
Here's pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>1</groupId>
<artifactId>1</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.17</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.17</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20080701</version>
</dependency>
</dependencies>
</project>
And here's the basic rest class:
package Test;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
/**
* Created by * on 4.02.2017.
*/
#Path("/api")
public class Test {
#GET
#Path("/get/test")
public String getSmth(String request) {
return "Testing";
}
}
And when I go to:
http://127.0.0.1:8080/Test/rest/api/get/test
I get:
HTTP Status 404 -
type Status report
message
description The requested resource is not available.
Apache Tomcat/9.0.0.M17
When I go to the Tomcat app manager I can see my app running there. Am I doing something really wrong or missing something?
Thanks,
Eerik
In the code you are using glassfish server and not tomcat. In the IDE you are using try to use glassfish server instead of tomcat with the same code.

Maven + Jersey RESTful API : Internal Server Error from POSTMAN on GET request

I am sending a GET request to my StoryBoardResource, class responsible for generating JSON format data, using POSTMAN app. The associated method consumes nothing but produces Application/JSON data: #Produces(MediaType.APPLICATION_JSON).
I am recieving 500 internal server error on POSTMAN though there is nothing showing up on my IDE's console as am logging some statements too for debugging purpose.
If there had been some jar file issue it must have thrown an error for no MesageBodyWriter found ...right? I have updated pom.xml to include JSON dependency and the jar is also there.
Here is my StoryBoardResource class to which the request is delegated:
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.harsh.webapp.storyBoard.model.StoryBoardModel;
import org.harsh.webapp.storyBoard.service.StoryBoardService;
#Path("/authenticateUser")
public class StoryBoardResource {
private StoryBoardService sts = new StoryBoardService();
#GET
#Produces(MediaType.APPLICATION_JSON)
public StoryBoardModel authUser(#QueryParam("username") String username, #QueryParam("password") String password){
return sts.authUser(username, password);
}
}
which calls authUser method on my service class StoryBoardService :
public StoryBoardModel authUser(String username, String password){
System.out.println("In here");
if(username.equals(map.get(username).getUsername()) && password.equals(map.get(username).getPassword())){
System.out.println("true");
return map.get(username);
}
return map.get(username);
}
Could this be bcoz of some jar or Jersey version conflict?
Here is my pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.harsh.webapp</groupId>
<artifactId>storyBoard</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>storyBoard</name>
<build>
<finalName>storyBoard</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
</dependency>
</dependencies>
<properties>
<jersey.version>2.16</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
And here is a snapshot of Maven Dependencies
Sorry for such a long post but I thought I should explain things clearly.
Please help on finding what could I be doing wrong here?
And web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container,
see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html -->
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>Jersey Web 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>org.harsh.webapp.storyBoard</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/webapi/*</url-pattern>
</servlet-mapping>
</web-app>
I worked it out and it appeared so that I missed adding a NO-Argumentconstructor in a model class.
public someClass(){};
Always remember to add a No-Arg constructor whenever you create a model class for your Maven-Jersey application.
And it worked!
However, I am not clear on why would a no-arg constructor make the application run or fail!!
If any body know the answer to this. Please share your knowledge!!

404 error with a simple RESTeasy service on tomcat 8 running with eclipse luna

I always end up with a 404 response.
Resource not found. Testing with tomcat
v8.0. Below are the
details.
URL : http://localhost:8080/ESTServer/rest/message/hello
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ESTServer</groupId>
<artifactId>ESTServer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>JBoss repository</id>
<url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.0.13.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-servlet-initializer</artifactId>
<version>3.0.13.Final</version>
</dependency>
</dependencies>
web.xml
<?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" version="3.1"> <display-name>ESTServer</display-name>
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/rest</param-value>
</context-param>
<servlet>
<servlet-name>resteasy-servlet</servlet-name>
<servlet-class>
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.mota.rest.CaDistributionApplication</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>resteasy-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
Service code :
package com.mota.rest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
#Path("/message")
public class CaDistributionService {
#GET
#Path("/{param}")
public Response printMessage(#PathParam("param") String msg) {
String result = "Restful example : " + msg;
return Response.status(200).entity(result).build();
}
}
project structure
CaDistributionApplication.java
package com.mota.rest;
import javax.ws.rs.core.Application;
import java.util.HashSet;
import java.util.Set;
import com.mota.rest.CaDistributionService;;
public class CaDistributionApplication extends Application{
private Set<Object> singletons = new HashSet<Object>();
public CaDistributionApplication() {
singletons.add(new CaDistributionService());
}
#Override
public Set<Object> getSingletons() {
return singletons;
}
}
What am I missing here ?
Please help !!!!
I just tried restarting the eclipse.
Multiple clean/build/refresh/install.
Checking the Target folder for generated
war and classes. Launching tomcat in debug mode.
But basically didn't change anything in the code.
And yes it works finally.

Categories