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

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top