Giter Site home page Giter Site logo

Comments (10)

GoogleCodeExporter avatar GoogleCodeExporter commented on July 19, 2024
I don't see the need except with proxied requests for this ones :
urlConnection.setRequestProperty("Content-Type", "text/plain");
urlConnection.setRequestProperty("Accept-Encoding", "identity");

Original comment by [email protected] on 5 Apr 2013 at 6:43

from webiopi.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 19, 2024
When establishing a connection with my Android App to Webiopi from External 
using a OpenVPN Connection via GSM or 3G I got timeout exceptions from the 
HTTP/Socket layer. It looks that in this case the time needed to connect and 
sometimes read the sockets through the VPN tunnel is too long for the default 
values of Android.

Adding the possibility to set the Timeout parameters and using appropriate 
values solved the problem. Thats the reason why I added the possibility to set 
the timeout values for the UrlConnection. In my app these values are then set 
via preferences to allow fine-tuning when needed.

The extended response handling allows me to deal with errors and manage the 
response switching between plain text and JSON.

Original comment by [email protected] on 7 Apr 2013 at 2:33

from webiopi.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 19, 2024
no problem about timeout, totally understand.
I asked about HTTP request headers Content-Type and Accept-Encoding

Original comment by [email protected] on 7 Apr 2013 at 2:59

from webiopi.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 19, 2024
Concerning ("Accept-Encoding", "identity"):

This a excerpt from the description of java.net HttpURLConnection:

>>>>>
By default, this implementation of HttpURLConnection requests that servers use 
gzip compression. Since getContentLength() returns the number of bytes 
transmitted, you cannot use that method to predict how many bytes can be read 
from getInputStream(). Instead, read that stream until it is exhausted: when 
read() returns -1. Gzip compression can be disabled by setting the acceptable 
encodings in the request header: 

   urlConnection.setRequestProperty("Accept-Encoding", "identity");
<<<<<

As I was not sure if the Python BaseHttpServer handles gzip handling correct 
(or at all) I wanted to avoid this problem by just disabling it. As in most 
cases the amount of data exchanged via webiopi rest calls is very small gzip 
compression may just be an overhead.


Concerning ("Content-Type", "text/plain"):

I encountered some http response errors
when doing POST calls which do not POST content in the case of webiopi rest 
calls. Looks like some HTTP servers either need a POSTed content to try 
auto-discovery of the posted content or a Request-Header set appropriately so 
that auto-discovery is unnecessary. Seemed that if there is no content and no 
content-type request header they have a potential problem with this POST call. 
But I cannot remember exactly which kind of HTTP server it was at the time I 
tested it, maybe it was the NanoHTTPD for Java which I also used for testing 
some times and not the webiopi Python server.

So just keep this one as a backed-up possible solution if anyone else may 
encounter this kind of problem.

Andreas

Original comment by [email protected] on 8 Apr 2013 at 11:19

from webiopi.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 19, 2024
Ok I see the problem with gzip and need for Accept-Encoding header.
For the content-type one, this is certainly due to NanoHTTPD POST handling like 
you say.
I will certainly check this and make changes this week.

Original comment by [email protected] on 8 Apr 2013 at 6:41

  • Changed state: Accepted

from webiopi.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 19, 2024
Eric,

in the last days I read much details about Hadoop components family and its 
Java implementation (has nothing to do with my Raspi work). Looking how Hadoop 
is implemented I came across the way its configured at runtime. Aside other 
things it uses a Configuration class that allows dynamic configuration at 
runtime of many things. I found this an interesting approach that may also be 
of value for the Java Webiopi client package.

The way would be:

- define a Configuration Class thats instantiated with default values inside 
its constructor.
- When creating a PiClient it creates its own default configuration object or 
uses a configuration instance thats created somewhere else and provided to the 
constructor
- First use would be to create a configuration object with specific settings 
from Java code directly just before creating the PiClients
- Later you could add a subclass or methods to instantiate (and serialize back) 
the configuration object from external sources like config-files, XML-Files, 
JSON structures, jvm command-line arguments or whatever may make sense
- Maybe the PiClient can even be re-configured by setting a new configuration 
at runtime

Later within a Webiopi Android client app framework package a subclass could be 
added to read settings from a set of predefined (by pref keys) Android 
preferences.

Andreas

Original comment by [email protected] on 10 Apr 2013 at 8:25

from webiopi.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 19, 2024
As additional information these are the classes I mean:

http://hadoop.apache.org/docs/current/api/org/apache/hadoop/conf/Configuration.h
tml
http://hadoop.apache.org/docs/current/api/org/apache/hadoop/mapred/JobConf.html

To start, just some methods would be sufficient like

public void setInt(String name,int value)
public void set(String name, String value)
public String get(String name, String defaultValue)
public int getInt(String name, int defaultValue)

The first arguments are the parameter identifiers. According to the examples in 
class JobConf they could be like

webiopi.http.connecttimeout
webiopi.http.readtimeout
webiopi.coap.port

Usage would be 

...
PiConf conf = new PiConf();
conf.setInt("webiopi.http.port", 8000);
conf.set("webiopi.http.user", "webiopi");
...
PiClient client = new PiClient(conf);
...

PiConf could then have additional methods to read/write to formats like XML, 
webiopi config, JSON etc.

And for Android I could provide a subclass that reads/writes from Android 
Preferences. Nicely the keys of the Preferences could be the same as the 
parameter names above.

Andreas


Original comment by [email protected] on 19 Apr 2013 at 9:47

from webiopi.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 19, 2024

Original comment by [email protected] on 4 Jan 2014 at 9:00

  • Added labels: Priority-High
  • Removed labels: Priority-Medium

from webiopi.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 19, 2024

Original comment by [email protected] on 4 Jan 2014 at 9:01

from webiopi.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 19, 2024

Original comment by [email protected] on 28 Jan 2014 at 9:13

  • Added labels: Priority-Medium
  • Removed labels: Priority-High

from webiopi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.