integrated the GeoportalExporterActionServlet
This commit is contained in:
parent
b8be15921e
commit
9e49f6f281
|
@ -30,5 +30,10 @@
|
|||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/geoportal-data-viewer-app-3.7.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/geoportal-data-viewer-app-3.7.0-SNAPSHOT/WEB-INF/classes"/>
|
||||
</classpath>
|
||||
|
|
|
@ -1,5 +1,25 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -109,7 +129,27 @@
|
|||
|
||||
|
||||
<wb-module deploy-name="geoportal-data-viewer-app-3.7.0-SNAPSHOT">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -219,7 +259,27 @@
|
|||
|
||||
|
||||
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -329,7 +389,27 @@
|
|||
|
||||
|
||||
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -439,7 +519,27 @@
|
|||
|
||||
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/gwt"/>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -549,7 +649,49 @@
|
|||
|
||||
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
|
||||
<dependent-module archiveName="geoportal-data-mapper-1.1.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/geoportal-data-mapper/geoportal-data-mapper">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
<dependent-module archiveName="uri-resolver-manager-1.8.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/uri-resolver-manager/uri-resolver-manager">
|
||||
<dependency-type>uses</dependency-type>
|
||||
</dependent-module>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -659,7 +801,27 @@
|
|||
|
||||
|
||||
<property name="java-output-path" value="/geoportal-data-viewer-app/target/geoportal-data-viewer-app-0.0.1-SNAPSHOT/WEB-INF/classes"/>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -769,7 +931,27 @@
|
|||
|
||||
|
||||
<property name="context-root" value="geoportal-data-viewer-app"/>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -879,7 +1061,27 @@
|
|||
|
||||
|
||||
</wb-module>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
7
pom.xml
7
pom.xml
|
@ -175,8 +175,13 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>keycloak-client</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
<version>[2.0.0, 3.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
<!-- <dependency> -->
|
||||
<!-- <groupId>org.gcube.common</groupId> -->
|
||||
<!-- <artifactId>authorization-utils</artifactId> -->
|
||||
<!-- <version>[2.0.0, 3.0.0-SNAPSHOT)</version> -->
|
||||
<!-- </dependency> -->
|
||||
<dependency>
|
||||
<groupId>com.liferay.portal</groupId>
|
||||
<artifactId>portal-service</artifactId>
|
||||
|
|
|
@ -16,12 +16,18 @@ import com.google.gwt.i18n.client.DateTimeFormat;
|
|||
*/
|
||||
public class GeoportalDataViewerConstants {
|
||||
|
||||
// //WAITING_SERVER_ACTION_SERVLET
|
||||
// public static final String WAITING_PARAMETER = "waiting";
|
||||
// public static final String ACTION_TITLE_PARAMETER = "action";
|
||||
// public static final String MESSAGE_PARAMETER = "message";
|
||||
// public static final String WAITING_SERVER_ACTION_SERVLET = GWT.getModuleBaseURL()
|
||||
// + "geoportaldataviewerwaitingservice";
|
||||
|
||||
//WAITING_SERVER_ACTION_SERVLET
|
||||
public static final String WAITING_PARAMETER = "waiting";
|
||||
public static final String ACTION_TITLE_PARAMETER = "action";
|
||||
public static final String MESSAGE_PARAMETER = "message";
|
||||
public static final String WAITING_SERVER_ACTION_SERVLET = GWT.getModuleBaseURL()
|
||||
+ "geoportaldataviewerwaitingservice";
|
||||
public static final String UCD_ID_PARAMETER = "ucdID";
|
||||
public static final String PROIECT_ID_PARAMETER = "projectID";
|
||||
public static final String GEOPORTAL_EXPORT_ACTION_SERVLET = GWT.getModuleBaseURL()
|
||||
+ "geoportalexporterservice";
|
||||
|
||||
public static final int TABLET_WIDTH = 1601;
|
||||
|
||||
|
|
|
@ -231,7 +231,7 @@ public interface GeoportalDataViewerService extends RemoteService {
|
|||
|
||||
Boolean checkExportAsPDFConfig();
|
||||
|
||||
String exportAsPDF(String profileID, String projectID, String profileTitle,
|
||||
GeoportalItemReferences geoportalItemReferences);
|
||||
// String exportAsPDF(String profileID, String projectID, String profileTitle,
|
||||
// GeoportalItemReferences geoportalItemReferences);
|
||||
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ public interface GeoportalDataViewerServiceAsync {
|
|||
|
||||
void checkExportAsPDFConfig(AsyncCallback<Boolean> callback);
|
||||
|
||||
void exportAsPDF(String profileID, String projectID, String profileTitle,
|
||||
GeoportalItemReferences geoportalItemReferences, AsyncCallback<String> callback);
|
||||
// void exportAsPDF(String profileID, String projectID, String profileTitle,
|
||||
// GeoportalItemReferences geoportalItemReferences, AsyncCallback<String> callback);
|
||||
|
||||
}
|
||||
|
|
|
@ -212,39 +212,42 @@ public class ProjectViewer extends Composite {
|
|||
|
||||
@Override
|
||||
public void onClick(ClickEvent event) {
|
||||
String theProjectName ="";
|
||||
String theProjectName = "";
|
||||
try {
|
||||
theProjectName = (String) projectView.getTheProjectDV().getTheDocument().getFirstEntryOfMap().getValue();
|
||||
theProjectName = theProjectName!=null?theProjectName: "Project ID: " + projectView.getTheProjectDV().getId();
|
||||
}catch (Exception e) {
|
||||
theProjectName = (String) projectView.getTheProjectDV().getTheDocument().getFirstEntryOfMap()
|
||||
.getValue();
|
||||
theProjectName = theProjectName != null ? theProjectName
|
||||
: "Project ID: " + projectView.getTheProjectDV().getId();
|
||||
} catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
}
|
||||
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(GeoportalDataViewerConstants.WAITING_SERVER_ACTION_SERVLET+"?");
|
||||
builder.append(GeoportalDataViewerConstants.ACTION_TITLE_PARAMETER+"=Exporting as PDF...&");
|
||||
builder.append(GeoportalDataViewerConstants.MESSAGE_PARAMETER+"="+theProjectName+"&");
|
||||
builder.append(GeoportalDataViewerConstants.WAITING_PARAMETER+"=true");
|
||||
builder.append(GeoportalDataViewerConstants.GEOPORTAL_EXPORT_ACTION_SERVLET + "?");
|
||||
builder.append(GeoportalDataViewerConstants.UCD_ID_PARAMETER + "="
|
||||
+ projectView.getTheProjectDV().getProfileID() + "&");
|
||||
builder.append(GeoportalDataViewerConstants.PROIECT_ID_PARAMETER + "="
|
||||
+ projectView.getTheProjectDV().getId());
|
||||
|
||||
String theWaitingServletRequest = builder.toString();
|
||||
final NewBrowserWindow ref = NewBrowserWindow.open(theWaitingServletRequest, "_blank", null);
|
||||
|
||||
GeoportalDataViewerServiceAsync.Util.getInstance().exportAsPDF(projectView.getTheProjectDV().getProfileID(),
|
||||
projectView.getTheProjectDV().getId(), theTitle, geoportalItemReferences,
|
||||
new AsyncCallback<String>() {
|
||||
String geoportalExportActionServlet = builder.toString();
|
||||
final NewBrowserWindow ref = NewBrowserWindow.open(geoportalExportActionServlet, "_blank", null);
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(String resultURL) {
|
||||
ref.setUrl(resultURL);
|
||||
|
||||
}
|
||||
});
|
||||
// GeoportalDataViewerServiceAsync.Util.getInstance().exportAsPDF(
|
||||
// projectView.getTheProjectDV().getProfileID(), projectView.getTheProjectDV().getId(), theTitle,
|
||||
// geoportalItemReferences, new AsyncCallback<String>() {
|
||||
//
|
||||
// @Override
|
||||
// public void onFailure(Throwable caught) {
|
||||
// // TODO Auto-generated method stub
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onSuccess(String resultURL) {
|
||||
// ref.setUrl(resultURL);
|
||||
//
|
||||
// }
|
||||
// });
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -70,8 +70,6 @@ import org.gcube.application.geoportalcommon.util.URLParserUtil;
|
|||
import org.gcube.application.geoportaldatamapper.GcubeProfilesPerUCDIdCache;
|
||||
import org.gcube.application.geoportaldatamapper.Geoportal_JSON_Mapper;
|
||||
import org.gcube.application.geoportaldatamapper.exporter.Geoportal_PDF_Exporter;
|
||||
import org.gcube.application.geoportaldatamapper.shared.ExporterProjectSource;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerService;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.server.gis.FeatureParser;
|
||||
|
@ -620,56 +618,6 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
|
|||
|
||||
}
|
||||
|
||||
// public Map<String, List<GroupedLayersDV>> getAvaiableCrossFilteringLayers() {
|
||||
//
|
||||
// Map<String, List<GroupedLayersDV>> mapProfileIDOvelayLayers = new LinkedHashMap<>();
|
||||
//
|
||||
// // Reading UCDs Collections from the session
|
||||
// Map<String, UseCaseDescriptor> ucdCollections = SessionUtil.getAvailableCollections(getThreadLocalRequest());
|
||||
//
|
||||
// for (String profileId : ucdCollections.keySet()) {
|
||||
//
|
||||
// UseCaseDescriptor u = ucdCollections.get(profileId);
|
||||
//
|
||||
// // Loading geoportal_grouped_overlay_layers if exists
|
||||
// GEOPORTAL_DATA_HANDLER theHandler = GEOPORTAL_DATA_HANDLER.geoportal_grouped_cross_filtering;
|
||||
// List<HandlerDeclaration> handlers = u.getHandlersByType(theHandler.getType());
|
||||
//
|
||||
// if (handlers != null && handlers.size() > 0) {
|
||||
// // Loading Handler gcube_profiles
|
||||
// HandlerDeclaration handler = handlers.get(0);
|
||||
// List<GroupedLayersDV> listGroupedCustomLayers = null;
|
||||
// try {
|
||||
//
|
||||
// HandlerDeclarationDV handlerDV = ConvertToDataValueObjectModel.toHandlerDeclarationDV(handler, u,
|
||||
// GEOPORTAL_CONFIGURATION_TYPE.grouped_overlay_layers);
|
||||
//
|
||||
// if (handler != null) {
|
||||
// ConfigurationDV<?> config = handlerDV.getConfiguration();
|
||||
// switch (config.getConfigurationType()) {
|
||||
// case grouped_overlay_layers:
|
||||
// listGroupedCustomLayers = (List<GroupedLayersDV>) config.getConfiguration();
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// LOG.error("Error on loading {} config for ucd Id {}. Returning null",
|
||||
// GEOPORTAL_CONFIGURATION_TYPE.grouped_overlay_layers, u.getId());
|
||||
// }
|
||||
//
|
||||
// mapProfileIDOvelayLayers.put(profileId, listGroupedCustomLayers);
|
||||
// } else {
|
||||
// LOG.warn("No handler " + theHandler + "found into UCD " + u.getId() + ", continue...");
|
||||
// mapProfileIDOvelayLayers.put(profileId, null);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return mapProfileIDOvelayLayers;
|
||||
//
|
||||
// }
|
||||
|
||||
/**
|
||||
* Gets the layer index.
|
||||
*
|
||||
|
@ -1901,40 +1849,4 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
|
|||
return configChecked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String exportAsPDF(String profileID, String projectID, String profileTitle,
|
||||
GeoportalItemReferences geoportalItemReferences) {
|
||||
LOG.debug("exportAsPDF for profileID: " + profileID + ", projectID: " + projectID + "called");
|
||||
|
||||
String pdfURL = null;
|
||||
try {
|
||||
|
||||
GeoportalServiceIdentityProxy identity = new GeoportalServiceIdentityProxy(this.getThreadLocalRequest());
|
||||
|
||||
Geoportal_PDF_Exporter gpdfe = new Geoportal_PDF_Exporter();
|
||||
ExporterProjectSource exportSource = new ExporterProjectSource();
|
||||
exportSource.setProfileID(profileID);
|
||||
exportSource.setProfileTitle(profileTitle);
|
||||
exportSource.setProjectID(projectID);
|
||||
exportSource.setScope(ScopeProvider.instance.get());
|
||||
|
||||
GeoportalItemReferences gir = getPublicLinksFor(geoportalItemReferences);
|
||||
|
||||
if (identity.isUser()) {
|
||||
exportSource.setGisLink(gir.getRestrictedLink().getShortURL());
|
||||
GCubeUser user = SessionUtil.getCurrentUser(this.getThreadLocalRequest());
|
||||
exportSource.setAccountname(user.getUsername());
|
||||
} else {
|
||||
exportSource.setGisLink(gir.getOpenLink().getShortURL());
|
||||
exportSource.setAccountname(null);
|
||||
}
|
||||
|
||||
pdfURL = gpdfe.createPDFFile(exportSource);
|
||||
|
||||
} catch (Exception e1) {
|
||||
// silent
|
||||
}
|
||||
return pdfURL;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,197 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.geoportaldataviewer.server;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.Enumeration;
|
||||
|
||||
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;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.server.mongoservice.GeoportalServiceIdentityProxy;
|
||||
import org.gcube.portlets.user.uriresolvermanager.geoportal.GeoportalExporterAPI;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The Class GeoportalExporterActionServlet.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Apr 23, 2024
|
||||
*/
|
||||
public class GeoportalExporterActionServlet extends HttpServlet {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 6037090280489238565L;
|
||||
protected static Logger logger = LoggerFactory.getLogger(GeoportalExporterActionServlet.class);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void init() throws ServletException {
|
||||
super.init();
|
||||
logger.trace(GeoportalExporterActionServlet.class.getSimpleName() + " ready.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Do get.
|
||||
*
|
||||
* @param req the req
|
||||
* @param resp the resp
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
* @throws ServletException the servlet exception
|
||||
*/
|
||||
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
|
||||
// setSecretManager();
|
||||
String projectID = req.getParameter(GeoportalDataViewerConstants.PROIECT_ID_PARAMETER);
|
||||
String ucdID = req.getParameter(GeoportalDataViewerConstants.UCD_ID_PARAMETER);
|
||||
|
||||
logger.info("doGet called with Input Params [projectID: " + projectID + ", ucdID: " + ucdID + "]");
|
||||
|
||||
try {
|
||||
|
||||
GeoportalServiceIdentityProxy identity = new GeoportalServiceIdentityProxy(req);
|
||||
String theToken = identity.getToken();
|
||||
String theIdentity = identity.getIdentity();
|
||||
|
||||
GeoportalExporterAPI geoportalExporterAPI = new GeoportalExporterAPI();
|
||||
URL urlRequest = geoportalExporterAPI.exportProject("pdf", ucdID, projectID, false);
|
||||
String urlToRedirect = urlRequest.toString();
|
||||
logger.info("Performing request to {} with identity {}", urlToRedirect, identity.getDescription());
|
||||
logger.info("Token is {}", theToken.substring(0, 20) + "_MASKED_TOKEN");
|
||||
|
||||
InputStream is = performHttpRequestToSGService(urlToRedirect, theIdentity, theToken);
|
||||
IOUtils.copy(is, resp.getOutputStream());
|
||||
resp.flushBuffer();
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Error occurred when exporting the Project with id: " + projectID, e);
|
||||
sendError(resp, "Error occurred when exporting the Project. Error is: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static InputStream performHttpRequestToSGService(String urlToService, String identity, String token)
|
||||
throws IOException {
|
||||
logger.debug("performHttpRequestToSGService called");
|
||||
try {
|
||||
|
||||
URL url = new URL(urlToService);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
// timeout at 60sec
|
||||
conn.setConnectTimeout(6000);
|
||||
conn.setDoOutput(true);
|
||||
|
||||
if (token.length() > 50) {
|
||||
// is JWT TOKEN
|
||||
conn.setRequestProperty("Authorization", "Bearer " + token);
|
||||
} else {
|
||||
// is legacy Token
|
||||
conn.setRequestProperty("gcube-token", token);
|
||||
}
|
||||
|
||||
conn.setRequestProperty("Content-Type", "text/html");
|
||||
conn.setRequestMethod("GET");
|
||||
logger.debug("performHttpRequestToSGService done, returning");
|
||||
return conn.getInputStream();
|
||||
} catch (IOException e) {
|
||||
logger.error("Error on performing request to url " + urlToService, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the headers to target.
|
||||
*
|
||||
* @param httpSource the http source
|
||||
* @param response the response
|
||||
* @return the http servlet response
|
||||
*/
|
||||
public static HttpServletResponse setHeadersToTarget(HttpServletRequest httpSource, HttpServletResponse response) {
|
||||
|
||||
Enumeration<String> headersNames = httpSource.getHeaderNames();
|
||||
while (headersNames.hasMoreElements()) {
|
||||
String headerName = (String) headersNames.nextElement();
|
||||
Enumeration<String> values = httpSource.getHeaders(headerName);
|
||||
while (values.hasMoreElements()) {
|
||||
String value = values.nextElement();
|
||||
logger.info("Copying header {} with value {}", headerName, value);
|
||||
response.addHeader(headerName, value);
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the headers to target.
|
||||
*
|
||||
* @param httpSource the http source
|
||||
* @param httpTarget the http target
|
||||
* @return the http get
|
||||
*/
|
||||
public static HttpGet setHeadersToTarget(HttpServletRequest httpSource, HttpGet httpTarget) {
|
||||
|
||||
Enumeration<String> headersNames = httpSource.getHeaderNames();
|
||||
while (headersNames.hasMoreElements()) {
|
||||
String headerName = (String) headersNames.nextElement();
|
||||
Enumeration<String> values = httpSource.getHeaders(headerName);
|
||||
while (values.hasMoreElements()) {
|
||||
String value = values.nextElement();
|
||||
logger.info("Copying header {} with value {}", headerName, value);
|
||||
httpTarget.addHeader(headerName, value);
|
||||
}
|
||||
}
|
||||
return httpTarget;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the headers to response.
|
||||
*
|
||||
* @param httpSource the http source
|
||||
* @param httpTarget the http target
|
||||
* @return the http get
|
||||
*/
|
||||
public static HttpGet setHeadersToResponse(HttpServletRequest httpSource, HttpGet httpTarget) {
|
||||
|
||||
Enumeration<String> headersNames = httpSource.getHeaderNames();
|
||||
while (headersNames.hasMoreElements()) {
|
||||
String headerName = (String) headersNames.nextElement();
|
||||
Enumeration<String> values = httpSource.getHeaders(headerName);
|
||||
while (values.hasMoreElements()) {
|
||||
String value = values.nextElement();
|
||||
logger.info("Copying header {} with value {}", headerName, value);
|
||||
httpTarget.addHeader(headerName, value);
|
||||
}
|
||||
}
|
||||
return httpTarget;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send response.
|
||||
*
|
||||
* @param response the response
|
||||
* @param message the message
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
protected void sendError(HttpServletResponse response, String message) throws IOException {
|
||||
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||
response.setContentType("text/html");
|
||||
response.getWriter().write("<html><head><title>Error</title></head><body>" + message + "</body></html>");
|
||||
response.flushBuffer();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,137 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.geoportaldataviewer.server;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* The Class WatingServerActionServlet.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Nov 22, 2023
|
||||
*/
|
||||
public class WatingServerActionServlet extends HttpServlet {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -1058074450240555475L;
|
||||
protected static Logger logger = LoggerFactory.getLogger(WatingServerActionServlet.class);
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void init() throws ServletException {
|
||||
super.init();
|
||||
logger.trace("Workspace WatingServerActionServlet ready.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Do get.
|
||||
*
|
||||
* @param req the req
|
||||
* @param resp the resp
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
|
||||
* javax.servlet.http.HttpServletResponse)
|
||||
*/
|
||||
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||
|
||||
String action = req.getParameter(GeoportalDataViewerConstants.ACTION_TITLE_PARAMETER);
|
||||
String message = req.getParameter(GeoportalDataViewerConstants.MESSAGE_PARAMETER);
|
||||
boolean waiting = req.getParameter(GeoportalDataViewerConstants.WAITING_PARAMETER) == null ? true
|
||||
: req.getParameter(GeoportalDataViewerConstants.WAITING_PARAMETER).equals("true");
|
||||
|
||||
logger.debug("Input Params [action: " + action + ", message: "+ message +", waiting: " + waiting + "]");
|
||||
|
||||
action = action == null || action.isEmpty() ? "Loading" : action;
|
||||
|
||||
message = message == null || message.isEmpty() ? "" : message;
|
||||
|
||||
sendResponse(resp, action, message, waiting);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send response.
|
||||
*
|
||||
* @param response the response
|
||||
* @param action the action
|
||||
* @param message the message
|
||||
* @param waiting the waiting
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
protected void sendResponse(HttpServletResponse response, String action, String message, boolean waiting) throws IOException {
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
response.setContentType("text/html");
|
||||
response.getWriter().write(setHTMLMessage(action, message, waiting));
|
||||
response.flushBuffer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the HTML message.
|
||||
*
|
||||
* @param action the action
|
||||
* @param message the message
|
||||
* @param waiting the waiting
|
||||
* @return the string
|
||||
*/
|
||||
protected String setHTMLMessage(String action, String message, boolean waiting) {
|
||||
|
||||
String html = "<html>" + "<head>" + "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">"
|
||||
+ "<style>"
|
||||
+ "html, body {\n"
|
||||
+ " margin: 10px;\n"
|
||||
+ " width: 100%;\n"
|
||||
+ " height: 100%;\n"
|
||||
+ " display: table\n"
|
||||
+ "}\n"
|
||||
+ "#content {\n"
|
||||
+ " position: absolute;\n"
|
||||
+ " left: 50%;\n"
|
||||
+ " top: 50%;\n"
|
||||
+ " -webkit-transform: translate(-50%, -50%);\n"
|
||||
+ " transform: translate(-50%, -50%);\n"
|
||||
+ " text-align: center;\n"
|
||||
+ "}"
|
||||
+ "#message {\n"
|
||||
+ " color:gray;"
|
||||
+ " font-size: 24px;"
|
||||
+ "}"
|
||||
+ "</style>"
|
||||
+ "<title>D4Science Geoportal - Action</title>" + "</head>" + "<body>";
|
||||
|
||||
|
||||
html += "<img alt=\"D4Science Logo\" src=\"https://services.d4science.org/image/layout_set_logo?img_id=32727\"><br />";
|
||||
|
||||
html += "<div id=\"content\">";
|
||||
html += "<p style=\"font-size: 18px;\">" + action + "</p>";
|
||||
|
||||
if (waiting) {
|
||||
html += "<img alt=\"D4Science Geoportal Loading...\" src=\"../img/loading-gears.gif\"><br />";
|
||||
}
|
||||
|
||||
html += "<br/><p id=\"message\">" + message + "</p>";
|
||||
html += "</div></body></html>";
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
}
|
|
@ -22,9 +22,9 @@ public class GeoportalServiceIdentityProxy {
|
|||
private static final Logger LOG = LoggerFactory.getLogger(GeoportalServiceIdentityProxy.class);
|
||||
|
||||
private GcubeIdentity gCubeIdentity;
|
||||
|
||||
|
||||
private boolean isUser = false;
|
||||
|
||||
|
||||
private boolean isIAMClient = false;
|
||||
|
||||
/**
|
||||
|
@ -57,12 +57,24 @@ public class GeoportalServiceIdentityProxy {
|
|||
|
||||
gCubeIdentity.setIdentity(request);
|
||||
}
|
||||
|
||||
|
||||
public boolean isUser() {
|
||||
return isUser;
|
||||
}
|
||||
|
||||
|
||||
public boolean isIAMClient() {
|
||||
return isIAMClient;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return gCubeIdentity.getIdentityDescription();
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return gCubeIdentity.getToken();
|
||||
}
|
||||
|
||||
public String getIdentity() {
|
||||
return gCubeIdentity.getIdentity();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,16 +2,15 @@ package org.gcube.portlets.user.geoportaldataviewer.server.mongoservice.accessid
|
|||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
|
||||
/**
|
||||
* The Interface GcubeIdentity.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Sep 23, 2021
|
||||
* Sep 23, 2021
|
||||
*/
|
||||
public interface GcubeIdentity {
|
||||
|
||||
|
||||
/**
|
||||
* Sets the identity.
|
||||
*
|
||||
|
@ -19,10 +18,32 @@ public interface GcubeIdentity {
|
|||
* @throws Exception the exception
|
||||
*/
|
||||
public void setIdentity(HttpServletRequest httpRequest) throws Exception;
|
||||
|
||||
|
||||
/**
|
||||
* Reset identity.
|
||||
*/
|
||||
public void resetIdentity();
|
||||
|
||||
/**
|
||||
* Gets the identity description.
|
||||
*
|
||||
* @return the identity description
|
||||
*/
|
||||
public String getIdentityDescription();
|
||||
|
||||
|
||||
/**
|
||||
* Gets the identity.
|
||||
*
|
||||
* @return the identity
|
||||
*/
|
||||
public String getIdentity();
|
||||
|
||||
/**
|
||||
* Gets the token.
|
||||
*
|
||||
* @return the token
|
||||
*/
|
||||
public String getToken();
|
||||
|
||||
}
|
||||
|
|
|
@ -16,18 +16,22 @@ public class IAMClientIdentity implements GcubeIdentity {
|
|||
private static final Logger LOG = LoggerFactory.getLogger(IAMClientIdentity.class);
|
||||
|
||||
private String previousUMAToken = null;
|
||||
|
||||
private String currentUMAToken = null;
|
||||
|
||||
private String clientId = null;
|
||||
|
||||
private static final String IAM_CLIENT_CREDENTIALS = "IAM_CLIENT_CREDENTIALS";
|
||||
|
||||
@Override
|
||||
public void setIdentity(HttpServletRequest httpRequest) throws Exception {
|
||||
LOG.info("setIdentity called");
|
||||
String currentScope = SessionUtil.getCurrentContext(httpRequest, true);
|
||||
IAMClientCredentials credentials = sessionGetIAMClientCredentials(httpRequest);
|
||||
IAMClientCredentials credentials = sessionGetIAMClientCredentials(httpRequest);
|
||||
try {
|
||||
if(credentials==null) {
|
||||
if (credentials == null) {
|
||||
credentials = IAMClientCredentialsReader.getCredentials();
|
||||
sessionSetIAMClientCredentials(httpRequest,credentials);
|
||||
sessionSetIAMClientCredentials(httpRequest, credentials);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error on discovering IAM Client credentials", e);
|
||||
|
@ -36,7 +40,7 @@ public class IAMClientIdentity implements GcubeIdentity {
|
|||
|
||||
LOG.trace("Read credentials: " + credentials);
|
||||
String umaAcessToken = null;
|
||||
String clientId = credentials.getClientId();
|
||||
clientId = credentials.getClientId();
|
||||
String clientSecret = credentials.getClientSecret();
|
||||
try {
|
||||
|
||||
|
@ -46,6 +50,7 @@ public class IAMClientIdentity implements GcubeIdentity {
|
|||
umaAcessToken = tr.getAccessToken();
|
||||
if (umaAcessToken != null && !umaAcessToken.isEmpty()) {
|
||||
LOG.info("UMA Access Token read correctly");
|
||||
currentUMAToken = umaAcessToken;
|
||||
} else {
|
||||
LOG.error("UMA Access Token NOT RETRIEVED!!!");
|
||||
throw new Exception("UMA Access Token is null or empty");
|
||||
|
@ -75,6 +80,11 @@ public class IAMClientIdentity implements GcubeIdentity {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getToken() {
|
||||
return currentUMAToken;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetIdentity() {
|
||||
LOG.info("resetIdentity called");
|
||||
|
@ -82,7 +92,7 @@ public class IAMClientIdentity implements GcubeIdentity {
|
|||
LOG.info("resetIdentity to previous AccessToken");
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the IAM client credentials.
|
||||
*
|
||||
|
@ -103,7 +113,7 @@ public class IAMClientIdentity implements GcubeIdentity {
|
|||
* Sets the IAM client credentials.
|
||||
*
|
||||
* @param httpRequest the http request
|
||||
* @param iamCC the iam CC
|
||||
* @param iamCC the iam CC
|
||||
*/
|
||||
public static void sessionSetIAMClientCredentials(HttpServletRequest httpRequest, IAMClientCredentials iamCC) {
|
||||
HttpSession session = httpRequest.getSession();
|
||||
|
@ -114,4 +124,15 @@ public class IAMClientIdentity implements GcubeIdentity {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityDescription() {
|
||||
return "ClientId: "+ clientId;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentity() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.gcube.portlets.user.geoportaldataviewer.server.mongoservice.accessid
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.gcube.portlets.user.geoportaldataviewer.server.util.SessionUtil;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -10,13 +11,19 @@ public class UserIdentity implements GcubeIdentity {
|
|||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(UserIdentity.class);
|
||||
|
||||
private HttpServletRequest httpRequest;
|
||||
|
||||
private GCubeUser user;
|
||||
|
||||
public UserIdentity() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIdentity(HttpServletRequest httpRequest) throws Exception {
|
||||
LOG.info("setIdentity called");
|
||||
this.httpRequest = httpRequest;
|
||||
SessionUtil.getCurrentToken(httpRequest, true);
|
||||
user = SessionUtil.getCurrentUser(httpRequest);
|
||||
|
||||
}
|
||||
|
||||
|
@ -25,4 +32,20 @@ public class UserIdentity implements GcubeIdentity {
|
|||
LOG.info("resetIdentity called, doing nothing");
|
||||
// doing nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getToken() {
|
||||
return SessionUtil.getCurrentToken(httpRequest, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentityDescription() {
|
||||
return user != null ? "user: " + user.getUsername() : "null";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentity() {
|
||||
return user.getUsername();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,11 +16,16 @@
|
|||
<servlet-class>org.gcube.portlets.user.geoportaldataviewer.server.GeoportalDataViewerServiceImpl</servlet-class>
|
||||
</servlet>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>geoportalWaitingServerActionServlet</servlet-name>
|
||||
<servlet-class>org.gcube.portlets.user.geoportaldataviewer.server.WatingServerActionServlet</servlet-class>
|
||||
<!-- <servlet> -->
|
||||
<!-- <servlet-name>geoportalWaitingServerActionServlet</servlet-name> -->
|
||||
<!-- <servlet-class>org.gcube.portlets.user.geoportaldataviewer.server.WatingServerActionServlet</servlet-class> -->
|
||||
<!-- </servlet> -->
|
||||
|
||||
<servlet>
|
||||
<servlet-name>geoportalExporterServerActionServlet</servlet-name>
|
||||
<servlet-class>org.gcube.portlets.user.geoportaldataviewer.server.GeoportalExporterActionServlet</servlet-class>
|
||||
</servlet>
|
||||
|
||||
|
||||
<servlet>
|
||||
<servlet-name>mpformbuilderServlet</servlet-name>
|
||||
<servlet-class>org.gcube.portlets.widgets.mpformbuilder.server.MetadataProfileFormBuilderServiceImpl</servlet-class>
|
||||
|
@ -37,9 +42,14 @@
|
|||
<url-pattern>/GeoportalDataViewer/geoportaldataviewerservice</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>geoportalWaitingServerActionServlet</servlet-name>
|
||||
<url-pattern>/GeoportalDataViewer/geoportaldataviewerwaitingservice</url-pattern>
|
||||
<!-- <servlet-mapping> -->
|
||||
<!-- <servlet-name>geoportalWaitingServerActionServlet</servlet-name> -->
|
||||
<!-- <url-pattern>/GeoportalDataViewer/geoportaldataviewerwaitingservice</url-pattern> -->
|
||||
<!-- </servlet-mapping> -->
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>geoportalExporterServerActionServlet</servlet-name>
|
||||
<url-pattern>/GeoportalDataViewer/geoportalexporterservice</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
</web-app>
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.geoportaldataviewer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.gcube.portlets.user.geoportaldataviewer.server.GeoportalExporterActionServlet;
|
||||
|
||||
/**
|
||||
* The Class GeoportalExporterActionServletTest.
|
||||
*
|
||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||
*
|
||||
* Apr 24, 2024
|
||||
*/
|
||||
public class GeoportalExporterActionServletTest {
|
||||
|
||||
/**
|
||||
* The main method.
|
||||
*
|
||||
* @param args the arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
String url = "https://data.dev.d4science.org/geoportal/export/pdf/profiledConcessioni/661d2c6f8804530afb90b132";
|
||||
String identity = "francesco.mangiacrapa";
|
||||
String token = "";
|
||||
System.out.println("Start");
|
||||
InputStream response;
|
||||
try {
|
||||
response = GeoportalExporterActionServlet.performHttpRequestToSGService(url, identity, token);
|
||||
System.out.println(IOUtils.toString(response));
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("End");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue