Re: [android-developers] Run http server in android

2013-07-01 Thread jrichards1...@googlemail.com
Edit. sorry that wont work. i get stuck on the proxy part. 

i get the folllowing error in the proxy code


*07-01 15:44:02.894: E/GAEProxy.ProxySettings(11267): error setting up 
webkit proxying = java.lang.RuntimeException: Can't create handler inside 
thread that has not called Looper.prepare()*

it happens when i call setProxy.

any suggestions?

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [android-developers] Run http server in android

2013-07-01 Thread jrichards1...@googlemail.com
ok i will try that

On Monday, July 1, 2013 1:28:15 PM UTC+1, Andrew Brampton wrote:
>
> I adapted Nanohttpd to work on Android: https://github.com/bramp/NanoHTTPd 
> you 
> can easily adapt that to make it a proxy.
>
>
> On 1 July 2013 04:15, jricha...@googlemail.com  <
> jricha...@gmail.com > wrote:
>
>> anyone? 
>>
>> -- 
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to 
>> android-d...@googlegroups.com
>> To unsubscribe from this group, send email to
>> android-developers+unsubscr...@googlegroups.com 
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "Android Developers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to android-developers+unsubscr...@googlegroups.com .
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [android-developers] Run http server in android

2013-07-01 Thread Andrew Brampton
I adapted Nanohttpd to work on Android: https://github.com/bramp/NanoHTTPd you
can easily adapt that to make it a proxy.


On 1 July 2013 04:15, jrichards1...@googlemail.com
wrote:

> anyone?
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Android Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to android-developers+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [android-developers] Run http server in android

2013-07-01 Thread jrichards1...@googlemail.com
anyone?

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [android-developers] Run http server in android

2013-06-28 Thread jrichards1...@googlemail.com
i have setup my webview's proxy using this snippet of code below:

   * ProxySettings.setProxy(mContext, "http://127.0.0.1";, PORT);*

Here is my socket server listener


*serverSocket = new ServerSocket(PORT);*
*thread = new Thread(runnable, this.getClass().getSimpleName());*
**
**
*public void startlistener() {*
*listening = true;*
*thread.start();*
**
*}*
**
*private Runnable runnable = new Runnable() {*
**
*@Override*
*public void run() {*
*while (listening) {*
*try {*
*Socket accept = serverSocket.accept();*
**
*String data = getData(accept);*
**
*httpHandler.handleRequest(data);*
**
*} catch (IOException e) {*
*// TODO Auto-generated catch block*
*e.printStackTrace();*
*}*
*}*
**
*}*
*};*

i have put a breakpoint on String data = getData(accept); and it never hits 
it

Below is the proxy class taken from https://gist.github.com/madeye/2297083 

   * public class ProxySettings {*
**
*private static final String TAG = "GAEProxy.ProxySettings";*
**
*static final int PROXY_CHANGED = 193;*
**
*private static Object getDeclaredField(Object obj, String name)*
*throws SecurityException, NoSuchFieldException,*
*IllegalArgumentException, IllegalAccessException {*
*Field f = obj.getClass().getDeclaredField(name);*
*f.setAccessible(true);*
*Object out = f.get(obj);*
*// System.out.println(obj.getClass().getName() + "." + name + " = "+*
*// out);*
*return out;*
*}*
**
*public static Object getRequestQueue(Context ctx) throws Exception {*
*Object ret = null;*
*Class networkClass = Class.forName("android.webkit.Network");*
*if (networkClass != null) {*
*Object networkObj = invokeMethod(networkClass, "getInstance",*
*new Object[] { ctx }, Context.class);*
*if (networkObj != null) {*
*ret = getDeclaredField(networkObj, "mRequestQueue");*
*}*
*}*
*return ret;*
*}*
**
*private static Object invokeMethod(Object object, String methodName,*
*Object[] params, Class... types) throws Exception {*
*Object out = null;*
*Class c = object instanceof Class ? (Class) object : object.getClass();
*
*if (types != null) {*
*Method method = c.getMethod(methodName, types);*
*out = method.invoke(object, params);*
*} else {*
*Method method = c.getMethod(methodName);*
*out = method.invoke(object);*
*}*
*// System.out.println(object.getClass().getName() + "." + methodName +*
*// "() = "+ out);*
*return out;*
*}*
**
*public static void resetProxy(Context ctx) throws Exception {*
*Object requestQueueObject = getRequestQueue(ctx);*
*if (requestQueueObject != null) {*
*setDeclaredField(requestQueueObject, "mProxyHost", null);*
*}*
*}*
**
*private static void setDeclaredField(Object obj, String name, Object 
value)*
*throws SecurityException, NoSuchFieldException,*
*IllegalArgumentException, IllegalAccessException {*
*Field f = obj.getClass().getDeclaredField(name);*
*f.setAccessible(true);*
*f.set(obj, value);*
*}*
**
*/***
* * Override WebKit Proxy settings*
* * *
* * @param ctx*
* *Android ApplicationContext*
* * @param host*
* * @param port*
* * @return true if Proxy was successfully set*
* */*
*public static boolean setProxy(Context ctx, String host, int port) {*
*boolean ret = false;*
*setSystemProperties(host, port);*
**
*try {*
*if (Build.VERSION.SDK_INT < 14) {*
**
*Object requestQueueObject = getRequestQueue(ctx);*
*if (requestQueueObject != null) {*
*// Create Proxy config object and set it into request Q*
*HttpHost httpHost = new HttpHost(host, port, "http");*
**
*setDeclaredField(requestQueueObject, "mProxyHost", httpHost);*
*ret = true;*
*}*
**
*} else {*
*ret = setICSProxy(host, port);*
*}*
*} catch (Exception e) {*
*Log.e(TAG, "error setting up webkit proxying", e);*
*}*
*return ret;*
*}*
**
*private static boolean setICSProxy(String host, int port)*
*throws ClassNotFoundException, NoSuchMethodException,*
*IllegalArgumentException, InstantiationException,*
*IllegalAccessException, InvocationTargetException {*
*Class webViewCoreClass = Class.forName("android.webkit.WebViewCore");*
*Class proxyPropertiesClass = Class*
*.forName("android.net.ProxyProperties");*
*if (webViewCoreClass != null && proxyPropertiesClass != null) {*
*Method m = webViewCoreClass.getDeclaredMethod("sendStaticMessage",*
*Integer.TYPE, Object.class);*
*Constructor c = proxyPropertiesClass.getConstructor(String.class,*
*Integer.TYPE, String.class);*
*m.setAccessible(true);*
*c.setAccessible(true);*
*Object properties = c.newInstance(host, port, null);*
*m.invoke(null, PROXY_CHANGED, properties);*
*  

Re: [android-developers] Run http server in android

2013-06-28 Thread Michael Banzon
It is quite possible - but:

Another alternative is to set up a local wireless network containing a
proxy - this can by done by most laptops/desktops with wireless
networking and the right software. By doing this you can connect
through the proxy running on the computer and debug communication in a
bit more (IMHO) convenient way.

On Fri, Jun 28, 2013 at 1:22 PM, jrichards1...@googlemail.com
 wrote:
> Hi all.
>
> is it possible to create a mini HTTP server that acts as a proxy where i can
> recieve any requests from a webview and it will pass that request to my http
> proxy server running inside the app that can then view the raw contents of
> that request(http headers, bodies etc) and handle it from my own proxy?
>
> I can see that the apahce libraries only contain objects that allow you to
> create requests and handle responses but not how i can create a mini http
> server.
>
> Thanks
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Android Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to android-developers+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



-- 
Michael Banzon
http://michaelbanzon.com/

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.