Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

Não consigo levantar o servidor HTTP Grizzly

Bom dia pessoal,

Segue abaixo o que aparece no console:

mai 30, 2017 11:21:47 AM org.glassfish.jersey.server.ApplicationHandler initialize INFORMAÇÕES: Initiating Jersey application, version Jersey: 2.5 2013-12-18 14:27:29... Exception in thread "main" javax.ws.rs.ProcessingException: IOException thrown when trying to start grizzly server at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory.createHttpServer(GrizzlyHttpServerFactory.java:276) at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory.createHttpServer(GrizzlyHttpServerFactory.java:110) at br.com.alura.loja.Servidor.main(Servidor.java:14) Caused by: java.net.BindException: Address already in use at sun.nio.ch.Net.bind0(Native Method) at sun.nio.ch.Net.bind(Net.java:433) at sun.nio.ch.Net.bind(Net.java:425) at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223) at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74) at org.glassfish.grizzly.nio.transport.TCPNIOBindingHandler.bindToChannelAndAddress(TCPNIOBindingHandler.java:131) at org.glassfish.grizzly.nio.transport.TCPNIOBindingHandler.bind(TCPNIOBindingHandler.java:87) at org.glassfish.grizzly.nio.transport.TCPNIOTransport.bind(TCPNIOTransport.java:449) at org.glassfish.grizzly.nio.transport.TCPNIOTransport.bind(TCPNIOTransport.java:429) at org.glassfish.grizzly.nio.transport.TCPNIOTransport.bind(TCPNIOTransport.java:420) at org.glassfish.grizzly.http.server.NetworkListener.start(NetworkListener.java:658) at org.glassfish.grizzly.http.server.HttpServer.start(HttpServer.java:264) at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory.createHttpServer(GrizzlyHttpServerFactory.java:274) ... 2 more

2 respostas

Consegui rodar o servidor, era apenas um erro de porta.

Porém quando vou acessar a URI "carrinhos", me volta um HTTP ERROR 500.

Segue meu codigo do servidor:

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 {
        ResourceConfig config = new ResourceConfig().packages("br.com.alura.loja");
        URI uri = URI.create("http://localhost:8080/");
        HttpServer server = GrizzlyHttpServerFactory.createHttpServer(uri,config);
        System.out.println("Servidor rodando");
        System.in.read();
        server.stop();

    }
}

E meu codigo do cliente:

package br.com.alura.loja;

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

import org.junit.Test;

import junit.framework.Assert;


public class ClienteTest {

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


    }

}
solução!

Alguem?!