bjithinb / hessdroid

Automatically exported from code.google.com/p/hessdroid
0 stars 0 forks source link

how to reuse Proxy Interface? #4

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hello

ActivityManager gives a warning: 
"Launch timeout has expired, giving up wake lock!" after call 1
Later a exception :
"Caused by: com.caucho.hessian.client.HessianConnectionException: -1: " 
is thrown

...
proxyFactory.setHessian2Reply(false);
api = (BasicAPI) proxyFactory.create(BasicAPI.class, webServiceUrl,
getClassLoader());
System.out.println(api.saySomething()); // call 1
System.out.println(api.saySomething()); // call 2
...

saySomething() returns a random number from the server

call 1 works fine and returns a random number as expected
call 2 was expected to do the same but hangs for a few seconds and throws
the exception mentioned above

i am running the above code in eclipse with android plugin

How should i reuse the same interface(api from code above), so that i can
recall the web service a few more time. 
Since now it is only working only once during a execution. 

Note: the string returned for the call 2 is seen in the LogCat though
mangled as "rSRandom String 14351 From serverz"
which was expected as "Random String 14351 From server" in System Out.

i appreciate your any help in this issue.

thank you and regards
-robin

Original issue reported on code.google.com by roberto.robin@gmail.com on 1 Sep 2009 at 7:56

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
I have the same Error!

But I have tried to strip hessian from caucho by myself and had sucess. But 
there I
have also the same error :-/ Any ideas?

Original comment by najjan...@gmail.com on 2 Oct 2009 at 7:58

GoogleCodeExporter commented 8 years ago
Hi guys, I think this problem is related to the issue other Android developers 
are seeing here: 
http://groups.google.com/group/android-developers/browse_thread/thread/bc5454ffc
71f77dc. I believe it 
is related to HTTPUrlConnection's use (/misuse) of persistent connections and 
response body's not being read 
fully.

I stumbled across a similar, more serious issue in Hessdroid where if your 
remote service throws an 
exception, the next request to the service (even if you recreate the service 
interface from scratch) will exhibit 
the same behaviour.

It seems there are two workarounds to the problem:

The first is to set System.setProperty("http.keepAlive", "false") somewhere in 
the code. The second is to retry 
your connection if the response code comes back as -1. 

Although option 2 seems ugly, option 1 loses the benefits of persistent 
connections. Therefore by adding the 
following code to the HessianProxy (circa line 170) I was able to workaround 
the problem:

...
try {
    code = httpConn.getResponseCode();
} catch (Exception e) {
}

parseResponseHeaders(conn);

if (code == -1)
{
    int retries = 3;
    int currentTry = 0;
    while (code == -1 && currentTry < retries)
    {
        conn = sendRequest(mangleName, args);
        httpConn = (HttpURLConnection) conn;
        code = 500;

        try {
            code = httpConn.getResponseCode();
            } catch (Exception e) 
        {
        }

        parseResponseHeaders(conn);
        currentTry++;
        }
}
if (code != 200) {
    StringBuffer sb = new StringBuffer();
    int ch;
...

This is similar to John Coryat's solution provided in the URL above. If anyone 
has any improved suggestions 
please let me know.

Cheers,
Robert

Original comment by robert.t...@googlemail.com on 6 Oct 2009 at 3:17

GoogleCodeExporter commented 8 years ago
i worked around using

        BasicAPI api;
        try {
            proxyFactory.setHessian2Reply(false);
            proxyFactory.setChunkedPost(true);
            proxyFactory.setReadTimeout(30000);
            proxyFactory.setDebug(true);//this line is the workaround
            api = (BasicAPI) proxyFactory.create

Thanks and regards
Robin
@Katalytik Inc.

Original comment by roberto.robin@gmail.com on 6 Oct 2009 at 5:12

GoogleCodeExporter commented 8 years ago
Your solution is certainly better - in fact the one I proposed above is 
outright wrong for anyone wishing to post 
data to the server, since it will be posted multiple times. Don't use it! :)

Regards,
Robert

Original comment by robert.t...@googlemail.com on 6 Oct 2009 at 8:21

GoogleCodeExporter commented 8 years ago
Using proxyFactory.setDebug(true) as a workaround is not a good idea. A call 
that
takes under 1 second without debug takes 15 seconds with debug set to true.

Looking at HessianProxyFactory's code, I see that if debug is true a
HessianDebugInputStream is used. HessianDebugInputStream prints all data to
System.out, which would be the main cause of the performance hit.

However, if I don't set debug to true I eventually get the
"com.caucho.hessian.client.HessianConnectionException: -1". I have yet to 
determine
why that is.

Original comment by claes.bu...@gmail.com on 7 Nov 2009 at 1:13

GoogleCodeExporter commented 8 years ago
It looks like something is wrong in Android's
org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.Chunked
InputStream.read(byte[]
buf, int offset, int length). When in  debug mode, HessianDebugInputStream, 
which
extends InputStream, is used instead. Since InputStream.read(byte[] buf, int 
offset,
int length) is called instead, the problem is avoided.

However, debug mode gives unacceptable performance. I have found that a better
workaround is to disable debug mode and to disable chunked posts, which are 
enabled
by default:

    proxyFactory.setChunkedPost(false);
    proxyFactory.setDebug(false);

This works for me.

Original comment by claes.bu...@gmail.com on 7 Nov 2009 at 5:39

GoogleCodeExporter commented 8 years ago
thanks guys. I had the same problem and using 
    proxyFactory.setChunkedPost(false);
    proxyFactory.setDebug(false);

solved my issue

Fedeo

Original comment by federico...@gmail.com on 25 Feb 2010 at 12:37

GoogleCodeExporter commented 8 years ago
thanks guys. I had the same problem and using 
    proxyFactory.setChunkedPost(false);
    proxyFactory.setDebug(false);

solved my issue

GOOD

Jia

Original comment by ncep...@googlemail.com on 3 Aug 2013 at 2:24