スケジュールされたジョブ クラスがあり、Quartz Job クラスを実装します。そこから、DB テーブルのフラグを更新するサーブレット クラスを呼び出し、適切なメーリング リストにメールを送信します。
を取得しjava.net.ConnectException
ます。ただし、サーブレットは、ブラウザに URL を入力するか、JSP ページで JavaScript を使用して適切に呼び出されます。
私のJavaクラスは次のとおりです。
public class ExpirationJob implements Job {
org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger("ExpirationJob.class");
public void execute(JobExecutionContext context)
throws JobExecutionException {
try {
URL serv = new URL("http://localhost:8080/app/emailExpirationServlet");
URLConnection sr = serv.openConnection();
sr.connect();
InputStream is = sr.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader in = new BufferedReader(isr);
String inputLine;
int i =0;
while ((inputLine = in.readLine()) != null)
i = i +1;
log.debug("Input line: " + inputLine);
in.close();
} catch (MalformedURLException e) {
log.debug("Error while calling the emailExpirationServlet -- MalformedURLException: "+ e.getMessage());
e.printStackTrace();
} catch (IOException e) {
log.debug("Error while calling the emailExpirationServlet -- IOException: "+ e.getMessage());
e.printStackTrace();
}
}
}
私のサーブレットコードは次のとおりです。
public class emailExpireServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=UTF-8";
org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger("emailExpireServlet.class");
public void init(ServletConfig config) throws ServletException {
super.init(config);
log.debug("Initializing emailExpireServlet");
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
response.setDateHeader("Expires", 0);
response.setHeader("Cache-Control", "no-cache");
log.debug("Starting emailExpireServlet");
//do some business logic here - I have commented it out to rule out any other blocking issue
response.setStatus(200);
response.getOutputStream().print("Invoked emailExpireServlet! Status is OK");
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
私が得る例外は次のとおりです。
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:525)
at java.net.Socket.connect(Socket.java:475)
at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:233)
at sun.net.www.http.HttpClient.New(HttpClient.java:306)
at sun.net.www.http.HttpClient.New(HttpClient.java:323)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:860)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:801)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:726)
at schedulers.ExpirationJob.execute(Unknown Source)
at org.quartz.core.JobRunShell.run(JobRunShell.java:213)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557)
Tomcat 5.5 を使用しています。
私は他の多くの相対的な投稿を見てきましたが、助けにはなりませんでした。私も試しましHttpClient
たが、同じ例外がありました.
誰が問題が何であるかを理解できますか?
上のサーブレット構成web.xml
は次のとおりです。
<servlet>
<servlet-name>emailExpireServlet</servlet-name>
<servlet-class>emailExpireServlet</servlet-class>
</servlet>
...
<servlet-mapping>
<servlet-name>emailExpireServlet</servlet-name>
<url-pattern>/emailExpireServlet</url-pattern>
</servlet-mapping>