Olá, tudo bem?
Estou tendo o seguinte erro ao executar o ClienteWebService Exception in thread "main" org.apache.http.client.HttpResponseException: at org.apache.http.impl.client.AbstractResponseHandler.handleResponse(AbstractResponseHandler.java:70) at org.apache.http.client.fluent.Response.handleResponse(Response.java:90) at org.apache.http.client.fluent.Response.returnContent(Response.java:97) at br.com.alura.cliente.ClienteWebService.main(ClienteWebService.java:12)
O cliente WebService esta assim:
package br.com.alura.cliente;
import org.apache.http.client.fluent.Request;
public class ClienteWebService {
public static void main(String[] args) throws Exception {
String conteudo = Request
.Post("http://localhost:8080/gerenciador/empresas")
.addHeader("accept", "application/xml")
.execute()
.returnContent()
.asString();
System.out.println(conteudo);
}
}
Já o empresasService:
package br.com.alura.gerenciador.servlet;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.gson.Gson;
import com.thoughtworks.xstream.XStream;
import br.com.alura.gerenciador.modelo.Banco;
import br.com.alura.gerenciador.modelo.Empresa;
/**
* Servlet implementation class EmpresasService
*/
@WebServlet("/empresas")
public class EmpresasService extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List<Empresa> empresas = new Banco().getEmpresas();
String valor = request.getHeader("accept");
if(valor.endsWith("xml")) {
XStream xstream = new XStream();
xstream.alias("empresa", Empresa.class);
String xml = xstream.toXML(empresas);
response.setContentType("application/xml");
response.getWriter().print(xml);
} else if (valor.endsWith("xml")) {
Gson gson = new Gson();
String json = gson.toJson(empresas);
response.setContentType("application/json");
response.getWriter().print(json);
} else {
response.setContentType("application/json");
response.getWriter().print("{'message:': 'no content'}");
}
}
}
Não sei onde estou errando, poderiam me ajudar?