mirror of
https://github.com/zxing/zxing.git
synced 2025-01-12 11:47:26 -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");
|
connection.setRequestProperty(HttpHeaders.CONNECTION, "close");
|
||||||
|
|
||||||
try {
|
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 {
|
try {
|
||||||
connection.connect();
|
if (connection.getResponseCode() != HttpServletResponse.SC_OK) {
|
||||||
} catch (IOException ioe) {
|
log.info("Unsuccessful return code: " + connection.getResponseCode());
|
||||||
// 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());
|
|
||||||
response.sendRedirect("badurl.jspx");
|
response.sendRedirect("badurl.jspx");
|
||||||
} finally {
|
return;
|
||||||
consumeRemainder(is);
|
}
|
||||||
|
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 {
|
} finally {
|
||||||
connection.disconnect();
|
connection.disconnect();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue