ref 16252: NLP Hub portlet not working when token is passed

https://support.d4science.org/issues/16252

Fixed DataMiner Discover by token

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-analysis/nlphub@178563 82a268e6-3cf1-43bd-a215-b396298e98cf
master
Giancarlo Panichi 5 years ago
parent 2eb9091e33
commit bf73c82d57

@ -63,13 +63,7 @@
<version>2.8.2</version>
<scope>compile</scope>
</dependency>
<!-- GCube -->
<!-- <dependency> -->
<!-- <groupId>org.gcube.data.analysis</groupId> -->
<!-- <artifactId>data-miner-manager-cl</artifactId> -->
<!-- <version>[1.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version> -->
<!-- <scope>compile</scope> -->
<!-- </dependency> -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-authorization</artifactId>
@ -123,12 +117,14 @@
<scope>compile</scope>
</dependency>
<!-- LOGGER -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
@ -194,6 +190,8 @@
</execution>
</executions>
</plugin>
</plugins>
</build>

@ -28,7 +28,7 @@ public class DMDiscover {
private String retrieveServiceInScope(String scope) throws Exception {
List<String> serviceAddress = InformationSystemUtils
.retrieveServiceAddress(Constants.DATAMINER_SERVICE_CATEGORY, Constants.DATA_MINER_SERVICE_NAME, scope);
.retrieveServiceEndpoint(Constants.DATAMINER_SERVICE_CATEGORY, Constants.DATA_MINER_SERVICE_NAME, scope);
logger.debug("Service Address retrieved:" + serviceAddress);
if (serviceAddress == null || serviceAddress.size() < 1) {
logger.error("No DataMiner service address available!");

@ -3,6 +3,7 @@ package org.gcube.data.analysis.nlphub.is;
import java.util.ArrayList;
import java.util.List;
import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.resources.discovery.client.api.DiscoveryClient;
@ -14,7 +15,7 @@ import org.slf4j.LoggerFactory;
public class InformationSystemUtils {
private static Logger logger = LoggerFactory.getLogger(InformationSystemUtils.class);
public static List<String> retrieveServiceAddress(String category, String name, String scope) throws Exception {
public static List<String> retrieveServiceEndpoint(String category, String name, String scope) throws Exception {
try {
if (scope == null || scope.length() == 0)
@ -33,8 +34,31 @@ public class InformationSystemUtils {
} catch (Throwable e) {
logger.error("Error in discovery DataMiner Service Endpoint in scope: " + scope);
logger.error("Error: " + e.getLocalizedMessage());
e.printStackTrace();
logger.error("Error: " + e.getLocalizedMessage(),e);
throw e;
}
}
public static List<String> retrieveGCoreEndpoint(String category, String name, String scope) throws Exception {
try {
if (scope == null || scope.length() == 0)
return new ArrayList<String>();
ScopeProvider.instance.set(scope);
SimpleQuery query = ICFactory.queryFor(GCoreEndpoint.class);
query.addCondition("$resource/Profile/ServiceClass/text() eq '" + category + "'")
.addCondition("$resource/Profile/ServiceName/text() eq '" + name + "'")
.setResult("$resource/Profile/AccessPoint/Interface/text()");
DiscoveryClient<String> client = ICFactory.client();
List<String> addresses = client.submit(query);
return addresses;
} catch (Throwable e) {
logger.error("Error in discovery DataMiner Service Endpoint in scope: " + scope);
logger.error("Error: " + e.getLocalizedMessage(),e);
throw e;
}
}

@ -1,43 +1,39 @@
package org.gcube.data.analysis.nlphub.shared;
public class Constants {
public static final boolean DEBUG = false;
public static final boolean TEST_ENABLE = false;
public static final boolean TEST_ENABLE = true;
public static final String DEFAULT_USER = "giancarlo.panichi";
public static final String DEFAULT_SCOPE = "/gcube/devNext/NextNext";
public static final String DEFAULT_TOKEN = "";
public static final String DEFAULT_TOKEN = "d35c72d3-f6b5-4363-afbe-8e330ef9a913-843339462";
public static final String IS_URL = "http://registry.d4science.org";
public static final String STORAGEHUB_SERVICE_CLASS = "DataAccess";
public static final String STORAGEHUB_SERVICE_NAME = "StorageHub";
public static final String DATA_MINER_SERVICE_NAME = "DataMiner";
public static final String DATAMINER_SERVICE_CATEGORY = "DataAnalysis";
public static final String DEFAULT_DATAMINER_URL = "http://dataminer-prototypes.d4science.org/wps/WebProcessingService";
public static final String TOKEN_PARAMETER = "gcube-token";
public static final String DEFAULT_DESCRIPTION = "NlpHub upload";
public static final String MIME_TEXT = "text/plain";
public static final String CONTENT_TYPE = "Content-Type";
public static final String UNAVAILABLE = "unavailable";
public static final String ERROR_ID = "ERROR";
public static final String INPUT_FILE_PARAMETER = "input";
public static final String REQUEST = "Request";
/*public static String hexDump(byte[] bytes) {
char[] hexArray = "0123456789ABCDEF".toCharArray();
char[] hexChars = new char[bytes.length * 3];
for (int j = 0; j < bytes.length; j++) {
hexChars[3*j] = hexArray[bytes[j] / 16];
hexChars[3*j+1] = hexArray[bytes[j] % 16];
hexChars[3*j+2] = ' ';
}
return new String(hexChars);
}*/
/*
* public static String hexDump(byte[] bytes) { char[] hexArray =
* "0123456789ABCDEF".toCharArray(); char[] hexChars = new char[bytes.length
* * 3]; for (int j = 0; j < bytes.length; j++) { hexChars[3*j] =
* hexArray[bytes[j] / 16]; hexChars[3*j+1] = hexArray[bytes[j] % 16];
* hexChars[3*j+2] = ' '; } return new String(hexChars); }
*/
}

@ -1,88 +0,0 @@
package nlphub;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.gcube.data.analysis.nlphub.shared.Constants;
import org.junit.Assert;
import org.junit.Test;
public class DiscoverDataMinerServiceTest {
private static final Logger logger = LoggerFactory.getLogger(DiscoverDataMinerServiceTest.class);
@Test
public void discover() {
if (Constants.TEST_ENABLE) {
try {
String dataMinerServiceUrl = null;
String urlInformationSystem = "http://registry.d4science.org/icproxy/gcube/service/ServiceEndpoint/DataAnalysis/DataMiner?";
logger.debug("Request url: " + urlInformationSystem);
urlInformationSystem += "gcube-token=" + "f57441ac-b361-4c2d-992a-40db034f1b8c-843339462";
URL url = new URL(urlInformationSystem);
HttpURLConnection connection = null;
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setDoInput(true);
connection.setDoOutput(false);
connection.setUseCaches(false);
try (BufferedReader r = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
dataMinerServiceUrl = readProfileInfo(r);
}
logger.debug("DataMinerServiceUrl: " + dataMinerServiceUrl);
Assert.assertTrue(true);
} catch (Throwable e) {
logger.error("Error retrieving DataMinerServiceUrl: "+e.getLocalizedMessage(),e);
Assert.fail("Error retrieving DataMinerServiceUrl: "+e.getLocalizedMessage());
}
} else {
Assert.assertTrue(true);
}
}
private String readProfileInfo(BufferedReader r) throws FactoryConfigurationError, XMLStreamException {
String dataMinerServiceUrl = null;
XMLInputFactory xmlInFact = XMLInputFactory.newInstance();
XMLStreamReader reader = xmlInFact.createXMLStreamReader(r);
while (reader.hasNext()) {
int eventType = reader.next();
if (eventType == XMLStreamConstants.START_ELEMENT) {
logger.debug("Read Element: " + reader.getLocalName());
if (reader.getLocalName().compareToIgnoreCase("EndPoint") == 0) {
logger.debug("Attribute count:" + reader.getAttributeCount());
for (int i = 0; i < reader.getAttributeCount(); i++) {
logger.debug("Attribute Name: " + reader.getAttributeName(i));
logger.debug("Attribute Value: " + reader.getAttributeValue(i));
if (reader.getAttributeName(i).toString().compareToIgnoreCase("EntryName") == 0
&& reader.getAttributeValue(i).toString()
.compareToIgnoreCase("dataminer-prototypes.d4science.org") == 0) {
dataMinerServiceUrl = reader.getElementText();
dataMinerServiceUrl = dataMinerServiceUrl.replace("\\n", "").replace("\\r", "");
logger.debug("DataMiner service url retrieved: " + dataMinerServiceUrl);
return dataMinerServiceUrl;
}
}
}
}
}
return dataMinerServiceUrl;
}
}

@ -0,0 +1,30 @@
package org.gcube.data.analysis.nlphub;
import org.gcube.data.analysis.nlphub.is.DMDiscover;
import org.gcube.data.analysis.nlphub.shared.Constants;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DiscoverDataMinerServiceTest {
private static final Logger logger = LoggerFactory.getLogger(DiscoverDataMinerServiceTest.class);
@Test
public void discover() {
if (Constants.TEST_ENABLE) {
try{
DMDiscover dmDiscover=new DMDiscover();
String url=dmDiscover.retrieveServiceUrl(Constants.DEFAULT_TOKEN);
logger.debug("Url Retrieved: "+url);
Assert.assertTrue(true);
} catch (Throwable e) {
logger.error("Error retrieving DataMinerServiceUrl: "+e.getLocalizedMessage(),e);
Assert.fail("Error retrieving DataMinerServiceUrl: "+e.getLocalizedMessage());
}
} else {
Assert.assertTrue(true);
}
}
}

@ -1,83 +0,0 @@
<configuration scan="true" debug="false">
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/home/gcube/tomcat/logs/ghn.log</file>
<append>true</append>
<encoder>
<pattern>%date [%thread] %-5level %logger{0}: %msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>/home/gcube/tomcat/logs/ghn.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxHistory>30</maxHistory>
<maxFileSize>10MB</maxFileSize>
<totalSizeCap>2GB</totalSizeCap>
</rollingPolicy>
</appender>
<appender name="ACCOUNT_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/home/gcube/tomcat/logs/accounting.log</file>
<append>true</append>
<encoder>
<pattern>%date [%thread] %-5level %logger{0}: %msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>/home/gcube/tomcat/logs/accounting.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxHistory>30</maxHistory>
<maxFileSize>10MB</maxFileSize>
<totalSizeCap>2GB</totalSizeCap>
</rollingPolicy>
</appender>
<appender name="ACCESS_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/home/gcube/tomcat/logs/access.log</file>
<append>true</append>
<encoder>
<pattern>%date [%thread] %-5level %logger{0}: %msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>/home/gcube/tomcat/logs/access.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxHistory>30</maxHistory>
<maxFileSize>10MB</maxFileSize>
<totalSizeCap>2GB</totalSizeCap>
</rollingPolicy>
</appender>
<appender name="NLP_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/home/gcube/tomcat/logs/nlphub.log</file>
<append>true</append>
<encoder>
<pattern>%date [%thread] %-5level %logger{0}: %msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>/home/gcube/tomcat/logs/nlphub.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxHistory>30</maxHistory>
<maxFileSize>10MB</maxFileSize>
<totalSizeCap>2GB</totalSizeCap>
</rollingPolicy>
</appender>
<logger name="org.gcube.data.publishing" level="ERROR">
<appender-ref ref="ACCOUNT_FILE" />
</logger>
<logger name="org.gcube.documentstore" level="ERROR">
<appender-ref ref="ACCOUNT_FILE" />
</logger>
<logger name="org.gcube.smartgears.handlers.application.request" level="INFO">
<appender-ref ref="ACCESS_FILE" />
</logger>
<logger name="org.gcube" level="WARN" />
<logger name="org.gcube.smartgears" level="WARN" />
<logger name="org.gcube.common.events" level="WARN" />
<logger name="org.gcube.data.analysis.nlphub" level="DEBUG">
<appender-ref ref="NLP_FILE" />
</logger>
<root level="WARN">
<appender-ref ref="FILE" />
</root>
</configuration>
Loading…
Cancel
Save