Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exercicios #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/main/java/br/com/alura/loja/ClienteTeste.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package br.com.alura.loja;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;

import org.junit.Assert;
import org.junit.Test;

public class ClienteTeste {
@Test
public void testaQueAConexaoComOServidorFunciona() {
Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://www.mocky.io");
String conteudo = target.path("/v2/52aaf5deee7ba8c70329fb7d").request().get(String.class);
Assert.assertTrue(conteudo.contains("<rua>Rua Vergueiro 3185"));

}

}
22 changes: 22 additions & 0 deletions src/main/java/br/com/alura/loja/Servidor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package br.com.alura.loja;

import java.io.IOException;
import java.net.URI;

import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
import org.glassfish.jersey.server.ResourceConfig;

public class Servidor {

public static void main(String[] args) throws IOException {
URI uri = URI.create("http://localhost:8080/");
ResourceConfig config = new ResourceConfig().packages("br.com.alura.loja");
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(uri, config);
System.out.println("Servidor rodando");
System.in.read();
server.stop();

}

}
4 changes: 4 additions & 0 deletions src/main/java/br/com/alura/loja/modelo/Carrinho.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,8 @@ public List<Produto> getProdutos() {
return produtos;
}

public String toXML() {
return new XStream().toXML(this);
}

}
21 changes: 21 additions & 0 deletions src/main/java/br/com/alura/loja/resource/CarrinhoResource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package br.com.alura.loja.resource;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import com.thoughtworks.xstream.XStream;

import br.com.alura.loja.dao.CarrinhoDAO;
import br.com.alura.loja.modelo.Carrinho;

@Path("carrinhos")
@Produces(MediaType.APPLICATION_XML)
public class CarrinhoResource {
@GET
public String busca() {
Carrinho carrinho = new CarrinhoDAO().busca(1l);
return carrinho.toXML();
}
}
1 change: 1 addition & 0 deletions src/main/webapp/WEB-INF/classes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/br/
Binary file not shown.
Binary file not shown.
Binary file not shown.