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