萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> oracle教程 >> 簡單解決復雜的Oracle IAS問題

簡單解決復雜的Oracle IAS問題

筆者做了一個小的系統輔助功能,可以周期性訪問某個URL、執行某個SQL語句or 執行某個系統命令 。

執行SQL語句和系統命令比較簡單,這裡不再詳述,主要說一下訪問某個URL。

實際上JDK自身已有工具類用於創建HTTP請求,類名是:java.net.HttpURLConnection,但考慮到基礎類通常比 較粗糙,很多情況要自己考慮和處理,就轉頭去Google了下,發現果然有開源的工具包可以使用,幾個工具包中以HttpClient較為常用,而且是apache的東東,於是決定采用HttpClient。

從apache上 down了包commons-httpclient-3.1.jar和commons-codec-1.3.jar兩個包,後者是HttpClient依賴的包。

幫助寫的很好,即便是像我這樣英文很爛,也能很快上手。

public boolean  visitURL(String url) {

// Commons HttpClient 3.1
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(url);

// Provide custom retry handler is necessary
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new  DefaultHttpMethodRetryHandler(3, false));

boolean rs = false;

try {

// Execute the method.
int statusCode = client.executeMethod(method);

if (statusCode != HttpStatus.SC_OK) {
logger.error("Method failed: " + method.getStatusLine());
}
else {
rs = true;
}

} catch (HttpException e) {
logger.error("Fatal protocol violation: " + e.getMessage());
} catch (IOException e) {
logger.error("Fatal transport error: " + e.getMessage());
} finally {
// Release the connection.
method.releaseConnection();
}

return rs;
}

本機Tomcat下run一下,工作正常,隨即丟到服務器(Oracle IAS環境)上測試,程序 應該出乎意料的報了個錯。

09/03/16 19:03:43 java.lang.NoClassDefFoundError
09/03/16 19:03:43 at org.apache.commons.httpclient.HttpMethodBase.writeRequestLine (HttpMethodBase.java:2015)
09/03/16 19:03:43 at org.apache.commons.httpclient.HttpMethodBase.writeRequest (HttpMethodBase.java:1864)
09/03/16 19:03:43 at org.apache.commons.httpclient.HttpMethodBase.execute (HttpMethodBase.java:975)
09/03/16 19:03:43 at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry (HttpMethodDirector.java:368)
09/03/16 19:03:43 at org.apache.commons.httpclient.HttpMethodDirector.executeMethod (HttpMethodDirector.java:164)
09/03/16 19:03:43 at org.apache.commons.httpclient.HttpClient.executeMethod (HttpClient.java:437)
09/03/16 19:03:43 at org.apache.commons.httpclient.HttpClient.executeMethod (HttpClient.java:324)
09/03/16 19:03:43 at com.zbht.util.TimerTaskManager.runURLTask (TimerTaskManager.java:237)
09/03/16 19:03:43 at _system._timer__task._test._jspService(_test.java:182)
09/03/16 19:03:43 at com.orionserver.http.OrionHttpJspPage.service (OrionHttpJspPage.java:59)
09/03/16 19:03:43 at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:462)
09/03/16 19:03:43 at oracle.jsp.runtimev2.JspServlet.internalService (JspServlet.java:594)
09/03/16 19:03:43 at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:518)
09/03/16 19:03:43 at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
09/03/16 19:03:43 at com.evermind.server.http.ServletRequestDispatcher.invoke (ServletRequestDispatcher.java:713)
09/03/16 19:03:43 at com.evermind.server.http.ServletRequestDispatcher.forwardInternal (ServletRequestDispatcher.java:370)
09/03/16 19:03:43 at com.evermind.server.http.HttpRequestHandler.doProcessRequest (HttpRequestHandler.java:871)
09/03/16 19:03:43 at com.evermind.server.http.HttpRequestHandler.processRequest (HttpRequestHandler.java:453)
09/03/16 19:03:43 at com.evermind.server.http.AJPRequestHandler.run (AJPRequestHandler.java:302)
09/03/16 19:03:43 at com.evermind.server.http.AJPRequestHandler.run (AJPRequestHandler.java:190)
09/03/16 19:03:43 at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run (ServerSocketReadHandler.java:260)
09/03/16 19:03:43 at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run (ReleasableResourcePooledExecutor.java:303)
09/03/16 19:03:43 at java.lang.Thread.run(Thread.java:595)

  • 共2頁:
  • 上一頁
  • 1
  • 2
  • 下一頁
copyright © 萬盛學電腦網 all rights reserved