Fixed project profile and logs

This commit is contained in:
Giancarlo Panichi 2024-04-15 15:53:19 +02:00
parent b47943dd71
commit 89be6ec090
17 changed files with 243 additions and 160 deletions

View File

@ -1,36 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="test" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -308,4 +308,4 @@ This licence shall be governed by the Belgian law if:
- Eclipse Public License v. 1.0
- Cecill v. 2.0
- Cecill v. 2.0

View File

@ -0,0 +1,46 @@
# gCube Geonetwork Connector
This is the implementation of the DataMiner service that integrates the WPS 52North in the D4Science Infrastructure.
## Structure of the project
* The source code is present in the src folder.
## Built With
* [OpenJDK](https://openjdk.java.net/) - The JDK used
* [Maven](https://maven.apache.org/) - Dependency Management
## Documentation
* Use of this service is is described on [Wiki](https://wiki.gcube-system.org/gcube/SDI-Service).
## Change log
See [Releases](https://code-repo.d4science.org/gCubeSystem/gcube-geonetwork-connector/releases).
## Authors
* **Roberto Cirillo** ([ORCID]()) - [ISTI-CNR Infrascience Group](http://nemis.isti.cnr.it/groups/infrascience)
## License
This project is licensed under the EUPL V.1.1 License - see the [LICENSE.md](LICENSE.md) file for details.
## About the gCube Framework
This software is part of the [gCubeFramework](https://www.gcube-system.org/ "gCubeFramework"): an
open-source software toolkit used for building and operating Hybrid Data
Infrastructures enabling the dynamic deployment of Virtual Research Environments
by favouring the realisation of reuse oriented policies.
The projects leading to this software have received funding from a series of European Union programmes including:
- the Sixth Framework Programme for Research and Technological Development
- DILIGENT (grant no. 004260);
- the Seventh Framework Programme for research, technological development and demonstration
- D4Science (grant no. 212488), D4Science-II (grant no.239019), ENVRI (grant no. 283465), EUBrazilOpenBio (grant no. 288754), iMarine(grant no. 283644);
- the H2020 research and innovation programme
- BlueBRIDGE (grant no. 675680), EGIEngage (grant no. 654142), ENVRIplus (grant no. 654182), Parthenos (grant no. 654119), SoBigData (grant no. 654024),DESIRA (grant no. 818194), ARIADNEplus (grant no. 823914), RISIS2 (grant no. 824091), PerformFish (grant no. 727610), AGINFRAplus (grant no. 731001);

View File

@ -9,23 +9,21 @@
<baseDirectory>/</baseDirectory>
<fileSets>
<fileSet>
<directory>${distroDirectory}</directory>
<outputDirectory>/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>README</include>
<include>changelog.xml</include>
<include>README.md</include>
<include>LICENSE.md</include>
<include>CHANGELOG.md</include>
<include>profile.xml</include>
</includes>
<fileMode>755</fileMode>
<filtered>true</filtered>
</fileSet>
</fileSets>
<files>
<file>
<source>${distroDirectory}/profile.xml</source>
<outputDirectory>/</outputDirectory>
</file>
<file>
<source>target/${build.finalName}.${packaging}</source>
<source>target/${build.finalName}.${project.packaging}</source>
<outputDirectory>/${artifactId}</outputDirectory>
</file>
</files>

View File

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Resource>
<ID></ID>
<Type>Library</Type>
<Profile>
<Description>${project.description}</Description>
<Class>DataAccess</Class>
<Name>${project.artifactId}</Name>
<Version>1.0.0</Version>
<Packages>
<Software>
<Description>${project.description}</Description>
<Name>${project.artifactId}</Name>
<Version>${project.version}</Version>
<MavenCoordinates>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
</MavenCoordinates>
<Type>Library</Type>
<Files>
<File>${project.build.finalName}.${project.packaging}</File>
</Files>
</Software>
</Packages>
</Profile>
</Resource>

59
pom.xml
View File

@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@ -11,16 +12,16 @@
<version>1.0.0-SNAPSHOT</version>
<scm>
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection>
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</developerConnection>
<url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url>
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection>
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</developerConnection>
<url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url>
</scm>
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
@ -46,16 +47,7 @@
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gcube.resources.discovery</groupId>
<artifactId>ic-client</artifactId>
@ -83,12 +75,31 @@
<version>4.5.2</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.6.2</version>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.6.2</version>
</dependency>
<!-- Logger -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<!-- JUnit TEST -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
@ -96,7 +107,7 @@
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>${distroDirectory}/descriptor.xml</descriptor>
<descriptor>descriptor.xml</descriptor>
</descriptors>
</configuration>
<executions>

29
profile.xml Normal file
View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<Resource>
<ID></ID>
<Type>Library</Type>
<Profile>
<Description>${description}</Description>
<Class>DataAccess</Class>
<Name>${artifactId}</Name>
<Version>1.0.0</Version>
<Packages>
<Software>
<Description>${description}</Description>
<Name>${artifactId}</Name>
<Version>${version}</Version>
<MavenCoordinates>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
</MavenCoordinates>
<Type>Library</Type>
<Files>
<File>${build.finalName}.${packaging}</File>
</Files>
</Software>
</Packages>
</Profile>
</Resource>

View File

@ -32,7 +32,9 @@ public class GeoNetworkConnectorRequestHandler extends RequestHandler {
private static final String SDI = "/SDI";
private static final boolean GENERAL = true; //retrieve the general credentials from SDI (without web service)
private Logger logger;
private static Logger logger = LoggerFactory
.getLogger(GeoNetworkConnectorRequestHandler.class);
private GCubeCache<String, String> gCubeCache;
private GCubeRestClient restClient = new GCubeRestClient();
@ -49,7 +51,7 @@ public class GeoNetworkConnectorRequestHandler extends RequestHandler {
@Override
public void handleRequest(RequestEvent e) {
System.out.println("Handling request");
logger.debug("Handling request");
HttpServletRequest httpServletRequest = e.request();
// get host from ApplicationContext
@ -57,15 +59,15 @@ public class GeoNetworkConnectorRequestHandler extends RequestHandler {
// get token from request
String token = getToken(httpServletRequest);
System.out.println("Retrieve token from request = " + token);
logger.debug("Retrieve token from request = " + token);
if (AuthenticationUtils.isNotNullNotEmptyNotWhiteSpace(token)) {
System.out.println("Token found: " + token);
logger.debug("Token found: " + token);
if (validateToken(token)) {
// retrieve endpoint to get credentials in Geonetwork
String endpoint = getEndpoint(token);
System.out.println("Endpoint found: " + endpoint);
logger.debug("Endpoint found: " + endpoint);
// TODO - Can be the endpoint stored in the cache object?
if (AuthenticationUtils.isNotNullNotEmptyNotWhiteSpace(endpoint)) {
@ -76,24 +78,24 @@ public class GeoNetworkConnectorRequestHandler extends RequestHandler {
// check current token with tokenCache
if (token.equals(tokenCache)) {
System.out.println("Set credentials attribute retrieved from cache " + usernameCache + " " + passwordCache);
logger.debug("Set credentials attribute retrieved from cache " + usernameCache + " " + passwordCache);
httpServletRequest.setAttribute(AuthenticationUtils.USERNAME, usernameCache);
httpServletRequest.setAttribute(AuthenticationUtils.PASSWORD, passwordCache);
} else {
//get credentials
System.out.println("RETRIEVE CREDENTIALS IN GENERAL MODE = " + GENERAL);
logger.debug("RETRIEVE CREDENTIALS IN GENERAL MODE = " + GENERAL);
AccessibleCredentialsEntity accessibleCredentials = getAccessibleCredentials(endpoint, host, token, GENERAL);
System.out.println("Credentials: " + accessibleCredentials.getUsername() + "/" + accessibleCredentials.getPassword());
logger.debug("Credentials: " + accessibleCredentials.getUsername() + "/" + accessibleCredentials.getPassword());
httpServletRequest.setAttribute(AuthenticationUtils.USERNAME, accessibleCredentials.getUsername());
httpServletRequest.setAttribute(AuthenticationUtils.PASSWORD, accessibleCredentials.getPassword());
// set/update data in the cache
System.out.println("Put token in the cache: " + token);
logger.debug("Put token in the cache: " + token);
gCubeCache.put(AuthenticationUtils.TOKEN_CACHE, token);
System.out.println("Put also username and password in the cache");
logger.debug("Put also username and password in the cache");
gCubeCache.put(AuthenticationUtils.USERNAME, accessibleCredentials.getUsername());
gCubeCache.put(AuthenticationUtils.PASSWORD, accessibleCredentials.getPassword());
}
@ -103,7 +105,7 @@ public class GeoNetworkConnectorRequestHandler extends RequestHandler {
RequestError.request_not_authorized_error.fire("Invalid token in the request");
}
} else {
System.out.println("Token not present in the request: NO/OP");
logger.debug("Token not present in the request: NO/OP");
}
}
@ -118,14 +120,14 @@ public class GeoNetworkConnectorRequestHandler extends RequestHandler {
// case 1 - get token from gcube-token query-string
String gCubeToken = httpServletRequest.getParameter(AuthenticationUtils.GCUBE_QUERY_STRING);
if (AuthenticationUtils.isNotNullNotEmptyNotWhiteSpace(gCubeToken)) {
System.out.println("Get token from query-string");
logger.debug("Get token from query-string");
return gCubeToken;
}
// case 2 - get token from gcube-token header
gCubeToken = httpServletRequest.getHeader(AuthenticationUtils.GCUBE_QUERY_STRING);
if (AuthenticationUtils.isNotNullNotEmptyNotWhiteSpace(gCubeToken)) {
System.out.println("Get token from gcube-token header");
logger.debug("Get token from gcube-token header");
return gCubeToken;
}
@ -133,7 +135,7 @@ public class GeoNetworkConnectorRequestHandler extends RequestHandler {
String authorization = httpServletRequest.getHeader(AuthenticationUtils.AUTHORIZATION);
if (AuthenticationUtils.isNotNullNotEmptyNotWhiteSpace(authorization)
&& authorization.startsWith(AuthenticationUtils.BASIC)) {
System.out.println("Get token from basic authorization header");
logger.debug("Get token from basic authorization header");
// header = Authorization: Basic base64credentials
String base64Credentials = authorization.replace(AuthenticationUtils.BASIC, "");
String credentials = new String(Base64.decodeBase64(base64Credentials.trim()));
@ -143,22 +145,22 @@ public class GeoNetworkConnectorRequestHandler extends RequestHandler {
return values[1];
}
System.out.println("gcube-token not found in query-string, in header and in basic authorization header");
logger.info("gcube-token not found in query-string, in header and in basic authorization header");
// case 4 - get token from HTML form in the password field
gCubeToken = httpServletRequest.getParameter(AuthenticationUtils.PASSWORD);
if (AuthenticationUtils.isNotNullNotEmptyNotWhiteSpace(gCubeToken)) {
System.out.println("Get token from HTML form (in the password field)");
logger.debug("Get token from HTML form (in the password field)");
String user = httpServletRequest.getParameter(AuthenticationUtils.USERNAME);
System.out.println("Get username from HTML form: " + user);
logger.debug("Get username from HTML form: " + user);
if (AuthenticationUtils.isNotNullNotEmptyNotWhiteSpace(user) && user.equals(getUser(gCubeToken))) //check username
return gCubeToken;
System.out.println("Username doesn't match with ClientInfo of gcube");
logger.info("Username doesn't match with ClientInfo of gcube");
} else
System.out.println("gcube-token also not found in the HTML form in the password field");
logger.info("gcube-token also not found in the HTML form in the password field");
return null;
}
@ -168,7 +170,7 @@ public class GeoNetworkConnectorRequestHandler extends RequestHandler {
try {
AuthorizationEntry authorizationEntry = authorizationService().get(token);
String scope = authorizationEntry.getContext();
System.out.println("Set scope in to " + scope);
logger.debug("Set scope in to " + scope);
ScopeProvider.instance.set(scope);
SecurityTokenProvider.instance.set(token);
@ -186,7 +188,7 @@ public class GeoNetworkConnectorRequestHandler extends RequestHandler {
List<GCoreEndpoint> gCoreEndpoints = client.submit(query);
int size = gCoreEndpoints.size();
System.out.println("gCoreEndpoints size = " + size);
logger.debug("gCoreEndpoints size = " + size);
if (size > 0) {//I get only the first. Usually it must be only one
GCoreEndpoint gCoreEndpoint = gCoreEndpoints.get(0);
@ -212,7 +214,7 @@ public class GeoNetworkConnectorRequestHandler extends RequestHandler {
private boolean validateToken(String token) {
// TODO How to implement the validation of the token
System.out.println("Validate token in progress...");
logger.debug("Validate token in progress...");
return true;
}
@ -221,19 +223,19 @@ public class GeoNetworkConnectorRequestHandler extends RequestHandler {
if (general){
String url = endpoint + SDI + "?" + AuthenticationUtils.GCUBE_QUERY_STRING + "=" + token;
//http://sdi-d-d4s.d4science.org/sdi-service/gcube/service/SDI?gcube-token=feda0617-cd9d-4841-b6f0-e047da5d32ed-98187548";
System.out.println("general url : " + url );
logger.info("general url : " + url );
return restClient.getGeneralAccessibleCredentials(url, host);
}else{
/*
String url = endpoint + GEONETWORK_CREDENTIALS + host + "?" + AuthenticationUtils.GCUBE_QUERY_STRING + "=" + token;
//http://sdi-d-d4s.d4science.org:80/sdi-service/gcube/service/GeoNetwork/credentials/geonetwork-sdi.dev.d4science.org?gcube-token=feda0617-cd9d-4841-b6f0-e047da5d32ed-98187548
System.out.println("url : " + url );
logger.debug("url : " + url );
return restClient.getAccessibleCredentials(url);
*/
String hst = "sdi-d-d4s.d4science.org";
String get = "/sdi-service/gcube/service/GeoNetwork/credentials/geonetwork-sdi.dev.d4science.org?gcube-token=feda0617-cd9d-4841-b6f0-e047da5d32ed-98187548";
System.out.println("url : " + hst + get );
logger.info("url : " + hst + get );
return restClient.getAccessibleCredentialsHttp(hst, get);
}
}

View File

@ -18,17 +18,17 @@ import org.slf4j.LoggerFactory;
public class GeoNetworkFilter implements Filter {
private Logger logger = LoggerFactory.getLogger(this.getClass());
private Logger logger = LoggerFactory.getLogger(GeoNetworkFilter.class);
@Override
public void init(FilterConfig filterConfig) throws ServletException {
System.out.println("init() method");
logger.info("init() GeoNetworkFilter");
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
throws IOException, ServletException {
System.out.println("doFilter() method");
logger.debug("doFilter() method");
ServletRequestWrapper request = new ServletRequestWrapper((HttpServletRequest) servletRequest);
HttpServletResponse response = (HttpServletResponse) servletResponse;
@ -46,11 +46,11 @@ public class GeoNetworkFilter implements Filter {
+ Base64.encodeBase64String(token.getBytes());
request.addHeader(AuthenticationUtils.AUTHORIZATION, basic_authentication);
System.out.println("Added authorization header : " + request.getHeader(AuthenticationUtils.AUTHORIZATION));
logger.debug("Added authorization header : " + request.getHeader(AuthenticationUtils.AUTHORIZATION));
request.addParameter(AuthenticationUtils.USERNAME, username);
request.addParameter(AuthenticationUtils.PASSWORD, password);
System.out.println("Added parameters in the request : " + username + "/" + password);
logger.debug("Added parameters in the request : " + username + "/" + password);
}
filterChain.doFilter(request, response);
@ -58,7 +58,7 @@ public class GeoNetworkFilter implements Filter {
@Override
public void destroy() {
System.out.println("destroy() method");
logger.info("destroy() GeoNetworkFilter");
}
}

View File

@ -4,15 +4,10 @@ import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
@ -20,6 +15,7 @@ import org.gcube.data.access.connector.rest.entity.AccessibleCredentialsEntity;
import org.gcube.data.access.connector.rest.entity.SDIEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
import net.sf.json.JSONObject;
@ -29,7 +25,7 @@ public class GCubeRestClient {
private static String CONTEXT_MANAGER = "CONTEXT_MANAGER";
private static String CONTEXT_USER = "CONTEXT_USER";
private Logger logger = LoggerFactory.getLogger(this.getClass());
private Logger logger = LoggerFactory.getLogger(GCubeRestClient.class);
public AccessibleCredentialsEntity getAccessibleCredentials(String url) {
@ -39,14 +35,14 @@ public class GCubeRestClient {
HttpGet httpget = new HttpGet(url);
httpget.setConfig(config);
logger.warn("Executing request " + httpget.getRequestLine() + " to " + url);
logger.debug("Executing request " + httpget.getRequestLine() + " to " + url);
try {
CloseableHttpResponse response = httpclient.execute(httpget);
String json = EntityUtils.toString(response.getEntity());
logger.warn("JSON response: \n" + json);
logger.debug("JSON response: \n" + json);
JSONObject jsonObject = JSONObject.fromObject(json);
return (AccessibleCredentialsEntity) JSONObject.toBean(jsonObject, AccessibleCredentialsEntity.class);
@ -58,7 +54,7 @@ public class GCubeRestClient {
public AccessibleCredentialsEntity getGeneralAccessibleCredentials(String url, String host) {
logger.warn("REST call to URL: " + url);
logger.debug("REST call to URL: " + url);
CloseableHttpClient httpclient = HttpClients.custom().build();
@ -68,13 +64,13 @@ public class GCubeRestClient {
HttpGet httpget = new HttpGet(url);
httpget.setConfig(config);
logger.warn("Executing request " + httpget.getRequestLine() + " to " + url);
logger.debug("Executing request " + httpget.getRequestLine() + " to " + url);
try {
CloseableHttpResponse resp = httpclient.execute(target, httpget);
String json = EntityUtils.toString(resp.getEntity());
logger.warn("JSON response: \n" + json);
logger.debug("JSON response: \n" + json);
Gson gson = new Gson();
SDIEntity response =(SDIEntity) gson.fromJson(json, SDIEntity.class);
@ -115,12 +111,12 @@ public class GCubeRestClient {
HttpGet httpget = new HttpGet(get);
httpget.setConfig(config);
logger.warn("Executing request " + httpget.getRequestLine() + " to " + get);
logger.debug("Executing request " + httpget.getRequestLine() + " to " + get);
try {
CloseableHttpResponse response = httpclient.execute(target, httpget);
String json = EntityUtils.toString(response.getEntity());
logger.warn("JSON response: \n" + json);
logger.debug("JSON response: \n" + json);
JSONObject jsonObject = JSONObject.fromObject(json);
AccessibleCredentialsEntity ac = (AccessibleCredentialsEntity) JSONObject.toBean(jsonObject, AccessibleCredentialsEntity.class);

View File

@ -2,6 +2,7 @@ package org.gcube.data.access.connector.rest.entity;
import java.util.List;
public class AvailableInstances {
private List<InstancesEntity> availableInstances;
@ -14,4 +15,10 @@ public class AvailableInstances {
this.availableInstances = availableInstances;
}
@Override
public String toString() {
return "AvailableInstances [availableInstances=" + availableInstances + "]";
}
}

View File

@ -14,4 +14,9 @@ public class GeoserverClusterConfigurationEntity {
this.availableInstances = availableInstances;
}
@Override
public String toString() {
return "GeoserverClusterConfigurationEntity [availableInstances=" + availableInstances + "]";
}
}

View File

@ -91,4 +91,13 @@ public class InstancesEntity {
}
@Override
public String toString() {
return "InstancesEntity [baseEndpoint=" + baseEndpoint + ", accessibleCredentials=" + accessibleCredentials
+ ", version=" + version + ", contextGroup=" + contextGroup + ", sharedGroup=" + sharedGroup
+ ", publicGroup=" + publicGroup + "]";
}
}

View File

@ -1,9 +1,5 @@
package org.gcube.data.access.connector;
import java.util.Arrays;
import net.sf.json.JSONObject;
import org.apache.commons.codec.binary.Base64;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
@ -16,10 +12,12 @@ import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.gcube.data.access.connector.rest.entity.AccessibleCredentialsEntity;
import org.junit.Ignore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Ignore
public class Test {
private static Logger logger = LoggerFactory.getLogger("Test");
@ -28,7 +26,7 @@ public class Test {
try {
logger.info("Test");
String url = "http://geonetwork-sdi.dev.d4science.org/geonetwork/srv/api/0.1/me";
String url = "https://geonetwork-1.dev.d4science.org/geonetwork/srv/api/0.1/me";
String token = "admin:admin";

View File

@ -7,20 +7,29 @@ import java.net.Proxy;
import java.util.Arrays;
import org.apache.commons.codec.binary.Base64;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
import org.junit.Ignore;
//import org.springframework.http.HttpEntity;
//import org.springframework.http.HttpHeaders;
//import org.springframework.http.HttpMethod;
//import org.springframework.http.MediaType;
//import org.springframework.http.ResponseEntity;
//import org.springframework.http.client.SimpleClientHttpRequestFactory;
//import org.springframework.web.client.RestTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Ignore
public class TestGN264 {
private static Logger logger = LoggerFactory
.getLogger(TestGN264.class);
public static void main(String[] args) {
try {
String url = "http://geonetwork-sdi.dev.d4science.org/geonetwork/srv/en/metadata.show?id=29";
RestTemplate restTemplate = getRestTemplate(); //new RestTemplate();
/*RestTemplate restTemplate = getRestTemplate(); //new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
@ -33,14 +42,14 @@ public class TestGN264 {
System.out.println("Result - status ("+ response.getStatusCode() + ") has body: " + response.hasBody());
System.out.println(response.getBody());
// String response = restTemplate.getForObject(url, String.class);
// System.out.println(response);
// System.out.println(response);*/
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
}
private static RestTemplate getRestTemplate() {
private static void getRestTemplate() {
final Authenticator authenticator = new Authenticator() {
@Override
@ -51,7 +60,7 @@ public class TestGN264 {
Authenticator.setDefault(authenticator);
final SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
/*final SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
final InetSocketAddress address = new InetSocketAddress("proxy.eng.it", 3128);
final Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
factory.setProxy(proxy);
@ -59,7 +68,8 @@ public class TestGN264 {
final RestTemplate restTemplate = new RestTemplate();
restTemplate.setRequestFactory(factory);// pass the factory instance to restTemplate
return restTemplate;
*/
return;
}
}

View File

@ -22,11 +22,13 @@ import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.gcube.data.access.connector.rest.entity.AccessibleCredentialsEntity;
import org.gcube.data.access.connector.rest.entity.SDIEntity;
import org.junit.Ignore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
@Ignore
public class TestGeonetworkConfiguration {
private static String CONTEXT_MANAGER = "CONTEXT_MANAGER";

View File

@ -12,11 +12,13 @@ import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.gcube.data.access.connector.rest.entity.AccessibleCredentialsEntity;
import org.junit.Ignore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.sf.json.JSONObject;
@Ignore
public class TestRest {
private static Logger logger = LoggerFactory.getLogger("TestRest");