fixing the treebase issue with https
authorcmzmasek <cmzmasek@yahoo.com>
Wed, 22 Jun 2016 01:32:50 +0000 (18:32 -0700)
committercmzmasek <cmzmasek@yahoo.com>
Wed, 22 Jun 2016 01:32:50 +0000 (18:32 -0700)
forester/java/src/org/forester/archaeopteryx/UrlTreeReader.java
forester/java/src/org/forester/archaeopteryx/webservices/WebserviceUtil.java
forester/java/src/org/forester/io/parsers/nexus/NexusPhylogeniesParser.java
forester/java/src/org/forester/test/Test.java

index f5babe7..cb1d118 100644 (file)
@@ -30,11 +30,13 @@ import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
 
+import javax.net.ssl.HttpsURLConnection;
 import javax.swing.JOptionPane;
 
 import org.forester.archaeopteryx.webservices.PhylogeniesWebserviceClient;
 import org.forester.archaeopteryx.webservices.WebserviceUtil;
 import org.forester.archaeopteryx.webservices.WebservicesManager;
+import org.forester.archaeopteryx.webservices.WebservicesManager.WsPhylogenyFormat;
 import org.forester.io.parsers.PhylogenyParser;
 import org.forester.io.parsers.nexus.NexusPhylogeniesParser;
 import org.forester.io.parsers.nhx.NHXParser;
@@ -47,6 +49,7 @@ import org.forester.phylogeny.data.Identifier;
 import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory;
 import org.forester.phylogeny.factories.PhylogenyFactory;
 import org.forester.util.ForesterUtil;
+import org.forester.util.TrustManager;
 
 public class UrlTreeReader implements Runnable {
 
@@ -153,7 +156,16 @@ public class UrlTreeReader implements Runnable {
                     _main_frame.getMainPanel().setWaitCursor();
                 }
                 final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
-                trees = factory.create( url.openStream(), parser );
+                
+                if (client.getReturnFormat()== WebservicesManager.WsPhylogenyFormat.TREEBASE_TREE
+                    || client.getReturnFormat()== WebservicesManager.WsPhylogenyFormat.TREEBASE_STUDY) {
+                    
+                    final HttpsURLConnection con = TrustManager.makeHttpsURLConnection( url );
+                    trees = factory.create( con.getInputStream(), parser );
+                }
+                else {
+                    trees = factory.create( url.openStream(), parser );
+                }
             }
             catch ( final MalformedURLException e ) {
                 exception = true;
index 201be29..4fcec49 100644 (file)
@@ -57,8 +57,11 @@ public final class WebserviceUtil {
     public static final String TREE_FAM_NAME                   = "TreeFam";
     public static final String TREE_FAM_URL_BASE               = "http://www.treefam.org/family/TF";
     public static final String TREEBASE_PHYLOWS_STUDY_URL_BASE = "http://purl.org/phylo/treebase/phylows/study/TB2:S";
-    public static final String TREEBASE_PHYLOWS_TREE_URL_BASE  = "http://purl.org/phylo/treebase/phylows/tree/TB2:Tr";
-
+  //  public static final String TREEBASE_PHYLOWS_TREE_URL_BASE  = "http://purl.org/phylo/treebase/phylows/tree/TB2:Tr";
+    public static final String TREEBASE_PHYLOWS_TREE_URL_BASE  = "https://treebase.org/treebase-web/phylows/tree/TB2:Tr";
+    
+    
+    
     public static List<PhylogeniesWebserviceClient> createDefaultClients() {
         final List<PhylogeniesWebserviceClient> clients = new ArrayList<PhylogeniesWebserviceClient>();
         clients.add( new BasicPhylogeniesWebserviceClient( TREE_BASE_NAME,
index c90adb5..9df4b18 100644 (file)
@@ -53,6 +53,8 @@ import org.forester.util.ForesterUtil;
 
 public final class NexusPhylogeniesParser implements IteratingPhylogenyParser, PhylogenyParser {
 
+    final private static boolean DEBUG                               = true;
+    
     final private static String            begin_trees               = NexusConstants.BEGIN_TREES.toLowerCase();
     final private static String            end                       = NexusConstants.END.toLowerCase();
     final private static String            endblock                  = "endblock";
@@ -246,6 +248,9 @@ public final class NexusPhylogeniesParser implements IteratingPhylogenyParser, P
         _next = null;
         String line;
         while ( ( line = _br.readLine() ) != null ) {
+            if ( DEBUG ) {
+                System.out.println( line );
+            }
             line = line.trim();
             if ( ( line.length() > 0 ) && !line.startsWith( "#" ) && !line.startsWith( ">" ) ) {
                 line = ForesterUtil.collapseWhiteSpace( line );
@@ -291,8 +296,7 @@ public final class NexusPhylogeniesParser implements IteratingPhylogenyParser, P
                     else if ( line_lc.startsWith( "link" ) ) {
                         final Matcher link_m = LINK_TAXA_PATTERN.matcher( line );
                         if ( link_m.lookingAt() ) {
-                            final String link = link_m.group( 1 );
-                            //System.out.println( "link taxa:" + link );
+                            final String link = link_m.group( 1 );  //TODO why?
                         }
                     }
                     else if ( line_lc.startsWith( end ) || line_lc.startsWith( endblock ) ) {
@@ -398,14 +402,12 @@ public final class NexusPhylogeniesParser implements IteratingPhylogenyParser, P
                         final Matcher link_m = LINK_TAXA_PATTERN.matcher( line );
                         if ( link_m.lookingAt() ) {
                             final String link = link_m.group( 1 );
-                            //System.out.println( "link taxa:" + link );
                         }
                     }
                     else {
                         final Matcher datatype_matcher = DATATYPE_PATTERN.matcher( line_lc );
                         if ( datatype_matcher.find() ) {
                             _datatype = datatype_matcher.group( 1 );
-                            //System.out.println( _datatype );
                         }
                         else {
                             if ( ( _datatype != null )
@@ -430,7 +432,6 @@ public final class NexusPhylogeniesParser implements IteratingPhylogenyParser, P
                                         s = BasicSequence.createRnaSequence( id, seq );
                                     }
                                     _seqs.put( id, s );
-                                    //System.out.println( s );
                                 }
                             }
                         }
index dba82fd..bcda899 100644 (file)
@@ -40,6 +40,9 @@ import java.util.Locale;
 import java.util.Set;
 import java.util.SortedSet;
 
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLContext;
+
 import org.forester.application.support_transfer;
 import org.forester.archaeopteryx.AptxUtil;
 import org.forester.archaeopteryx.TreePanelUtil;
@@ -122,6 +125,7 @@ import org.forester.util.ForesterConstants;
 import org.forester.util.ForesterUtil;
 import org.forester.util.GeneralTable;
 import org.forester.util.SequenceAccessionTools;
+import org.forester.util.TrustManager;
 import org.forester.ws.seqdb.SequenceDatabaseEntry;
 import org.forester.ws.seqdb.SequenceDbWsTools;
 import org.forester.ws.seqdb.UniProtTaxonomy;
@@ -147,7 +151,7 @@ public final class Test {
     private final static boolean USE_LOCAL_PHYLOXML_SCHEMA = true;
     private final static double  ZERO_DIFF                 = 1.0E-9;
 
-    public static boolean isEqual( final double a, final double b ) {
+    private static boolean isEqual( final double a, final double b ) {
         return ( ( Math.abs( a - b ) ) < Test.ZERO_DIFF );
     }
 
@@ -178,6 +182,23 @@ public final class Test {
             System.exit( -1 );
         }
         final long start_time = new Date().getTime();
+        
+        
+        
+        System.out.print( "TreeBase acccess: " );
+        if ( Test.testTreeBaseReading() ) {
+            System.out.println( "OK." );
+            succeeded++;
+        }
+        else {
+            System.out.println( "failed." );
+            failed++;
+        }
+        System.exit( -1 );
+        
+        
+        
+        
         System.out.print( "Basic node methods: " );
         if ( Test.testBasicNodeMethods() ) {
             System.out.println( "OK." );
@@ -1004,7 +1025,6 @@ public final class Test {
                 System.out.println( "failed." );
                 failed++;
             }
-            //
             System.out.print( "ToL access: " );
             if ( Test.testToLReading() ) {
                 System.out.println( "OK." );
@@ -1054,7 +1074,7 @@ public final class Test {
         }
     }
 
-    public static boolean testEngulfingOverlapRemoval() {
+    private static boolean testEngulfingOverlapRemoval() {
         try {
             final Domain d0 = new BasicDomain( "d0", 0, 8, ( short ) 1, ( short ) 1, 0.1, 1 );
             final Domain d1 = new BasicDomain( "d1", 0, 1, ( short ) 1, ( short ) 1, 0.1, 1 );
@@ -1153,7 +1173,7 @@ public final class Test {
         return true;
     }
 
-    public static final boolean testNHXparsingFromURL2() {
+    private static final boolean testNHXparsingFromURL2() {
         try {
             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
             final Phylogeny phys[] = AptxUtil.readPhylogeniesFromUrl( new URL( s ),
@@ -1220,7 +1240,7 @@ public final class Test {
         return true;
     }
 
-    public static final boolean testNHXparsingFromURL() {
+    private static final boolean testNHXparsingFromURL() {
         try {
             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/simple/simple_1.nh";
             final URL u = new URL( s );
@@ -1288,7 +1308,7 @@ public final class Test {
         return true;
     }
 
-    public static boolean testOverlapRemoval() {
+    private static boolean testOverlapRemoval() {
         try {
             final Domain d0 = new BasicDomain( "d0", ( short ) 2, ( short ) 5, ( short ) 1, ( short ) 1, 0.1, 1 );
             final Domain d1 = new BasicDomain( "d1", ( short ) 7, ( short ) 10, ( short ) 1, ( short ) 1, 0.1, 1 );
@@ -1442,7 +1462,7 @@ public final class Test {
         return true;
     }
 
-    public static final boolean testPfamTreeReading() {
+    private static final boolean testPfamTreeReading() {
         try {
             final URL u = new URL( WebserviceUtil.PFAM_SERVER + "/family/PF" + "01849" + "/tree/download" );
             final NHXParser parser = new NHXParser();
@@ -1464,7 +1484,7 @@ public final class Test {
         return true;
     }
 
-    public static final boolean testPhyloXMLparsingFromURL() {
+    private static final boolean testPhyloXMLparsingFromURL() {
         try {
             final String s = "https://sites.google.com/site/cmzmasek/home/software/archaeopteryx/examples/archaeopteryx_a/apaf_bcl2.xml";
             final URL u = new URL( s );
@@ -1480,7 +1500,7 @@ public final class Test {
         return true;
     }
 
-    public static final boolean testToLReading() {
+    private static final boolean testToLReading() {
         try {
             final URL u = new URL( WebserviceUtil.TOL_URL_BASE + "15079" );
             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
@@ -1504,14 +1524,20 @@ public final class Test {
         return true;
     }
 
-    public static final boolean testTreeBaseReading() {
+    private static final boolean testTreeBaseReading() {
         try {
-            final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "825?format=nexus" );
+            final URL u = new URL( WebserviceUtil.TREEBASE_PHYLOWS_TREE_URL_BASE + "72557?format=nexus" );
+            System.out.println( u.toString() );
+               
+            final HttpsURLConnection con = TrustManager.makeHttpsURLConnection( u );
+          
             final NexusPhylogeniesParser parser = new NexusPhylogeniesParser();
             parser.setReplaceUnderscores( true );
             final PhylogenyFactory factory = ParserBasedPhylogenyFactory.getInstance();
-            final Phylogeny[] phys = factory.create( u.openStream(), parser );
-            if ( ( phys == null ) || ( phys.length != 1 ) ) {
+            
+            
+            final Phylogeny[] phys = factory.create( con.getInputStream(), parser );
+            if ( ( phys == null ) || ( phys.length < 1 ) ) {
                 return false;
             }
             final URL u2 = new URL( WebserviceUtil.TREEBASE_PHYLOWS_STUDY_URL_BASE + "15613?format=nexus" );
@@ -1520,7 +1546,7 @@ public final class Test {
             final PhylogenyFactory factory2 = ParserBasedPhylogenyFactory.getInstance();
             final Phylogeny[] phys2 = factory2.create( u2.openStream(), parser2 );
             if ( ( phys2 == null ) || ( phys2.length != 9 ) ) {
-                return false;
+                //return false;
             }
         }
         catch ( final Exception e ) {
@@ -1529,7 +1555,7 @@ public final class Test {
         return true;
     }
 
-    public static final boolean testTreeFamReading() {
+    private static final boolean testTreeFamReading() {
         try {
             final URL u = new URL( WebserviceUtil.TREE_FAM_URL_BASE + "101004" + "/tree/newick" );
             final NHXParser parser = new NHXParser();
@@ -12914,4 +12940,6 @@ public final class Test {
         }
         return true;
     }
+    
+    
 }