簡體   English   中英

Java調用方法使用軸Web服務引發InvocationTargetException

[英]java invoke method throws InvocationTargetException using axis web service

我正在使用Axis用Java開發Web服務,以從Google獲取所有新聞,以下是代碼:

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";

這是我的Java客戶端:

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);

沒有此代碼:

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

一切正常,否則我得到一個java.lang.reflect.InvocationTargetException。

Web Service可以單獨正常工作,當我使用invoke方法與客戶端調用它時,就會出現問題。

任何想法?

感謝幫助

好的,當您在Java項目中使用外部jar時,必須將其添加到axis lib文件夾中(路徑:/ web_server_local_folder / axis / WEB-INF / lib)。 我解決了在該文件夾中添加gson jar的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM