• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

opensrp / opensrp-server-core / #162

pending completion
#162

Pull #621

Github

web-flow
Merge b5d4652eb into 68d7f3ff3
Pull Request #621: update selectStructureAndFamilyWithinRadius query

8286 of 10652 relevant lines covered (77.79%)

0.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/org/opensrp/util/NetClientGet.java
1
/**
2
  * Contributors: muhammad.ahmed@ihsinformatics.com
3
 */
4
package org.opensrp.util;
5

6
import java.io.BufferedReader;
7
import java.io.IOException;
8
import java.io.InputStream;
9
import java.io.InputStreamReader;
10
import java.net.HttpURLConnection;
11
import java.net.MalformedURLException;
12
import java.net.URL;
13
import java.net.URLConnection;
14

15
import org.apache.commons.codec.binary.Base64;
16

17
public class NetClientGet {
×
18
        
19
        // http://localhost:8080/RESTfulExample/json/product/get
20
        public String convertToString(String dataurl, String username, String formId) {
21
                
22
                try {
23
                        
24
                        URL url = new URL("https://enketo.formhub.org/transform/get_html_form");
×
25
                        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
×
26
                        conn.setRequestMethod("POST");
×
27
                        conn.setDoInput(true);
×
28
                        conn.setDoOutput(true);
×
29
                        String url1 = "server_url=https://ona.io/" + username + "&form_id=" + formId; //+dataurl;
×
30
                        //String url2="server_url=https://ona.io/"+username+"/forms/"+formId+"/form.json&callback=CALLBACKFN";            
31
                        
32
                        //    System.out.println(url2);
33
                        //"server_url=https://ona.io/ahmedihs&form_id=crvs_birth_notification"
34
                        conn.getOutputStream().write(url1.getBytes());
×
35
                        if (conn.getResponseCode() != 200) {
×
36
                                throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
×
37
                        }
38
                        //      System.out.println(conn.getResponseCode());
39
                        BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
×
40
                        
41
                        StringBuilder sb = new StringBuilder();
×
42
                        String output = null;
×
43
                        //        System.out.println("Output from Server .... \n");
44
                        
45
                        while ((output = br.readLine()) != null) {
×
46
                                //        System.out.println(output);
47
                                sb.append(output);
×
48
                        }
49
                        
50
                        /*FileOutputStream fop = new FileOutputStream("d:\\tlocal201312161608.xml");
51
                        fop.write(sb.toString().getBytes());
52
                        conn.disconnect();*/
53
                        return sb.toString();
×
54
                        
55
                }
56
                catch (MalformedURLException e) {
×
57
                        
58
                        e.printStackTrace();
×
59
                        
60
                }
61
                catch (IOException e) {
×
62
                        
63
                        e.printStackTrace();
×
64
                        
65
                }
×
66
                return null;
×
67
        }
68
        
69
        public byte[] downloadJson(String username, String password, String formPk) throws IOException {
70
                
71
                try {
72
                        String authString = username + ":" + password;
×
73
                        System.out.println("auth string: " + authString);
×
74
                        byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
×
75
                        String authStringEnc = new String(authEncBytes);
×
76
                        System.out.println("Base64 encoded auth string: " + authStringEnc);
×
77
                        //The file that you want to download
78
                        String url2 = "https://api.ona.io/api/v1/forms/" + formPk + "/form.json";
×
79
                        URL link = new URL(url2);
×
80
                        URLConnection urlConnection = link.openConnection();
×
81
                        urlConnection.setRequestProperty("Authorization", "Basic " + authStringEnc);
×
82
                        InputStream is = urlConnection.getInputStream();
×
83
                        InputStreamReader isr = new InputStreamReader(is);
×
84
                        
85
                        int numCharsRead;
86
                        char[] charArray = new char[1024];
×
87
                        StringBuffer sb = new StringBuffer();
×
88
                        while ((numCharsRead = isr.read(charArray)) > 0) {
×
89
                                sb.append(charArray, 0, numCharsRead);
×
90
                        }
91
                        String result = sb.toString();
×
92
                        
93
                        System.out.println("*** BEGIN ***");
×
94
                        System.out.println(result);
×
95
                        System.out.println("*** END ***");
×
96
                        
97
                        return result.getBytes();
×
98
                }
99
                catch (MalformedURLException e) {
×
100
                        e.printStackTrace();
×
101
                }
102
                catch (IOException e) {
×
103
                        e.printStackTrace();
×
104
                }
×
105
                
106
                return null;
×
107
        }
108
        
109
        public String getModel(String data) {
110
                
111
                return data.substring(data.indexOf("<model>"), data.indexOf("</model>") + 8);
×
112
                
113
        }
114
        
115
        public String getForm(String data) {
116
                
117
                return data.substring(data.indexOf("<form "), data.indexOf("</form>") + 7);
×
118
        }
119
        
120
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc