added StaticFileController
This commit is contained in:
parent
bc3b6c4c04
commit
ebad8120df
|
@ -30,8 +30,7 @@ public class ConstantsResolver {
|
||||||
public static final String QUERY_PARAM_CONTENT_TYPE = "contentType";
|
public static final String QUERY_PARAM_CONTENT_TYPE = "contentType";
|
||||||
public static final String QUERY_PARAM_FILE_NAME = "fileName";
|
public static final String QUERY_PARAM_FILE_NAME = "fileName";
|
||||||
|
|
||||||
//img is the path to refer images from https://data.dev.d4science.org/img/*
|
public static final String[] resourcesHardCoded = { "ctlg" };
|
||||||
public static final String[] resourcesHardCoded = { "ctlg", "img" };
|
|
||||||
|
|
||||||
// The default resource candidate to manage the input requests not matching any
|
// The default resource candidate to manage the input requests not matching any
|
||||||
// resolver services
|
// resolver services
|
||||||
|
|
|
@ -18,8 +18,8 @@ public class UriResolver extends ResourceConfig {
|
||||||
// Register all resources present under the package.
|
// Register all resources present under the package.
|
||||||
packages(CatalogueResolver.class.getPackage().getName(), RequestHandler.class.getPackage().getName(), BackCatalogueResolver.class.getPackage().getName());
|
packages(CatalogueResolver.class.getPackage().getName(), RequestHandler.class.getPackage().getName(), BackCatalogueResolver.class.getPackage().getName());
|
||||||
packages(DataMinerInvocation.class.getPackage().getName());
|
packages(DataMinerInvocation.class.getPackage().getName());
|
||||||
|
//
|
||||||
// register(JspMvcFeature.class);
|
// register(JspMvcFeature.class);
|
||||||
//property(JspMvcFeature.TEMPLATE_BASE_PATH, "/WEB-INF/jsp");
|
// property(JspMvcFeature.TEMPLATE_BASE_PATH, "/WEB-INF/img");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.datatransfer.resolver.services;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.WebApplicationException;
|
||||||
|
import javax.ws.rs.core.Context;
|
||||||
|
|
||||||
|
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class StaticFileController.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* May 2, 2024
|
||||||
|
*/
|
||||||
|
@Path("pub")
|
||||||
|
public class StaticFileController {
|
||||||
|
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(StaticFileController.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To doc.
|
||||||
|
*
|
||||||
|
* @param req the req
|
||||||
|
* @return the input stream
|
||||||
|
* @throws WebApplicationException the web application exception
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Path("/{any: .*}")
|
||||||
|
public InputStream toFile(@Context HttpServletRequest req) throws WebApplicationException {
|
||||||
|
logger.info(StaticFileController.class.getSimpleName() + " toFile called");
|
||||||
|
|
||||||
|
String pathInfo = req.getPathInfo();
|
||||||
|
logger.debug("pathInfo {}", pathInfo);
|
||||||
|
try {
|
||||||
|
|
||||||
|
logger.info("going to {}", pathInfo);
|
||||||
|
|
||||||
|
String realPath = req.getServletContext().getRealPath(pathInfo);
|
||||||
|
return new FileInputStream(new File(realPath));
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
if (!(e instanceof WebApplicationException)) {
|
||||||
|
// UNEXPECTED EXCEPTION managing it as WebApplicationException
|
||||||
|
String error = pathInfo + " not found. Please, contact the support!";
|
||||||
|
throw ExceptionManager.internalErrorException(req, error, this.getClass(), null);
|
||||||
|
}
|
||||||
|
// ALREADY MANAGED AS WebApplicationException
|
||||||
|
logger.error("Exception:", e);
|
||||||
|
throw (WebApplicationException) e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 55 KiB |
Loading…
Reference in New Issue