Passing WFS requests from the servlet due to CORS issue, see
#25074?#note-7
This commit is contained in:
parent
36bfcd2b9e
commit
a28d2433a0
|
@ -1,5 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
|
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,7 +84,8 @@
|
||||||
|
|
||||||
|
|
||||||
<wb-module deploy-name="geoportal-data-viewer-app-3.5.0-SNAPSHOT">
|
<wb-module deploy-name="geoportal-data-viewer-app-3.5.0-SNAPSHOT">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -167,7 +169,8 @@
|
||||||
|
|
||||||
|
|
||||||
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
|
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -251,7 +254,8 @@
|
||||||
|
|
||||||
|
|
||||||
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
|
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -335,7 +339,8 @@
|
||||||
|
|
||||||
|
|
||||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/gwt"/>
|
<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/gwt"/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -419,7 +424,8 @@
|
||||||
|
|
||||||
|
|
||||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
|
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -503,10 +509,11 @@
|
||||||
|
|
||||||
|
|
||||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
|
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
|
||||||
<dependent-module archiveName="geoportal-data-common-2.2.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/geoportal-data-common/geoportal-data-common">
|
<dependent-module archiveName="geoportal-data-mapper-1.0.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/geoportal-data-mapper/geoportal-data-mapper">
|
||||||
<dependency-type>uses</dependency-type>
|
<dependency-type>uses</dependency-type>
|
||||||
</dependent-module>
|
</dependent-module>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -590,7 +597,8 @@
|
||||||
|
|
||||||
|
|
||||||
<property name="java-output-path" value="/geoportal-data-viewer-app/target/geoportal-data-viewer-app-0.0.1-SNAPSHOT/WEB-INF/classes"/>
|
<property name="java-output-path" value="/geoportal-data-viewer-app/target/geoportal-data-viewer-app-0.0.1-SNAPSHOT/WEB-INF/classes"/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -674,7 +682,8 @@
|
||||||
|
|
||||||
|
|
||||||
<property name="context-root" value="geoportal-data-viewer-app"/>
|
<property name="context-root" value="geoportal-data-viewer-app"/>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -758,7 +767,8 @@
|
||||||
|
|
||||||
|
|
||||||
</wb-module>
|
</wb-module>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -219,4 +219,12 @@ public interface GeoportalDataViewerService extends RemoteService {
|
||||||
Map<String, List<GroupedLayersDV<? extends LayerIDV>>> getAvaiableCustomGroupedLayersForUCD(
|
Map<String, List<GroupedLayersDV<? extends LayerIDV>>> getAvaiableCustomGroupedLayersForUCD(
|
||||||
GEOPORTAL_DATA_HANDLER theHandler);
|
GEOPORTAL_DATA_HANDLER theHandler);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the HTTP response for URL.
|
||||||
|
*
|
||||||
|
* @param url the url
|
||||||
|
* @return the HTTP response for URL
|
||||||
|
*/
|
||||||
|
String getHTTPResponseForURL(String url);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,4 +89,6 @@ public interface GeoportalDataViewerServiceAsync {
|
||||||
void getAvaiableCustomGroupedLayersForUCD(GEOPORTAL_DATA_HANDLER theHandler,
|
void getAvaiableCustomGroupedLayersForUCD(GEOPORTAL_DATA_HANDLER theHandler,
|
||||||
AsyncCallback<Map<String, List<GroupedLayersDV<? extends LayerIDV>>>> callback);
|
AsyncCallback<Map<String, List<GroupedLayersDV<? extends LayerIDV>>>> callback);
|
||||||
|
|
||||||
|
void getHTTPResponseForURL(String url, AsyncCallback<String> callback);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import org.gcube.application.geoportalcommon.shared.geoportal.config.layers.Laye
|
||||||
import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GCubeSDILayer;
|
import org.gcube.application.geoportalcommon.shared.geoportal.materialization.GCubeSDILayer;
|
||||||
import org.gcube.application.geoportalcommon.shared.geoportal.materialization.IndexLayerDV;
|
import org.gcube.application.geoportalcommon.shared.geoportal.materialization.IndexLayerDV;
|
||||||
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MAP_PROJECTION;
|
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerConstants.MAP_PROJECTION;
|
||||||
|
import org.gcube.portlets.user.geoportaldataviewer.client.GeoportalDataViewerServiceAsync;
|
||||||
import org.gcube.portlets.user.geoportaldataviewer.client.events.ApplyCQLToLayerMapEvent;
|
import org.gcube.portlets.user.geoportaldataviewer.client.events.ApplyCQLToLayerMapEvent;
|
||||||
import org.gcube.portlets.user.geoportaldataviewer.client.ui.util.OLGeoJSONUtil;
|
import org.gcube.portlets.user.geoportaldataviewer.client.ui.util.OLGeoJSONUtil;
|
||||||
import org.gcube.portlets.user.geoportaldataviewer.client.util.LoaderIcon;
|
import org.gcube.portlets.user.geoportaldataviewer.client.util.LoaderIcon;
|
||||||
|
@ -37,14 +38,10 @@ import com.google.gwt.event.dom.client.ChangeHandler;
|
||||||
import com.google.gwt.event.dom.client.ClickEvent;
|
import com.google.gwt.event.dom.client.ClickEvent;
|
||||||
import com.google.gwt.event.dom.client.ClickHandler;
|
import com.google.gwt.event.dom.client.ClickHandler;
|
||||||
import com.google.gwt.event.shared.HandlerManager;
|
import com.google.gwt.event.shared.HandlerManager;
|
||||||
import com.google.gwt.http.client.Request;
|
|
||||||
import com.google.gwt.http.client.RequestBuilder;
|
|
||||||
import com.google.gwt.http.client.RequestCallback;
|
|
||||||
import com.google.gwt.http.client.RequestException;
|
|
||||||
import com.google.gwt.http.client.Response;
|
|
||||||
import com.google.gwt.http.client.URL;
|
import com.google.gwt.http.client.URL;
|
||||||
import com.google.gwt.uibinder.client.UiBinder;
|
import com.google.gwt.uibinder.client.UiBinder;
|
||||||
import com.google.gwt.uibinder.client.UiField;
|
import com.google.gwt.uibinder.client.UiField;
|
||||||
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||||
import com.google.gwt.user.client.ui.Composite;
|
import com.google.gwt.user.client.ui.Composite;
|
||||||
import com.google.gwt.user.client.ui.HTML;
|
import com.google.gwt.user.client.ui.HTML;
|
||||||
import com.google.gwt.user.client.ui.HTMLPanel;
|
import com.google.gwt.user.client.ui.HTMLPanel;
|
||||||
|
@ -64,9 +61,6 @@ public class CrossFilteringLayerPanel extends Composite {
|
||||||
|
|
||||||
public static String COLORSCALERANGE = "COLORSCALERANGE";
|
public static String COLORSCALERANGE = "COLORSCALERANGE";
|
||||||
|
|
||||||
// @UiField
|
|
||||||
// WellForm panelContainer;
|
|
||||||
|
|
||||||
@UiField
|
@UiField
|
||||||
Fieldset fieldSet;
|
Fieldset fieldSet;
|
||||||
|
|
||||||
|
@ -218,52 +212,55 @@ public class CrossFilteringLayerPanel extends Composite {
|
||||||
|
|
||||||
}
|
}
|
||||||
GWT.log("wfsURL request: " + wfsURL);
|
GWT.log("wfsURL request: " + wfsURL);
|
||||||
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, wfsURL);
|
|
||||||
|
|
||||||
try {
|
GeoportalDataViewerServiceAsync.Util.getInstance().getHTTPResponseForURL(wfsURL,
|
||||||
|
new AsyncCallback<String>() {
|
||||||
|
|
||||||
Request response = builder.sendRequest(null, new RequestCallback() {
|
@Override
|
||||||
public void onError(Request request, Throwable exception) {
|
public void onSuccess(String response) {
|
||||||
// Code omitted for clarity
|
GWT.log("wfsURL response: " + response);
|
||||||
}
|
Feature[] features = OLGeoJSONUtil.readGeoJsonFeatures(MAP_PROJECTION.EPSG_4326, response);
|
||||||
|
|
||||||
public void onResponseReceived(Request request, Response response) {
|
for (Feature feature : features) {
|
||||||
GWT.log("wfsURL response: " + response.getText());
|
JsPropertyMap<Object> properties = feature.getProperties();
|
||||||
Feature[] features = OLGeoJSONUtil.readGeoJsonFeatures(MAP_PROJECTION.EPSG_4326,
|
Object keyValue = properties.get(crossFilteringLayer.getTable_key_field());
|
||||||
response.getText());
|
Object itemField = properties.get(crossFilteringLayer.getTable_show_field());
|
||||||
|
|
||||||
for (Feature feature : features) {
|
Object parentKey = null;
|
||||||
JsPropertyMap<Object> properties = feature.getProperties();
|
if (crossFilteringLayer.getTable_parent_key_field() != null
|
||||||
Object keyValue = properties.get(crossFilteringLayer.getTable_key_field());
|
&& !crossFilteringLayer.getTable_parent_key_field().isEmpty())
|
||||||
Object itemField = properties.get(crossFilteringLayer.getTable_show_field());
|
parentKey = properties.get(crossFilteringLayer.getTable_parent_key_field());
|
||||||
|
|
||||||
Object parentKey = null;
|
parentKey = parentKey == null ? "" : parentKey;
|
||||||
if (crossFilteringLayer.getTable_parent_key_field() != null
|
|
||||||
&& !crossFilteringLayer.getTable_parent_key_field().isEmpty())
|
|
||||||
parentKey = properties.get(crossFilteringLayer.getTable_parent_key_field());
|
|
||||||
|
|
||||||
parentKey = parentKey == null ? "" : parentKey;
|
SelectableItem selectableItem = new SelectableItem(
|
||||||
|
crossFilteringLayer.getTable_key_field() + "", keyValue + "",
|
||||||
|
crossFilteringLayer.getTable_parent_key_field(), itemField + "",
|
||||||
|
crossFilteringLayer.getName(), crossFilteringLayer.getTable_geometry_name());
|
||||||
|
GWT.log("selectableItem: " + selectableItem);
|
||||||
|
|
||||||
SelectableItem selectableItem = new SelectableItem(
|
String pathFeatureKey = pathFeatureKey(selectableItem);
|
||||||
crossFilteringLayer.getTable_key_field() + "", keyValue + "",
|
mapSelectableFeatures.put(pathFeatureKey, selectableItem);
|
||||||
crossFilteringLayer.getTable_parent_key_field(), itemField + "",
|
|
||||||
crossFilteringLayer.getName(), crossFilteringLayer.getTable_geometry_name());
|
|
||||||
GWT.log("selectableItem: " + selectableItem);
|
|
||||||
|
|
||||||
String pathFeatureKey = pathFeatureKey(selectableItem);
|
}
|
||||||
mapSelectableFeatures.put(pathFeatureKey, selectableItem);
|
GWT.log("mapSelectableFeatures: " + mapSelectableFeatures);
|
||||||
|
mapInnestedFeatures.put(level, mapSelectableFeatures);
|
||||||
|
String placholder = placeholderLayer(layersIDV.get(0)); // Expected one
|
||||||
|
fillListBoxLevel(level, mapSelectableFeatures, listBoxes, placholder);
|
||||||
|
|
||||||
}
|
}
|
||||||
GWT.log("mapSelectableFeatures: " + mapSelectableFeatures);
|
|
||||||
mapInnestedFeatures.put(level, mapSelectableFeatures);
|
|
||||||
String placholder = placeholderLayer(layersIDV.get(0)); // Expected one
|
|
||||||
fillListBoxLevel(level, mapSelectableFeatures, listBoxes, placholder);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
} catch (RequestException e) {
|
@Override
|
||||||
// Code omitted for clarity
|
public void onFailure(Throwable caught) {
|
||||||
}
|
panelResults.clear();
|
||||||
|
HTML error = new HTML(
|
||||||
|
"Sorry, an issue is occurred on loading data for cross-filtering facility. Error is: "
|
||||||
|
+ caught.getMessage());
|
||||||
|
panelResults.add(error);
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -419,7 +416,6 @@ public class CrossFilteringLayerPanel extends Composite {
|
||||||
GWT.log("CQL FILTER built: " + setCqlFilter);
|
GWT.log("CQL FILTER built: " + setCqlFilter);
|
||||||
|
|
||||||
IndexLayerDV indexLayer = gCubeCollection.getIndexes().get(0);
|
IndexLayerDV indexLayer = gCubeCollection.getIndexes().get(0);
|
||||||
applicationBus.fireEvent(new ApplyCQLToLayerMapEvent(indexLayer, setCqlFilter));
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
GCubeSDILayer layer = indexLayer.getLayer();
|
GCubeSDILayer layer = indexLayer.getLayer();
|
||||||
|
@ -437,64 +433,57 @@ public class CrossFilteringLayerPanel extends Composite {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// TODO: handle exception
|
// TODO: handle exception
|
||||||
}
|
}
|
||||||
|
|
||||||
|
applicationBus.fireEvent(new ApplyCQLToLayerMapEvent(indexLayer, setCqlFilter));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showCountResultsOfWFSCrossFiltering(String wfsQuery) {
|
public void showCountResultsOfWFSCrossFiltering(String wfsQuery) {
|
||||||
|
|
||||||
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, wfsQuery);
|
|
||||||
panelResults.clear();
|
panelResults.clear();
|
||||||
panelResults.add(new HTML("<hr>"));
|
panelResults.add(new HTML("<hr>"));
|
||||||
panelResults.add(new LoaderIcon("Filtering..."));
|
panelResults.add(new LoaderIcon("Applying spatial filter..."));
|
||||||
try {
|
|
||||||
|
GeoportalDataViewerServiceAsync.Util.getInstance().getHTTPResponseForURL(wfsQuery, new AsyncCallback<String>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Throwable caught) {
|
||||||
|
panelResults.clear();
|
||||||
|
panelResults.add(new HTML("<hr>"));
|
||||||
|
Alert alert = new Alert("Error on returning number of items");
|
||||||
|
alert.setType(AlertType.ERROR);
|
||||||
|
alert.setClose(false);
|
||||||
|
panelResults.add(alert);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSuccess(String response) {
|
||||||
|
Feature[] features = OLGeoJSONUtil.readGeoJsonFeatures(MAP_PROJECTION.EPSG_4326, response);
|
||||||
|
|
||||||
|
if (features != null) {
|
||||||
|
int dataCount = features.length;
|
||||||
|
|
||||||
Request response = builder.sendRequest(null, new RequestCallback() {
|
|
||||||
public void onError(Request request, Throwable exception) {
|
|
||||||
// showLoading(false);
|
|
||||||
// Window.alert(caught.getMessage());
|
|
||||||
panelResults.clear();
|
panelResults.clear();
|
||||||
panelResults.add(new HTML("<hr>"));
|
panelResults.add(new HTML("<hr>"));
|
||||||
Alert alert = new Alert("Error on returning number of centroids");
|
|
||||||
alert.setType(AlertType.ERROR);
|
|
||||||
alert.setClose(false);
|
|
||||||
panelResults.add(alert);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onResponseReceived(Request request, Response response) {
|
String message = "";
|
||||||
|
|
||||||
Feature[] features = OLGeoJSONUtil.readGeoJsonFeatures(MAP_PROJECTION.EPSG_4326,
|
if (dataCount <= 0) {
|
||||||
response.getText());
|
message = "No item found";
|
||||||
|
} else {
|
||||||
|
|
||||||
if (features != null) {
|
message = "Found " + dataCount;
|
||||||
int dataCount = features.length;
|
message += dataCount > 1 ? " items" : " item";
|
||||||
|
message += ". ";
|
||||||
panelResults.clear();
|
|
||||||
panelResults.add(new HTML("<hr>"));
|
|
||||||
|
|
||||||
if (dataCount == 0) {
|
|
||||||
panelResults.add(new HTML("No result found"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String message = "";
|
|
||||||
|
|
||||||
if (dataCount > 0) {
|
|
||||||
message = "Found " + dataCount;
|
|
||||||
message += dataCount > 1 ? " centroids" : " centroid";
|
|
||||||
message += ". ";
|
|
||||||
}
|
|
||||||
|
|
||||||
HTML resultMessage = new HTML(message);
|
|
||||||
resultMessage.getElement().addClassName("search_result_msg");
|
|
||||||
|
|
||||||
panelResults.add(resultMessage);
|
|
||||||
}
|
}
|
||||||
|
HTML resultMessage = new HTML();
|
||||||
|
resultMessage.getElement().addClassName("search_result_msg");
|
||||||
|
resultMessage.setHTML(message);
|
||||||
|
panelResults.add(resultMessage);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
} catch (RequestException e) {
|
}
|
||||||
panelResults.clear();
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -15,7 +15,7 @@ import ol.proj.ProjectionOptions;
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
*
|
*
|
||||||
* May 25, 2023
|
* May 25, 2023
|
||||||
*/
|
*/
|
||||||
public class OLGeoJSONUtil {
|
public class OLGeoJSONUtil {
|
||||||
|
|
||||||
|
@ -23,27 +23,31 @@ public class OLGeoJSONUtil {
|
||||||
* Builds the geo JSON.
|
* Builds the geo JSON.
|
||||||
*
|
*
|
||||||
* @param projection the projection
|
* @param projection the projection
|
||||||
* @param geoJSONString the geo JSON string
|
|
||||||
* @return the geo json
|
* @return the geo json
|
||||||
*/
|
*/
|
||||||
public static GeoJson buildGeoJSON(MAP_PROJECTION projection) {
|
public static GeoJson buildGeoJSON(MAP_PROJECTION projection) {
|
||||||
GeoJsonFeatureOptions fo = new GeoJsonFeatureOptions();
|
try {
|
||||||
ProjectionOptions projectionOptions = new ProjectionOptions();
|
GeoJsonFeatureOptions fo = new GeoJsonFeatureOptions();
|
||||||
projectionOptions.setCode(projection.getName());
|
ProjectionOptions projectionOptions = new ProjectionOptions();
|
||||||
Projection fp = new Projection(projectionOptions);
|
projectionOptions.setCode(projection.getName());
|
||||||
fo.setFeatureProjection(fp);
|
Projection fp = new Projection(projectionOptions);
|
||||||
fo.setDataProjection(fp);
|
fo.setFeatureProjection(fp);
|
||||||
GeoJsonOptions geoJsonOpt = new GeoJsonOptions();
|
fo.setDataProjection(fp);
|
||||||
geoJsonOpt.setDefaultDataProjection(fp);
|
GeoJsonOptions geoJsonOpt = new GeoJsonOptions();
|
||||||
geoJsonOpt.setFeatureProjection(fp);
|
geoJsonOpt.setDefaultDataProjection(fp);
|
||||||
return OLFactory.createGeoJSON(geoJsonOpt);
|
geoJsonOpt.setFeatureProjection(fp);
|
||||||
|
return OLFactory.createGeoJSON(geoJsonOpt);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// silent
|
||||||
|
return OLFactory.createGeoJSON();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read geo json features.
|
* Read geo json features.
|
||||||
*
|
*
|
||||||
* @param projection the projection
|
* @param projection the projection
|
||||||
* @param geoJSONString the geo JSON string
|
* @param geoJSONString the geo JSON string
|
||||||
* @return the feature[]
|
* @return the feature[]
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package org.gcube.portlets.user.geoportaldataviewer.client.util;
|
package org.gcube.portlets.user.geoportaldataviewer.client.util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class URLUtil.
|
* The Class HTTPRequestUtil.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
*
|
*
|
||||||
|
|
|
@ -3,10 +3,6 @@ package org.gcube.portlets.user.geoportaldataviewer.server;
|
||||||
import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.projects;
|
import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.projects;
|
||||||
import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.useCaseDescriptors;
|
import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.useCaseDescriptors;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -79,6 +75,7 @@ import org.gcube.portlets.user.geoportaldataviewer.server.gis.GisMakers;
|
||||||
import org.gcube.portlets.user.geoportaldataviewer.server.gis.WMSUrlValidator;
|
import org.gcube.portlets.user.geoportaldataviewer.server.gis.WMSUrlValidator;
|
||||||
import org.gcube.portlets.user.geoportaldataviewer.server.mongoservice.GeoportalServiceIdentityProxy;
|
import org.gcube.portlets.user.geoportaldataviewer.server.mongoservice.GeoportalServiceIdentityProxy;
|
||||||
import org.gcube.portlets.user.geoportaldataviewer.server.util.ContextRequest;
|
import org.gcube.portlets.user.geoportaldataviewer.server.util.ContextRequest;
|
||||||
|
import org.gcube.portlets.user.geoportaldataviewer.server.util.HTTPRequestUtil;
|
||||||
import org.gcube.portlets.user.geoportaldataviewer.server.util.SessionUtil;
|
import org.gcube.portlets.user.geoportaldataviewer.server.util.SessionUtil;
|
||||||
import org.gcube.portlets.user.geoportaldataviewer.server.util.TemporalComparatorUtil;
|
import org.gcube.portlets.user.geoportaldataviewer.server.util.TemporalComparatorUtil;
|
||||||
import org.gcube.portlets.user.geoportaldataviewer.shared.GCubeCollection;
|
import org.gcube.portlets.user.geoportaldataviewer.shared.GCubeCollection;
|
||||||
|
@ -608,7 +605,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
|
||||||
LOG.debug("listGroupedCustomLayers for type '{}' are: {}", configurationType, listGroupedCustomLayers);
|
LOG.debug("listGroupedCustomLayers for type '{}' are: {}", configurationType, listGroupedCustomLayers);
|
||||||
mapProfileIDCustomGroupedLayers.put(profileId, listGroupedCustomLayers);
|
mapProfileIDCustomGroupedLayers.put(profileId, listGroupedCustomLayers);
|
||||||
} else {
|
} else {
|
||||||
LOG.info("No handler '{}' found into UCD {}, continue...",theHandler, u.getId());
|
LOG.info("No handler '{}' found into UCD {}, continue...", theHandler, u.getId());
|
||||||
mapProfileIDCustomGroupedLayers.put(profileId, null);
|
mapProfileIDCustomGroupedLayers.put(profileId, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1825,6 +1822,22 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the HTTP response for URL.
|
||||||
|
*
|
||||||
|
* @param url the url
|
||||||
|
* @return the HTTP response for URL
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getHTTPResponseForURL(String url) {
|
||||||
|
LOG.info("getHTTPResponseForURL called");
|
||||||
|
|
||||||
|
if (LOG.isDebugEnabled()) {
|
||||||
|
LOG.debug("getHTTPResponseForURL for URL {} ", url);
|
||||||
|
}
|
||||||
|
return HTTPRequestUtil.getResponse(url);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the WFS response.
|
* Gets the WFS response.
|
||||||
*
|
*
|
||||||
|
@ -1846,39 +1859,7 @@ public class GeoportalDataViewerServiceImpl extends RemoteServiceServlet impleme
|
||||||
}
|
}
|
||||||
|
|
||||||
String url = getWFSRequest(layerItem, mapSrsName, mapBBOX, maxFeatures, outputFormat);
|
String url = getWFSRequest(layerItem, mapSrsName, mapBBOX, maxFeatures, outputFormat);
|
||||||
StringBuffer response = new StringBuffer();
|
return HTTPRequestUtil.getResponse(url);
|
||||||
String theResponseString = "";
|
|
||||||
HttpURLConnection con = null;
|
|
||||||
LOG.debug("Built URL: " + url);
|
|
||||||
try {
|
|
||||||
URL obj = new URL(url);
|
|
||||||
con = (HttpURLConnection) obj.openConnection();
|
|
||||||
con.setRequestMethod("GET");
|
|
||||||
int responseCode = con.getResponseCode();
|
|
||||||
LOG.debug("GET Response Code: " + responseCode);
|
|
||||||
if (responseCode == HttpURLConnection.HTTP_OK) { // success
|
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
|
||||||
String inputLine;
|
|
||||||
while ((inputLine = in.readLine()) != null) {
|
|
||||||
response.append(inputLine);
|
|
||||||
}
|
|
||||||
in.close();
|
|
||||||
} else {
|
|
||||||
LOG.info("GET request did not work.");
|
|
||||||
}
|
|
||||||
|
|
||||||
theResponseString = response.toString();
|
|
||||||
// LOG.trace(theResponseString);
|
|
||||||
|
|
||||||
if (LOG.isDebugEnabled()) {
|
|
||||||
LOG.debug("getWFSResponse is empty? " + theResponseString.isEmpty());
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOG.error("Error on performing the request to URL: " + url, e);
|
|
||||||
} finally {
|
|
||||||
|
|
||||||
}
|
|
||||||
return theResponseString;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
package org.gcube.portlets.user.geoportaldataviewer.server.util;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import org.gcube.portlets.user.geoportaldataviewer.server.GeoportalDataViewerServiceImpl;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class HTTPRequestUtil.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
|
||||||
|
*
|
||||||
|
* Jun 5, 2023
|
||||||
|
*/
|
||||||
|
public class HTTPRequestUtil {
|
||||||
|
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(GeoportalDataViewerServiceImpl.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the response.
|
||||||
|
*
|
||||||
|
* @param url the url
|
||||||
|
* @return the response
|
||||||
|
*/
|
||||||
|
public static String getResponse(String url) {
|
||||||
|
if (url == null || url.isEmpty())
|
||||||
|
return null;
|
||||||
|
|
||||||
|
StringBuffer response = new StringBuffer();
|
||||||
|
String theResponseString = "";
|
||||||
|
HttpURLConnection con = null;
|
||||||
|
LOG.debug("Calling URL: " + url);
|
||||||
|
try {
|
||||||
|
URL obj = new URL(url);
|
||||||
|
con = (HttpURLConnection) obj.openConnection();
|
||||||
|
con.setRequestMethod("GET");
|
||||||
|
int responseCode = con.getResponseCode();
|
||||||
|
LOG.debug("GET Response Code: " + responseCode);
|
||||||
|
if (responseCode == HttpURLConnection.HTTP_OK) { // success
|
||||||
|
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
|
||||||
|
String inputLine;
|
||||||
|
while ((inputLine = in.readLine()) != null) {
|
||||||
|
response.append(inputLine);
|
||||||
|
}
|
||||||
|
in.close();
|
||||||
|
} else {
|
||||||
|
LOG.info("GET request did not work.");
|
||||||
|
}
|
||||||
|
|
||||||
|
theResponseString = response.toString();
|
||||||
|
// LOG.trace(theResponseString);
|
||||||
|
|
||||||
|
if (LOG.isDebugEnabled()) {
|
||||||
|
LOG.debug("getResponse is empty? " + theResponseString.isEmpty());
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.error("Error on performing the request to URL: " + url, e);
|
||||||
|
} finally {
|
||||||
|
|
||||||
|
}
|
||||||
|
LOG.debug("returning response with size: " + theResponseString.length());
|
||||||
|
return theResponseString;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -9,7 +9,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class URLUtil.
|
* The Class URLParserUtil.
|
||||||
*
|
*
|
||||||
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
* @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it)
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue