Clover icon

Coverage Report

  1. Project Clover database Thu Nov 7 2024 17:01:39 GMT
  2. Package jalview.javascript.web

File ClientResponse.java

 

Coverage histogram

../../../img/srcFileCovDistChart0.png
0% of files have more coverage

Code metrics

8
14
4
1
113
47
10
0.71
3.5
4
2.5

Classes

Class Line # Actions
ClientResponse 34 14 10
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.javascript.web;
22   
23    import jalview.javascript.json.JSON;
24    import jalview.util.Platform;
25   
26    import java.net.URL;
27   
28    /**
29    * minimal implementation of com.sun.jersey.api.client.ClientResponse
30    *
31    * @author hansonr
32    *
33    */
 
34    public class ClientResponse
35    {
36   
37    private String response;
38   
39    private boolean isJSON;
40   
41    private Object jsonData;
42   
43    int responseCode = -1;
44   
 
45  0 toggle public ClientResponse(URL url, String[] encoding)
46    {
47    // OK, so it turns out that ajax "json" format - or for that matter, any
48    // format for json is still just text. There is no point in getting this
49    // using special jQuery "json" formats. Duh. BH wasted a whole day try to
50    // "do it right".
51  0 response = Platform.getFileAsString(url.toString());
52  0 responseCode = (response == null || response == "" ? 404 : 200);
53  0 isJSON = encoding[0].equals("application/json");
54  0 if (isJSON)
55    {
56  0 try
57    {
58  0 jsonData = JSON.parse(response);
59    } catch (Exception e)
60    {
61  0 jsonData = null;
62    }
63  0 if (jsonData == null)
64    {
65  0 responseCode = 400;
66    }
67    }
68    }
69   
 
70  0 toggle public Object getEntity(Class<?> c)
71    {
72   
73  0 if (c == java.util.Map.class)
74    {
75  0 return jsonData;
76    }
77  0 return response;
78    }
79   
80    // https://www.ebi.ac.uk/pdbe/search/pdb/select?wt=json&fl=pdb_id,title,experimental_method,resolution&rows=500&start=0&q=(text:q93xj9_soltu)+AND+molecule_sequence:%5B%27%27+TO+*%5D+AND+status:REL&sort=overall_quality+desc
81   
82    // {
83    // "responseHeader":{
84    // "status":0,
85    // "QTime":0,
86    // "params":{
87    // "q":"(text:q93xj9_soltu) AND molecule_sequence:['' TO *] AND status:REL",
88    // "fl":"pdb_id,title,experimental_method,resolution",
89    // "start":"0",
90    // "sort":"overall_quality desc",
91    // "rows":"500",
92    // "wt":"json"}},
93    // "response":{"numFound":1,"start":0,"docs":[
94    // {
95    // "experimental_method":["X-ray diffraction"],
96    // "pdb_id":"4zhp",
97    // "resolution":2.46,
98    // "title":"The crystal structure of Potato ferredoxin I with 2Fe-2S
99    // cluster"}]
100    // }}
101    //
102   
 
103  0 toggle public int getStatus()
104    {
105  0 return responseCode;
106    }
107   
 
108  0 toggle public Object getJSONData()
109    {
110  0 return jsonData;
111    }
112   
113    }