Reputation: 1494
I am deploying a WAR file (vimbaserver-1.0.war) to my JBoss web server with the following web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:web="http://java.sun.com/xml/ns/javaee" 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>vimbaserver</display-name>
<servlet>
<servlet-name>vimbaserver</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.vimba.main.ServerStart</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>vimbaserver</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
The WAR contains two REST functions that I want to test:
@GET
@Path("/getWord/{word}")
@Produces(MediaType.TEXT_PLAIN)
public String getWord(@PathParam("word") String word) {
return "hello world " + " " + word;
}
@GET
@Path("/register/{userid}/{email}/{password}/{displayname}/{genderpref}/{hot}/{not}")
@Produces(MediaType.TEXT_PLAIN)
public String register(@PathParam("userid") String userid, @PathParam("email") String email, @PathParam("password") String password, @PathParam("displayname") String displayname, @PathParam("genderpref") GenderPreference gender, @PathParam("hot") int hot, @PathParam("not") int not) {
if (userid == null || email == null || password == null
|| displayname == null || gender == null) {
throw new IllegalArgumentException(
"Required fields are null when registering");
}
try{
RegistrationStatus status = factory.register(userid, email, password,displayname, gender.getValue(), hot, not);
if(status == RegistrationStatus.SUCCESSFUL){
MailSender.generateSignUpEmail(userid, email, password);
}
return status.getValue();
} catch(MajorMinorException e){
logger.error("An error occurred whilst trying to register user: ",e);
}
return RegistrationStatus.FAILED.getValue();
}
From the above, we would have expected the following REST URL to work: http://xx.xx.xx.xx:8080/vimbaserver-1.0/functions/getWord/test. However, this doesn't seem to be the case.
What is strange is that we have another application deployed to our server that exposes a number of REST functions that appear to be working fine.
Upvotes: 1
Views: 1584
Reputation: 22972
As specified in web.xml
your URL
pattern is <url-pattern>/rest/*</url-pattern>
so URL
should be,
http://xx.xx.xx.xx:8080/vimbaserver-1.0/rest/functions/getWord/test
^^^^^^^Add rest in your url
Make sure your service class contains @Path("/functions")
at start and annotated properly.It sounds like you missed some annotation(s). For example @Service
or @Component
please check.
Upvotes: 1