mirror of
https://github.com/zxing/zxing.git
synced 2024-11-09 20:44:03 -08:00
Untangle try-catch a bit in servlet, to properly catch 404 errors
This commit is contained in:
parent
937d087365
commit
7f300ce09a
|
@ -205,44 +205,39 @@ public final class DecodeServlet extends HttpServlet {
|
|||
connection.setRequestProperty(HttpHeaders.CONNECTION, "close");
|
||||
|
||||
try {
|
||||
connection.connect();
|
||||
} catch (IOException ioe) {
|
||||
// Encompasses lots of stuff, including
|
||||
// java.net.SocketException, java.net.UnknownHostException,
|
||||
// javax.net.ssl.SSLPeerUnverifiedException,
|
||||
// org.apache.http.NoHttpResponseException,
|
||||
// org.apache.http.client.ClientProtocolException,
|
||||
log.info(ioe.toString());
|
||||
response.sendRedirect("badurl.jspx");
|
||||
return;
|
||||
}
|
||||
|
||||
try (InputStream is = connection.getInputStream()) {
|
||||
try {
|
||||
connection.connect();
|
||||
} catch (IOException ioe) {
|
||||
// Encompasses lots of stuff, including
|
||||
// java.net.SocketException, java.net.UnknownHostException,
|
||||
// javax.net.ssl.SSLPeerUnverifiedException,
|
||||
// org.apache.http.NoHttpResponseException,
|
||||
// org.apache.http.client.ClientProtocolException,
|
||||
log.info(ioe.toString());
|
||||
response.sendRedirect("badurl.jspx");
|
||||
return;
|
||||
}
|
||||
|
||||
try (InputStream is = connection.getInputStream()) {
|
||||
try {
|
||||
if (connection.getResponseCode() != HttpServletResponse.SC_OK) {
|
||||
log.info("Unsuccessful return code: " + connection.getResponseCode());
|
||||
response.sendRedirect("badurl.jspx");
|
||||
return;
|
||||
}
|
||||
if (connection.getHeaderFieldInt(HttpHeaders.CONTENT_LENGTH, 0) > MAX_IMAGE_SIZE) {
|
||||
log.info("Too large");
|
||||
response.sendRedirect("badimage.jspx");
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("Decoding " + imageURL);
|
||||
processStream(is, request, response);
|
||||
|
||||
} catch (IOException ioe) {
|
||||
log.info(ioe.toString());
|
||||
if (connection.getResponseCode() != HttpServletResponse.SC_OK) {
|
||||
log.info("Unsuccessful return code: " + connection.getResponseCode());
|
||||
response.sendRedirect("badurl.jspx");
|
||||
} finally {
|
||||
consumeRemainder(is);
|
||||
return;
|
||||
}
|
||||
if (connection.getHeaderFieldInt(HttpHeaders.CONTENT_LENGTH, 0) > MAX_IMAGE_SIZE) {
|
||||
log.info("Too large");
|
||||
response.sendRedirect("badimage.jspx");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
log.info("Decoding " + imageURL);
|
||||
processStream(is, request, response);
|
||||
} finally {
|
||||
consumeRemainder(is);
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
log.info(ioe.toString());
|
||||
response.sendRedirect("badurl.jspx");
|
||||
} finally {
|
||||
connection.disconnect();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue