Quantcast
Channel: SCN : All Content - SAP HANA Cloud Platform Developer Center
Viewing all articles
Browse latest Browse all 3285

Parse Odata Responce in android

$
0
0

Hello,

 

I have got odata service running and give xml and json response properly,

 

but when i try to consume that odata on android device i am not able to, used the code from the below blog with many combination to get odata response and parse

 

How to create an Android app on SAP HANA One in 20 minutes

 

 

BufferedReader in = new BufferedReader(new InputStreamReader(getInputStream( "https://s8hanaxs.hanatrial.ondemand.com/p1941468224trial/devtest/empdemo/services.xsodata/" +

                    "Employees?$format=json", "DEV_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "xxxxxxx")));

 

using the below method it gives

java.io.FileNotFoundException: https://s8hanaxs.hanatrial.ondemand.com/p1941468224trial/devtest/empdemo/services.xsodata/Employees?$format=json

 

 

private InputStream getInputStream(String urlStr, String user, String password) throws IOException

    {

        URL url = new URL(urlStr);

        HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();

        try {

            conn.setDefaultHostnameVerifier(new HostnameVerifier(){

                    public boolean verify(String hostname, SSLSession session) {

                            return true;

                    }});

            SSLContext context = SSLContext.getInstance("TLS");

            context.init(null, new X509TrustManager[]{new X509TrustManager(){

                    public void checkClientTrusted(X509Certificate[] chain,

                                    String authType) throws CertificateException {}

                    public void checkServerTrusted(X509Certificate[] chain,

                                    String authType) throws CertificateException {}

                    public X509Certificate[] getAcceptedIssuers() {

                            return new X509Certificate[0];

                    }}}, new SecureRandom());

            conn.setDefaultSSLSocketFactory(

                            context.getSocketFactory());

    } catch (Exception e) { // should never happen

            e.printStackTrace();

    }

     

        // Create the SSL connection

        SSLContext sc;

        try {

            sc = SSLContext.getInstance("TLS");

     

        sc.init(null, null, new java.security.SecureRandom());

        conn.setSSLSocketFactory(sc.getSocketFactory());

        } catch (NoSuchAlgorithmException e) {

            e.printStackTrace();

        } catch (KeyManagementException e) {

            e.printStackTrace();

        }

        // Use this if you need SSL authentication

        String userpass = user + ":" + password;

        String basicAuth = "Basic " + Base64.encodeToString(userpass.getBytes(), Base64.DEFAULT);

        conn.setRequestProperty("Authorization", basicAuth);

 

        // set Timeout and method

        conn.setReadTimeout(117000);

        conn.setConnectTimeout(117000);

        conn.setRequestMethod("POST");

        conn.setDoInput(true);

 

        // Add any data you wish to post here

 

        conn.connect();

        return conn.getInputStream();

    }

 

 

any one help will be highly appreciated.

 

Thanks

Lakhan


Viewing all articles
Browse latest Browse all 3285

Trending Articles