integrated url validation
git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/uri-resolver@101618 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
d3b01364d2
commit
b75e4a8692
|
@ -24,13 +24,16 @@ import org.slf4j.LoggerFactory;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Andrea Manzi(CERN)
|
* @author Andrea Manzi(CERN)
|
||||||
|
* updated by Francesco Mangiacrapa
|
||||||
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class HttpResolver extends HttpServlet {
|
public class HttpResolver extends HttpServlet {
|
||||||
|
|
||||||
String uri =null;
|
protected static final String SMP_URI = "smp-uri";
|
||||||
String fileName =null;
|
protected static final String VALIDATION = "validation";
|
||||||
String contentType =null;
|
protected static final String CONTENT_TYPE = "contentType";
|
||||||
|
protected static final String FILE_NAME = "fileName";
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@ -44,14 +47,15 @@ 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());
|
|
||||||
|
|
||||||
logger.debug("Original URI = "+ uri);
|
String uri =null;
|
||||||
|
String fileName =null;
|
||||||
|
String contentType =null;
|
||||||
|
boolean validatingURI = false;
|
||||||
|
|
||||||
|
// logger.info("The http session id is: " + request.getSession().getId());
|
||||||
uri = request.getParameter("smp-uri");
|
|
||||||
|
uri = request.getParameter(SMP_URI);
|
||||||
|
|
||||||
if (uri == null || uri.equals("")) {
|
if (uri == null || uri.equals("")) {
|
||||||
logger.debug("URI not found");
|
logger.debug("URI not found");
|
||||||
|
@ -59,7 +63,7 @@ public class HttpResolver extends HttpServlet {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fileName = request.getParameter("fileName");
|
fileName = request.getParameter(FILE_NAME);
|
||||||
|
|
||||||
|
|
||||||
if (fileName == null || fileName.equals("")) {
|
if (fileName == null || fileName.equals("")) {
|
||||||
|
@ -67,13 +71,17 @@ public class HttpResolver extends HttpServlet {
|
||||||
fileName = null;
|
fileName = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
contentType = request.getParameter("contentType");
|
contentType = request.getParameter(CONTENT_TYPE);
|
||||||
|
|
||||||
if (contentType == null || contentType.equals("")) {
|
if (contentType == null || contentType.equals("")) {
|
||||||
logger.debug("contentType not found");
|
logger.debug("contentType not found");
|
||||||
contentType = null;
|
contentType = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String validation = request.getParameter(VALIDATION);
|
||||||
|
validatingURI = Boolean.parseBoolean(validation);
|
||||||
|
logger.debug("validation? "+validatingURI);
|
||||||
|
|
||||||
//we should not unescape the filename with spaces
|
//we should not unescape the filename with spaces
|
||||||
|
|
||||||
int index= uri.indexOf("?");
|
int index= uri.indexOf("?");
|
||||||
|
@ -123,8 +131,27 @@ public class HttpResolver extends HttpServlet {
|
||||||
logger.error("URLConnection Exception:", e);
|
logger.error("URLConnection Exception:", e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//CASE InputStream NULL
|
||||||
|
if(in==null){
|
||||||
|
logger.warn("Input stream is null, sending status error 404");
|
||||||
|
sendErrorQuietly(response, 404);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//CASE VALIDATION
|
||||||
|
if(validatingURI){
|
||||||
|
byte[] bytes = new byte[1]; //1B
|
||||||
|
int c = in.read(bytes);
|
||||||
|
logger.info(c+" byte read from InputStream");
|
||||||
|
if(c>0){
|
||||||
|
logger.info("at least 1 byte read, returning status 200");
|
||||||
|
IOUtils.closeQuietly(in);
|
||||||
|
response.setStatus(200);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
IOUtils.copy(in, out);
|
IOUtils.copy(in, out);
|
||||||
|
|
||||||
|
@ -133,8 +160,6 @@ public class HttpResolver extends HttpServlet {
|
||||||
in.close();
|
in.close();
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if(in!=null)
|
|
||||||
|
|
||||||
//CHANGED BY FRANCESCO M.
|
//CHANGED BY FRANCESCO M.
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
@ -148,7 +173,7 @@ public class HttpResolver extends HttpServlet {
|
||||||
throw e; //Sending Exceptions
|
throw e; //Sending Exceptions
|
||||||
|
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
logger.warn("NullPointerException: input stream is null, skipping printStrackTrace");
|
logger.warn("NullPointerException during copy, skipping printStrackTrace");
|
||||||
sendErrorQuietly(response, 404);
|
sendErrorQuietly(response, 404);
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -171,6 +196,7 @@ public class HttpResolver extends HttpServlet {
|
||||||
if(response!=null){
|
if(response!=null){
|
||||||
try {
|
try {
|
||||||
response.sendError(code);
|
response.sendError(code);
|
||||||
|
logger.info("Response sent error: "+code);
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue