HTTPService request via proxy

April 29, 2012

I am working on this side project in Flex that I need to use PHP and curl (code is very similar to this) to delegate my http calls to some RESTful services. While I debug it from Flash Builder IDE, everything works fine; but when I put my release build to the server, I get the following errors:

[RPC Fault faultString="HTTP request error" faultCode="Server.Error.Request" faultDetail="Error: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: Stream Error. URL: http://localhost:37813/views/INLINE/rows.json?accessType=API&method=clustered2&min_lon=-89.761262&min_lat=41.700473&max_lon=-85.806184&max_lat=42.294452&target_node_clusters=250&min_distance_between_clusters=0.005188813084372479&https=Y%5D. URL: https://data.cityofchicago.org/views/INLINE/rows.json?accessType=API&method=clustered2&min_lon=-89.761262&min_lat=41.700473&max_lon=-85.806184&max_lat=42.294452&target_node_clusters=250&min_distance_between_clusters=0.005188813084372479"]
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::faultHandler()[E:\dev\4.y\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:345]
at mx.rpc::Responder/fault()[E:\dev\4.y\frameworks\projects\rpc\src\mx\rpc\Responder.as:68]
at mx.rpc::AsyncRequest/fault()[E:\dev\4.y\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:113]
at DirectHTTPMessageResponder/errorHandler()[E:\dev\4.y\frameworks\projects\rpc\src\mx\messaging\channels\DirectHTTPChannel.as:410]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()

To debug, I went back from the very beginning and tested my DAO interfaces one method after another until I nailed down to the following error. The reason is that requests through an HTTPService through the aforementioned proxy with its headers property specified will trigger the following sandbox violation (Flash Player 11.2.202).

myHTTP.headers = {Accept: "application/json"};
or
var header:Object=new Object();
header["Accept"] = "application/json";
myHTTP.headers = header;

[RPC Fault faultString="Security error accessing url" faultCode="Channel.Security.Error" faultDetail="Destination: DefaultHTTP"]
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::faultHandler()[E:\dev\4.y\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:345]
at mx.rpc::Responder/fault()[E:\dev\4.y\frameworks\projects\rpc\src\mx\rpc\Responder.as:68]
at mx.rpc::AsyncRequest/fault()[E:\dev\4.y\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:113]
at DirectHTTPMessageResponder/securityErrorHandler()[E:\dev\4.y\frameworks\projects\rpc\src\mx\messaging\channels\DirectHTTPChannel.as:437]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/redirectEvent()

As my proxy already specifies the headers of my calls (‘Accept: application/json’,  ‘Content-type: application/json’,  “X-App-Token:XXXxxxxXX”), there doesn’t seem a need to specify this headers property for any HTTPService used in Flex at all.

Java bitwise operators

December 25, 2011

This is a code snippet found in android.widget.AutoCompleteTextView class:

        // Always turn on the auto complete input type flag, since it
        // makes no sense to use this widget without it.
        int inputType = getInputType();
        if ((inputType&EditorInfo.TYPE_MASK_CLASS)
                == EditorInfo.TYPE_CLASS_TEXT) {
            inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE;
            setRawInputType(inputType);
        }

Here is what I found out: Java Notes: Bitwise Operators

System.out.println("3 & 7 = "+(3 & 7));//3
System.out.println("2 & 4 = "+(2 & 4));//0
System.out.println("2 & 5 = "+(2 & 5));//0
System.out.println("1 & 2 = "+(1 & 2));//0
System.out.println("1 & 0 = "+(1 & 0));//0

System.out.println("3 | 7 = "+(3 | 7));//7
System.out.println("2 | 4 = "+(2 | 4));//6
System.out.println("2 | 5 = "+(2 | 5));//7
System.out.println("1 | 2 = "+(1 | 2));//3
System.out.println("1 | 0 = "+(1 | 0));//1

Root Nexus One 2.3.6

December 17, 2011

Used this “DooMLoRD Easy Rooting Toolkit v3.0 (using zergRush exploit)” (Windows) and rooted my phone in less than 3 minutes. Also downloaded this  ROM Toolbox .

In the future if I find more time and energy, I may play around with some custom ROMs like CyanogenMod. I would probably be most interested in  getting them running on an emulator; It would be nice if someone put the compiled system.img files somewhere so that I don’t need to build from the source;).

Facebook for Android API 101

December 11, 2011

This morning I got to sit down and had a jump start on my first Facebook/mobile adventure! It seems I was able to follow through most part of their documentation (Android Tutorial and Graph API).

When I tried to get my app signature (Android key hash) using the java keytool, my Windows XP said it couldn’t find openssl command. I had to download both Visual C++ 2008 Redistributables and Win32 OpenSSL v1.0.0e from here.

I wasn’t able to save/get the access token from the preference file and I had to manually set the access token in the app. I got the token from the Graph API Explorer.

Escaping Angle Brackets in XML in Android

November 20, 2011

Either specify those characters like this:

< = &lt; > = &gt; 

Or use a CDATA section and put those characters inside:

<![CDATA[<]]> <![CDATA[>]]>

Here.

Accessing resources in Android

November 20, 2011

In most cases, you need to get hold of the Context object in order to access the resources in the app (the local package). Because Activity extends Context, you can get all the resources accessible from an instance of Context. For example:

Context.getResources().getString(R.string.resName);

or simply

Context.getString(R.string.resName);

If you want to access the resources in the local package from an object that doesn’t inherit from Context, you need to pass the context object to it somehow. On the other hand, you can access the resources provided by the system (Android) without any context object:

final Resources r = Resources.getSystem();
r.getString(android.R.string.untitled);

Here.

So color in KML is in aaBBGGRR!

September 20, 2011

not in aaRRGGBB as you normally expect:

<color>ffFFFF00</color> is cyan

<color>ffff00ff</color> is pink

Android: Sqlite long to datetime

August 21, 2011

If you store time using android.text.format.Time.toMillis, it will end up in the sqlite as a 13 chars “text/numeric”, something like “1311123600000″. You can do the following to make them human readable:

SELECT datetime(start/1000, 'unixepoch') as start, datetime(end/1000, 'unixepoch') as end from countdowns

//output: 2011-07-20 01:00:00 (I think this means 12:00 AM but I am not sure)

Android AppWidget 101

May 23, 2011

0. To create an appWidget, you would need 4 things: in your application manifest xml, declare the appWidget Provider (in a <receiver> tag, see code below);  a layout xml for your remote views (in “res/layout”); an app widget provider xml (in “res/xml” with an <appwidget-provider> tag); and optionally implementing AppWidgetProvider for the logic in your app.

<receiver android:name=".TestAppWidgetProvider" android:enabled="true">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>
<meta-data android:resource="@xml/widget" android:name="android.appwidget.provider"></meta-data>
</receiver>

1. You can explicitly update the appWidgets using AppWidgetManager and not rely on the timer mechanism. This means your app can register with all kinds of listeners and update your appWidgets based on the corresponding events when they occur:

final AppWidgetManager gm = AppWidgetManager.getInstance(context);
gm.updateAppWidget( new ComponentName("com.maohao.android.myappnamespace",
"com.maohao.android.myappnamespace.MyAppWidgetProvider"), views);

2. Each time a new appWidget is added to the home screen,

AppWidgetProvider.onReceive > onUpdate

also get called; each time an appWidget is deleted from the home screen,

onReceive > onDelete

get called.

When the first appWidget is added to home,

onReceive > onEnabled > onReceive > onUpdate

anddroid.appWidget.action.APPWIDGET_ENABLED is the onReceived intent action;

When the last appWidget is removed from home,

 onReceive - onDeleted > onReceive - onDisabled

anddroid.appWidget.action.APPWIDGET_DELETED for onDeleted and anddroid.appWidget.action.APPWIDGET_DISABLED for onDeleted get called.

You don’t seem to explicitly declare in your manifest xml for your appWidgetProvider to receive APPWIDGET_DELETED/APPWIDGET_DISABLED actions but you need to declare an intent filter for ACTION_APPWIDGET_UPDATE action.

Run extra DOS commands before and after build in VS2001

April 6, 2011

Gotcha! Visual Studio Pre/Post-Build Events


Follow

Get every new post delivered to your Inbox.