I just committed the fixes for setting the HTTP headers, btw. Along with some other HTTP improvements. Testing/feedback appreciated!
Great!
So just pulled and updated. So on iOS
it works now, I can see that headers were modified:
Time: Tue, 01 Mar 16 10:48:08 -0800
Source ip: 89.97.90.230
Headers (Some may be inserted by server)
REQUEST_URI = /post.php?dir=swift-promise
QUERY_STRING = dir=swift-promise
REQUEST_METHOD = POST
GATEWAY_INTERFACE = CGI/1.1
REMOTE_PORT = 50620
REMOTE_ADDR = 89.97.90.230
HTTP_ACCEPT_ENCODING = gzip, deflate
HTTP_ACCEPT_LANGUAGE = it-it
CONTENT_LENGTH = 48
HTTP_USER_AGENT = mxmevents
HTTP_ACCEPT = */*
HTTP_CONNECTION = close
CONTENT_TYPE = application/x-www-form-urlencoded
HTTP_HOST = posttestserver.com
SSL_TLS_SNI = posttestserver.com
HTTPS = on
UNIQUE_ID = VtXj6EBaMGUAAAn8BjcAAAAc
REQUEST_TIME_FLOAT = 1456858088.6908
REQUEST_TIME = 1456858088
Post Params:
key: 'item' value: '{
name = track;
}'
key: 'timestamp' value: '1456858087'
Empty post body.
Upload contains PUT data:
&item={
name = track;
}×tamp=1456858087
On Android
I get a verification failed error:
03-01 19:50:11.513 21513-21900/musixmatch.com.sampleandroidapp I/art: Verification error in sugar.HttpResponse sugar.Http.ExecuteRequestSynchronous(sugar.HttpRequest)
03-01 19:50:11.514 21513-21900/musixmatch.com.sampleandroidapp I/art: sugar.HttpResponse sugar.Http.ExecuteRequestSynchronous(sugar.HttpRequest) failed to verify: sugar.HttpResponse sugar.Http.ExecuteRequestSynchronous(sugar.HttpRequest): [0x82] thrown class Precise Reference: sugar.HttpResponse not instanceof Throwable
03-01 19:50:11.520 21513-21900/musixmatch.com.sampleandroidapp W/art: Verification failed on class sugar.Http in /data/app/musixmatch.com.sampleandroidapp-2/base.apk because: Verifier rejected class sugar.Http due to bad method sugar.HttpResponse sugar.Http.ExecuteRequestSynchronous(sugar.HttpRequest)
Iām trying to check if this could be due to something else in the code, but not sure. The code was:
public func getJsonObject(var url: String, success: (response:MXMEvent?) ->(), error: (response:Exception?) ->() ) -> () {
let jsonCallback: HttpContentResponseBlock<Sugar.Json.JsonDocument!>! = { response in
if response.Success {
let jsonObject:Sugar.Json.JsonObject = response.Content.RootObject;
let rndIndex=(Sugar.Random()).NextInt();
let key="USER_"+Sugar.Convert.ToString(rndIndex,10);
let now = DateTime.UtcNow
let unixMsec = (now.Ticks - DateTime.TicksSince1970 ) / TimeSpan.TicksPerSecond;
var jsonString = "{}";
do {
jsonString = try jsonObject.ToString();
} catch error {
}
var cacheObject:MXMEvent = MXMEvent(key:key, value:jsonString, timestamp: Convert.ToString( unixMsec, 10 ) );
cacheObject.map( jsonString );
success( cacheObject );
}
else {
error(response.Exception);
}
}
let signedUrl=getSignedUrl(url);
Http.ExecuteRequestAsJson( Url(url), jsonCallback)
} //testGetJson
and the error referenced was in Http.ExecuteRequestAsJson( Url(url), jsonCallback)
Thanks, logged as bugs://74652
That verify error is weird. Iāll take a look.
@ck If it helps, this happens for every HttpRequest like:
Http.ExecuteRequestAsJson( Url(url), jsonCallback)
or Http.ExecuteRequest
, were this one this was for a HttpRequestMode.Post
.
So this:
import Sugar
let jsonCallback: HttpContentResponseBlock<Sugar.Json.JsonDocument!>! = {
response in
writeLn(response)
}
Http.ExecuteRequestAsJson( Url("http://blogname.blogspot.com/feeds/posts/default?alt=json-in-script&callback=myFunc"), jsonCallback)
writeLn("meh")
in java should have failed? Or only on Android? Seems to work on Java.
@ck It fails in Android.
Just tried this:
import java.util
import android.app
import android.content
import android.os
import android.util
import android.view
import android.widget
import Sugar
public class MainActivity: Activity {
public override func onCreate(savedInstanceState: Bundle!) {
super.onCreate(savedInstanceState)
ContentView = R.layout.main
let jsonCallback: HttpContentResponseBlock<Sugar.Json.JsonDocument!>! = {
response in
writeLn(response)
}
Http.ExecuteRequestAsJson( Url("http://blogname.blogspot.com/feeds/posts/default?alt=json-in-script&callback=myFunc"), jsonCallback)
writeLn("meh")
}
}
with:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
and a Jellybean (4.2) emulator. Works fine? (Last beta)
@ck thanks let me try to figure out whatās going on.
Im running: Fire (8.3.90.1951)
, Sugar commit e190f0243ce880db5eebaeab86f948a7aa9e5178
, testing on Nexus 7
, Android 6.0.1
.
What I see with this set up is the issue reported here: Fire Beta: Unable to run template Android Application (Swift)
so that Fire get stuck before deploy the Android Application
template to the device:
Installing org.me.androidsilversampleapp Calling adb -s 0a21584f install -r "/Users/admin/Projects/MusiXmatch/MXMPortableNETLib/Samples/AndroidSilverSampleApp/./bin/Release/AndroidSilverSampleApp.apk" The process failed to start with the following error:
Then, having no option, I try with AndroidStudio 1.5.1
, API Level 23, Marshmallow
.
Here before pulling Sugar to latest develop
commit (I presume) I get this verifier error:
03-03 14:35:07.048 24771-24732/musixmatch.com.sampleandroidapp W/art: Verification failed on class sugar.Http in /data/app/musixmatch.com.sampleandroidapp-2/base.apk because: Verifier rejected class sugar.Http due to bad method sugar.HttpResponse sugar.Http.ExecuteRequestSynchronous(sugar.HttpRequest)
Maybe, bu this is my supposition, is that those two errors are related in some way.
I donāt think the 'stcuk during deploy" is related. Can you send the exact project you used?
Let me know a fresh install, kill adb
, etc since it could be a wrong or misconfigured environment issue first. Back with the project asap.
Sorry I meant unrelated.
@ck So I have
- killed adb
- restared the mac and the device;
- installed Xamarin emulator just to be sure it was something not related to my configuration of AndroidStudio VDs;
tried now in this first test my configuration with
Xamarin Android Player
/ Nexus 7 Marshmallow
and I get the same
03-03 15:44:54.625 1706-1905/musixmatch.com.sampleandroidapp I/art: Verification error in sugar.HttpResponse sugar.Http.ExecuteRequestSynchronous(sugar.HttpRequest)
03-03 15:44:54.625 1706-1905/musixmatch.com.sampleandroidapp I/art: sugar.HttpResponse sugar.Http.ExecuteRequestSynchronous(sugar.HttpRequest) failed to verify: sugar.HttpResponse sugar.Http.ExecuteRequestSynchronous(sugar.HttpRequest): [0x82] thrown class Precise Reference: sugar.HttpResponse not instanceof Throwable
03-03 15:44:54.625 1706-1905/musixmatch.com.sampleandroidapp W/art: Verification failed on class sugar.Http in /data/app/musixmatch.com.sampleandroidapp-1/base.apk because: Verifier rejected class sugar.Http due to bad method sugar.HttpResponse sugar.Http.ExecuteRequestSynchronous(sugar.HttpRequest)
The application is here:
https://github.com/loretoparisi/swift-promise-example/tree/master/SampleAndroidApp
Doing further tests.
@ck Which was your API level?
Btw, I have found which is the issue with debugger (see Fire Beta: Unable to run template Android Application (Swift)).
Now looking at this error againā¦
@ck after 2 hours struggling with my config having
Fire
+ Android Xamarin Player
/ Nexus7 (marshmellow)
/ API Level 23
+ Sugar/Sugar.data latest commit, I was able to reproduce this error in Fire as well!
Here is a screen:
and the logcat from adb
:
03-03 17:25:55.851 2150 2150 I art : Verification error in sugar.HttpResponse sugar.Http.ExecuteRequestSynchronous(sugar.HttpRequest) 03-03 17:25:55.851 2150 2150 I art : sugar.HttpResponse sugar.Http.ExecuteRequestSynchronous(sugar.HttpRequest) failed to verify: sugar.HttpResponse sugar.Http.ExecuteRequestSynchronous(sugar.HttpRequest): [0x82] thrown class Precise Reference: sugar.HttpResponse not instanceof Throwable 03-03 17:25:55.866 2150 2150 W art : Verification failed on class sugar.Http in /data/app/org.me.androidsilversampleapp-2/base.apk because: Verifier rejected class sugar.Http due to bad method sugar.HttpResponse sugar.Http.ExecuteRequestSynchronous(sugar.HttpRequest)
while the Fire console says:
Installing org.me.androidsilversampleapp Calling adb -s 10.71.34.101:5555 install -r "/Users/admin/Projects/MusiXmatch/MXMPortableNETLib/Samples/AndroidSilverSampleApp/./bin/Debug/AndroidSilverSampleApp.apk" Started Process started. An exception of type: android.system.ErrnoException occurred and was ignored An exception of type: android.system.ErrnoException occurred and was ignored Fatal exception on thread 0003 () Type: java.lang.VerifyError Message: Verifier rejected class sugar.Http due to bad method sugar.HttpResponse sugar.Http.ExecuteRequestSynchronous(sugar.HttpRequest) (declaration of 'sugar.Http' appears in /data/app/org.me.androidsilversampleapp-2/base.apk)
Iām not sure if I can get more stack trace from hereā¦
I donāt see org.me.androidsilversampleapp on https://github.com/loretoparisi/swift-promise-example ?
Yes I have two projects but basically the code itās the same
So I rebuild sugar.data, opened SampleAndroidAppFire,
fixed the projitems reference (which was hardcoded),
fixed the sugar reference,
ran a matching android virtual machine.
Ran the android app.
Noticed the security exception and added:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Then I finally got an:
-
error {java.lang.ClassCastException: java.lang.Object[] cannot be cast to java.lang.String[]} java.lang.Exception
and the other one.
Just pull latest sugar and itās fixed.
bugs://74652 got closed with status fixed.
@ck I confirm that both bug have been fixed, closing!