feature_23113 #4
|
@ -6,7 +6,9 @@ package org.gcube.datatransfer.resolver.services;
|
|||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
|
@ -14,6 +16,8 @@ import javax.ws.rs.Produces;
|
|||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriBuilder;
|
||||
|
||||
import org.gcube.datatransfer.resolver.services.error.ExceptionManager;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -39,9 +43,9 @@ public class UriResolverDocs {
|
|||
* @throws WebApplicationException the web application exception
|
||||
*/
|
||||
@GET
|
||||
@Produces({ MediaType.TEXT_HTML })
|
||||
//@Produces({ MediaType.TEXT_HTML })
|
||||
@Path("/{any: .*}")
|
||||
public InputStream toDoc(@Context HttpServletRequest req) throws WebApplicationException {
|
||||
public Response toDoc(@Context HttpServletRequest req) throws WebApplicationException {
|
||||
logger.info(UriResolverDocs.class.getSimpleName() + " toDoc called");
|
||||
|
||||
String pathInfo = req.getPathInfo();
|
||||
|
@ -51,10 +55,15 @@ public class UriResolverDocs {
|
|||
if (pathInfo.equals("/docs/"))
|
||||
pathInfo += "index.html";
|
||||
|
||||
logger.info("redirecting to {}", pathInfo);
|
||||
ServletContext context = req.getServletContext();
|
||||
//String realPath = context.getRealPath(pathInfo);
|
||||
UriBuilder builder = UriBuilder.fromPath(context.getContextPath());
|
||||
pathInfo=pathInfo.startsWith("/")?pathInfo:"/"+pathInfo;
|
||||
builder.path(pathInfo);
|
||||
|
||||
String realPath = req.getServletContext().getRealPath(pathInfo);
|
||||
return new FileInputStream(new File(realPath));
|
||||
URI redirectTo = builder.build();
|
||||
logger.info("redirecting to {}", redirectTo);
|
||||
return Response.seeOther(redirectTo).build();
|
||||
} catch (Exception e) {
|
||||
|
||||
if (!(e instanceof WebApplicationException)) {
|
||||
|
|
Loading…
Reference in New Issue