JAL-3144 SequenceFetcher without JDatabaseTree
[jalview.git] / src / jalview / fts / service / uniprot / UniProtFTSRestClient.java
index 262ed86..924b061 100644 (file)
@@ -22,6 +22,7 @@
 package jalview.fts.service.uniprot;
 
 import jalview.bin.Cache;
+import jalview.bin.Jalview;
 import jalview.fts.api.FTSData;
 import jalview.fts.api.FTSDataColumnI;
 import jalview.fts.api.FTSRestClientI;
@@ -40,7 +41,6 @@ import javax.ws.rs.core.MediaType;
 import com.sun.jersey.api.client.Client;
 import com.sun.jersey.api.client.ClientResponse;
 import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.client.config.ClientConfig;
 import com.sun.jersey.api.client.config.DefaultClientConfig;
 
 public class UniProtFTSRestClient extends FTSRestClient
@@ -64,9 +64,6 @@ public class UniProtFTSRestClient extends FTSRestClient
   {
     try
     {
-      ClientConfig clientConfig = new DefaultClientConfig();
-      Client client = Client.create(clientConfig);
-
       String wantedFields = getDataColumnsFieldsAsCommaDelimitedString(
               uniportRestRequest.getWantedFields());
       int responseSize = (uniportRestRequest.getResponseSize() == 0)
@@ -90,6 +87,25 @@ public class UniProtFTSRestClient extends FTSRestClient
                                 + uniportRestRequest.getSearchTerm();
       }
 
+      // BH 2018 the trick here is to coerce the classes in Javascript to be
+      // different from the ones in Java yet still allow this to be correct for
+      // Java
+      Client client;
+      Class<ClientResponse> clientResponseClass;
+      if (/** @j2sNative true || */
+      false)
+      {
+        // JavaScript only -- coerce types to Java types for Java
+        client = (Client) (Object) new jalview.javascript.web.Client();
+        clientResponseClass = (Class<ClientResponse>) (Object) jalview.javascript.web.ClientResponse.class;
+      }
+      else
+      {
+        // Java only
+        client = Client.create(new DefaultClientConfig());
+        clientResponseClass = ClientResponse.class;
+      }
+
       WebResource webResource = null;
       webResource = client.resource(uniprotSearchEndpoint)
               .queryParam("format", "tab")
@@ -99,7 +115,7 @@ public class UniProtFTSRestClient extends FTSRestClient
               .queryParam("sort", "score").queryParam("query", query);
       // Execute the REST request
       ClientResponse clientResponse = webResource
-              .accept(MediaType.TEXT_PLAIN).get(ClientResponse.class);
+              .accept(MediaType.TEXT_PLAIN).get(clientResponseClass);
       String uniProtTabDelimittedResponseString = clientResponse
               .getEntity(String.class);
       // Make redundant objects eligible for garbage collection to conserve
@@ -113,8 +129,9 @@ public class UniProtFTSRestClient extends FTSRestClient
         throw new Exception(errorMessage);
 
       }
-      int xTotalResults = Integer.valueOf(
-              clientResponse.getHeaders().get("X-Total-Results").get(0));
+      int xTotalResults = Jalview.isJS() ? 1
+              : Integer.valueOf(clientResponse.getHeaders()
+                      .get("X-Total-Results").get(0));
       clientResponse = null;
       client = null;
       return parseUniprotResponse(uniProtTabDelimittedResponseString,