studying REST I stumbled into sub-resources and I did some experiments, but no success. Here is the code, I'm using RESTeasy 3.0.9.
@Path(value="/user")
public interface UsersHttp {
@GET
@Produces(MediaType.APPLICATION_JSON)
public User[] getUsers();
@GET
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
public User getUser(@PathParam("id") Long id);
...
}
this interface is implemented by this session-bean:
@Stateless
public class UsersHttpImpl implements UsersHttp {
@Inject
private UserPersistence persist;
@Inject
private MediaUtils mediaUtils;
@Override
public User[] getUsers() {
return persist.getUsers(null);
}
@Override
public User getUser(Long id) {
return persist.getUser(id);
}
...
}
This is a snippet of the User
class:
@SuppressWarnings("serial")
@Entity
@Table(name = "usr_user")
@XmlRootElement
public class User implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "usr_id")
private Long id;
@Column(name = "usr_name", nullable = false)
private String name;
...
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Path("/name")
public String getName() {
return name;
}
...
}
I can successfully get a User
by MyApplication/user/1
, but when I do GET
with MyApplication/user/1/name
I get a javax.ws.rs.NotFoundException
, I was expecting Alice
instead. What did I miss?