Question

I'm developing a web service in Java using Axis to get all the news from google, here is the code:

String s = "http://ajax.googleapis.com/ajax/services/search/news?v=1.0&rsz=8&q=";
URL url = new URL(s + URLEncoder.encode("test", "UTF-8"));
Reader reader = new InputStreamReader(url.openStream(), "UTF-8");
GoogleResults results = new Gson().fromJson(reader, GoogleResults.class); //here is the problem
return "service ok";

Here is my Java client:

Call call = (Call) new Service().createCall();
URL url = new URL("http://localhost:8080/axis/services/googleNews");
call.setTargetEndpointAddress(url);
call.setOperationName(new QName("method_name"));
Object answerWS = call.invoke(new Object[]{});
System.out.println(answerWS);

Without this code:

GoogleResults results = new Gson().fromJson(reader, GoogleResults.class);

everything works, otherwise I get a java.lang.reflect.InvocationTargetException.

The Web Service properly works alone, the problem occours when I call it with a client using the invoke method.

Any idea?

Thanks for help

Was it helpful?

Solution

Ok, when you use an external jar in your java project you have to add it in the axis lib folder (path: /web_server_local_folder/axis/WEB-INF/lib). I resolved my issue adding the gson jar in that folder.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top