2014-10-10 14:53:39 +02:00
|
|
|
/**
|
2016-01-26 16:22:37 +01:00
|
|
|
*
|
2014-10-10 14:53:39 +02:00
|
|
|
*/
|
|
|
|
package org.gcube.datatransfer.resolver.gis;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.StringReader;
|
|
|
|
import java.net.URLEncoder;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
2016-01-26 16:22:37 +01:00
|
|
|
import java.util.Random;
|
2014-10-10 14:53:39 +02:00
|
|
|
import java.util.Timer;
|
|
|
|
import java.util.TimerTask;
|
|
|
|
|
|
|
|
import javax.servlet.ServletException;
|
|
|
|
import javax.servlet.http.HttpServlet;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
import org.apache.commons.io.IOUtils;
|
2014-10-13 18:55:53 +02:00
|
|
|
import org.gcube.datatransfer.resolver.applicationprofile.ApplicationProfileReader;
|
|
|
|
import org.gcube.datatransfer.resolver.applicationprofile.ScopeUtil;
|
2014-10-14 12:05:38 +02:00
|
|
|
import org.gcube.datatransfer.resolver.gis.GeoRuntimeReader.GEO_SERVICE;
|
2014-10-10 14:53:39 +02:00
|
|
|
import org.gcube.datatransfer.resolver.gis.entity.ServerParameters;
|
2014-10-14 18:36:13 +02:00
|
|
|
import org.gcube.datatransfer.resolver.gis.exception.GeonetworkInstanceException;
|
|
|
|
import org.gcube.datatransfer.resolver.gis.exception.IllegalArgumentException;
|
2014-10-13 18:55:53 +02:00
|
|
|
import org.gcube.datatransfer.resolver.gis.property.GisViewerAppGenericResourcePropertyReader;
|
|
|
|
import org.gcube.datatransfer.resolver.gis.property.PropertyFileNotFoundException;
|
2014-10-10 14:53:39 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2016-01-12 17:34:36 +01:00
|
|
|
|
2014-10-10 14:53:39 +02:00
|
|
|
/**
|
2016-01-12 17:34:36 +01:00
|
|
|
* The Class GisResolver.
|
2014-10-10 14:53:39 +02:00
|
|
|
*
|
2016-01-12 17:34:36 +01:00
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
|
|
* Jan 7, 2016
|
2014-10-10 14:53:39 +02:00
|
|
|
*/
|
|
|
|
public class GisResolver extends HttpServlet{
|
|
|
|
|
2014-10-13 18:55:53 +02:00
|
|
|
private static final String UTF_8 = "UTF-8";
|
|
|
|
private static final String TEXT_PLAIN = "text/plain";
|
2014-10-10 14:53:39 +02:00
|
|
|
public static final String PARAM_SEPARATOR_REPLACEMENT_VALUE = "%%";
|
|
|
|
public static final String PARAM_SEPARATOR_REPLACEMENT_KEY = "separtor";
|
|
|
|
private static final long serialVersionUID = 5605107730993617579L;
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-10 14:53:39 +02:00
|
|
|
public static final String GIS_UUID = "gis-UUID";
|
|
|
|
public static final String SCOPE = "scope";
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-10 14:53:39 +02:00
|
|
|
/** The logger. */
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(GisResolver.class);
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-14 10:45:35 +02:00
|
|
|
protected Map<String, ServerParameters> cachedServerParams; //A cache: scope - geonetwork parameters
|
|
|
|
protected Map<String, String> cachedGisViewerApplHostname; //A cache: scope - GisViewerApp hostname
|
2014-10-10 14:53:39 +02:00
|
|
|
|
|
|
|
private Timer timer;
|
2014-10-13 18:55:53 +02:00
|
|
|
private GisViewerAppGenericResourcePropertyReader gisViewerAppPropertyReader;
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2015-03-03 15:26:46 +01:00
|
|
|
//THIRTY MINUTES
|
|
|
|
public static final long CACHE_RESET_TIME = 30*60*1000;
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2015-03-03 15:26:46 +01:00
|
|
|
//TEN MINUTES
|
|
|
|
public static final long CACHE_RESET_DELAY = 10*1000;
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2016-01-12 17:34:36 +01:00
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see javax.servlet.GenericServlet#init()
|
|
|
|
*/
|
2014-10-10 14:53:39 +02:00
|
|
|
@Override
|
|
|
|
public void init() throws ServletException {
|
|
|
|
super.init();
|
|
|
|
timer = new Timer(true);
|
|
|
|
timer.schedule(new TimerTask() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2014-10-15 12:27:21 +02:00
|
|
|
logger.info("Resetting cache...");
|
2014-10-10 14:53:39 +02:00
|
|
|
reseCacheServerParameters();
|
2016-01-12 17:34:36 +01:00
|
|
|
resetGisViewerAppEndPoint();
|
2014-10-13 18:55:53 +02:00
|
|
|
reseCacheGisViewerApplicationHostname();
|
2014-10-10 14:53:39 +02:00
|
|
|
}
|
2014-10-15 12:27:21 +02:00
|
|
|
}, CACHE_RESET_DELAY, CACHE_RESET_TIME);
|
2014-10-10 14:53:39 +02:00
|
|
|
}
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2016-01-12 17:34:36 +01:00
|
|
|
/**
|
|
|
|
* Gets the cached server parameters.
|
|
|
|
*
|
|
|
|
* @param scope the scope
|
|
|
|
* @return the cached server parameters
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2014-10-10 14:53:39 +02:00
|
|
|
protected ServerParameters getCachedServerParameters(String scope) throws Exception{
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-13 18:55:53 +02:00
|
|
|
if(cachedServerParams==null)
|
2014-10-10 14:53:39 +02:00
|
|
|
reseCacheServerParameters();
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-10 14:53:39 +02:00
|
|
|
logger.info("Tentative to recovering gis server param from cache to scope "+scope);
|
|
|
|
ServerParameters serverParam = cachedServerParams.get(scope);
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-10 14:53:39 +02:00
|
|
|
if(serverParam==null){
|
|
|
|
logger.info("Gis server param is null, reading from application profile..");
|
2014-10-14 12:05:38 +02:00
|
|
|
GeoRuntimeReader reader = new GeoRuntimeReader();
|
2014-10-10 14:53:39 +02:00
|
|
|
try {
|
|
|
|
serverParam = reader.retrieveGisParameters(scope, GEO_SERVICE.GEONETWORK);
|
|
|
|
cachedServerParams.put(scope, serverParam);
|
2014-10-13 18:55:53 +02:00
|
|
|
logger.info("Updated Gis server cache! Scope "+scope+" linking "+serverParam);
|
2014-10-10 14:53:39 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("An error occurred on reading application profile to "+GEO_SERVICE.GEONETWORK, e);
|
|
|
|
throw new Exception("Sorry, An error occurred on reading configuration to "+GEO_SERVICE.GEONETWORK);
|
|
|
|
}
|
|
|
|
}else
|
|
|
|
logger.info("Cache gis server param is not null using it");
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-10 14:53:39 +02:00
|
|
|
logger.info("returning geonetworkParams "+serverParam);
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-10 14:53:39 +02:00
|
|
|
return serverParam;
|
|
|
|
}
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2016-01-12 17:34:36 +01:00
|
|
|
/**
|
|
|
|
* Rese cache server parameters.
|
|
|
|
*/
|
2014-10-10 14:53:39 +02:00
|
|
|
private void reseCacheServerParameters(){
|
|
|
|
cachedServerParams = new HashMap<String, ServerParameters>();
|
|
|
|
logger.info("Cache server params reset!");
|
|
|
|
}
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2016-01-12 17:34:36 +01:00
|
|
|
/**
|
|
|
|
* Rese cache gis viewer application hostname.
|
|
|
|
*/
|
2014-10-13 18:55:53 +02:00
|
|
|
private void reseCacheGisViewerApplicationHostname(){
|
|
|
|
cachedGisViewerApplHostname = new HashMap<String, String>();
|
|
|
|
logger.info("Cache Gis Viewer Hostname reset!");
|
|
|
|
}
|
2016-01-12 17:34:36 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reset gis viewer app end point.
|
|
|
|
*/
|
|
|
|
private void resetGisViewerAppEndPoint(){
|
2014-10-13 18:55:53 +02:00
|
|
|
try {
|
|
|
|
gisViewerAppPropertyReader = new GisViewerAppGenericResourcePropertyReader();
|
|
|
|
logger.info("GisViewerApp end point updated!");
|
|
|
|
} catch (PropertyFileNotFoundException e) {
|
|
|
|
logger.error("Error on reset GisViewerAppEndPoint ",e);
|
|
|
|
}
|
|
|
|
}
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2016-01-12 17:34:36 +01:00
|
|
|
/**
|
|
|
|
* Gets the gis viewer application url.
|
|
|
|
*
|
|
|
|
* @param scope the scope
|
|
|
|
* @return the gis viewer application url
|
|
|
|
* @throws Exception the exception
|
|
|
|
*/
|
2014-10-13 18:55:53 +02:00
|
|
|
protected String getGisViewerApplicationURL(String scope) throws Exception{
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-13 18:55:53 +02:00
|
|
|
if(cachedGisViewerApplHostname==null)
|
|
|
|
reseCacheGisViewerApplicationHostname();
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-13 18:55:53 +02:00
|
|
|
String infra = ScopeUtil.getInfrastructureNameFromScope(scope);
|
2016-01-12 17:34:36 +01:00
|
|
|
logger.info("Tentative of recovering gis viewer application hostname from cache for scope: "+scope);
|
2014-10-13 18:55:53 +02:00
|
|
|
String gisViewerAppHostname = cachedGisViewerApplHostname.get(infra);
|
|
|
|
if(gisViewerAppHostname==null){
|
|
|
|
logger.info("Gis viewer application hostname is null, reading from application profile..");
|
|
|
|
if(gisViewerAppPropertyReader==null)
|
2016-01-12 17:34:36 +01:00
|
|
|
resetGisViewerAppEndPoint();
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-13 18:55:53 +02:00
|
|
|
ApplicationProfileReader reader = new ApplicationProfileReader(infra, gisViewerAppPropertyReader.getGenericResource(), gisViewerAppPropertyReader.getAppId());
|
|
|
|
String url = reader.getApplicationProfile().getUrl();
|
|
|
|
cachedGisViewerApplHostname.put(infra, url);
|
|
|
|
logger.info("Updated GisViewerApplication cache! Scope "+scope+" linking "+url);
|
|
|
|
return url;
|
|
|
|
}else
|
|
|
|
logger.info("Cache Gis viewer application is not null using it");
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-13 18:55:53 +02:00
|
|
|
return gisViewerAppHostname;
|
2016-01-26 16:22:37 +01:00
|
|
|
|
|
|
|
|
2014-10-13 18:55:53 +02:00
|
|
|
}
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-10 14:53:39 +02:00
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
|
|
|
logger.info("The http session id is: " + req.getSession().getId());
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-10 14:53:39 +02:00
|
|
|
String gisUUID = req.getParameter(GIS_UUID);
|
|
|
|
|
|
|
|
if (gisUUID == null || gisUUID.equals("")) {
|
|
|
|
logger.debug("GIS UUID not found");
|
|
|
|
sendError(resp, HttpServletResponse.SC_BAD_REQUEST, GIS_UUID+" not found or empty");
|
|
|
|
return;
|
|
|
|
}
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-10 14:53:39 +02:00
|
|
|
logger.info("GIS UUID is: " + gisUUID);
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-10 14:53:39 +02:00
|
|
|
String scope = req.getParameter(SCOPE);
|
|
|
|
|
|
|
|
if (scope == null || scope.equals("")) {
|
|
|
|
logger.debug("Scope not found");
|
|
|
|
sendError(resp, HttpServletResponse.SC_BAD_REQUEST, SCOPE+" not found or empty");
|
|
|
|
return;
|
|
|
|
}
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-10 14:53:39 +02:00
|
|
|
logger.info("SCOPE is: " + gisUUID);
|
|
|
|
|
|
|
|
try {
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-10 14:53:39 +02:00
|
|
|
ServerParameters geonetworkParams = getCachedServerParameters(scope);
|
|
|
|
String wmsRequest = getLayerWmsRequest(scope, gisUUID, geonetworkParams);
|
2014-10-13 18:55:53 +02:00
|
|
|
logger.info("wms url is: " + wmsRequest);
|
|
|
|
wmsRequest = URLEncoder.encode(wmsRequest, UTF_8);
|
|
|
|
logger.info("encoded WMS url is: " + wmsRequest);
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-13 18:55:53 +02:00
|
|
|
String gisPortletUrl = getGisViewerApplicationURL(scope);
|
|
|
|
logger.info("Gis Viewer Application url is: " + gisPortletUrl);
|
2016-01-26 16:22:37 +01:00
|
|
|
gisPortletUrl+="?rid="+new Random().nextLong()+"&wmsrequest="+wmsRequest;
|
|
|
|
|
|
|
|
/*resp.setContentType(TEXT_PLAIN);
|
|
|
|
resp.setCharacterEncoding(UTF_8);
|
2014-10-13 18:55:53 +02:00
|
|
|
PrintWriter out = resp.getWriter();
|
|
|
|
out.println(gisPortletUrl);
|
2014-10-14 11:20:47 +02:00
|
|
|
logger.info("returning link: " + gisPortletUrl);
|
2014-10-14 12:28:35 +02:00
|
|
|
out.close();*/
|
|
|
|
urlRedirect(req, resp, gisPortletUrl);
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-14 18:36:13 +02:00
|
|
|
} catch (IllegalArgumentException e){
|
|
|
|
logger.error("IllegalArgumentException:", e);
|
2014-10-14 18:38:01 +02:00
|
|
|
sendError(resp, HttpServletResponse.SC_BAD_REQUEST, "Illegal argument to carry out the request!");
|
2014-10-14 18:36:13 +02:00
|
|
|
return;
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-10 14:53:39 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("Exception:", e);
|
|
|
|
String error = "Sorry, an error occurred on resolving request with UUID "+gisUUID+" and scope "+scope+". Please, contact support!";
|
|
|
|
sendError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, error);
|
|
|
|
return;
|
|
|
|
}
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-10 14:53:39 +02:00
|
|
|
}
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-10 14:53:39 +02:00
|
|
|
/**
|
2016-01-12 17:34:36 +01:00
|
|
|
* Encode url with param delimiter.
|
|
|
|
*
|
|
|
|
* @param wmsRequest the wms request
|
|
|
|
* @return the string
|
2014-10-10 14:53:39 +02:00
|
|
|
*/
|
|
|
|
private String encodeURLWithParamDelimiter(String wmsRequest){
|
|
|
|
return wmsRequest.replaceAll("&", PARAM_SEPARATOR_REPLACEMENT_VALUE);
|
|
|
|
}
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-10 14:53:39 +02:00
|
|
|
/**
|
2016-01-12 17:34:36 +01:00
|
|
|
* Decode url with param delimiter.
|
|
|
|
*
|
|
|
|
* @param wmsRequest the wms request
|
|
|
|
* @return the string
|
2014-10-10 14:53:39 +02:00
|
|
|
*/
|
|
|
|
private String decodeURLWithParamDelimiter(String wmsRequest){
|
|
|
|
return wmsRequest.replaceAll(PARAM_SEPARATOR_REPLACEMENT_VALUE, "&");
|
|
|
|
}
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-10 14:53:39 +02:00
|
|
|
/**
|
2016-01-12 17:34:36 +01:00
|
|
|
* Append param replacement.
|
|
|
|
*
|
|
|
|
* @param wmsRequest the wms request
|
|
|
|
* @return the string
|
2014-10-10 14:53:39 +02:00
|
|
|
*/
|
|
|
|
private String appendParamReplacement(String wmsRequest){
|
|
|
|
return wmsRequest+"&"+PARAM_SEPARATOR_REPLACEMENT_KEY+"="+PARAM_SEPARATOR_REPLACEMENT_VALUE;
|
|
|
|
}
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-10 14:53:39 +02:00
|
|
|
/**
|
2016-01-12 17:34:36 +01:00
|
|
|
* Gets the layer wms request.
|
|
|
|
*
|
|
|
|
* @param scope the scope
|
|
|
|
* @param gisUUID the gis uuid
|
|
|
|
* @param geonetworkParams the geonetwork params
|
|
|
|
* @return the layer wms request
|
|
|
|
* @throws Exception the exception
|
2014-10-10 14:53:39 +02:00
|
|
|
*/
|
|
|
|
protected String getLayerWmsRequest(String scope, String gisUUID, ServerParameters geonetworkParams) throws Exception{
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-10 14:53:39 +02:00
|
|
|
try {
|
|
|
|
GeonetworkServiceInterface gntwAccess = new GeonetowrkAccessParameter(scope, geonetworkParams);
|
|
|
|
return MetadataConverter.getWMSOnLineResource(gntwAccess.getGeonetworkInstance(true), gisUUID);
|
2014-10-14 18:36:13 +02:00
|
|
|
}catch (GeonetworkInstanceException e){
|
|
|
|
logger.error("An error occurred when instancing geonetowrk gis layer with UUID "+gisUUID, e);
|
|
|
|
throw new IllegalArgumentException("Sorry, An error occurred when instancing geonetwork with UUID: "+gisUUID);
|
2014-10-10 14:53:39 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("An error occurred when retrieving gis layer with UUID "+gisUUID, e);
|
2014-10-14 18:36:13 +02:00
|
|
|
throw new IllegalArgumentException("Sorry, An error occurred when retrieving gis layer with UUID "+gisUUID);
|
2014-10-10 14:53:39 +02:00
|
|
|
}
|
|
|
|
}
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-10 14:53:39 +02:00
|
|
|
/* (non-Javadoc)
|
|
|
|
* @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void doPost(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {
|
|
|
|
this.doGet(req, resp);
|
|
|
|
}
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-10 14:53:39 +02:00
|
|
|
/**
|
2016-01-12 17:34:36 +01:00
|
|
|
* Send error.
|
|
|
|
*
|
|
|
|
* @param response the response
|
|
|
|
* @param status the status
|
|
|
|
* @param message the message
|
|
|
|
* @throws IOException Signals that an I/O exception has occurred.
|
2014-10-10 14:53:39 +02:00
|
|
|
*/
|
|
|
|
protected void sendError(HttpServletResponse response, int status, String message) throws IOException
|
2016-01-26 16:22:37 +01:00
|
|
|
{
|
2014-10-10 14:53:39 +02:00
|
|
|
// response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
response.setStatus(status);
|
|
|
|
logger.info("error message: "+message);
|
|
|
|
logger.info("writing response...");
|
|
|
|
StringReader sr = new StringReader(message);
|
|
|
|
IOUtils.copy(sr, response.getOutputStream());
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-10 14:53:39 +02:00
|
|
|
// response.getWriter().write(resultMessage.toString());
|
|
|
|
logger.info("response writed");
|
|
|
|
response.flushBuffer();
|
|
|
|
}
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2016-01-12 17:34:36 +01:00
|
|
|
/**
|
|
|
|
* Url redirect.
|
|
|
|
*
|
|
|
|
* @param req the req
|
|
|
|
* @param response the response
|
|
|
|
* @param redirectTo the redirect to
|
|
|
|
* @throws IOException Signals that an I/O exception has occurred.
|
|
|
|
*/
|
2014-10-10 14:53:39 +02:00
|
|
|
protected void urlRedirect(HttpServletRequest req, HttpServletResponse response, String redirectTo) throws IOException {
|
|
|
|
response.sendRedirect(response.encodeRedirectURL(redirectTo));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-12 17:34:36 +01:00
|
|
|
/**
|
|
|
|
* Gets the request url.
|
|
|
|
*
|
|
|
|
* @param req the req
|
|
|
|
* @return the request url
|
|
|
|
*/
|
2014-10-10 14:53:39 +02:00
|
|
|
public static String getRequestURL(HttpServletRequest req) {
|
|
|
|
|
|
|
|
String scheme = req.getScheme(); // http
|
|
|
|
String serverName = req.getServerName(); // hostname.com
|
|
|
|
int serverPort = req.getServerPort(); // 80
|
|
|
|
String contextPath = req.getContextPath(); // /mywebapp
|
|
|
|
// String servletPath = req.getServletPath(); // /servlet/MyServlet
|
|
|
|
// String pathInfo = req.getPathInfo(); // /a/b;c=123
|
|
|
|
// String queryString = req.getQueryString(); // d=789
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-10 14:53:39 +02:00
|
|
|
// Reconstruct original requesting URL
|
|
|
|
StringBuffer url = new StringBuffer();
|
|
|
|
url.append(scheme).append("://").append(serverName);
|
2016-01-26 16:22:37 +01:00
|
|
|
|
|
|
|
if (serverPort != 80 && serverPort != 443) {
|
2014-10-10 14:53:39 +02:00
|
|
|
url.append(":").append(serverPort);
|
|
|
|
}
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-10 14:53:39 +02:00
|
|
|
logger.trace("server: "+url);
|
|
|
|
logger.trace("omitted contextPath: "+contextPath);
|
|
|
|
return url.toString();
|
|
|
|
}
|
2016-01-12 17:34:36 +01:00
|
|
|
/*
|
2014-10-10 14:53:39 +02:00
|
|
|
public static void main(String[] args) {
|
|
|
|
GisResolver gisResolver = new GisResolver();
|
|
|
|
String scope = "/gcube/devsec/devVRE";
|
|
|
|
String UUID = "177e1c3c-4a22-4ad9-b015-bfc443d16cb8";
|
|
|
|
try {
|
|
|
|
ServerParameters geonetworkParams = gisResolver.getCachedServerParameters(scope);
|
|
|
|
String wmsRequest = gisResolver.getLayerWmsRequest(scope, UUID, geonetworkParams);
|
|
|
|
logger.info("Final url is: " + wmsRequest);
|
2014-10-13 18:55:53 +02:00
|
|
|
wmsRequest = URLEncoder.encode(wmsRequest, UTF_8);
|
2014-10-10 14:53:39 +02:00
|
|
|
logger.info("Encoded WMS request is: " + wmsRequest);
|
2014-10-13 18:55:53 +02:00
|
|
|
String gisPortletUrl = gisResolver.getGisViewerApplicationURL(scope);
|
|
|
|
logger.info("Gis Viewer Application url is: " + gisPortletUrl);
|
|
|
|
// logger.info("WmsRequest is: " + wmsRequest);
|
|
|
|
// wmsRequest = encodeURLWithParamDelimiter(wmsRequest);
|
|
|
|
// logger.info("Encoded url is: " + wmsRequest);
|
|
|
|
// wmsRequest = appendParamReplacement(wmsRequest);
|
|
|
|
gisPortletUrl+="?wmsrequest="+wmsRequest;
|
2016-01-26 16:22:37 +01:00
|
|
|
|
2014-10-13 18:55:53 +02:00
|
|
|
System.out.println(gisPortletUrl);
|
2014-10-10 14:53:39 +02:00
|
|
|
// urlRedirect(req, resp, gisPortletUrl);
|
|
|
|
} catch (Exception e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2016-01-12 17:34:36 +01:00
|
|
|
}*/
|
2014-10-10 14:53:39 +02:00
|
|
|
}
|