POST with accept variants

2011-07-04 Thread Chris Davis
I want to be able to return an XML or JSON response from a POST request 
depending on the HTTP accept header and was wondering if its possible to 
leverage the existing variant stuff from the represent(variant) method from 
within the POST handler? or do I just need to check the header manually?
thanks in advance

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2784424


RE: Multiple applications with serverservlet and < v2.0

2011-04-14 Thread Chris Davis
ok no worries I just found the component javadoc

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2719712


Multiple applications with serverservlet and < v2.0

2011-04-13 Thread Chris Davis
Quick question is it possible to have multiple restlet applications with 
restlet < 2.0 (e.g.1.1.9) when using the servlet extension and config in a 
web.xml file?

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2719537


RE: Re: Reading/setting date header fields is extreme slow on android

2011-02-18 Thread Chris Davis
I have also come across this problem, the restlet client chooses between using 
simpledateformat and internetdateformat depending on the format of the date 
header passed to it. simpledateformat is slow because it loads all the timezone 
names for each instance. 

It is possible that if your server uses internetdateformat for its date headers 
then the client will too but I have not been able to actually confirm this yet


The decision code is in DateUtils.parse

if (FORMAT_RFC_3339.get(0).equals(format)) {
parser = new InternetDateFormat(TIMEZONE_GMT);
} else {
parser = new java.text.SimpleDateFormat(format,
java.util.Locale.US);
parser.setTimeZone(TIMEZONE_GMT);

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2705331


RE: Re: ClientResource without error? (Restlet 2.0.5)

2011-02-17 Thread Chris Davis
Oh I thought he only wanted the status.
but could you not just call res.getResponse().getEntity()?

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2705025


RE: ClientResource without error? (Restlet 2.0.5)

2011-02-16 Thread Chris Davis
Surround the get() with a try catch, catch the resource exception and check the 
status there as well as after the get(), something like

ClientResource res = new ClientResource();
Status stat;

try{
res.get();
stat = res.getStatus();
} catch (ResourceException e){
stat = res.getStatus();
}

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2704818


RE: Problem using android 2.0.4 and apache http client with HTTPS

2011-02-14 Thread Chris Davis
Any word on why it was removed? and more relevantly is it safe to use?

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2703914


RE: Problem using android 2.0.4 and apache http client with HTTPS

2011-02-07 Thread Chris Davis
I extended the HttpClientHelper and overrode configure to register the https 
scheme 

schemeRegistry.register(new Scheme("https", 
SSLSocketFactory.getSocketFactory(), 443));

and now have https working

So now just the other problem where the client seems to stop in the middle of 
making multiple requests, see original post

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2702689


RE: Problem using android 2.0.4 and apache http client with HTTPS

2011-02-07 Thread Chris Davis
Ignore that last problem I mentioned it was my fault.

I had a static Client object but was also using a Decoder that had a shorter 
lifecycle. So when the Decoder was finalized it was of course calling stop() on 
the Client

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2702694


RE: Problem using android 2.0.4 and apache http client with HTTPS

2011-02-07 Thread Chris Davis
OK I can see in the HttpClientHelper that it only registers the http scheme and 
not the https as its own javadoc says


/**
 * Configures the scheme registry. By default, it registers the HTTP and the
 * HTTPS schemes.
 * 
 * @param schemeRegistry
 *The scheme registry to configure.
 */
protected void configure(SchemeRegistry schemeRegistry) {
schemeRegistry.register(new Scheme("http", PlainSocketFactory
.getSocketFactory(), 80));

}

Is that a bug then or am I just missing something?

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2702677


Problem using android 2.0.4 and apache http client with HTTPS

2011-02-04 Thread Chris Davis
Hi,

I've been having trouble to getting the apache http client working on
android.

I have the restlet.jar and ext.httpclient.jar on my class path and I am
adding the HttpClientHelper as per the instructions,

   Engine.getInstance().getRegisteredClients().add(new HttpClientHelper(null
));


I am creating my Client as a static so I can reuse it with
clientresource.setNext(client);


OK first thing learnt, dont initialise your client in the member declaration
because it will be created before the Engine has the client helper
registered with it. doh.


Second, you need to name the Apache client helper class when you create your
Client otherwise the engine just uses the first helper in its list that
matches the protocol which is the default http client.

That is not mentioned anywhere in the docs (that I can find)


So finally I got it using the apache http client but when I call get on a
uri with https I get the following error:


java.lang.IllegalStateException: Scheme 'https' not registered.

at
org.apache.http.conn.scheme.SchemeRegistry.getScheme(SchemeRegistry.java:80)

at
org.apache.http.impl.conn.DefaultHttpRoutePlanner.determineRoute(DefaultHttpRoutePlanner.java:107)

at
org.apache.http.impl.client.DefaultRequestDirector.determineRoute(DefaultRequestDirector.java:565)

at
org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:292)

at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)

at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)

at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)

at
org.restlet.ext.httpclient.internal.HttpMethodCall.sendRequest(HttpMethodCall.java:331)

at
org.restlet.engine.http.adapter.ClientAdapter.commit(ClientAdapter.java:112)

at
org.restlet.engine.http.HttpClientHelper.handle(HttpClientHelper.java:110)

at org.restlet.Client.handle(Client.java:177)

at org.restlet.routing.Filter.doHandle(Filter.java:156)

at org.restlet.routing.Filter.handle(Filter.java:203)

at org.restlet.resource.ClientResource.handle(ClientResource.java:928)

at org.restlet.resource.ClientResource.handle(ClientResource.java:999)

at org.restlet.resource.ClientResource.handle(ClientResource.java:896)

at org.restlet.resource.ClientResource.handle(ClientResource.java:851)

at org.restlet.resource.ClientResource.handle(ClientResource.java:759)

at org.restlet.resource.ClientResource.get(ClientResource.java:492)

at
com.hullomail.android.messaging.webapi.HmBaseResource.get(HmBaseResource.java:148)


Any ideas how to fix that?


On top of that I am finding with both clients (I tried the apache one with
just http) that when I make multiple requests at the same time I see from
the logs that sometimes the client stops before one the request completes
and an exception is thrown. With the default client I get an 1002 Internal
connector error with the apache client i
get  java.lang.IllegalStateException: Connection is not open.


I thought the client would stay running if I reused it? I am not explicitly
stopping it.


Stopping the HTTP client

 Error while handling an HTTP client call

 java.lang.IllegalStateException: Connection is not open

 at
org.apache.http.impl.SocketHttpClientConnection.assertOpen(SocketHttpClientConnection.java:75)

 at
org.apache.http.impl.AbstractHttpClientConnection.receiveResponseEntity(AbstractHttpClientConnection.java:191)

 at
org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseEntity(AbstractClientConnAdapter.java:246)

 at
org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:281)

 at
org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:121)

 at
org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:410)

 at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)

 at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)

 at
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)

 at
org.restlet.ext.httpclient.internal.HttpMethodCall.sendRequest(HttpMethodCall.java:331)

 at
org.restlet.engine.http.adapter.ClientAdapter.commit(ClientAdapter.java:112)

 at
org.restlet.engine.http.HttpClientHelper.handle(HttpClientHelper.java:110)

 at org.restlet.Client.handle(Client.java:177)

 at org.restlet.routing.Filter.doHandle(Filter.java:156)

 at org.restlet.routing.Filter.handle(Filter.java:203)

 at org.restlet.resource.ClientResource.handle(ClientResource.java:928)

 at org.restlet.resource.ClientResource.handle(ClientResource.java:896)

 at org.restlet.resource.ClientResource.handle(ClientResource.java:851)

 at org.restlet.resource.ClientResource.handle(ClientResource.java:759)

 at org.restlet

RE: Re: Inefficient parsing of date header clientresource 2.0.3

2011-01-25 Thread Chris Davis
I see after more digging that InternetDateFormat was added in 2.0, if I do 
upgrade the server side will it use an offset timezone rather than a timezone 
code by default?

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2700337


RE: Re: class not found exception android 2.0.3

2011-01-17 Thread Chris Davis
No I've only had that single crash report, I'm putting it down to an android OS 
bug

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2698685


class not found exception android 2.0.3

2011-01-13 Thread Chris Davis
I've received a strange crash report from an android device using restlet
2.0.3 for android.
It looks like the classloader is trying to load org.joda.time.DateTime when
initialising org.restlet.engine.Engine but I have no idea why it would try
to do that as there are no references to that class anywhere in restlet or
my own code

java.lang.ExceptionInInitializerError
at
com.hullomail.android.messaging.service.HmCoreService.applicationInitRequest(HmCoreService.java:490)
at
com.hullomail.android.messaging.messagelist.HmMessageListActivity.onServiceConnected(HmMessageListActivity.java:639)
at
com.hullomail.android.messaging.HmBaseActivity$1.onServiceConnected(HmBaseActivity.java:38)
at
android.app.ActivityThread$PackageInfo$ServiceDispatcher.doConnected(ActivityThread.java:1247)
at
android.app.ActivityThread$PackageInfo$ServiceDispatcher$RunConnection.run(ActivityThread.java:1264)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ExceptionInInitializerError
at org.restlet.data.Method.(Method.java:331)
at org.restlet.data.Method.(Method.java:390)
at org.restlet.data.Method.(Method.java:355)
at org.restlet.data.Method.(Method.java:54)
... 14 more
Caused by: java.lang.NoClassDefFoundError: org.joda.time.DateTime
at org.restlet.engine.Engine.(Engine.java:102)
... 18 more
Caused by: java.lang.ClassNotFoundException: org.joda.time.DateTime in
loader
dalvik.system.PathClassLoader[/data/app/com.hullomail.messaging.android-2.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
... 19 more

Any ideas?
could just be something going wrong in the android OS I guess I've only had
the one single report

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2697879

Enabling gzip for clientresource

2010-09-17 Thread Chris Davis
Hi,
How do I enable support for using gzip from the android client code?

I don't necessarily need to gzip the request but would like to set the 
accept-encoding:gzip header and unzip the response.

cheers
Chris D

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2661287


Decoding url encoded form values

2010-09-09 Thread Chris Davis
Hi,
I am posting a x-www-form-urlencoded form (using the restlet client api) and 
getting the value on the server in my the acceptRepresentation method using:

Form form = new Form(entity)
form.getFirstValue()

The value is url encoded but my question is should I have to decode the value 
myself or should restlet already have done it for me?  and if it should have 
done it already what could I missing?

thanks in advance
Chris D

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2656832


RE: Correct way to use android ClientResource

2010-08-03 Thread Chris Davis
I've traced further into the code and it seems to be the BaseHelper class that 
is creating a controller service and worker service. This happens for each new 
clientresource object. 

I currently have a clientresource object for each of my resources, is this the 
right way to go about it or should I be sharing one clientresource or maybe 
using the lower level client class??

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2642256


Correct way to use android ClientResource

2010-08-02 Thread Chris Davis
Just a quick one, (i hope) I am using the android ClientResource in my
android app and I am wondering what is the correct way to use that object
when it is necessary to make multiple requests on it.

Should I be creating one resource object and holding a reference to that or
is it preferable to create a new object for each call?

I have tried the latter way and it seems OK except each call seems to create
a new Executor service and 2 threads that are never cleared up even though I
am not using the asynchronous functionality.

Perhaps I am simply missing a method call or something?

kind regards
Chris

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2641904

Multipart form post from android client

2010-05-06 Thread Chris Davis
Hi, I was wondering if you guys had implemented the multi-part form request
in the android client lib yet?
If not I understand I can use the apache httpclient? could anyone point me
at a good example of how to do this?

thanks in advance
Chris D

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2602795

Considering Restlet for my web service

2009-07-28 Thread Chris Davis
Hello,

I am currently trying to implement web service that will run on our existing
servlet based system. Restlet looks almost perfect for what I need but there
are two things that I need to be sure I can do before I can proceed with it.

1) Authentication - I need to allow a user to authenticate themselves before
accepting any other requests from that user

2) Server side caching - I need to keep data retrieved from a 3rd party
system temporarily cached in memory for each user, to open new a connection
and retrieve this data is too expensive an operation to do on every request.

Of course you know I am going to say I need some sort of session :) but I
also agree that to do without the session is a good way to go.
So do you have any suggestions as to what to do? I am sure others must have
come up against this scenario.
Or perhaps restlet is not the correct solution in this case?

Any advice is much appreciated, this is my first stab at a web service and I
have looked at most of the other possible java web service solutions but
they all seem so overweight and disparate  (which I guess is why restlet was
created in the first place)

thanks in advance
Chris D

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2376280