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@178539 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
b847f5df4d
commit
90711b50bb
|
@ -1,23 +1,15 @@
|
|||
package org.gcube.data.analysis.nlphub;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
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.gcube.data.analysis.nlphub.is.DMDiscover;
|
||||
import org.gcube.data.analysis.nlphub.session.SessionUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -67,77 +59,15 @@ public class DiscoverDataMinerService extends HttpServlet {
|
|||
private void discoverDataMinerService(HttpServletRequest request, HttpServletResponse response, String token)
|
||||
throws ServletException, IOException {
|
||||
|
||||
HttpURLConnection connection = null;
|
||||
String dataMinerServiceUrl = "";
|
||||
response.setContentType("text/plain;charset=UTF-8");
|
||||
try (PrintWriter writer = response.getWriter()) {
|
||||
|
||||
try {
|
||||
String urlInformationSystem = "http://registry.d4science.org/icproxy/gcube/service/ServiceEndpoint/DataAnalysis/DataMiner?";
|
||||
|
||||
logger.debug("Request url: " + urlInformationSystem);
|
||||
urlInformationSystem += "gcube-token=" + token;
|
||||
URL url = new URL(urlInformationSystem);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("Discover DataMiner Service error: " + e.getLocalizedMessage(), e);
|
||||
} finally {
|
||||
try {
|
||||
if (connection != null)
|
||||
connection.disconnect();
|
||||
} catch (Exception e) {
|
||||
logger.error("Discover DataMiner Service error: " + e.getLocalizedMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
DMDiscover dmDiscover = new DMDiscover();
|
||||
dataMinerServiceUrl = dmDiscover.retrieveServiceUrl(token);
|
||||
writer.println(dataMinerServiceUrl);
|
||||
|
||||
|
||||
} catch (Throwable e) {
|
||||
logger.error("Error discovering DataMiner Service Url: " + e.getLocalizedMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
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.trim();
|
||||
dataMinerServiceUrl = dataMinerServiceUrl.replace("\\n", "").replace("\\r", "");
|
||||
logger.debug("url lenght: "+dataMinerServiceUrl.length());
|
||||
logger.debug("DataMiner service url retrieved: " + dataMinerServiceUrl);
|
||||
return dataMinerServiceUrl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return dataMinerServiceUrl;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,9 +9,9 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||
|
||||
public class DiscoverDataMinerService {
|
||||
public class DMDiscover {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(DiscoverDataMinerService.class);
|
||||
private static Logger logger = LoggerFactory.getLogger(DMDiscover.class);
|
||||
|
||||
public String retrieveServiceUrl(String token) throws Exception {
|
||||
logger.debug("Retrieve DataMiner Service by token: " + token);
|
|
@ -9,7 +9,7 @@ import java.net.URLEncoder;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.gcube.data.analysis.nlphub.is.DiscoverDataMinerService;
|
||||
import org.gcube.data.analysis.nlphub.is.DMDiscover;
|
||||
import org.gcube.data.analysis.nlphub.legacy.JsonManager;
|
||||
import org.gcube.data.analysis.nlphub.legacy.NlpHubException;
|
||||
import org.gcube.data.analysis.nlphub.shared.Constants;
|
||||
|
@ -49,7 +49,7 @@ public class NLpLanguageRecognizer {
|
|||
HttpServletResponse response) throws NlpHubException {
|
||||
try {
|
||||
try {
|
||||
DiscoverDataMinerService discoverDataMinerService=new DiscoverDataMinerService();
|
||||
DMDiscover discoverDataMinerService=new DMDiscover();
|
||||
dataMiner=discoverDataMinerService.retrieveServiceUrl(token);
|
||||
} catch (Exception e) {
|
||||
logger.error("Error retrieving DataMiner service:" + e.getMessage(),e);
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.util.ArrayList;
|
|||
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import org.gcube.data.analysis.nlphub.is.DiscoverDataMinerService;
|
||||
import org.gcube.data.analysis.nlphub.is.DMDiscover;
|
||||
import org.gcube.data.analysis.nlphub.legacy.AsyncHttpRequest;
|
||||
import org.gcube.data.analysis.nlphub.shared.Constants;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -39,7 +39,7 @@ public class NlpAsyncNerRunner extends AsyncHttpRequest {
|
|||
|
||||
|
||||
try {
|
||||
DiscoverDataMinerService discoverDataMinerService=new DiscoverDataMinerService();
|
||||
DMDiscover discoverDataMinerService=new DMDiscover();
|
||||
dataMiner=discoverDataMinerService.retrieveServiceUrl(token);
|
||||
} catch (Exception e) {
|
||||
logger.error("Error retrieving DataMiner service:" + e.getMessage(),e);
|
||||
|
|
|
@ -33,8 +33,8 @@
|
|||
var gCubeToken = '<%=requestToken%>';
|
||||
|
||||
<% } %>
|
||||
var scheme = '<%= request.getScheme() %>';
|
||||
console.log('Scheme: '+scheme);
|
||||
var scheme = '<%=request.getHeader("x-forwarded-proto")%>';
|
||||
console.log('Protocol: '+scheme);
|
||||
var contextPath = '<%= request.getContextPath() %>';
|
||||
</script>
|
||||
</head>
|
||||
|
|
Loading…
Reference in New Issue