não consigo acessar o WS subindo o war pelo wildfly......
segue o codigo:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container,
see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html -->
<web-app version="2.5" 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_2_5.xsd">
<servlet>
<servlet-name>restTest</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>br.com.alura.loja.webservice</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>restTest</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping>
</web-app>
rest java:
package br.com.alura.loja.webservice;
.....
@Path("/carrinhos")
public classFazTudo {
@Path("{id}")
@GET
@Produces(MediaType.APPLICATION_JSON)
public String busca(@PathParam("id") Long id){
Carrinho carrinho = new CarrinhoDAO().busca(id);
return carrinho.toJson();
}
@POST
@Produces(MediaType.APPLICATION_JSON)
public String adiciona(String item){
Gson json = new Gson();
Carrinho c = json.fromJson(item, Carrinho.class);
System.out.println("item: "+c);
new CarrinhoDAO().adiciona(c);
Boolean func = Boolean.TRUE;
return json.toJson(func);
}
}
teste sem wildfly
String url = "http://localhost:8080";
Servidor s = new Servidor();
s.rodarServidores(url);
Client cliente = ClientBuilder.newClient();
WebTarget wt = cliente.target(url);
String conteudo = wt.path("/carrinhos/1").request().get(String.class);
Gson json = new Gson();
Carrinho c = json.fromJson(conteudo, Carrinho.class);
System.out.println("Carrinho.rua: "+c.getRua());
s.pararServidores();
teste no wildfly
link: http://localhost:8080/TesteRest/ws/carrinhos/1
resultado: Not Found
ao acessar apenas http://localhost:8080/TesteRest/ :
<div>TODO TESTE É POUCO!</div>