Skip to content

Commit

Permalink
Fixed access to Sesar and Geochron apis (#195)
Browse files Browse the repository at this point in the history
* Fixed access to Sesar and Geochron apis

* Updated api test

* New version 3.6.91
  • Loading branch information
bowring authored Feb 20, 2021
1 parent 99e897e commit a205418
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<groupId>org.cirdles</groupId>
<artifactId>ET_Redux</artifactId>
<name>ET_Redux</name>
<version>3.6.90</version>
<version>3.6.91</version>
<description>Successor to U-Pb_Redux</description>
<url>https://cirdles.org</url>
<inceptionYear>2006</inceptionYear>
Expand Down Expand Up @@ -119,7 +119,7 @@
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.14</version>
<version>1.4.15</version>
</dependency>
<dependency>
<groupId>javax.help</groupId>
Expand Down
48 changes: 47 additions & 1 deletion src/main/java/org/earthtime/archivingTools/URIHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import javax.net.ssl.HttpsURLConnection;
import javax.swing.JOptionPane;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
Expand Down Expand Up @@ -64,6 +65,45 @@ public class URIHelper {
public URIHelper() {
}

/**
*
* @param fileURI
* @return
*/
public static InputStream getInputStreamFromHttpsURI(String fileURI) {
URL url;
HttpsURLConnection urlConn = null;

InputStream retval = null;
try {

url = new URL(fileURI);

urlConn = (HttpsURLConnection) url.openConnection();

urlConn.setDoInput(true);
urlConn.setUseCaches(false);
// Feb 2021 started throwing 403 so used advice from
// https://stackoverflow.com/questions/13670692/403-forbidden-with-java-but-not-web-browser
urlConn.setRequestProperty(
"User-Agent",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");

// july 2019
urlConn.setConnectTimeout(10000);
urlConn.setReadTimeout(10000);

retval = urlConn.getInputStream();

} catch (IOException iOException) {
// JOptionPane.showMessageDialog(null,
// new String[]{"Error reaching server: "//
// + iOException.getMessage()});
}

return retval;
}

/**
*
* @param fileURI
Expand Down Expand Up @@ -137,7 +177,13 @@ public static BufferedReader getBufferedReader(String filename)
Reader inReader = null;

try {
if (filename.startsWith("http")) {
if (filename.startsWith("https")) {
try {
inReader = new InputStreamReader(getInputStreamFromHttpsURI(filename));
reader = new BufferedReader(inReader);
} catch (Exception e) {
}
} else if (filename.startsWith("http")) {
try {
inReader = new InputStreamReader(getInputStreamFromURI(filename));
reader = new BufferedReader(inReader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public enum SampleRegistries {
/**
*
*/
GeochronID( "GeochronID", "GCH", "http://www.geochron.org/igsnexists.php?igsn=");// "http://www.geochronid.org/display.php?geochronid=" ),
GeochronID( "GeochronID", "GCH", "https://www.geochron.org/igsnexists.php?igsn=");// "http://www.geochronid.org/display.php?geochronid=" ),


//EARTHTIME_ID( "EARTHTIME-ID", "ERT", "" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ public class SampleRegistriesTest {
*/
@Test
public void test_constructor_0(){
System.out.println("Testing SampleRegistries's enumerations and getters.");
System.out.println("Testing SampleRegistries' enumerations and getters.");
//Tests if values are correct for all enumerations, and tests the getters as well. You cannot instantiate new inumerations.

SampleRegistries ave=SampleRegistries.GeochronID;
assertEquals("GeochronID",ave.getName());
assertEquals("GCH",ave.getCode());
assertEquals("http://www.geochron.org/igsnexists.php?igsn=",ave.getConnectionString());
assertEquals("https://www.geochron.org/igsnexists.php?igsn=",ave.getConnectionString());

ave=SampleRegistries.SESAR;
assertEquals("SESAR",ave.getName());
Expand Down

0 comments on commit a205418

Please sign in to comment.