我有以下代码在直接从 Eclipse 执行时可以正常工作,但是当我从服务器(IBM WAS)上的标准(Eclipse 生成)客户端调用它时,它会给出异常。
public Dispatcher() { //constructor
try {
ResourceBundle rb = ResourceBundle.getBundle("dispatchersettings", Locale.ENGLISH);
server = "http://" + rb.getString("UserID") +":" + rb.getString("UserPassword")
+ "@"+ rb.getString("ServerAppURL") + ":" + rb.getString("ServerAppPort")
+ rb.getString("ServerAppContextPath");
}
catch (Exception configException) {
configException.printStackTrace();
}
}
public boolean sendTransactionUpdate(String name, String msgTitle, String msgContents, String transORalert) {
DefaultHttpClient httpclient = new DefaultHttpClient();
ResponseHandler<String> responseHandler = new BasicResponseHandler(); // auto-reads the response stream
String responseBody = "";
try {
HttpGet httpget = new HttpGet( new URIBuilder( server +
"/invoke?adapter=rcAdapter&procedure=sendTransactionUpdate")
.addParameter("parameters", "[\"" +name +"\",\"" + msgTitle+ "\",\"" + msgContents +"\",\"" + transORalert + "\"]").build() );
try {
System.out.println("Inside Webservice :Executing URL -->" +httpget.toString() );
responseBody = httpclient.execute(httpget, responseHandler);
System.out.println( responseBody );
} catch (Exception e) {
e.printStackTrace();
} finally {
httpget.releaseConnection();
}
if( responseBody.indexOf("\"isSuccessful\":true") > -1 )
return true;
} catch (Exception e) {
e.printStackTrace();
} finally {
// When HttpClient instance is no longer needed,shut down the connection manager to ensure
// immediate deallocation of all system resources
httpclient.getConnectionManager().shutdown();
}
return false;
}
例外:
java.lang.reflect.InvocationTargetException Message: java.lang.reflect.InvocationTargetException
它只到达 System.out.println("Inside Webservice :Executing URL -->" +httpget.toString() );
之前 responseBody = httpclient.execute(httpget, responseHandler);
我认为上面的行应该导致这个异常。
它甚至没有进入catch 块并显示异常,这很奇怪。下面的直接块根本没有被执行。
catch (Exception e) {
System.out.println("Exception LeveL 1:" + e.getMessage() );
e.printStackTrace();
}
请有任何建议。
谢谢