0
I would like to know what I should do to implement a client for a webservice
in the Eclipse as a Dynamic Web Project
. I can’t generate a client, so I have to start from scratch.
0
I would like to know what I should do to implement a client for a webservice
in the Eclipse as a Dynamic Web Project
. I can’t generate a client, so I have to start from scratch.
3
Emanuella Gomes, I will answer your question, based on your comments(without specifying necessary technologies or rules) .
As you already have a deployed webservice you will need the methods that already exist in it (if you don’t have you need to create and deploy again).
Example of a dummy method in your Webservice
@GET
@Path("/NovoModulo")
@Produces("application/json")
@Consumes("application/json")
public String listarFaturas()
{
String gson = "";
try
{
gson = new Gson().toJson(sincronizador.exportarFaturasREST());
} catch (SQLException e)
{
e.printStackTrace();
gson = e.getMessage();
}
return gson;
}
That one Gson i particularly like to use because we can generate a Json from objects and it gets very easy to work with.
I imagine you already know how to create and configure a Dynamic Web Project
then from that, you need to develop your new module according to the specifications(if it exists) and implement access to your WebService
.
Example of access to this method via Java in your DWP
:
private final String metodo = "NovoMetodo/";
public List<FaturaPendente> listarFaturas() throws Exception
{
ConexaoWebService conexaoWebService = ConexaoWebService.getInstance();
//Aqui você poderia criar uma validação para garantir que existe seus dados de oconexão
//como ip, porta e nome do webservice
//Aqui podemos chamar de "manha" você monta uma URL com os dados que foram verificados acima
URL_WS = conexaoWebService.getProtocolor() + conexaoWebService.getIp() + conexaoWebService.getPorta() + conexaoWebService.getWebservice() + conexaoWebService.getClasse();
//aqui é onde você monta o acesso ao seu método exemplo : 192.168.0.200:8080/WebService/NovoMetodo
String[] resposta = new WebServiceCliente().get(URL_WS + metodo);
List<Fatura> faturas = new ArrayList<Fatura>();
//se a resposta for OK retornará 200 e você terá acesso aos dados do webservice
if (resposta[0].equals("200"))
{
//utilizando o Gson
Gson gson = new Gson();
JsonParser parser = new JsonParser();
JsonArray array = parser.parse(resposta[1]).getAsJsonArray();
for (int i = 0; i < array.size(); i++)
{
FaturaImportado faturaImportada = gson.fromJson(array.get(i), FaturaImportado.class);
Fatura fatura = new Fatura(faturaImportada.getCodigoCliente(), faturaImportada.getNomeCliente(), faturaImportada.getFormaPagamento());
faturas.add(fatura);
}
}
return faturas;
}
An idea for you is to put on some button to trigger this check, or every time the user enters this module list what you need.
** Return invoices : As your object is already filled in at this time you can use it in the way that best suits you and use the result to display your information.
Remembering that this is a new module, your Webservice needs to have the methods that will be consumed by your application "New Module".
Browser other questions tagged java web-service eclipse
You are not signed in. Login or sign up in order to post.
The
cliente
you are referring to the project?– Wellington Avelino
The project is a customer will use a service already implemented.
– Emanuella Gomes
See if I got it right: You want to develop another "module" that will communicate with your web service that is already deployed ?? @Emanuellagomes
– Wellington Avelino
Yes, @Wellingtonavelino
– Emanuella Gomes