android robolectric : mocking HTTP Requests - cannot find class Http - android

This is probably a stupid question; however, I am out of options and would appreciate help. I am trying to mock file downloads using Robolectric. I am referring to the class HttpTest.java, and the Robolectric blog post.
My problem: Maven is unable to find the Http class referred to in the HttpTest.java code. I could manually bring it over as a class in the same package, but I ended up getting a NullPtrException in one of the methods of class Http.
I have searched on the net for a solution. I have also verified the modules configuration in the pom file. I do have com.pivotlabs present there.
Has anyone gotten this working? Please let me know what I am missing here.

I got this working.
Http is a class internal to Robolectric's sample code. It can be used outside; but you might not want to do that if your code is gonna be built non-locally.
The clarification/mention in documentation that would have gone long way in helping me is: "Robolectric will give you the response you create using addPendingHttpResponse() for your HTTP request, no matter how you do the request. Robolectric will NOT do an actual HTTP request." Once I understood this, rest was easy.
I used Apache's DefaultHttpClient for my request, and verified received response against the already created response.
Hope this helps; I'd be happy to clarify further.
Thanks for the help I received here.
[I had asked this question on Robolectric's google group as well.]

Related

Kairos API - get JSON response

I would like to use Kairos' API for face recognition. It seems a pretty good system, but have no idea, how to catch examples. If I use a string, it is empty after the process. There isn't any example about this in API documentation, nor in its GitHub repo: https://github.com/kairosinc/Kairos-SDK-Android
I try to connect to http://api.kairos.com, but maybe there is a problem with authentication, or should use URL with some parameters added. I cannot found any information about this.
You might be missing the proper APP_ID and APP_KEY headers. Check out this answered solution using a Curl example.

android:--java.net.ProtocolException:Too many follow-up requests:21

I am trying to sync my app with the server (periodically,on-demand & when network outage happens),which uses the basic authentication for the syncing.Here i am facing this error.
Had done some research on this but found no solution.Have anyone come across this & have a solution???
PS:I am a novice developer in android.
I recommend double checking the method url that you are using.
For instance, can you run it using Postman or some other REST client and get a valid response?
This behavior happened in one of my project while I accidentally used a broken method URL but with a right host.
good luck:)

a url's response may be replaced by another url

I have two different domain urls named A.com and B.com.
This is the code to send request: the asyncHttpClient is the same one.
asyncHttpClient.post(context, "A.com", aParams, aResponseHandler);
asyncHttpClient.post(context, "B.com", bParams, bRsponseHandler);
There is a chance to happen: get "B.com" response in aResponseHandler, although it doesn't happen frequently. Why does it mistake the response ?
Whehter i perform either of them solely, it's ok.
I find another guy has the same question.
The issue you linked on github seems to be closed.
The original poster wrote the following:
in my local tests ,no way to reproduce this problem, but truly
happened.....
It seems unlikely that this would occur, and the issue cannot be reproduced. Personally, I wouldn't worry about this happening in your application. You could write a conditional statement to check and throw an exception if the wrong ResponseHandler is triggered.

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 :)

Android Rest client to Delphi XE2 Datasnap Rest server

I found many examples on Stack Overflow and I just don't know where to start since I have a particular prerequisite:
My Delphi Datasnap Rest server is using ZLibCompression and RSA encryption (in TTransportFilterCollection of DSHTTPWebDispatcher). Is there an Android restful API that can handle those? Any sample that already implements that?
I found this thread Android REST client, Sample? as a good starting point, both lightweight and well-formed clients are presented but is it enough for me?
Thanks in advance for any hint, sample or library that you could point me to.
you can use the Android Rest-Client for sending data to a webservice
see my answer in the post Adding body of call to POST using HttpURLConnection
I just used the proxy generator from Danasnap server TDSProxyGenerator component (http://yourserver:port/proxy/java_android.zip) and added this code to my android project...
I had to search for the DSRESTSSLFactory.java file that is not generated by the proxy (but required !!), i found it in a demo from embarcadero, and from that point the communication is entirely handled, all accessible procedures are publicated, and really really simple to use...

Categories

Resources