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-b396298e98cfmaster
parent
2eb9091e33
commit
bf73c82d57
@ -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…
Reference in New Issue