1

I have the following code, which i use to check the second level of internet connectivity to a particular server.

HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
                        SchemeRegistry registry = new SchemeRegistry();
                        SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
                        socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);
                        registry.register(new Scheme("https", socketFactory, 8443));

                        DefaultHttpClient client = new DefaultHttpClient();

                        SingleClientConnManager mgr = new SingleClientConnManager(client.getParams(), registry);
                        DefaultHttpClient httpClient = new DefaultHttpClient(mgr, client.getParams());


                        HttpParams httpParameters = new BasicHttpParams();
                        HttpConnectionParams.setConnectionTimeout(httpParameters, Constants.HTTP_CONNECTION_TIMEOUT);

                        HttpConnectionParams.setSoTimeout(httpParameters, Constants.HTTP_CONNECTION_TIMEOUT);

                        HttpGet httpget = new HttpGet(Utility.getCloudUrl());

                        try {
                            HttpResponse response = httpClient.execute(httpget);

                            BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
                            StringBuffer sb = new StringBuffer("");
                            String l = new String();
                            while ((l = in.readLine()) !=null){
                                sb.append(l);
                            }
                            in.close();
                            String data = sb.toString();
                            if (data.length() > 0){

                                synchronized (lock) {
                                    isInternetAvialbale = true;
                                }
                                listener.onInternetReachable();

                            }else{


                                synchronized (lock) {
                                    isInternetAvialbale = false;
                                }
                                listener.onInternetNotReachable();
                            }
                        } catch (IOException e) {


                            synchronized (lock) {
                                isInternetAvialbale = false;
                            }
                            listener.onInternetNotReachable();
                            return;
                        }

Everything works fine on a Wifi network. But when this code executes on a 3g network, I get the following exception:

java.lang.IllegalStateException: Scheme 'http' not registered.
       at org.apache.http.conn.scheme.SchemeRegistry.getScheme(SchemeRegistry.java:80)
       at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:126)
       at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
       at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
       at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
       at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:670)
       at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:509)
       at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
       at com.day.demo.DayApplication$3.run(DayApplication.java:340)
       at java.lang.Thread.run(Thread.java:841)

I did search through a few similar questions but was not able to understand. Could someone please help me with this?

Sunny
  • 7,444
  • 22
  • 63
  • 104

1 Answers1

0

If you are connected to the internet using an organization's WiFi, make sure you can access the internet (and not just connect to it). If the WiFi access requires a sign in, please sign in and then proceed with the HTTP/HTTPS requests.

BajajG
  • 2,134
  • 2
  • 25
  • 32