From 03b533ed757d856385972d1c07bb50ed3f655e9c Mon Sep 17 00:00:00 2001 From: nmoreau Date: Tue, 26 Oct 2021 17:37:00 +0200 Subject: [PATCH 1/6] Fix error in HTTP request url when a redirection occurs --- .../org/vamdc/portal/species/NodeSpecies.java | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/portal.ejb/src/main/java/org/vamdc/portal/species/NodeSpecies.java b/portal.ejb/src/main/java/org/vamdc/portal/species/NodeSpecies.java index ec734e5..45756ee 100644 --- a/portal.ejb/src/main/java/org/vamdc/portal/species/NodeSpecies.java +++ b/portal.ejb/src/main/java/org/vamdc/portal/species/NodeSpecies.java @@ -68,30 +68,26 @@ public void querySpecies(String ivoaId, SpeciesResult resultBean){ resultBean.setReady(true); return; } - System.out.println("### test "); resultBean.setMirrorCount(mirrors.size()); for(URL node:mirrors){ + resultBean.setMessage("Timeout : query execution was too long."); resultBean.nextMirror(); URL queryUrl=node; System.out.println("query"); - System.out.println(query); - System.out.println(queryUrl); + try { queryUrl = new URL(node.toExternalForm()+query); - - System.out.print("queryUrl"); - System.out.print(queryUrl); + System.out.println(queryUrl); resultBean.setFormattedResult( formatRequestResult(queryUrl)); - resultBean.setMessage(""); + resultBean.setMessage(""); resultBean.setReady(true); return; } catch (MalformedURLException e) { // TODO Auto-generated catch block resultBean.setMessage("Incorrect service URL "+queryUrl); } catch (IOException e) { - // TODO Auto-generated catch block - + // TODO Auto-generated catch block e.printStackTrace(); resultBean.setMessage("Error while proceeding request"); } catch (TransformerException e) { @@ -102,9 +98,14 @@ public void querySpecies(String ivoaId, SpeciesResult resultBean){ if(e.getCode() == 204) { resultBean.setMessage("Request returned an empty response"); } else if(e.getCode() >= 400){ + System.out.println(e); resultBean.setMessage("Node returned the error " +e.getCode() +" while processing the request "+queryUrl); } - }finally{ + }catch(Exception e) { + System.out.println(e); + resultBean.setMessage("An exception occurred"); + } + finally{ resultBean.setReady(true); } } @@ -117,11 +118,8 @@ public void querySpecies(String ivoaId, SpeciesResult resultBean){ * @throws IOException * @throws TransformerException */ - private static String formatRequestResult(URL url) throws IOException, TransformerException, PortalHttpException{ - System.out.print("###"); - System.out.print(url); + private/* static */ String formatRequestResult(URL url) throws IOException, TransformerException, PortalHttpException{ HttpURLConnection c = (HttpURLConnection)url.openConnection(); - if(c.getResponseCode() == 200){ c.setConnectTimeout(Settings.HTTP_CONNECT_TIMEOUT.getInt()); c.setReadTimeout(Settings.HTTP_DATA_TIMEOUT.getInt()); @@ -137,7 +135,12 @@ private static String formatRequestResult(URL url) throws IOException, Transform return bOut.toString(); }else{ - throw new PortalHttpException("Http error while executing TAP request", c.getResponseCode()); + if(c.getResponseCode() == 301 || c.getResponseCode() == 302){ + String newUrl = c.getHeaderField("Location"); + return this.formatRequestResult(new URL(newUrl)); + }else { + throw new PortalHttpException("Http error while executing TAP request", c.getResponseCode()); + } } } } From 06623f3a77332fc0424275c682ca1734cbbbd7b8 Mon Sep 17 00:00:00 2001 From: nmoreau Date: Tue, 17 May 2022 15:16:16 +0200 Subject: [PATCH 2/6] mark not recommended processor explicitely instead of using ** --- .../portal/session/consumers/ConsumerRequestRegistry.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/portal.ejb/src/main/java/org/vamdc/portal/session/consumers/ConsumerRequestRegistry.java b/portal.ejb/src/main/java/org/vamdc/portal/session/consumers/ConsumerRequestRegistry.java index 3ed83d8..0505ce2 100644 --- a/portal.ejb/src/main/java/org/vamdc/portal/session/consumers/ConsumerRequestRegistry.java +++ b/portal.ejb/src/main/java/org/vamdc/portal/session/consumers/ConsumerRequestRegistry.java @@ -74,14 +74,13 @@ private void initNodeConsumers() { // recommended consumers for (String ivoaID : visibleConsumers) { - consumers.add(new SelectItem(ivoaID, " ** " - + registryFacade.getResourceTitle(ivoaID))); + consumers.add(new SelectItem(ivoaID, registryFacade.getResourceTitle(ivoaID))); } // other consumers for (String ivoaID : registryFacade.getConsumerIvoaIDs()) { - if (visibleConsumers.contains(ivoaID) == false) { - consumers.add(new SelectItem(ivoaID, registryFacade + if (!visibleConsumers.contains(ivoaID)) { + consumers.add(new SelectItem(ivoaID, " " + registryFacade .getResourceTitle(ivoaID))); } } From 2252b729416ee5977027f0444ab01c81e874cb24 Mon Sep 17 00:00:00 2001 From: nmoreau Date: Tue, 17 May 2022 15:18:52 +0200 Subject: [PATCH 3/6] urlencode parameter value in request --- .../portal/session/consumers/PostRequest.java | 48 +++++++++---------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/portal.ejb/src/main/java/org/vamdc/portal/session/consumers/PostRequest.java b/portal.ejb/src/main/java/org/vamdc/portal/session/consumers/PostRequest.java index 1149432..178b862 100644 --- a/portal.ejb/src/main/java/org/vamdc/portal/session/consumers/PostRequest.java +++ b/portal.ejb/src/main/java/org/vamdc/portal/session/consumers/PostRequest.java @@ -12,59 +12,55 @@ import org.vamdc.portal.Settings; - - -public class PostRequest implements Callable{ +public class PostRequest implements Callable { private URL consumer; private Collection nodes; - public PostRequest(URL consumer, Collection nodes){ + + public PostRequest(URL consumer, Collection nodes) { this.consumer = consumer; this.nodes = nodes; } - + @Override public URL call() throws Exception { - + HttpURLConnection connection = setupConnection(); - + return processResponse(connection); } - private URL processResponse(HttpURLConnection connection) - throws IOException, MalformedURLException { - URL result=null; + private URL processResponse(HttpURLConnection connection) throws IOException, MalformedURLException { + URL result = null; int resultCode = connection.getResponseCode(); - - if (resultCode== HttpURLConnection.HTTP_MOVED_TEMP || resultCode== HttpURLConnection.HTTP_SEE_OTHER || resultCode==HttpURLConnection.HTTP_MOVED_PERM){ + if (resultCode == HttpURLConnection.HTTP_MOVED_TEMP || resultCode == HttpURLConnection.HTTP_SEE_OTHER + || resultCode == HttpURLConnection.HTTP_MOVED_PERM) { result = new URL(connection.getHeaderField("Location")); - }else{ - throw new IOException("XSAMS processor service returned "+resultCode+" status code."); + } else { + throw new IOException("XSAMS processor service returned " + resultCode + " status code."); } return result; } - private HttpURLConnection setupConnection() throws IOException, - ProtocolException { + private HttpURLConnection setupConnection() throws IOException, ProtocolException { HttpURLConnection connection = (HttpURLConnection) consumer.openConnection(); connection.setInstanceFollowRedirects(false); connection.setRequestMethod("POST"); connection.setReadTimeout(Settings.HTTP_DATA_TIMEOUT.getInt()); connection.setDoOutput(true); - - String data=""; - for (URL node:nodes){ - if (data.length()>0) - data+="&"; - data+=URLEncoder.encode("url", "UTF-8") + "=" + URLEncoder.encode(node.toString(), "UTF-8"); - - }; + + String data = ""; + for (URL node : nodes) { + if (data.length() > 0) + data += "&"; + data += URLEncoder.encode("url", "UTF-8") + "=" + URLEncoder.encode(node.toString(), "UTF-8"); + } OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream()); wr.write(data); wr.flush(); wr.close(); - + return connection; } - + } From 23aaa8ba23bd8d1f32ba402554988a69a12b378d Mon Sep 17 00:00:00 2001 From: nmoreau Date: Tue, 17 May 2022 15:27:28 +0200 Subject: [PATCH 4/6] https in request to node mirros --- .../portal/session/preview/PreviewThread.java | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/portal.ejb/src/main/java/org/vamdc/portal/session/preview/PreviewThread.java b/portal.ejb/src/main/java/org/vamdc/portal/session/preview/PreviewThread.java index 7069a02..c2e8109 100644 --- a/portal.ejb/src/main/java/org/vamdc/portal/session/preview/PreviewThread.java +++ b/portal.ejb/src/main/java/org/vamdc/portal/session/preview/PreviewThread.java @@ -1,5 +1,6 @@ package org.vamdc.portal.session.preview; +import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.MalformedURLException; @@ -45,6 +46,22 @@ private URL getQuery(URL mirror) { return result; } + + private HttpURLConnection getHttpURLConnection(URL url) throws IOException { + HttpURLConnection connection = null; + + + //http request + if (!url.getProtocol().equals("https")) { + connection = (HttpURLConnection) url.openConnection(); + } + //https request + else { + connection = (HttpsURLConnection) url.openConnection(); + } + + return connection; + } /** * Send a HEAD request to a node by testing its mirrors @@ -54,21 +71,19 @@ public HttpHeadResponse call() throws Exception { HttpHeadResponse response = null; for (URL mirror : mirrors) { HttpURLConnection connection = null; - URL queryURL = getQuery(mirror); - - //http request - if (!mirror.getProtocol().equals("https")) { - connection = (HttpURLConnection) queryURL.openConnection(); - } - //https request - else { - connection = (HttpsURLConnection) queryURL.openConnection(); - } - + connection = this.getHttpURLConnection(getQuery(mirror)); connection.setRequestMethod("HEAD"); connection.setReadTimeout(Settings.HTTP_HEAD_TIMEOUT.getInt()); - + /*if(connection.getResponseCode() == 301 || connection.getResponseCode() == 302) { + connection.disconnect(); + String newUrl = connection.getHeaderField("Location"); + System.out.println("### try new url : " + newUrl); + connection = this.getHttpURLConnection(new URL(newUrl)); + connection.setRequestMethod("HEAD"); + connection.setReadTimeout(Settings.HTTP_HEAD_TIMEOUT.getInt()); + }*/ response = new HttpHeadResponse(ivoaID, connection); + if (response.isOk()) return response; } From b717e7f9f8f61138f89397115f2efa4cb1352694 Mon Sep 17 00:00:00 2001 From: nmoreau Date: Wed, 18 May 2022 12:52:21 +0200 Subject: [PATCH 5/6] Modifications in portal to query https services, required a change in drool version. This works with jdk1.8.0_152 --- notes | 3 +++ pom.xml | 16 ++++++++++++---- portal.ear/pom.xml | 18 +++++++++++++++++- portal.ejb/pom.xml | 6 +++--- .../main/java/org/vamdc/portal/Settings.java | 1 + .../org/vamdc/portal/entity/EntityQuery.java | 8 +++++--- .../org/vamdc/portal/species/NodeSpecies.java | 1 - 7 files changed, 41 insertions(+), 12 deletions(-) diff --git a/notes b/notes index 546f415..d16ad5f 100644 --- a/notes +++ b/notes @@ -10,5 +10,8 @@ Could not instantiate Seam component: registration Le fichier ~/.mavenrc a été édité pour que JAVA_HOME pointe sur java7 JAVA_HOME est défini dans deploy.sh pour que jboss utilise java7 +Autre solution : export JAVA_HOME=~/Applications/jdk1.8.0_152/ + + Utilise JSF en version 1.x diff --git a/pom.xml b/pom.xml index 017af82..daced0d 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ vamdc repository VAMDC repository - http://dev.vamdc.org/nexus/content/groups/public/ + http://nexus.vamdc.org/nexus/content/groups/public/ default @@ -50,17 +50,25 @@ 1.6 - + maven-resources-plugin 2.5 - + + + org.apache.maven.plugins + maven-surefire-plugin + 2.12.4 + + true + + diff --git a/portal.ear/pom.xml b/portal.ear/pom.xml index 96135e9..c3bcf70 100644 --- a/portal.ear/pom.xml +++ b/portal.ear/pom.xml @@ -36,6 +36,7 @@ org.drools drools-compiler + 6.0.1.Final com.sun.xml.ws @@ -48,6 +49,21 @@ el-api provided + + + org.drools + drools-core + 5.4.0.Final + + + + + org.drools + drools-compiler + 5.4.0.Final + + + @@ -114,4 +130,4 @@ - \ No newline at end of file + diff --git a/portal.ejb/pom.xml b/portal.ejb/pom.xml index 0161446..c721e58 100644 --- a/portal.ejb/pom.xml +++ b/portal.ejb/pom.xml @@ -120,8 +120,8 @@ org.json json - 20160810 - + 20220320 + @@ -175,4 +175,4 @@ - \ No newline at end of file + diff --git a/portal.ejb/src/main/java/org/vamdc/portal/Settings.java b/portal.ejb/src/main/java/org/vamdc/portal/Settings.java index 3b8e924..2fa6dfb 100644 --- a/portal.ejb/src/main/java/org/vamdc/portal/Settings.java +++ b/portal.ejb/src/main/java/org/vamdc/portal/Settings.java @@ -11,6 +11,7 @@ */ public enum Settings { + //superseded by values in server/default/deploy/properties-service.xml of jboss server HTTP_CONNECT_TIMEOUT("HTTPConnTimeout", "2000"), HTTP_DATA_TIMEOUT("HTTPDataTimeout","30000"), REGISTRY_URL("registryURL","http://registry.vamdc.eu/registry-12.07/services/RegistryQueryv1_0"), diff --git a/portal.ejb/src/main/java/org/vamdc/portal/entity/EntityQuery.java b/portal.ejb/src/main/java/org/vamdc/portal/entity/EntityQuery.java index 79da830..be1e5e0 100644 --- a/portal.ejb/src/main/java/org/vamdc/portal/entity/EntityQuery.java +++ b/portal.ejb/src/main/java/org/vamdc/portal/entity/EntityQuery.java @@ -3,6 +3,7 @@ import java.util.Collection; import javax.persistence.EntityManager; +import javax.persistence.Query; import org.vamdc.portal.entity.constant.Species; @@ -40,13 +41,14 @@ static Collection suggestMoleculeName(EntityManager em, @SuppressWarnings("unchecked") private static Collection suggestRestrictedSpeciesName(EntityManager em, String name, Integer speciesType) { - return em.createQuery("SELECT DISTINCT vsn.name from VamdcSpeciesNames vsn JOIN vsn.vamdcSpecies vsp " + + Query q = em.createQuery("SELECT DISTINCT vsn.name from VamdcSpeciesNames vsn JOIN vsn.vamdcSpecies vsp " + "WHERE vsn.name LIKE :speciesName and vsn.vamdcMarkupTypes.id=1 and vsp.speciesType=:speciesType " + " order by length(vsn.name), vsn.searchPriority") .setParameter("speciesName", "%"+name+"%") .setParameter("speciesType", speciesType) - .setMaxResults(20) - .getResultList(); + .setMaxResults(20); + return q.getResultList(); + } diff --git a/portal.ejb/src/main/java/org/vamdc/portal/species/NodeSpecies.java b/portal.ejb/src/main/java/org/vamdc/portal/species/NodeSpecies.java index ec734e5..bb61990 100644 --- a/portal.ejb/src/main/java/org/vamdc/portal/species/NodeSpecies.java +++ b/portal.ejb/src/main/java/org/vamdc/portal/species/NodeSpecies.java @@ -68,7 +68,6 @@ public void querySpecies(String ivoaId, SpeciesResult resultBean){ resultBean.setReady(true); return; } - System.out.println("### test "); resultBean.setMirrorCount(mirrors.size()); for(URL node:mirrors){ resultBean.setMessage("Timeout : query execution was too long."); From 2874c7b29aafd643e64bb768a9666f77daa1576a Mon Sep 17 00:00:00 2001 From: nmoreau Date: Wed, 18 May 2022 15:32:41 +0200 Subject: [PATCH 6/6] removes duplicated artifact --- portal.ear/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/portal.ear/pom.xml b/portal.ear/pom.xml index c3bcf70..8b43012 100644 --- a/portal.ear/pom.xml +++ b/portal.ear/pom.xml @@ -33,11 +33,11 @@ org.jboss.el jboss-el - + com.sun.xml.ws jaxws-rt