Skip to content

Commit

Permalink
Update zxing.org libs, update NOTICE, try again to fix CLOSE_WAIT iss…
Browse files Browse the repository at this point in the history
…ue with simpler HTTP client handling

git-svn-id: https://zxing.googlecode.com/svn/trunk@2237 59b500cc-1b3d-0410-9834-0bbf25fbcc57
  • Loading branch information
srowen committed Mar 29, 2012
1 parent 674783b commit bd1d0c4
Show file tree
Hide file tree
Showing 14 changed files with 19 additions and 27 deletions.
10 changes: 10 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,13 @@ Copyright 2005-2006 Dietmar Bürkle
Portions of this software were contributed under section 5 of the
Apache License. Contributors are listed under:
http://barcode4j.sourceforge.net/contributors.html

--------------------------------------------------------------------------------
NOTICES FOR APACHE HTTPCOMPONENTS, COMMONS IO, COMMONS LANG,
COMMONS LOGGING, COMMONS FILEUPLOAD
--------------------------------------------------------------------------------

Copyright 1999-2012 The Apache Software Foundation

This product includes software developed by
The Apache Software Foundation (http://www.apache.org/).
36 changes: 9 additions & 27 deletions zxingorg/src/com/google/zxing/web/DecodeServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,12 @@
import org.apache.http.Header;
import org.apache.http.HttpMessage;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.HttpEntity;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.SingleClientConnManager;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
import org.apache.http.util.EntityUtils;

import java.awt.color.CMMException;
Expand All @@ -72,6 +63,7 @@
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -109,33 +101,23 @@ public final class DecodeServlet extends HttpServlet {
HINTS_PURE.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE);
}

private HttpParams params;
private SchemeRegistry registry;
private DiskFileItemFactory diskFileItemFactory;
private HttpClient client;

@Override
public void init(ServletConfig servletConfig) {

Logger logger = Logger.getLogger("com.google.zxing");
logger.addHandler(new ServletContextLogHandler(servletConfig.getServletContext()));

params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);

registry = new SchemeRegistry();
registry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
registry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));

diskFileItemFactory = new DiskFileItemFactory();

client = new DefaultHttpClient();
log.info("DecodeServlet configured");
}

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String imageURIString = request.getParameter("u");
if (imageURIString == null || imageURIString.length() == 0) {
if (imageURIString == null || imageURIString.isEmpty()) {
log.fine("URI was empty");
response.sendRedirect("badurl.jspx");
return;
Expand All @@ -158,9 +140,6 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
return;
}

ClientConnectionManager connectionManager = new SingleClientConnManager(registry);
HttpClient client = new DefaultHttpClient(connectionManager, params);

HttpUriRequest getRequest = new HttpGet(imageURI);
getRequest.addHeader("Connection", "close"); // Avoids CLOSE_WAIT socket issue?

Expand Down Expand Up @@ -215,14 +194,16 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
}

} finally {
connectionManager.shutdown();
ClientConnectionManager connectionManager = client.getConnectionManager();
connectionManager.closeExpiredConnections();
connectionManager.closeIdleConnections(1, TimeUnit.SECONDS);
}

}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
throws ServletException, IOException {

if (!ServletFileUpload.isMultipartContent(request)) {
log.fine("File upload was not multipart");
Expand Down Expand Up @@ -409,6 +390,7 @@ private static boolean isSizeOK(HttpMessage getResponse) {
@Override
public void destroy() {
log.config("DecodeServlet shutting down...");
client.getConnectionManager().shutdown();
}

}
Binary file removed zxingorg/web/WEB-INF/lib/commons-io-1.4.jar
Binary file not shown.
Binary file added zxingorg/web/WEB-INF/lib/commons-io-2.1.jar
Binary file not shown.
Binary file removed zxingorg/web/WEB-INF/lib/commons-lang-2.4.jar
Binary file not shown.
Binary file added zxingorg/web/WEB-INF/lib/commons-lang-2.6.jar
Binary file not shown.
Binary file added zxingorg/web/WEB-INF/lib/fluent-hc-4.2-beta1.jar
Binary file not shown.
Binary file removed zxingorg/web/WEB-INF/lib/httpclient-4.1.2.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed zxingorg/web/WEB-INF/lib/httpcore-4.1.3.jar
Binary file not shown.
Binary file added zxingorg/web/WEB-INF/lib/httpcore-4.2-beta1.jar
Binary file not shown.
Binary file removed zxingorg/web/WEB-INF/lib/httpcore-nio-4.1.3.jar
Binary file not shown.
Binary file not shown.

0 comments on commit bd1d0c4

Please sign in to comment.