21411 #2
|
@ -27,6 +27,7 @@
|
||||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="output" path="target/classes"/>
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
|
|
|
@ -1,10 +1,28 @@
|
||||||
<?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">
|
||||||
<wb-module deploy-name="uri-resolver">
|
|
||||||
|
<wb-module deploy-name="uri-resolver-2.6.1-SNAPSHOT">
|
||||||
|
|
||||||
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
|
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
|
||||||
|
|
||||||
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
|
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
|
||||||
|
|
||||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
|
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
|
||||||
|
|
||||||
<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="storage-manager-wrapper-2.6.1-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/storage-manager-wrapper/storage-manager-wrapper">
|
||||||
|
<dependency-type>uses</dependency-type>
|
||||||
|
</dependent-module>
|
||||||
|
<dependent-module archiveName="storage-manager-core-2.13.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/storage-manager-core/storage-manager-core">
|
||||||
|
<dependency-type>uses</dependency-type>
|
||||||
|
</dependent-module>
|
||||||
|
<dependent-module archiveName="common-encryption-1.2.1.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/common-encryption/common-encryption">
|
||||||
|
<dependency-type>uses</dependency-type>
|
||||||
|
</dependent-module>
|
||||||
|
|
||||||
<property name="context-root" value="uri-resolver"/>
|
<property name="context-root" value="uri-resolver"/>
|
||||||
|
|
||||||
<property name="java-output-path" value="/uri-resolver/target/classes"/>
|
<property name="java-output-path" value="/uri-resolver/target/classes"/>
|
||||||
|
|
||||||
</wb-module>
|
</wb-module>
|
||||||
|
|
||||||
</project-modules>
|
</project-modules>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<faceted-project>
|
<faceted-project>
|
||||||
<fixed facet="wst.jsdt.web"/>
|
<fixed facet="wst.jsdt.web"/>
|
||||||
<installed facet="wst.jsdt.web" version="1.0"/>
|
<installed facet="wst.jsdt.web" version="1.0"/>
|
||||||
<installed facet="jst.web" version="2.3"/>
|
|
||||||
<installed facet="java" version="1.7"/>
|
<installed facet="java" version="1.7"/>
|
||||||
<installed facet="jst.jaxrs" version="2.0"/>
|
<installed facet="jst.jaxrs" version="2.0"/>
|
||||||
|
<installed facet="jst.web" version="3.0"/>
|
||||||
</faceted-project>
|
</faceted-project>
|
||||||
|
|
|
@ -3,6 +3,11 @@
|
||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
## [v2-6-1-SNAPSHOT] - 2021-09-02
|
||||||
|
|
||||||
|
**New features**
|
||||||
|
|
||||||
|
[#21411] add forceClose method from storage-manager, used for closing mongodb connections related to the old https urls (managed by storage-manager)
|
||||||
|
|
||||||
## [v2-5-1-SNAPSHOT] - 2021-06-04
|
## [v2-5-1-SNAPSHOT] - 2021-06-04
|
||||||
|
|
||||||
|
|
4
pom.xml
4
pom.xml
|
@ -9,7 +9,7 @@
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>org.gcube.data.transfer</groupId>
|
<groupId>org.gcube.data.transfer</groupId>
|
||||||
<artifactId>uri-resolver</artifactId>
|
<artifactId>uri-resolver</artifactId>
|
||||||
<version>2.5.1-SNAPSHOT</version>
|
<version>2.6.1-SNAPSHOT</version>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
<description>The URI Resolver is an HTTP URI resolver implemented as an REST service which gives access trough HTTP to different gcube Resolvers and gCube Applications.</description>
|
<description>The URI Resolver is an HTTP URI resolver implemented as an REST service which gives access trough HTTP to different gcube Resolvers and gCube Applications.</description>
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.contentmanagement</groupId>
|
<groupId>org.gcube.contentmanagement</groupId>
|
||||||
<artifactId>storage-manager-wrapper</artifactId>
|
<artifactId>storage-manager-wrapper</artifactId>
|
||||||
<version>[2.0.0, 3.0.0-SNAPSHOT)</version>
|
<version>[2.6.1-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.gcube.datatransfer.resolver.services;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
|
@ -20,6 +21,7 @@ import org.apache.http.HttpStatus;
|
||||||
import org.gcube.contentmanagement.blobstorage.resource.MyFile;
|
import org.gcube.contentmanagement.blobstorage.resource.MyFile;
|
||||||
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
||||||
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
|
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
|
||||||
|
import org.gcube.contentmanager.storageclient.wrapper.BackendType;
|
||||||
import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
|
import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
|
||||||
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
|
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
|
||||||
import org.gcube.datatransfer.resolver.ConstantsResolver;
|
import org.gcube.datatransfer.resolver.ConstantsResolver;
|
||||||
|
@ -48,11 +50,14 @@ public class StorageIDResolver {
|
||||||
*/
|
*/
|
||||||
protected static final String STORAGEID_RESOLVER = "storageid-resolver";
|
protected static final String STORAGEID_RESOLVER = "storageid-resolver";
|
||||||
private static final String STORAGE_ID = "storage-id";
|
private static final String STORAGE_ID = "storage-id";
|
||||||
|
private static final AccessType STORAGE_ACCESS_TYPE=AccessType.PUBLIC;
|
||||||
|
private static final BackendType STORAGE_BACKEND_TYPE=BackendType.MongoDB;
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(StorageIDResolver.class);
|
private static final Logger LOG = LoggerFactory.getLogger(StorageIDResolver.class);
|
||||||
|
|
||||||
private static String help = "https://wiki.gcube-system.org/gcube/URI_Resolver#STORAGE-ID_Resolver";
|
private static String help = "https://wiki.gcube-system.org/gcube/URI_Resolver#STORAGE-ID_Resolver";
|
||||||
|
|
||||||
|
protected static IClient storageManagerClient;
|
||||||
|
private static MemoryType memory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the storage id.
|
* Gets the storage id.
|
||||||
|
@ -123,21 +128,17 @@ public class StorageIDResolver {
|
||||||
LOG.error("storageId not found");
|
LOG.error("storageId not found");
|
||||||
throw ExceptionManager.badRequestException(httpRequest, "Missing mandatory path parameter "+STORAGE_ID, StorageIDResolver.class, help);
|
throw ExceptionManager.badRequestException(httpRequest, "Missing mandatory path parameter "+STORAGE_ID, StorageIDResolver.class, help);
|
||||||
}
|
}
|
||||||
|
storageId = identifyIdAndMemory(storageId);
|
||||||
StorageClientInstance scInstance = buildStorageClientInstance(storageId);
|
IClient iClient = getStorageClientInstance(memory);
|
||||||
String toSEID = null;
|
String toSEID = null;
|
||||||
IClient iClient = null;
|
|
||||||
storageId = scInstance.getStorageId(); //IT SHOULD BE CHANGED es. removing the suffix '-VLT'
|
|
||||||
LOG.info("I'm using the storageId {}",storageId);
|
LOG.info("I'm using the storageId {}",storageId);
|
||||||
try{
|
try{
|
||||||
iClient = scInstance.getStorageClient().getClient();
|
|
||||||
toSEID = iClient.getId(storageId); //to Storage Encrypted ID
|
toSEID = iClient.getId(storageId); //to Storage Encrypted ID
|
||||||
LOG.info("Decoded ID"+" = "+ toSEID);
|
LOG.info("Decoded ID"+" = "+ toSEID);
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
LOG.error("Storage Client Exception when getting file from storage: ", e);
|
LOG.error("Storage Client Exception when getting file from storage: ", e);
|
||||||
throw ExceptionManager.notFoundException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, StorageIDResolver.class, help);
|
throw ExceptionManager.notFoundException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, StorageIDResolver.class, help);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(toSEID==null || toSEID.isEmpty()){
|
if(toSEID==null || toSEID.isEmpty()){
|
||||||
LOG.error("Decrypted id for storageId: "+storageId +" is null or empty!");
|
LOG.error("Decrypted id for storageId: "+storageId +" is null or empty!");
|
||||||
throw ExceptionManager.notFoundException(httpRequest, "Error on decrypting the "+STORAGE_ID+ " '"+storageId+"'. Is it a valid id?", StorageIDResolver.class, help);
|
throw ExceptionManager.notFoundException(httpRequest, "Error on decrypting the "+STORAGE_ID+ " '"+storageId+"'. Is it a valid id?", StorageIDResolver.class, help);
|
||||||
|
@ -187,10 +188,13 @@ public class StorageIDResolver {
|
||||||
|
|
||||||
// if (contentType!= null)
|
// if (contentType!= null)
|
||||||
// response.header("Content-Type",contentType);
|
// response.header("Content-Type",contentType);
|
||||||
|
|
||||||
return response.build();
|
return response.build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -253,27 +257,22 @@ public class StorageIDResolver {
|
||||||
if (storageId == null || storageId.isEmpty()) {
|
if (storageId == null || storageId.isEmpty()) {
|
||||||
LOG.warn("storageId not found");
|
LOG.warn("storageId not found");
|
||||||
throw ExceptionManager.badRequestException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, this.getClass(), help);
|
throw ExceptionManager.badRequestException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, this.getClass(), help);
|
||||||
}
|
}
|
||||||
StorageClientInstance client = buildStorageClientInstance(storageId);
|
storageId = identifyIdAndMemory(storageId);
|
||||||
|
IClient iClient = getStorageClientInstance(memory);
|
||||||
String toSEID = null;
|
String toSEID = null;
|
||||||
IClient iClient = null;
|
|
||||||
storageId = client.getStorageId(); //IT SHOULD BE CHANGED es. removing the suffix '-VLT'
|
|
||||||
LOG.info("I'm using the storageId {}",storageId);
|
LOG.info("I'm using the storageId {}",storageId);
|
||||||
|
|
||||||
try{
|
try{
|
||||||
iClient = client.getStorageClient().getClient();
|
|
||||||
toSEID = iClient.getId(storageId); //to Storage Encrypted ID
|
toSEID = iClient.getId(storageId); //to Storage Encrypted ID
|
||||||
LOG.debug("Decoded ID"+" = "+ toSEID);
|
LOG.info("Decoded ID"+" = "+ toSEID);
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
LOG.error("Storage Client Exception when getting file from storage: ", e);
|
LOG.error("Storage Client Exception when getting file from storage: ", e);
|
||||||
throw ExceptionManager.internalErrorException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, StorageIDResolver.class, help);
|
throw ExceptionManager.notFoundException(httpRequest, "Storage Client Exception when getting file from storage with id: "+storageId, StorageIDResolver.class, help);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(toSEID==null || toSEID.isEmpty()){
|
if(toSEID==null || toSEID.isEmpty()){
|
||||||
LOG.error("Decrypted id for storageId: "+storageId +" is null or empty!");
|
LOG.error("Decrypted id for storageId: "+storageId +" is null or empty!");
|
||||||
throw ExceptionManager.notFoundException(httpRequest, "Error on decrypting the "+STORAGE_ID+ " '"+storageId+"'. Is it a valid id?", StorageIDResolver.class, help);
|
throw ExceptionManager.notFoundException(httpRequest, "Error on decrypting the "+STORAGE_ID+ " '"+storageId+"'. Is it a valid id?", StorageIDResolver.class, help);
|
||||||
}
|
}
|
||||||
|
|
||||||
//SETTING DEFAULT METADATA
|
//SETTING DEFAULT METADATA
|
||||||
String fileName = ConstantsResolver.DEFAULT_FILENAME_FROM_STORAGE_MANAGER;
|
String fileName = ConstantsResolver.DEFAULT_FILENAME_FROM_STORAGE_MANAGER;
|
||||||
String contentType = ConstantsResolver.DEFAULT_CONTENTTYPE_UNKNOWN_UNKNOWN;
|
String contentType = ConstantsResolver.DEFAULT_CONTENTTYPE_UNKNOWN_UNKNOWN;
|
||||||
|
@ -328,37 +327,47 @@ public class StorageIDResolver {
|
||||||
.header("Content-Type", contentType)
|
.header("Content-Type", contentType)
|
||||||
.header(ConstantsResolver.CONTENT_LENGTH, size)
|
.header(ConstantsResolver.CONTENT_LENGTH, size)
|
||||||
.header(ConstantsResolver.CONTENT_DISPOSITION,"attachment; filename=\""+fileName+"\"");
|
.header(ConstantsResolver.CONTENT_DISPOSITION,"attachment; filename=\""+fileName+"\"");
|
||||||
|
iClient.forceClose();
|
||||||
return response.build();
|
return response.build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds the storage client instance.
|
* Get a storage-manager client instance. A new storage instance will be instantied only if the memory type is not the same of the previous one.
|
||||||
|
* In this case the old connection will be closed.
|
||||||
*
|
*
|
||||||
* @param storageId the storage id
|
* @param memoryType indicates the memory type (Persistent, Volatile or whatever)
|
||||||
* @return the storage client instance
|
* @return the storage client instance
|
||||||
* @throws Exception the exception
|
|
||||||
*/
|
*/
|
||||||
protected static StorageClientInstance buildStorageClientInstance(String storageId) throws Exception{
|
protected static IClient getStorageClientInstance(MemoryType memory) {
|
||||||
|
if ((!Objects.isNull(storageManagerClient)) && (storageManagerClient.getGcubeMemoryType().equals(memory)))
|
||||||
MemoryType memory=null;
|
return storageManagerClient;
|
||||||
if(storageId.endsWith(org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants.VOLATILE_URL_IDENTIFICATOR)){
|
else {
|
||||||
memory=MemoryType.VOLATILE;
|
if(!Objects.isNull(storageManagerClient)) {
|
||||||
storageId=storageId.replace(org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants.VOLATILE_URL_IDENTIFICATOR, "");
|
LOG.debug("going to close an old storage-client instance");
|
||||||
|
storageManagerClient.forceClose();
|
||||||
|
}
|
||||||
|
LOG.debug("initializing a new storage-client instance");
|
||||||
|
storageManagerClient=new StorageClient(StorageIDResolver.class.getName(), StorageIDResolver.class.getSimpleName(), STORAGEID_RESOLVER, STORAGE_ACCESS_TYPE, memory, STORAGE_BACKEND_TYPE).getClient();
|
||||||
|
return storageManagerClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
StorageClient client;
|
|
||||||
if(memory==null)
|
|
||||||
client=new StorageClient(StorageIDResolver.class.getName(), StorageIDResolver.class.getSimpleName(), STORAGEID_RESOLVER, AccessType.PUBLIC);
|
|
||||||
else
|
|
||||||
client=new StorageClient(StorageIDResolver.class.getName(), StorageIDResolver.class.getSimpleName(), STORAGEID_RESOLVER, AccessType.PUBLIC, memory);
|
|
||||||
|
|
||||||
return new StorageClientInstance(client, memory, storageId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the right memory type extrapolated from the storageid
|
||||||
|
* @param storageId storageid with backend type specification (if present)
|
||||||
|
* @return storageId without backend type specification
|
||||||
|
*/
|
||||||
|
private static String identifyIdAndMemory(String storageId) {
|
||||||
|
if(storageId.endsWith(org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants.VOLATILE_URL_IDENTIFICATOR)){
|
||||||
|
LOG.info("identificated a VOLATILE url");
|
||||||
|
memory=MemoryType.VOLATILE;
|
||||||
|
storageId=storageId.replace(org.gcube.contentmanagement.blobstorage.transport.backend.util.Costants.VOLATILE_URL_IDENTIFICATOR, "");
|
||||||
|
}else {
|
||||||
|
memory=MemoryType.PERSISTENT;
|
||||||
|
}
|
||||||
|
return storageId;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the storage metadata file.
|
* Gets the storage metadata file.
|
||||||
|
|
Loading…
Reference in New Issue