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@178557 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
90711b50bb
commit
2eb9091e33
|
@ -13,12 +13,16 @@ public class DMDiscover {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(DMDiscover.class);
|
private static Logger logger = LoggerFactory.getLogger(DMDiscover.class);
|
||||||
|
|
||||||
|
public DMDiscover() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public String retrieveServiceUrl(String token) throws Exception {
|
public String retrieveServiceUrl(String token) throws Exception {
|
||||||
logger.debug("Retrieve DataMiner Service by token: " + token);
|
logger.debug("Retrieve DataMiner Service by token: " + token);
|
||||||
String scope = retrieveScope(token);
|
String scope = retrieveScope(token);
|
||||||
logger.debug("Retrieve DataMiner Service in scope: "+scope);
|
logger.debug("Retrieve DataMiner Service in scope: " + scope);
|
||||||
String url= retrieveServiceInScope(scope);
|
String url = retrieveServiceInScope(scope);
|
||||||
logger.debug("DataMiner url: "+url);
|
logger.debug("DataMiner url: " + url);
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,28 +14,19 @@ public class NerAnnotationData {
|
||||||
private String name;
|
private String name;
|
||||||
private ArrayList<NerEntity> nerEntities;
|
private ArrayList<NerEntity> nerEntities;
|
||||||
|
|
||||||
/**
|
|
||||||
* Class constructor; require the name of the annotation
|
|
||||||
* @param name
|
|
||||||
*/
|
|
||||||
public NerAnnotationData(String name) {
|
public NerAnnotationData(String name) {
|
||||||
logger.debug("NerAnnotationData: "+name);
|
logger.debug("NerAnnotationData: "+name);
|
||||||
this.name = name;
|
this.name = name;
|
||||||
nerEntities = new ArrayList<>();
|
nerEntities = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* add a new NerEntity to the collection
|
|
||||||
* @param entity
|
|
||||||
*/
|
|
||||||
public void addNerEntity(NerEntity entity) {
|
public void addNerEntity(NerEntity entity) {
|
||||||
nerEntities.add(entity);
|
nerEntities.add(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* build the proper Json object.
|
|
||||||
* @return JsonObject
|
|
||||||
*/
|
|
||||||
public JsonObject toJson() {
|
public JsonObject toJson() {
|
||||||
JsonObject json = new JsonObject();
|
JsonObject json = new JsonObject();
|
||||||
JsonArray entities = new JsonArray();
|
JsonArray entities = new JsonArray();
|
||||||
|
|
|
@ -30,8 +30,8 @@ public class NerEntity {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an additional property (property is a couple {name, value})
|
* Add an additional property (property is a couple {name, value})
|
||||||
* @param name
|
* @param name name
|
||||||
* @param value
|
* @param value value
|
||||||
*/
|
*/
|
||||||
public void addProperty(String name, String value) {
|
public void addProperty(String name, String value) {
|
||||||
properties.put(name, value);
|
properties.put(name, value);
|
||||||
|
|
|
@ -48,16 +48,19 @@ public class NLpLanguageRecognizer {
|
||||||
public static void run(String dataMiner, String sentence, String token, String publicLink,
|
public static void run(String dataMiner, String sentence, String token, String publicLink,
|
||||||
HttpServletResponse response) throws NlpHubException {
|
HttpServletResponse response) throws NlpHubException {
|
||||||
try {
|
try {
|
||||||
try {
|
|
||||||
DMDiscover discoverDataMinerService=new DMDiscover();
|
if (dataMiner == null || dataMiner.isEmpty()) {
|
||||||
dataMiner=discoverDataMinerService.retrieveServiceUrl(token);
|
try {
|
||||||
} catch (Exception e) {
|
DMDiscover discoverDataMinerService = new DMDiscover();
|
||||||
logger.error("Error retrieving DataMiner service:" + e.getMessage(),e);
|
dataMiner = discoverDataMinerService.retrieveServiceUrl(token);
|
||||||
throw new Exception("Error retrieving DataMiner service:" + e.getMessage());
|
} catch (Exception e) {
|
||||||
|
logger.error("Error retrieving DataMiner service:" + e.getMessage(), e);
|
||||||
|
throw new Exception("Error retrieving DataMiner service:" + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//else
|
// else
|
||||||
// dataMiner = "http://" + dataMiner;
|
// dataMiner = "http://" + dataMiner;
|
||||||
String urlService = dataMiner + "?request=Execute&service=WPS&Version=1.0.0";
|
String urlService = dataMiner + "?request=Execute&service=WPS&Version=1.0.0";
|
||||||
urlService += "&gcube-token=" + token;
|
urlService += "&gcube-token=" + token;
|
||||||
urlService += "&lang=en-US";
|
urlService += "&lang=en-US";
|
||||||
|
|
|
@ -33,21 +33,20 @@ public class NlpAsyncNerRunner extends AsyncHttpRequest {
|
||||||
public NlpAsyncNerRunner(String dataMiner, String identifier, String token, String publicLink, String annotations,
|
public NlpAsyncNerRunner(String dataMiner, String identifier, String token, String publicLink, String annotations,
|
||||||
String language, RunnerCommander commander) throws Exception {
|
String language, RunnerCommander commander) throws Exception {
|
||||||
super();
|
super();
|
||||||
this.commander=commander;
|
this.commander = commander;
|
||||||
this.identifier=identifier;
|
this.identifier = identifier;
|
||||||
String httpMethod = "GET";
|
String httpMethod = "GET";
|
||||||
|
|
||||||
|
if (dataMiner == null || dataMiner.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
DMDiscover discoverDataMinerService=new DMDiscover();
|
DMDiscover discoverDataMinerService = new DMDiscover();
|
||||||
dataMiner=discoverDataMinerService.retrieveServiceUrl(token);
|
dataMiner = discoverDataMinerService.retrieveServiceUrl(token);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("Error retrieving DataMiner service:" + e.getMessage(),e);
|
logger.error("Error retrieving DataMiner service:" + e.getMessage(), e);
|
||||||
throw new Exception("Error retrieving DataMiner service:" + e.getMessage());
|
throw new Exception("Error retrieving DataMiner service:" + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// else
|
// else
|
||||||
// this.dataMiner = "http://" + dataMiner;
|
// this.dataMiner = "http://" + dataMiner;
|
||||||
logger.debug("NlpAsyncNerRunner: Create Excution Request");
|
logger.debug("NlpAsyncNerRunner: Create Excution Request");
|
||||||
|
@ -63,29 +62,25 @@ public class NlpAsyncNerRunner extends AsyncHttpRequest {
|
||||||
serviceUrl.append("&");
|
serviceUrl.append("&");
|
||||||
serviceUrl.append(setParams(params));
|
serviceUrl.append(setParams(params));
|
||||||
serviceUrl.append("&gcube-token=" + token);
|
serviceUrl.append("&gcube-token=" + token);
|
||||||
|
|
||||||
logger.debug("NlpAsyncNerRunner: [serviceUrl=" + serviceUrl + ", method=" + httpMethod + "]");
|
logger.debug("NlpAsyncNerRunner: [serviceUrl=" + serviceUrl + ", method=" + httpMethod + "]");
|
||||||
super.setBaseUrl(serviceUrl.toString());
|
super.setBaseUrl(serviceUrl.toString());
|
||||||
super.setMethod(httpMethod);
|
super.setMethod(httpMethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public NlpAsyncNerRunner(String baseUrl, String method) {
|
/*
|
||||||
super(baseUrl, method, null);
|
* public NlpAsyncNerRunner(String baseUrl, String method) { super(baseUrl,
|
||||||
}*/
|
* method, null); }
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
public String getIdentifier() {
|
* public String getIdentifier() { return identifier; }
|
||||||
return identifier;
|
*
|
||||||
}
|
*
|
||||||
|
* public String getToken() { return token; }
|
||||||
|
*
|
||||||
public String getToken() {
|
* public String getHttpMethod() { return httpMethod; }
|
||||||
return token;
|
*/
|
||||||
}
|
|
||||||
|
|
||||||
public String getHttpMethod() {
|
|
||||||
return httpMethod;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
private String setParams(ArrayList<NlpParameter> parameters) {
|
private String setParams(ArrayList<NlpParameter> parameters) {
|
||||||
logger.debug("Set Params");
|
logger.debug("Set Params");
|
||||||
|
@ -116,7 +111,7 @@ public class NlpAsyncNerRunner extends AsyncHttpRequest {
|
||||||
serviceUrl.append(token);
|
serviceUrl.append(token);
|
||||||
|
|
||||||
URL url = new URL(serviceUrl.toString());
|
URL url = new URL(serviceUrl.toString());
|
||||||
|
|
||||||
connection = (HttpURLConnection) url.openConnection();
|
connection = (HttpURLConnection) url.openConnection();
|
||||||
connection.setRequestMethod("GET");
|
connection.setRequestMethod("GET");
|
||||||
connection.setDoInput(true);
|
connection.setDoInput(true);
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
String requestToken=request.getParameter(Constants.TOKEN_PARAMETER);
|
String requestToken=request.getParameter(Constants.TOKEN_PARAMETER);
|
||||||
if( requestToken == null||requestToken.isEmpty()) {
|
if( requestToken == null||requestToken.isEmpty()) {
|
||||||
%>
|
%>
|
||||||
var gCubeToken = "fea75a5a-d84c-495f-b0ca-09cdd95bacce-843339462";
|
var gCubeToken = "d35c72d3-f6b5-4363-afbe-8e330ef9a913-843339462";
|
||||||
<% } else { %>
|
<% } else { %>
|
||||||
var gCubeToken = '<%=requestToken%>';
|
var gCubeToken = '<%=requestToken%>';
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue