Java – rest Service on wildfly pathparam is empty
•
Java
I am building a rest service using Jee 7 and deploying it on wildfly 8 With the exception of pathparam, everything seems to be working properly
My code is as follows:
web. In XML:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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"
version="3.0">
</web-app>
JaxRsActivator. java:
package nl.noread.tracker.rest;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@ApplicationPath("/")
public class JaxRsActivator extends Application {
/* class body intentionally left blank */
}
UserService:
package nl.noread.tracker.rest;
import nl.noread.tracker.domain.Location;
import nl.noread.tracker.manager.LocationManager;
import nl.noread.tracker.manager.UserManager;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.websocket.server.PathParam;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
@Stateless
@LocalBean
@Path("/user")
public class UserService {
@EJB
private LocationManager locationManager;
@EJB
private UserManager userManager;
@GET
@Path("location/{id}")
@Produces("application/json")
public Location getUserLocation(@PathParam("id") final String id) {
System.out.println("id: " + id);
return locationManager.getLastLocationForUser(userManager.getUserById(1));
}
}
Location is a POJO class
When I call this service with URL / user / location / test, the following output is generated:
Other services return this JSON data:
{"latitude":52.389672,"longitude":4.840009,"timestamp":1400237665000}
This is printed on standard output:
09:52:05,041 INFO [stdout] (default task-10) id:
When I debug this, I notice that the ID is an empty string, and I want it to be "test"
Does anyone have any opinion on this problem?
Solution
Your import for pathparam is:
import javax.websocket.server.PathParam;
This should be one of the following:
import javax.ws.rs.PathParam;
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
