0

Hi I'm rebuilding a API call using volley library

this is my test code to send XML data and receive xml response (I just need to successfully receive response in string format)

String url ="https://prdesb1.singpost.com/ma/FilterOverseasPostalInfo";
        final String payload = "<OverseasPostalInfoDetailsRequest xmlns=\"http://singpost.com/paw/ns\"><Country>AFAFG</Country><Weight>100</Weight><DeliveryServiceName></DeliveryServiceName><ItemType></ItemType><PriceRange>999</PriceRange><DeliveryTimeRange>999</DeliveryTimeRange></OverseasPostalInfoDetailsRequest>\n";

        RequestQueue mRequestQueue;

// Instantiate the cache
        Cache cache = new DiskBasedCache(getCacheDir(), 1024 * 1024); // 1MB cap

// Set up the network to use HttpURLConnection as the HTTP client.
        Network network = new BasicNetwork(new HurlStack());

// Instantiate the RequestQueue with the cache and network.
        mRequestQueue = new RequestQueue(cache, network);

// Start the queue
        mRequestQueue.start();

// Formulate the request and handle the response.
        StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        // Do something with the response
                        Log.v("tesResponse","testResponseS");
                        Log.v("response",response);
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        // Handle error
                        Log.v("tesResponse","testResponseF");
                        Log.v("error",error.toString());
                    }
                }
        ){
            @Override
            public String getBodyContentType() {
                return "application/xml; charset=" +
                        getParamsEncoding();
            }

            @Override
            public byte[] getBody() throws AuthFailureError {

                String postData = payload;
                try {
                    return postData == null ? null :
                            postData.getBytes(getParamsEncoding());
                } catch (UnsupportedEncodingException uee) {
                    // TODO consider if some other action should be taken
                    return null;
                }
            }
        };
//        stringRequest.setRetryPolicy(new DefaultRetryPolicy(5*DefaultRetryPolicy.DEFAULT_TIMEOUT_MS, 0, 0));
        stringRequest.setRetryPolicy(new DefaultRetryPolicy(0, 0, 0));

// Add the request to the RequestQueue.
        mRequestQueue.add(stringRequest);

I have test the String url and the payload on POSTMAN and give successful result. But don't know why my android app give this error

08-22 19:44:24.335 16319-16518/com.example.victory1908.test1 D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true

                                                                               [ 08-22 19:44:24.355 16319:16319 D/         ]
                                                                               HostConnection::get() New Host Connection established 0x7f67de64eac0, tid 16319


                                                                               [ 08-22 19:44:24.399 16319:16518 D/         ]
                                                                               HostConnection::get() New Host Connection established 0x7f67de64edc0, tid 16518
08-22 19:44:24.410 16319-16518/com.example.victory1908.test1 I/OpenGLRenderer: Initialized EGL, version 1.4
08-22 19:44:24.662 16319-16319/com.example.victory1908.test1 V/tesResponse: testResponseF
08-22 19:44:24.662 16319-16319/com.example.victory1908.test1 V/error: com.android.volley.NoConnectionError: javax.net.ssl.SSLHandshakeException: Handshake failed

Just notice problem only with API 23+ (android 6.0 and above) API 22 is working fine!

I have tried set the retry policy but does not work. Anyone know what wrong with the code. Thanks in advance

Lê Khánh Vinh
  • 2,591
  • 5
  • 31
  • 77
  • Just notice problem only with API 23+ (android 6.0 and above) API 22 is working fine! – Lê Khánh Vinh Aug 22 '16 at 17:22
  • Hi, Can you first of all try to increase the timeout to a higher value and see if the issue exists. I'm posting a link to an answer below. http://stackoverflow.com/questions/17094718/change-volley-timeout-duration – Ruchira Randana Aug 23 '16 at 10:09
  • Hi I tried set retry policy stringRequest.setRetryPolicy(new DefaultRetryPolicy(0, 0, 0)); but still same error. Only happen on android 6+ (API23) – Lê Khánh Vinh Aug 23 '16 at 10:16
  • Hi, it could be because Android has changed from OpenSSL from previous versions to BoringSSL from Android 6 onwards as mentioned here (https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html). You can check whether this is the issue if you can change the endpoint to work temporarily without SSL. You may need to collaborate with your backend developers to get it done. I'm suspecting this because you get an error during the SSL handshake. – Ruchira Randana Aug 23 '16 at 10:59
  • For now server support SSLv3 and TLS 1.0. I will make request to remove SSLv3. But before change server side can we remove SSLv3 from client (ie. from volley)? – Lê Khánh Vinh Aug 23 '16 at 11:06

0 Answers0