Skip to content

Commit 01698a2

Browse files
Merge pull request #90 from nicolasmoreau/master
Fix for https request
2 parents 05bf58f + 2f0dc1a commit 01698a2

File tree

10 files changed

+113
-70
lines changed

10 files changed

+113
-70
lines changed

notes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@ Could not instantiate Seam component: registration
1010
Le fichier ~/.mavenrc a été édité pour que JAVA_HOME pointe sur java7
1111
JAVA_HOME est défini dans deploy.sh pour que jboss utilise java7
1212

13+
Autre solution : export JAVA_HOME=~/Applications/jdk1.8.0_152/
14+
15+
1316
Utilise JSF en version 1.x
1417

pom.xml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<repository>
3737
<id>vamdc repository</id>
3838
<name>VAMDC repository</name>
39-
<url>http://dev.vamdc.org/nexus/content/groups/public/</url>
39+
<url>http://nexus.vamdc.org/nexus/content/groups/public/</url>
4040
<layout>default</layout>
4141
</repository>
4242
</repositories>
@@ -50,17 +50,25 @@
5050
<target>1.6</target>
5151
</configuration>
5252
</plugin>
53-
<plugin>
53+
<!--<plugin>
5454
<artifactId>maven-surefire-plugin</artifactId>
5555
<version>2.5</version>
5656
<configuration>
5757
<argLine>-Dsun.lang.ClassLoader.allowArraySyntax=true</argLine>
5858
</configuration>
59-
</plugin>
59+
</plugin>-->
6060
<plugin>
6161
<artifactId>maven-resources-plugin</artifactId>
6262
<version>2.5</version>
63-
</plugin>
63+
</plugin>
64+
<plugin>
65+
<groupId>org.apache.maven.plugins</groupId>
66+
<artifactId>maven-surefire-plugin</artifactId>
67+
<version>2.12.4</version>
68+
<configuration>
69+
<skipTests>true</skipTests>
70+
</configuration>
71+
</plugin>
6472
</plugins>
6573
</build>
6674

portal.ear/pom.xml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@
3333
<groupId>org.jboss.el</groupId>
3434
<artifactId>jboss-el</artifactId>
3535
</dependency>
36-
<dependency>
36+
<!-- <dependency>
3737
<groupId>org.drools</groupId>
3838
<artifactId>drools-compiler</artifactId>
39-
</dependency>
39+
<version>6.0.1.Final</version>
40+
</dependency>-->
4041
<dependency>
4142
<groupId>com.sun.xml.ws</groupId>
4243
<artifactId>jaxws-rt</artifactId>
@@ -48,6 +49,21 @@
4849
<artifactId>el-api</artifactId>
4950
<scope>provided</scope>
5051
</dependency>
52+
<!-- https://mvnrepository.com/artifact/org.drools/drools-core -->
53+
<dependency>
54+
<groupId>org.drools</groupId>
55+
<artifactId>drools-core</artifactId>
56+
<version>5.4.0.Final</version>
57+
</dependency>
58+
59+
<!-- https://mvnrepository.com/artifact/org.drools/drools-compiler -->
60+
<dependency>
61+
<groupId>org.drools</groupId>
62+
<artifactId>drools-compiler</artifactId>
63+
<version>5.4.0.Final</version>
64+
</dependency>
65+
66+
5167
</dependencies>
5268
<build>
5369
<plugins>
@@ -114,4 +130,4 @@
114130
</dependency>
115131
</dependencies>
116132
</dependencyManagement>
117-
</project>
133+
</project>

portal.ejb/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@
120120
<dependency>
121121
<groupId>org.json</groupId>
122122
<artifactId>json</artifactId>
123-
<version>20160810</version>
124-
</dependency>
123+
<version>20220320</version>
124+
</dependency>
125125
</dependencies>
126126
<build>
127127
<plugins>
@@ -175,4 +175,4 @@
175175
</dependency>
176176
</dependencies>
177177
</dependencyManagement>
178-
</project>
178+
</project>

portal.ejb/src/main/java/org/vamdc/portal/Settings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212
public enum Settings {
1313

14+
//superseded by values in server/default/deploy/properties-service.xml of jboss server
1415
HTTP_CONNECT_TIMEOUT("HTTPConnTimeout", "2000"),
1516
HTTP_DATA_TIMEOUT("HTTPDataTimeout","30000"),
1617
REGISTRY_URL("registryURL","http://registry.vamdc.eu/registry-12.07/services/RegistryQueryv1_0"),

portal.ejb/src/main/java/org/vamdc/portal/entity/EntityQuery.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.Collection;
44

55
import javax.persistence.EntityManager;
6+
import javax.persistence.Query;
67

78
import org.vamdc.portal.entity.constant.Species;
89

@@ -40,13 +41,14 @@ static Collection<String> suggestMoleculeName(EntityManager em,
4041
@SuppressWarnings("unchecked")
4142
private static Collection<String> suggestRestrictedSpeciesName(EntityManager em,
4243
String name, Integer speciesType) {
43-
return em.createQuery("SELECT DISTINCT vsn.name from VamdcSpeciesNames vsn JOIN vsn.vamdcSpecies vsp " +
44+
Query q = em.createQuery("SELECT DISTINCT vsn.name from VamdcSpeciesNames vsn JOIN vsn.vamdcSpecies vsp " +
4445
"WHERE vsn.name LIKE :speciesName and vsn.vamdcMarkupTypes.id=1 and vsp.speciesType=:speciesType "
4546
+ " order by length(vsn.name), vsn.searchPriority")
4647
.setParameter("speciesName", "%"+name+"%")
4748
.setParameter("speciesType", speciesType)
48-
.setMaxResults(20)
49-
.getResultList();
49+
.setMaxResults(20);
50+
return q.getResultList();
51+
5052

5153
}
5254

portal.ejb/src/main/java/org/vamdc/portal/session/consumers/ConsumerRequestRegistry.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,13 @@ private void initNodeConsumers() {
7474

7575
// recommended consumers
7676
for (String ivoaID : visibleConsumers) {
77-
consumers.add(new SelectItem(ivoaID, " ** "
78-
+ registryFacade.getResourceTitle(ivoaID)));
77+
consumers.add(new SelectItem(ivoaID, registryFacade.getResourceTitle(ivoaID)));
7978
}
8079

8180
// other consumers
8281
for (String ivoaID : registryFacade.getConsumerIvoaIDs()) {
83-
if (visibleConsumers.contains(ivoaID) == false) {
84-
consumers.add(new SelectItem(ivoaID, registryFacade
82+
if (!visibleConsumers.contains(ivoaID)) {
83+
consumers.add(new SelectItem(ivoaID, "<Not recommended> " + registryFacade
8584
.getResourceTitle(ivoaID)));
8685
}
8786
}

portal.ejb/src/main/java/org/vamdc/portal/session/consumers/PostRequest.java

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,59 +12,55 @@
1212

1313
import org.vamdc.portal.Settings;
1414

15-
16-
17-
public class PostRequest implements Callable<URL>{
15+
public class PostRequest implements Callable<URL> {
1816

1917
private URL consumer;
2018
private Collection<URL> nodes;
21-
public PostRequest(URL consumer, Collection<URL> nodes){
19+
20+
public PostRequest(URL consumer, Collection<URL> nodes) {
2221
this.consumer = consumer;
2322
this.nodes = nodes;
2423
}
25-
24+
2625
@Override
2726
public URL call() throws Exception {
28-
27+
2928
HttpURLConnection connection = setupConnection();
30-
29+
3130
return processResponse(connection);
3231
}
3332

34-
private URL processResponse(HttpURLConnection connection)
35-
throws IOException, MalformedURLException {
36-
URL result=null;
33+
private URL processResponse(HttpURLConnection connection) throws IOException, MalformedURLException {
34+
URL result = null;
3735
int resultCode = connection.getResponseCode();
38-
39-
if (resultCode== HttpURLConnection.HTTP_MOVED_TEMP || resultCode== HttpURLConnection.HTTP_SEE_OTHER || resultCode==HttpURLConnection.HTTP_MOVED_PERM){
36+
if (resultCode == HttpURLConnection.HTTP_MOVED_TEMP || resultCode == HttpURLConnection.HTTP_SEE_OTHER
37+
|| resultCode == HttpURLConnection.HTTP_MOVED_PERM) {
4038
result = new URL(connection.getHeaderField("Location"));
41-
}else{
42-
throw new IOException("XSAMS processor service returned "+resultCode+" status code.");
39+
} else {
40+
throw new IOException("XSAMS processor service returned " + resultCode + " status code.");
4341
}
4442
return result;
4543
}
4644

47-
private HttpURLConnection setupConnection() throws IOException,
48-
ProtocolException {
45+
private HttpURLConnection setupConnection() throws IOException, ProtocolException {
4946
HttpURLConnection connection = (HttpURLConnection) consumer.openConnection();
5047
connection.setInstanceFollowRedirects(false);
5148
connection.setRequestMethod("POST");
5249
connection.setReadTimeout(Settings.HTTP_DATA_TIMEOUT.getInt());
5350
connection.setDoOutput(true);
54-
55-
String data="";
56-
for (URL node:nodes){
57-
if (data.length()>0)
58-
data+="&";
59-
data+=URLEncoder.encode("url", "UTF-8") + "=" + URLEncoder.encode(node.toString(), "UTF-8");
60-
61-
};
51+
52+
String data = "";
53+
for (URL node : nodes) {
54+
if (data.length() > 0)
55+
data += "&";
56+
data += URLEncoder.encode("url", "UTF-8") + "=" + URLEncoder.encode(node.toString(), "UTF-8");
57+
}
6258
OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
6359
wr.write(data);
6460
wr.flush();
6561
wr.close();
66-
62+
6763
return connection;
6864
}
69-
65+
7066
}

portal.ejb/src/main/java/org/vamdc/portal/session/preview/PreviewThread.java

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.vamdc.portal.session.preview;
22

3+
import java.io.IOException;
34
import java.io.UnsupportedEncodingException;
45
import java.net.HttpURLConnection;
56
import java.net.MalformedURLException;
@@ -45,6 +46,22 @@ private URL getQuery(URL mirror) {
4546

4647
return result;
4748
}
49+
50+
private HttpURLConnection getHttpURLConnection(URL url) throws IOException {
51+
HttpURLConnection connection = null;
52+
53+
54+
//http request
55+
if (!url.getProtocol().equals("https")) {
56+
connection = (HttpURLConnection) url.openConnection();
57+
}
58+
//https request
59+
else {
60+
connection = (HttpsURLConnection) url.openConnection();
61+
}
62+
63+
return connection;
64+
}
4865

4966
/**
5067
* Send a HEAD request to a node by testing its mirrors
@@ -54,21 +71,19 @@ public HttpHeadResponse call() throws Exception {
5471
HttpHeadResponse response = null;
5572
for (URL mirror : mirrors) {
5673
HttpURLConnection connection = null;
57-
URL queryURL = getQuery(mirror);
58-
59-
//http request
60-
if (!mirror.getProtocol().equals("https")) {
61-
connection = (HttpURLConnection) queryURL.openConnection();
62-
}
63-
//https request
64-
else {
65-
connection = (HttpsURLConnection) queryURL.openConnection();
66-
}
67-
74+
connection = this.getHttpURLConnection(getQuery(mirror));
6875
connection.setRequestMethod("HEAD");
6976
connection.setReadTimeout(Settings.HTTP_HEAD_TIMEOUT.getInt());
70-
77+
/*if(connection.getResponseCode() == 301 || connection.getResponseCode() == 302) {
78+
connection.disconnect();
79+
String newUrl = connection.getHeaderField("Location");
80+
System.out.println("### try new url : " + newUrl);
81+
connection = this.getHttpURLConnection(new URL(newUrl));
82+
connection.setRequestMethod("HEAD");
83+
connection.setReadTimeout(Settings.HTTP_HEAD_TIMEOUT.getInt());
84+
}*/
7185
response = new HttpHeadResponse(ivoaID, connection);
86+
7287
if (response.isOk())
7388
return response;
7489
}

portal.ejb/src/main/java/org/vamdc/portal/species/NodeSpecies.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,30 +68,26 @@ public void querySpecies(String ivoaId, SpeciesResult resultBean){
6868
resultBean.setReady(true);
6969
return;
7070
}
71-
System.out.println("### test ");
7271
resultBean.setMirrorCount(mirrors.size());
7372
for(URL node:mirrors){
73+
7474
resultBean.setMessage("Timeout : query execution was too long.");
7575
resultBean.nextMirror();
7676
URL queryUrl=node;
7777
System.out.println("query");
78-
System.out.println(query);
79-
System.out.println(queryUrl);
78+
8079
try {
8180
queryUrl = new URL(node.toExternalForm()+query);
82-
83-
System.out.print("queryUrl");
84-
System.out.print(queryUrl);
81+
System.out.println(queryUrl);
8582
resultBean.setFormattedResult( formatRequestResult(queryUrl));
86-
resultBean.setMessage("");
83+
resultBean.setMessage("");
8784
resultBean.setReady(true);
8885
return;
8986
} catch (MalformedURLException e) {
9087
// TODO Auto-generated catch block
9188
resultBean.setMessage("Incorrect service URL "+queryUrl);
9289
} catch (IOException e) {
93-
// TODO Auto-generated catch block
94-
90+
// TODO Auto-generated catch block
9591
e.printStackTrace();
9692
resultBean.setMessage("Error while proceeding request");
9793
} catch (TransformerException e) {
@@ -102,9 +98,14 @@ public void querySpecies(String ivoaId, SpeciesResult resultBean){
10298
if(e.getCode() == 204) {
10399
resultBean.setMessage("Request returned an empty response");
104100
} else if(e.getCode() >= 400){
101+
System.out.println(e);
105102
resultBean.setMessage("Node returned the error " +e.getCode() +" while processing the request "+queryUrl);
106103
}
107-
}finally{
104+
}catch(Exception e) {
105+
System.out.println(e);
106+
resultBean.setMessage("An exception occurred");
107+
}
108+
finally{
108109
resultBean.setReady(true);
109110
}
110111
}
@@ -117,11 +118,8 @@ public void querySpecies(String ivoaId, SpeciesResult resultBean){
117118
* @throws IOException
118119
* @throws TransformerException
119120
*/
120-
private static String formatRequestResult(URL url) throws IOException, TransformerException, PortalHttpException{
121-
System.out.print("###");
122-
System.out.print(url);
121+
private/* static */ String formatRequestResult(URL url) throws IOException, TransformerException, PortalHttpException{
123122
HttpURLConnection c = (HttpURLConnection)url.openConnection();
124-
125123
if(c.getResponseCode() == 200){
126124
c.setConnectTimeout(Settings.HTTP_CONNECT_TIMEOUT.getInt());
127125
c.setReadTimeout(Settings.HTTP_DATA_TIMEOUT.getInt());
@@ -137,7 +135,12 @@ private static String formatRequestResult(URL url) throws IOException, Transform
137135

138136
return bOut.toString();
139137
}else{
140-
throw new PortalHttpException("Http error while executing TAP request", c.getResponseCode());
138+
if(c.getResponseCode() == 301 || c.getResponseCode() == 302){
139+
String newUrl = c.getHeaderField("Location");
140+
return this.formatRequestResult(new URL(newUrl));
141+
}else {
142+
throw new PortalHttpException("Http error while executing TAP request", c.getResponseCode());
143+
}
141144
}
142145
}
143146
}

0 commit comments

Comments
 (0)