Tenho o código…
@Path("usuario")
public class UsuarioResource extends HateoasApplication {
private Repository repo = new Repository();
@POST
@Path("login")
public Response login(@FormParam("mail") String mail, @FormParam("pwd") String pwd){
Usuario usuario = new Usuario(null,mail,pwd);
if(usuario.doLogin(usuario, repo)){
return Response.ok().build();
}
else
return Response.ok().status(Status.FORBIDDEN).build();
}
@GET
@Produces(MediaType.APPLICATION_XML)
public Response list(){
List<Usuario> usuarios = new ArrayList<Usuario>();
usuarios.addAll(repo.getSession().createCriteria(Usuario.class).list());
GenericEntity<List<Usuario>> genericEntity = new GenericEntity<List<Usuario>>(usuarios){};
return Response.ok().entity(genericEntity).type(MediaType.APPLICATION_XML).build();
}
@Linkable(value="listById")
@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_XML)
public Response listById(@PathParam(value="id") String id){
Usuario user = (Usuario) repo.getSession().get(Usuario.class,new Long(id));
return HateoasResponse.created("listById",user.getIdUsuario()).entity(user).build();
}
E a configuração no web.xml
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
metadata-complete="false">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
<param-value>com.sun.jersey.server.linking.LinkFilter</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>br.com.controle.se.resource</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
<param-value>com.sun.jersey.api.container.filter.LoggingFilter</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
<param-value>com.sun.jersey.api.container.filter.LoggingFilter</param-value>
</init-param>
<init-param>
<param-name>com.jayway.jaxrs.hateoas.HateoasLinkInjector</param-name>
<param-value>com.jayway.jaxrs.hateoas.support.StrategyBasedLinkInjector</param-value>
</init-param>
<init-param>
<param-name>com.jayway.jaxrs.hateoas.CollectionWrapperStrategy</param-name>
<param-value>com.jayway.jaxrs.hateoas.support.DefaultCollectionWrapperStrategy</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<!-- OpenSessionInViewFilter - filtro Hibernate -->
<filter-mapping>
<filter-name>OSIVFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Filtro dos usuários logados -->
<filter-mapping>
<filter-name>userSessionFilter</filter-name>
<url-pattern>/pages/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>userSessionFilter</filter-name>
<filter-class>br.com.controle.se.filter.UserSessionFilter</filter-class>
</filter>
<filter>
<filter-name>OSIVFilter</filter-name>
<filter-class>br.com.controle.se.filter.OpenSessionInViewFilter</filter-class>
</filter>
</web-app>
Quando eu faço uma chamada via rest para o método listById, ocorre a exceção abaixo
java.lang.IllegalArgumentException: Invalid link: listById
at org.apache.commons.lang.Validate.notNull(Validate.java:192)
at com.jayway.jaxrs.hateoas.DefaultHateoasContext.getLinkableInfo(DefaultHateoasContext.java:75)
at com.jayway.jaxrs.hateoas.core.HateoasResponse$HateoasResponseBuilder.makeLink(HateoasResponse.java:606)
at com.jayway.jaxrs.hateoas.core.HateoasResponse.created(HateoasResponse.java:246)
at br.com.controle.se.resource.UsuarioResource.listById(UsuarioResource.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
Pelo que eu vi existe um Map usado para manter as anotações @Linkable mas a minha está null.
Agradeço a quem puder me ajudar