orhanobut / wasp Goto Github PK
View Code? Open in Web Editor NEWCompact and easy to use, 'all-in-one' android network solution
License: Apache License 2.0
Compact and easy to use, 'all-in-one' android network solution
License: Apache License 2.0
Currently we parse the object in the main thread, we should do it in the worker thread, better to let the networkstack handle it and return back to the callback.
I should be able to add an XML parser.
When mock json is incorrect or has error library dont catch gson exception so dont call Callback onError method. We can see excepiton from logcat but it must call also onError
at com.google.gson.Gson.fromJson(Gson.java:815)
at com.google.gson.Gson.fromJson(Gson.java:770)
at com.google.gson.Gson.fromJson(Gson.java:719)
at com.orhanobut.wasp.parsers.GsonParser.fromBody(GsonParser.java:32)
at com.orhanobut.wasp.MockNetworkStack.invokeRequest(MockNetworkStack.java:53)
at com.orhanobut.wasp.NetworkHandler.invoke(NetworkHandler.java:116)
While fast-scrolling, because of the recycling requests are cancelled if the view is out of the screen. But if the new request is already same with the new one, there is no need to create a new request and fire it.
We need to add disk cache for the image caching
Excuse me,I'm from China,I have never before use Gradle and I have been using Eclipse develop Android applications,so I always import the jar file to my application,this wasp I'm download the source code and compile it,but it's very diffcult to me, because I must download and complie with volley,okhttp,okIo and so on,so I want to ask if have any way to use wasp easiler in eclipse or with out Gradle,e.g. is there a comlied jar file to import,Thank you!
Currently we use our implementation for cache in order to learn better. We should improve this class as much as possible with the new ideas. Please put your idea here and let's discuss before implementing.
We should accept Map<T,T> and convert it to String in behind.
Hi,
this is my request log :
Wasp﹕ ---> REQUEST GET http://myserver.com/api/Get
Wasp﹕ Header - [basic: test]
Wasp﹕ Body - no body
Wasp﹕ ---> END
Wasp﹕ ---> REQUEST GET http://myserver.com/api/Get
Wasp﹕ Header - [Accept-Encoding: gzip]
Wasp﹕ Header - [basic: test]
Wasp﹕ Header - [Connection: Keep-Alive]
Wasp﹕ Header - [Host: myserver.com]
Wasp﹕ Header - [User-Agent: okhttp/2.2.0]
Wasp﹕ Body - no body
Wasp﹕ ---> END
Wasp﹕ <--- RESPONSE 401 http://myserver.com/api/Get
Wasp﹕ Header - [Cache-Control: no-cache]
Wasp﹕ Header - [Content-Length: 85]
Wasp﹕ Header - [Content-Type: text/plain; charset=utf-8]
Wasp﹕ Header - [Date: Mon, 18 May 2015 09:50:38 GMT]
Wasp﹕ Header - [Expires: -1]
Wasp﹕ Header - [OkHttp-Received-Millis: 1431942628563]
Wasp﹕ Header - [OkHttp-Selected-Protocol: http/1.1]
Wasp﹕ Header - [OkHttp-Sent-Millis: 1431942628400]
Wasp﹕ Header - [Pragma: no-cache]
Wasp﹕ Header - [Server: Microsoft-IIS/7.5]
Wasp﹕ Header - [WWW-Authenticate: Negotiate]
Wasp﹕ Body - There has been an error. try again BODY !!!
Wasp﹕ <--- END (Size: 85 bytes - Network time: 164.154053 ms)
Volley﹕ [2241] BasicNetwork.performRequest: Unexpected response code 401 for http://myserver.com/api/Get
Wasp﹕ <--- ERROR
Wasp﹕ Message - [null]
Wasp﹕ <--- RESPONSE 0 http://myserver.com/api/Get
Wasp﹕ Body - no body
Wasp﹕ <--- END (Size: 0 bytes - Network time: 9386 ms)
Why in callback body is null but it should be : There has been an error. try again BODY !!!
@Override
public void onError(WaspError waspError) {
Log.e("TAG", "test: "+ waspError.getErrorMessage());
Log.e("TAG", "test: "+ waspError.getRespone().getBody());
Log.e("TAG", "test: "+ waspError.getRespone().getStatusCode());
}
Wasp.Image.from
should accept multiple urls and they all should load with the given order. This feature would allow to load the first very low resolution then the next high resolution.
We need a solution to load images into target, which may be used for textview compounds instead of imageview.
Can you consider this feature?
Should convert to pure Java instead of com.android.library
Java library advantages:
Android logger's max entry length is limited with ~4076 bytes. So, we should add this feature to be able to see whole request/response when the length is longer than the max limit.
We need to check the context usage in the wasp, we just need applicationContext.
OkHttp has added its own interceptors. https://github.com/square/okhttp/wiki/Interceptors
These currently don't work with url connection (Volley), but can be implemented.
OkHttp interceptors give more power both in terms of logging and request management.
I need to get WaspResponse of WaspError in onError cases for example to check status code of response.
is this possible to have a gradle setup for us?
We should discuss the implementation here. Poor implementation may cause harm and make negative effect
When loading an image which requires cookie(s) used in service requests, WaspImage does not send any cookie since it uses its own WaspHttpStack.
There is currently no way to do a normal form POST. The @field annotation from retrofit is missing in this library
I think we should simplify requestInterceptor. Currently methods must be overriden but we can do that with only one method overriding which contains the requestinterceptor and interceptor can add headers/auth/queryparams
Client should be able to cancel the specific request or requests in a very easy way. We should really discuss about this carefully.
Please consider following items for the suggestions:
The response object created by MockFactory should have a response object set.
WaspResponse waspResponse = new WaspResponse.Builder()
.setUrl(waspRequest.getUrl())
.setStatusCode(statusCode)
.setHeaders(Collections.<String, String>emptyMap())
.setBody(responseString)
.setLength(responseString.length())
.setNetworkTime(0)
.setResponseObject(object) // <-- This is missing.
.build();
There should be a method for getting response body. Moreover, it would be good if WaspError could provide a method which will get a type and return an instance of that type created from response body.
Query parameter has an space character. So I got this error:
Wasp Error: , Message:java.io.IOException: Illegal character in query at index 75:
can you add a callback when the request is beginning to start.
We should introduce File class in order to upload/download big files. This can stay for now but in the future we should think and discuss about it.
Wasp.File
I add some logs in WaspImageHandler.java like,
final String cacheKey = StringUtils.getCacheKey(url, maxWidth, maxHeight);
final Bitmap bitmap = imageCache.getBitmap(cacheKey);
if (bitmap != null) {
imageView.setImageBitmap(bitmap);
Log.d("wasp","cache image : " + url);
return;
} else {
Log.d("wasp","no use cache image : " + url);
}
the print log is,
03-20 23:12:28.068 22170-22170/com.orhanobut.waspsample D/wasp﹕ no use cache image : http://static.cnbetacdn.com/article/2015/0320/3e5026c844185c5.jpg
03-20 23:12:28.068 22170-22170/com.orhanobut.waspsample D/jiayh2﹕ LaunchIconThemeResourcegetDrawable packageName:com.orhanobut.waspsample asetfile:null
03-20 23:12:28.068 22170-22170/com.orhanobut.waspsample D/wasp﹕ no use cache image : http://static.cnbetacdn.com/article/2015/0320/3e5026c844185c5.jpg
Wasp should support RxJava
It seems that chunking does not show some part of the long texts.
Client should be able to select the mode such as Mode.MOCK etc. We need this feature in order to select the mocking or the real implementation. Deleting each mock annotation would take time and add them back will be frustrating.
I suggest the following implementation:
setMode()
Mode.MOCK, Mode.LIVE.
Can you add Example, Demo or Tutorial for AuthToken.
Images should be loaded from the disk as well. We need to consider the implementation.
Image.from() should accept local path and load the image.
Hey all,
I have two activities (activity_main and activity_test) in my Android App (just a test application). Each of them has a button. If this will be clicked a login request will be sent over wasp to my server and then the other activity will be opened. When I start another app and then going back to the test App, I get this exception: java.io.InterruptedIOException: timeout after sending several requests again. If you wait about 10 seconds you can send request without the error (exception).
Here the full log, the first request is successful but the other ones throwing the InterruptedIOException:
07-07 08:14:50.129 25489-25489/com.example.root.wasptest D/Wasp﹕ ---> REQUEST POST https://h2211501.stratoserver.net/bachelor_webservice/resources/session/login
07-07 08:14:50.129 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [Content-Type: application/json]
07-07 08:14:50.133 25489-25489/com.example.root.wasptest D/Wasp﹕ Body - {"email":"[email protected]","password":"test12"}
07-07 08:14:50.133 25489-25489/com.example.root.wasptest D/Wasp﹕ ---> END
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ <--- RESPONSE 200 https://h2211501.stratoserver.net/bachelor_webservice/resources/session/login
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [Access-Control-Allow-Credentials: true]
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [Access-Control-Allow-Headers: auth_token, main_category_id, Content-Type]
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [Access-Control-Allow-Methods: GET, POST, DELETE, PUT]
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [Access-Control-Allow-Origin: *]
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [Cache-Control: no-cache, no-transform, must-revalidate]
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [Connection: keep-alive]
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [Content-Length: 53]
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [Content-Type: application/json]
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [Date: Tue, 07 Jul 2015 08:14:50 GMT]
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [OkHttp-Received-Millis: 1436256890275]
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [OkHttp-Selected-Protocol: http/1.1]
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [OkHttp-Sent-Millis: 1436256890141]
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [Server: nginx/1.4.6 (Ubuntu)]
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ Body - {"auth_token":"e245bd5c-f102-4f91-8cd0-97c96c8581b7"}
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Wasp﹕ <--- END (Size: 53 bytes - Network time: 139 ms)
07-07 08:14:50.273 25489-25489/com.example.root.wasptest D/Login﹕ e245bd5c-f102-4f91-8cd0-97c96c8581b7
07-07 08:14:50.345 25489-25489/com.example.root.wasptest W/EGL_genymotion﹕ eglSurfaceAttrib not implemented
07-07 08:14:50.913 25489-25489/com.example.root.wasptest D/Wasp﹕ ---> REQUEST POST https://h2211501.stratoserver.net/bachelor_webservice/resources/session/login
07-07 08:14:50.913 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [Content-Type: application/json]
07-07 08:14:50.913 25489-25489/com.example.root.wasptest D/Wasp﹕ Body - {"email":"[email protected]","password":"test12"}
07-07 08:14:50.913 25489-25489/com.example.root.wasptest D/Wasp﹕ ---> END
07-07 08:14:52.493 25489-25489/com.example.root.wasptest D/Wasp﹕ ---> REQUEST POST https://h2211501.stratoserver.net/bachelor_webservice/resources/session/login
07-07 08:14:52.493 25489-25489/com.example.root.wasptest D/Wasp﹕ Header - [Content-Type: application/json]
07-07 08:14:52.493 25489-25489/com.example.root.wasptest D/Wasp﹕ Body - {"email":"[email protected]","password":"test12"}
07-07 08:14:52.493 25489-25489/com.example.root.wasptest D/Wasp﹕ ---> END
07-07 08:14:53.421 25489-25489/com.example.root.wasptest D/Wasp﹕ <--- ERROR
07-07 08:14:53.421 25489-25489/com.example.root.wasptest D/Wasp﹕ Message - [java.io.InterruptedIOException: timeout]
07-07 08:14:53.421 25489-25489/com.example.root.wasptest D/Wasp﹕ <--- RESPONSE 0 https://h2211501.stratoserver.net/bachelor_webservice/resources/session/login
07-07 08:14:53.421 25489-25489/com.example.root.wasptest D/Wasp﹕ Body - no body
07-07 08:14:53.421 25489-25489/com.example.root.wasptest D/Wasp﹕ <--- END (Size: 0 bytes - Network time: 5778 ms)
07-07 08:14:53.421 25489-25489/com.example.root.wasptest E/Login﹕ java.io.InterruptedIOException: timeout
07-07 08:14:55.993 25489-25489/com.example.root.wasptest D/Wasp﹕ <--- ERROR
07-07 08:14:55.993 25489-25489/com.example.root.wasptest D/Wasp﹕ Message - [java.io.InterruptedIOException: timeout]
07-07 08:14:55.993 25489-25489/com.example.root.wasptest D/Wasp﹕ <--- RESPONSE 0 https://h2211501.stratoserver.net/bachelor_webservice/resources/session/login
07-07 08:14:55.993 25489-25489/com.example.root.wasptest D/Wasp﹕ Body - no body
07-07 08:14:55.993 25489-25489/com.example.root.wasptest D/Wasp﹕ <--- END (Size: 0 bytes - Network time: 7382 ms)
Here is my source code. Did I do something wrong or is it a bug?
In the following I show just the MainActivity because the other one (TestActitvity) is exactly the same except that the MainActivity will be started.
WaspApplication.java
public class WaspApplication extends Application {
private static WaspService service;
public static WaspService getService(){
return service;
}
@Override
public void onCreate() {
super.onCreate();
service = new Wasp.Builder(this)
.setEndpoint("https://h2211501.stratoserver.net/bachelor_webservice/resources")
.setLogLevel(LogLevel.FULL)
.trustCertificates()
.build()
.create(WaspService.class);
}
}
WaspService.java
public interface WaspService {
//---Static header
@Headers("Content-Type:application/json")
@POST("/session/login")
WaspRequest login(
@Body LoginData loginData,
Callback<LoginResponse> callBack
);
}
MainActivity.java
public class MainActivity extends AppCompatActivity {
private final RequestManager requestManager = new SimpleRequestManager();
private final WaspService service = WaspApplication.getService();
private LoginData loginData;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loginData = new LoginData();
loginData.setEmail("[email protected]");
loginData.setPassword("test12");
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
WaspRequest request = service.login(loginData, callbackLogin);
requestManager.addRequest(request);
}
});
}
...
...
private final Callback<LoginResponse> callbackLogin = new Callback<LoginResponse>() {
@Override
public void onSuccess(Response response, LoginResponse loginResponse) {
Log.d("Login", loginResponse.getToken());
startTestActivity();
}
@Override
public void onError(WaspError waspError) {
Log.e("Login", waspError.getErrorMessage());
}
};
private void startTestActivity(){
startActivity(new Intent(this, TestActivity.class));
finish();
}
}
For example, when TimeoutError occurs we could not know the exception is due to time out because all we get from Wasp is a WaspError with status code 0 and null message.
Interceptor empties body of request during logging. Original body must be kept and sent to the network.
It will be useful to have information about license. :)
I have many images in recyclerview. If scrolls to bottom fastly when the application is opened, imageview shows wrong image while actual image is loading. Generally it shows image loaded in previous imageview. When the actual image is loaded, it shows correct image. But it's bad.
A loading spinner should be shown while image is loading.
It would be good if we can pass a callback to load method of WaspImage.
If I have two services when creating the second one it will call again VolleyNetworkStack.newInstance which will call the constructor again and because requestQueue is static it will override the previous one.
So for exemple if in my first service i need to trust a specific certificate, i will not be able to connect to my web service anymore.
I think it should be something like this :
private RequestQueue requestQueue;
private VolleyNetworkStack(Context context, WaspHttpStack stack) {
requestQueue = Volley.newRequestQueue(context, (HttpStack) stack.getHttpStack());
}
static VolleyNetworkStack newInstance(Context context, WaspHttpStack stack) {
return new VolleyNetworkStack(context, stack);
}
RequestQueue getRequestQueue() {
if (requestQueue == null) {
throw new NullPointerException("Wasp.Builder must be called");
}
return requestQueue;
}
Hey guys,
I use the wasp framework for the first time and I wanted to check out the wiki that you mention in your README.md (url = http://orhanobut.github.io/wasp/). But this page is offline, is their another url for the wiki page?
java.lang.ClassCastException: com.orhanobut.wasp.WaspOkHttpStack cannot be cast to com.android.volley.toolbox.HttpStack
at com.orhanobut.wasp.VolleyImageNetworkHandler.(VolleyImageNetworkHandler.java:28)
this.requestQueue = Volley.newRequestQueue(context, (HttpStack) httpStack);
should become
this.requestQueue = Volley.newRequestQueue(context, httpStack.getHttpStack());
?
We need to implement fit() method by considering the memory performance etc.
As the title says, we should also discuss about the implementation here.
Null check must be added for "body.contentType()" in "OkHttpStack.entityFromOkHttpResponse" method.
MockFactory has JSON de-serialise methods. Parser can be used instead.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.