Reputation: 8376
Under Tomcat and Jersey libraries I created a REST web service described in this class:
package Servicios;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.PathParam;
import javax.ws.rs.Consumes;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
@Path("service")
public class ServiceResource {
@Context
private UriInfo context;
/**
* Creates a new instance of ServiceResource
*/
public ServiceResource() {
}
@GET
@Produces("text/html")
public String getHtml() {
return "<h1>Here we are, at the contemplation of the most simple web service</h1>";
}
@PUT
@Consumes("text/html")
public void putHtml(String content) {
}
}
So, as I set it before accessing to http://localhost:8080/GetSomeRest
makes the default created .jsp
file created.
I set in project propierties (using NetBeans) a relative URL as webresources/service
, so service
part is same defined in @Path("service")
. All works ok, going to http://localhost:8080/GetSomeRest/webresources/service
makes the web service be consumed.
But what if I want to consume that service right from http://localhost:8080/GetSomeRest/service
? I tried to set only service
in such relative URL and I got an Error 404
message going to http://localhost:8080/GetSomeRest/service
How do virtual paths work?
What would it mean to add an alias to a web service?
Upvotes: 1
Views: 4270
Reputation: 424
Just for information
The path segment webresources
is set in the code by netbeans in the package
org.netbeans.rest.application.config - ApplicationConfig Class into your own project!!! so change it and it's done...
Upvotes: 0
Reputation:
The path segment webresources
is not set in the code you provide so I will guess what your code looks like.
A JAX-RS application can be configured with a class extending javax.ws.rs.core.Application
. Such a class can be annotated with @javax.ws.rs.ApplicationPath()
. My guess is that in your project this annotation is set to
@javax.ws.rs.ApplicationPath("webresources")
So the URL of a JAX-RS
resource class is build from these parts.
http://localhost:8080/
- host and portGetSomeRest
- the context, normally the name of the deployed .war
filewebresources
- the value of the @ApplicationPath
annotationservice
- the value of the @Path
annotation of the classI recommend not to skip step 3.
The value of the @ApplicationPath
annotation can be overridden by a servlet-mapping
element in the web.xml
.
Upvotes: 3