feature_23113 #4

Merged
francesco.mangiacrapa merged 58 commits from feature_23113 into master 2022-04-06 09:59:06 +02:00
1 changed files with 40 additions and 27 deletions
Showing only changes of commit 50c822904e - Show all commits

View File

@ -21,44 +21,57 @@ import org.slf4j.LoggerFactory;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Oct 22, 2018
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Oct 22, 2018
*/
@Path("docs/*")
@Path("docs")
public class UriResolverDocs {
private static Logger logger = LoggerFactory.getLogger(UriResolverDocs.class);
@GET
@Produces({MediaType.TEXT_HTML})
@Path("")
public InputStream index(@Context HttpServletRequest req) throws WebApplicationException{
logger.info(UriResolverDocs.class.getSimpleName() +" called");
String requestURI = req.getRequestURI();
try{
if(requestURI == null)
requestURI = "/index.html";
String pathInfo = req.getPathInfo();
logger.info("pathInfo {}",pathInfo);
logger.info("request URI {}", requestURI);
String realPath = req.getServletContext().getRealPath("/docs/"+requestURI);
return new FileInputStream(new File(realPath));
}catch (Exception e) {
@Produces({ MediaType.TEXT_HTML })
@Path("/")
public InputStream index(@Context HttpServletRequest req) throws WebApplicationException {
logger.info(UriResolverDocs.class.getSimpleName() + " called");
if(!(e instanceof WebApplicationException)){
//UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = requestURI+" not found. Please, contact the support!";
String requestURI = req.getRequestURI();
try {
if (requestURI == null)
requestURI = "/index.html";
String pathInfo = req.getPathInfo();
logger.info("pathInfo {}", pathInfo);
logger.info("request URI {}", requestURI);
String realPath = req.getServletContext().getRealPath("/docs/" + requestURI);
return new FileInputStream(new File(realPath));
} catch (Exception e) {
if (!(e instanceof WebApplicationException)) {
// UNEXPECTED EXCEPTION managing it as WebApplicationException
String error = requestURI + " not found. Please, contact the support!";
throw ExceptionManager.internalErrorException(req, error, this.getClass(), null);
}
//ALREADY MANAGED AS WebApplicationException
// ALREADY MANAGED AS WebApplicationException
logger.error("Exception:", e);
throw (WebApplicationException) e;
}
}
}
@GET
@Produces({ MediaType.TEXT_HTML })
@Path("*")
public InputStream toDoc1(@Context HttpServletRequest req) throws WebApplicationException {
logger.info(UriResolverDocs.class.getSimpleName() + " toDoc1 called");
return index(req);
}
@GET
@Produces({ MediaType.TEXT_HTML })
@Path("/*")
public InputStream toDoc2(@Context HttpServletRequest req) throws WebApplicationException {
logger.info(UriResolverDocs.class.getSimpleName() + " toDoc2 called");
return index(req);
}
}