mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Better separated out email decoding functionality
git-svn-id: https://zxing.googlecode.com/svn/trunk@558 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
966c5a8e97
commit
970382f1e0
50
zxingorg/src/com/google/zxing/web/DecodeEmailListener.java
Normal file
50
zxingorg/src/com/google/zxing/web/DecodeEmailListener.java
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright 2008 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.web;
|
||||
|
||||
import javax.mail.Authenticator;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
import java.util.Timer;
|
||||
|
||||
/**
|
||||
* @author Sean Owen (srowen@google.com)
|
||||
*/
|
||||
public final class DecodeEmailListener implements ServletContextListener {
|
||||
|
||||
private static final long EMAIL_CHECK_INTERVAL = 3L * 60 * 1000;
|
||||
|
||||
private Timer emailTimer;
|
||||
|
||||
public void contextInitialized(ServletContextEvent event) {
|
||||
ServletContext context = event.getServletContext();
|
||||
String emailAddress = context.getInitParameter("emailAddress");
|
||||
String emailPassword = context.getInitParameter("emailPassword");
|
||||
if (emailAddress == null || emailPassword == null) {
|
||||
throw new IllegalArgumentException("emailAddress or emailPassword not specified");
|
||||
}
|
||||
Authenticator emailAuthenticator = new EmailAuthenticator(emailAddress, emailPassword);
|
||||
emailTimer = new Timer("Email decoder timer", true);
|
||||
emailTimer.schedule(new DecodeEmailTask(emailAddress, emailAuthenticator), 0L, EMAIL_CHECK_INTERVAL);
|
||||
}
|
||||
|
||||
public void contextDestroyed(ServletContextEvent event) {
|
||||
emailTimer.cancel();
|
||||
}
|
||||
|
||||
}
|
|
@ -47,7 +47,6 @@ import org.apache.http.params.HttpParams;
|
|||
import org.apache.http.params.HttpProtocolParams;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.mail.Authenticator;
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
|
@ -64,7 +63,6 @@ import java.net.URISyntaxException;
|
|||
import java.net.UnknownHostException;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
|
@ -76,7 +74,6 @@ import java.util.logging.Logger;
|
|||
public final class DecodeServlet extends HttpServlet {
|
||||
|
||||
private static final long MAX_IMAGE_SIZE = 500000L;
|
||||
private static final long EMAIL_CHECK_INTERVAL = 2L * 60 * 1000;
|
||||
|
||||
private static final Logger log = Logger.getLogger(DecodeServlet.class.getName());
|
||||
|
||||
|
@ -89,20 +86,13 @@ public final class DecodeServlet extends HttpServlet {
|
|||
|
||||
private HttpClient client;
|
||||
private DiskFileItemFactory diskFileItemFactory;
|
||||
private Timer emailTimer;
|
||||
|
||||
@Override
|
||||
public void init(ServletConfig servletConfig) throws ServletException {
|
||||
public void init(ServletConfig servletConfig) {
|
||||
|
||||
Logger logger = Logger.getLogger("com.google.zxing");
|
||||
logger.addHandler(new ServletContextLogHandler(servletConfig.getServletContext()));
|
||||
|
||||
String emailAddress = servletConfig.getInitParameter("emailAddress");
|
||||
String emailPassword = servletConfig.getInitParameter("emailPassword");
|
||||
if (emailAddress == null || emailPassword == null) {
|
||||
throw new ServletException("emailAddress or emailPassword not specified");
|
||||
}
|
||||
|
||||
HttpParams params = new BasicHttpParams();
|
||||
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
|
||||
|
||||
|
@ -114,10 +104,6 @@ public final class DecodeServlet extends HttpServlet {
|
|||
|
||||
diskFileItemFactory = new DiskFileItemFactory();
|
||||
|
||||
Authenticator emailAuthenticator = new EmailAuthenticator(emailAddress, emailPassword);
|
||||
emailTimer = new Timer("Email decoder timer", true);
|
||||
emailTimer.schedule(new DecodeEmailTask(emailAddress, emailAuthenticator), 0L, EMAIL_CHECK_INTERVAL);
|
||||
|
||||
log.info("DecodeServlet configured");
|
||||
}
|
||||
|
||||
|
@ -304,7 +290,6 @@ public final class DecodeServlet extends HttpServlet {
|
|||
@Override
|
||||
public void destroy() {
|
||||
log.config("DecodeServlet shutting down...");
|
||||
emailTimer.cancel();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,18 +28,22 @@
|
|||
<listener>
|
||||
<listener-class>org.apache.commons.fileupload.servlet.FileCleanerCleanup</listener-class>
|
||||
</listener>
|
||||
<listener>
|
||||
<listener-class>com.google.zxing.web.DecodeEmailListener</listener-class>
|
||||
</listener>
|
||||
|
||||
<context-param>
|
||||
<param-name>emailAddress</param-name>
|
||||
<param-value>w@zxing.org</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>emailPassword</param-name>
|
||||
<param-value>@EMAIL_PASSWORD@</param-value>
|
||||
</context-param>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>DecodeServlet</servlet-name>
|
||||
<servlet-class>com.google.zxing.web.DecodeServlet</servlet-class>
|
||||
<init-param>
|
||||
<param-name>emailAddress</param-name>
|
||||
<param-value>w@zxing.org</param-value>
|
||||
</init-param>
|
||||
<init-param>
|
||||
<param-name>emailPassword</param-name>
|
||||
<param-value>@EMAIL_PASSWORD@</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
|
||||
|
|
Loading…
Reference in a new issue