updated to fix ClientAbortException

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@101615 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2014-11-13 18:10:24 +00:00
parent c45ad66f5f
commit d3b01364d2
1 changed files with 29 additions and 21 deletions

View File

@ -3,7 +3,6 @@ package org.gcube.datatransfer.resolver.http;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.SocketException;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.net.URLStreamHandler; import java.net.URLStreamHandler;
@ -44,8 +43,7 @@ public class HttpResolver extends HttpServlet {
} }
protected void doGet(HttpServletRequest request, protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
HttpServletResponse response) throws IOException {
logger.info("The http session id is: " + request.getSession().getId()); logger.info("The http session id is: " + request.getSession().getId());
@ -90,10 +88,9 @@ public class HttpResolver extends HttpServlet {
logger.debug("URI = "+ uri); logger.debug("URI = "+ uri);
InputStream in = null;
try { try {
OutputStream out = response.getOutputStream(); OutputStream out = response.getOutputStream();
if (fileName != null) if (fileName != null)
@ -117,8 +114,6 @@ public class HttpResolver extends HttpServlet {
URLConnection uc = null; URLConnection uc = null;
InputStream in = null;
try { try {
uc = ( URLConnection ) url.openConnection ( ); uc = ( URLConnection ) url.openConnection ( );
in = uc.getInputStream(); in = uc.getInputStream();
@ -138,37 +133,50 @@ public class HttpResolver extends HttpServlet {
in.close(); in.close();
*/ */
if(in!=null)
//CHANGED BY FRANCESCO M. //CHANGED BY FRANCESCO M.
try { try {
IOUtils.copy(in, out); IOUtils.copy(in, out);
} catch (SocketException e){ } catch (IOException e){
if (!e.getClass().getSimpleName().equals("ClientAbortException")) logger.warn("IOException class name: "+e.getClass().getSimpleName());
throw e; if (e.getClass().getSimpleName().equals("ClientAbortException"))
else logger.warn("Skipping ClientAbortException: "+e.getMessage());
logger.warn("Skipping ClientAbortException: "+e.getMessage()); else
throw e; //Sending Exceptions
} catch (NullPointerException e) {
logger.warn("NullPointerException: input stream is null, skipping printStrackTrace");
sendErrorQuietly(response, 404);
} finally { } finally {
IOUtils.closeQuietly(in); IOUtils.closeQuietly(in);
IOUtils.closeQuietly(out); IOUtils.closeQuietly(out);
} }
} catch (Exception e) { } catch (Exception e) {
// e.printStackTrace();
logger.error("Exception:", e); logger.error("Exception:", e);
// response.sendError(404); // response.sendError(404);
IOUtils.closeQuietly(in);
//CHANGED BY FRANCESCO M. sendErrorQuietly(response, 404);
if(!response.isCommitted())
response.sendError(404);
else
logger.warn("Response already committed, skipped send Error 404");
return; return;
} }
} }
protected void sendErrorQuietly(HttpServletResponse response, int code){
if(response!=null){
try {
response.sendError(code);
} catch (IOException ioe) {
// ignore
}
}
}
protected void doPost(HttpServletRequest request, protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws IOException { HttpServletResponse response) throws IOException {
doGet(request,response); doGet(request,response);