Quantcast
Channel: Programação - GUJ
Viewing all articles
Browse latest Browse all 33093

404 ao acessar WS pelo wildfly

$
0
0

@arcZendSun escreveu:

Bom dia,

estou com problemas para acessar o webservice no servidor wildfly, fiz um teste criando um método main com jersey e dessa forma ele funcionou, porem pelo wildfly é exibido na tela "Not Found".

segue o codigo:

web.xml

<?xml version="1.0" encoding="UTF-8"?>
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
TesteRest

<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>

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/ :

TODO TESTE É POUCO!

Mensagens: 1

Participantes: 1

Ler tópico completo


Viewing all articles
Browse latest Browse all 33093


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>