Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rest Service on Wildfly PathParam empty

I am building a REST Service using JEE 7 and deploying it on WildFLy 8. Everything seems to be working as it should except for the PathParam which is not.

My code is as follows:

web.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 using the url /user/location/test the following output is produced:

The rest service return this JSON data:

{"latitude":52.389672,"longitude":4.840009,"timestamp":1400237665000}

This is printed on the stdout:

09:52:05,041 INFO  [stdout] (default task-10) id: 

When I debug this I notice that id is an empty string while I expect it to be "test".

Does anyone have any insight on this issue?

like image 802
Remcoder Avatar asked Dec 11 '22 05:12

Remcoder


1 Answers

The import you use for the PathParam is:

import javax.websocket.server.PathParam;

This should be the following one:

import javax.ws.rs.PathParam;
like image 195
tom Avatar answered Dec 27 '22 20:12

tom