Android Restlet HTTPS - android

When trying to get some data on my android client from my webservice (running on app-engine) with this code
ClientResource cr = new ClientResource("https://myapp.appspot.com/restlet/service/");
IServiceResource res = cr.wrap(IServiceResource.class);
m_Services = res.getServices();
I get this error:
05-20 08:30:15.406: ERROR/AndroidRuntime(31767): Caused by: Communication Error (1001) - Could not change the mode after the initial handshake has begun.
i have the org.restlet.ext.ssl.jar for the https-support and i am using this line to add the client
Engine.getInstance().getRegisteredClients().add(new HttpsClientHelper(null));
this is the closest i have come to getting https:// calls to work since i moved up to restlet 2.1m4 (moved because i was in need of entityBuffering..)
Any ideas?
Any other information i need to share?

Got it working.
Changed HttpClient to org.restlet.ext.net.
On Android, you are told to do this to change the client
Engine.getInstance().getRegisteredClients().add(new HttpClientHelper(null));
However nothing changes by doing so, instead, i had success with
Engine.getInstance().getRegisteredClients().clear();
Engine.getInstance().getRegisteredClients().add(new HttpClientHelper(null));
This solves the issu(be sure to have org.restlet.ext.ssl in your build path aswell).
This also solves other issues such as the "Internal Connector Error (1002) - The calling thread timed out while waiting for a response to unblock it."

I had worked with web service using ksoap2, u can try using ksoap2 by downloading the jar and including in ur project.

Related

OkHttp connection leak log line even when OkHttp is not a dependency

I keep seeing the following log line in Logcat while I use my app:
19098-19147/<package> W/OkHttpClient: A connection to <my server> was leaked. Did you forget to close a response body?
I did some research on this bug and found that it can happen when you do things like forget to close a response body in an interceptor. I commented out all of interceptors to see if one of them was causing this issue, but I still saw the log line. I eventually commented out all uses of OkHttp and I still somehow got the error. I even went as far as to removing all OkHttp dependencies from my Gradle file and added an explicit line to make sure that it was excluded as a transitive dependency. I ran gradle app:dependencies in order to generate my dependency tree so I could make sure that OkHttp was not included. Somehow I am STILL seeing this log line. I don't understand how this is possible.
Does anyone know of any common libraries that may have copied and pasted this log line out of the OkHttp library and into theirs? I searched all of the source code of my other dependencies, but didn't find a similar log line in any of them.
Could this have something to do with the new profiling code that Android Studio injects? See this article for more information.
Update: Turns out that my Fresco dependency must have been using OkHttp provided by the system or something like that. #Selvin commented that Android uses it internally. Anyways, apparently when Fresco receives an HTTP response with an error when trying to load an image (in my case HTTP response code 401), it logs this error. I don't see any good way for handling HTTP errors with Fresco/OkHttp. I opened the following issue with Fresco: HTTP error response when loading image results in leaked connection #1983
I know it's very late response but maybe anyone is still getting crazy with this issue and finally I found out what happened. Yes: OkHttp is used internally in HttpURLConnection/HttpsURLConnection components since Android 4.4 so you can get these boring messages in logcat, even if you're not using OkHttp library directly in your project.
The problem is generated by 2 factors:
the socket is reused by the urlConnection object, trying to
optmizing performances on multiple requests on the same host.
the response stream is not correctly closed (see below how to solve)
To prevent these log lines or simply take more control on the flow I made some changes to my code and finally solved this issue.
I disabled persistent connections setting Connection: close header. Default is Connection: keep-alive
Before reading the content (body) of the response, check the http response code. As well described in this article if the response code is >= 400 you got an unsuccess: you have not to read the connection InputStream getInputStream() but the ErrorStream getErrorStream() and close it by calling .close() method on the right stream. The connection leak is here. Finally remember to disconnect() the urlConnection object.

No Connection error in Volley and Socket Time out in HttpClient by Async Task

I have spend near about 3 days in this issue of No Time error of Volley,
I am calling 10 web APIs sequentially, at 4th web API I am getting No Connection error of volley, out of 12 there are specifically 4 web APIs which are giving me same error(tries asynchronous as well).
I tried same by Async Task using Http Client getting Socket Time out error for the same web APis.
Note : All these web APIs are working in IOS as well as postman properly.
Can any one please let me know that this is the android side issue or from server side, if its of android please tell me the solution , how can I get rid of it?
I have resolved this issue after doing lots of work around.
Issue was of SSL Certification, As volley doesn't support SSL so need to allow externally.
To allow SSL Refer : here Create a HttpsTrustManager class that implements X509TrustManager:

403 AuthFailureError in Volley

I am having a very strange situation. I have a running script that makes JsonObjectRequest using Volley Singletone. The script has been working perfectly in domain example1.com. Recently I bought example2.com and hosted in the same hosting account. And when I copy all the php files as it is in the second domain, I am getting error "BasicNetwork.performRequest: Unexpected response code 403".
So, I have exactly same php files called using JsonObjectRequest and Volley Singletone working in example1.com, but not in example2.com. I have check the permission of the files in both domain, they are exactly same (644) and there is no htaccess in either of the domain.
I am stuck and don't understand what else I should check?
Any help will be highly appreciated.
Problem is with your server side php script - You can first try to test POST requests using some tool before implementing in your Android application:
If I performed a simple POST request (just using browser not Android) to your provided link I get following error:
403: Forbidden
403 Forbidden Forbidden You
don't have permission to access /mylibman_4_5.php on this server.
Additionally, a 404 Not Found error was encountered while trying to
use an ErrorDocument to handle the request. Apache
Server at mylibrarymanager.com Port 80

SendLogsRequestListener failure in worklight

I am re-implementing an existing worklight system. We have already have a hybrid version. We have decided to re-implement the Client side in pure native. The native client seems work fine.
However, the server seems to be quite unstable - sometimes we don't get a server response after invoking an adapter, sometimes we do get. I have checked the DDMS/Android console. And a Error/Exception was found. Any comments would be appreciated!
com.worklight.common.Logger$SendLogsRequestListener(4274): Logger$SendLogsRequestListener.onFailure in Logger.java:1726 :: Failed to POST data from file /data/data/${APP_NAME}/files/analytics.log.0.send due to: HTTP response code: 500
On a successful adapter call or WLClient connection to the server, the client will attempt to automatically send logs to the server. It looks like something bad is happening on the autosend for adapters. A temporary workaround would be to disable this auto sending behavior by calling
WL.Logger.setAutoSendLogs(false)
But you can only use this call if you do not wish for logs to be sent automatically. If you do wish to have this working properly, I'd suggest opening a PMR so that it can be determined if this is an error in your application or an actual defect.

Android Retrofit Causes Socket Timeout Exception

I am making a POST call to a tomcat server running Struts2 using the retrofit library on an Android Galaxy S3 (/Nexus 7) device. The POST call fails. The tomcat log shows Socket timeout exception.
The same POST using the exact same headers done via curl does not have any issues. I verified that the data on the wire matches using charles proxy.
Any tips/ideas on debugging this issue.
The post call is as follows
#POST(Constants.URL_GET_ORDER_LIST_BASE)
void getCardOrderList(#Body GetOrderListRequest getOrderListRequest, Callback<GetOrderListResponse> cbGetOrderListResponse);
Please let me know if I need to add more information to explain this better.
Adding Square's OKHTTP library into the libs folder fixed the issue.
I was having SocketTimeoutExceptions too. Pay attention to always add the final slash to your POST call.
Example:
BAD
#POST("/customers")
GOOD
#POST("/customers/")
My mistake was just this :)

Categories

Resources