Broken connection using Android client

2011-07-29 Thread Matt McMinn
I wrote a moderately complex server about 18 months ago based on Restlet 2.0 
that has been happily serving data since then.  I've recently needed to add 
some new features, and I'm running in to a problem with the new code.  I've 
updated to Restlet 2.0.8 as well.  For all requests to my new code from an 
android client, on the server (and after my code completes OK) I'm getting:

[07/28 17:25:09.009] I [LogFilter.afterHandle] 2011-07-28   17:25:09
xx.xxx.xxx.xxx  -   xxx.xxx.xxx.xx  8080POST/path/to/restlet  - 
  200 211725  35  1776
http://xxx.xxx.xxx.xx:8080  Restlet-Framework/2.0.8 -
[07/28 17:25:10.010] I [ServerAdapter.commit] The connection was broken. It was 
probably closed by the client.
[07/28 17:25:10.010] F1 [JettyCall.complete] Unable to flush the response
[07/28 17:25:10.010] F1 [JettyCall.complete] Unable to complete the response

Requests to the older code still work fine (I don't think there's a distinction 
between the old and new code though).  

On the client, I sometimes get a partial response (some of the XML that is 
being returned shows up, but not the complete xml document) and sometimes get a 
socket closed exception.  If I use a j2se client that I wrote to test the 
server, I get the entire response with no problems, so it seems like there 
could be something going on with the android client.  I've tried using both the 
net and http clients, both seem to give the same problem.  The XML being 
returned is about 200kb, but I've pulled bigger requests than that over 
restlet, so I'd be surprised if it's the amount of data.

Elsewhere in the discussion group someone said that they got this error 
occasionally, and the response was that it would occur when there was an error, 
which doesn't really help.  Any ideas what could be going wrong?

Thanks

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


RE: Broken connection using Android client

2011-07-29 Thread Matt McMinn
I think I've fixed this problem by explicitly setting the connector helper in 
my client with:
Engine.getInstance().getRegisteredClients().clear();
Engine.getInstance().getRegisteredClients().add(new HttpClientHelper(null));

I'm using the net client.  So far it seems to have fixed the issue.

Thanks!

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


Re: ClientResource leaves inactive thread

2011-07-28 Thread Matt Kennedy
I'm not clear from the question if you're asking about the number of task 
threads as Tim has explained, or the number of http listener threads, for that 
use:

Server httpServer = new Server(Protocol.HTTP, port);
serviceComponent.getServers().add(httpServer);
httpServer.getContext().getParameters().add(maxThreads, 
maxThreads);



On Jul 27, 2011, at 2:02 PM, Tim Peierls wrote:

 You can set the pool size of the executor used by the TaskService with 
 org.restlet.service.TaskService.setPoolSize.
 
 Or you can provide your own TaskService and override createExecutorService.to 
 return an ExecutorService tuned exactly the way you want.
 
 --tim
 
 On Wed, Jul 27, 2011 at 8:14 AM, Klemens Muthmann al...@gmx.de wrote:
 Hi,
 
 I read several threads about this problem now (including this one) and still 
 can't figure out how to solve the issues (My Restlet Version is 2.0.8). May 
 someone point me to the relevant tutorial or show some code on how to 
 increase the thread pool size on the RESTlet Server?
 
 Thanks and regards
 
 --
 http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2804569


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

Re: How-to for setting up Client PKI Cert based authentication?

2011-07-12 Thread Matt Kennedy
Have a look at this:

http://restlet-discuss.1400322.n2.nabble.com/fine-grained-authorization-based-on-DN-X-509-td6444949.html

Let me know if that answers the question for you...

On Tue, Jul 12, 2011 at 2:16 PM, Kevin Pauli ke...@thepaulis.com wrote:

 This page talks about setting up Basic and Digest based authentication...


 http://wiki.restlet.org/docs_2.0/13-restlet/27-restlet/46-restlet/112-restlet.html

 I am looking for a guide to setting up Client PKI Cert-based authentication
 in Restlet 2.0

 Can anyone point me in the right direction?

 --

 http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2791113


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

Re: how to use conditional get in restlet ?

2011-06-15 Thread Matt Kennedy
I'm moving this to the disc...@restlet.itgris.org, the code list is more for 
the restlet codebase itself. 

Anyhow, the answer to your question is two-fold:

First, Conditional Get means something very specific in HTTP parlance and it 
isn't what you describe.  A conditional get is a GET request that sends a 
special header that tells the server to not bother to send a response if the 
resource that is being requested hasn't been modified since the last time the 
client made the request.  So it isn't really for what you're talking about.

So, to do what you'd like to do, just use a query parameter.  For example:

http://www.example.com/people?age=over20

-Matt


On Jun 15, 2011, at 4:08 PM, infoSyS wrote:

 I am currently designing an API using the restlet framework; Can anyone
 please give me a clue on how to use conditional GET requests in RESTlet ?
 what I mean is : lets say I have the name and date of birth of many persons
 and I want to GET the name of persons that are older than 20 years, how
 could this be done ? Thanks in advance.
 
 --
 View this message in context: 
 http://restlet-code.1609877.n2.nabble.com/how-to-use-conditional-get-in-restlet-tp6480367p6480367.html
 Sent from the Restlet Code mailing list archive at Nabble.com.
 
 --
 http://restlet.tigris.org/ds/viewMessage.do?dsForumId=7458dsMessageId=2766359

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


Re: fine grained authorization based on DN/X.509

2011-06-07 Thread Matt Kennedy
That's one way to do it, but it isn't the way I usually design my restlet
applications.

I do all of my authentication and authorization in subclasses of the restlet
API classes, which are subclasses of filter.  These typically sit in front
of your resources in a filter chain, which you configure in your router set
up in createInboundRoute in your subclass of Application.

Steps 9-12 of http://www.restlet.org/documentation/2.0/tutorial have an
example that may be useful to you.  But if what you have works for your
situation, then it looks like you're on the right track.  It just may be
harder to re-use your code in other restlet applications later on.

-Matt

On Tue, Jun 7, 2011 at 6:31 AM, lambda daku lambdad...@gmail.com wrote:

 Thanks for the reply.

 I have few comments on your reply.

 Usually the certificate received at the server side has atleast 2
 certificates - one is a public key of the client and the rest are n
 trusted entries (in my case it is 1).

 As you have mentioned about the getRequest() method, where do you access it
 in a resource or in a application class? I am intercepting the requests in
 an application class (which extends from JaxRsApplication),  whereby I am
 overriding the handle(req,res) method and and getting the desired
 attributes, is the following were you referring to?:

 public class MyJaxRsApplication extends JaxRsApplication{

 @Override
 public void handle(Request request, Response response) {
  Maplt;String, Objectgt; map = request.getAttributes();
  @SuppressWarnings(unchecked)
  ListX509Certificate lst =  (ListX509Certificate)
 map.get(org.restlet.https.clientCertificates);
  //however the first item in the above list is the user's public key
  //here, delegation to the authorization PEP, PAP and PIP will be made
 }
 ..

 }


 Many thanks
 Daku

 --
 View this message in context:
 http://restlet-discuss.1400322.n2.nabble.com/fine-grained-authorization-based-on-DN-X-509-tp6444949p6448938.html
 Sent from the Restlet Discuss mailing list archive at Nabble.com.

 --

 http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2759531


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

Re: fine grained authorization based on DN/X.509

2011-06-06 Thread Matt Kennedy
There are two steps here, authenticating the client cert, and authorizing
the user, which correspond to the org.restlet.routing.filter.Authenticator
and org.restlet.routing.filter.Authorizer classes. These sit in front of the
resource you are controlling access to.  In the cases of client
certificates, the authenticator is really merely checking for the existence
of client certs available on the connection, the SSL layer has already
verified them and stashed them where restlet can access them, which is:
getRequest().getAttributes().get(org.restlet.https.clientCertificates),
which gives you a list (usually of length 1) of
java.security.cert.X509Certificate objects I think.

You can use that to get the DN, and then I would put that in a field of the
restlet User object or a custom subclass thereof.  Then when it gets to your
authorizer, you use the DN you pulled off the cert to query an LDAP to
determine if the user can do what they are attempting or not.

This is a good place to start research.  I could have sworn that at one
point Bruno Harbulot had posted a patch for a ClientCertAuthenticator.java
to the issue tracker, but I have no clue what happened to it.

-Matt




On Mon, Jun 6, 2011 at 8:44 AM, lambda daku lambdad...@gmail.com wrote:

 Hi,

 I have a Restlet application running on jetty usiing https (with client
 side
 authn). The required behavior is to intercept the client request and
 extract
 the DN on the server side (in-bound), on which the authorization will take
 place. Whereby the DN/x.509 would be matched against some external entity
 (ldap) where the DN/x.509 certs are stored.

 Is there any standard way to add interceptors on the client as well as on
 the server side to authorize the user based on a particular DN/x.509 or any
 other credential?

 Thanks
 Daku



 --
 View this message in context:
 http://restlet-discuss.1400322.n2.nabble.com/fine-grained-authorization-based-on-DN-X-509-tp6444949p6444949.html
 Sent from the Restlet Discuss mailing list archive at Nabble.com.

 --

 http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2759025


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

Re: fine grained authorization based on DN/X.509

2011-06-06 Thread Matt Kennedy
Sorry, forgot to include the link:
http://wiki.restlet.org/docs_1.1/13-restlet/27-restlet/46-restlet.html

On Mon, Jun 6, 2011 at 2:20 PM, Matt Kennedy stinkym...@gmail.com wrote:

 There are two steps here, authenticating the client cert, and authorizing
 the user, which correspond to the org.restlet.routing.filter.Authenticator
 and org.restlet.routing.filter.Authorizer classes. These sit in front of the
 resource you are controlling access to.  In the cases of client
 certificates, the authenticator is really merely checking for the existence
 of client certs available on the connection, the SSL layer has already
 verified them and stashed them where restlet can access them, which is:
 getRequest().getAttributes().get(org.restlet.https.clientCertificates),
 which gives you a list (usually of length 1) of
 java.security.cert.X509Certificate objects I think.

 You can use that to get the DN, and then I would put that in a field of the
 restlet User object or a custom subclass thereof.  Then when it gets to your
 authorizer, you use the DN you pulled off the cert to query an LDAP to
 determine if the user can do what they are attempting or not.

 This is a good place to start research.  I could have sworn that at one
 point Bruno Harbulot had posted a patch for a ClientCertAuthenticator.java
 to the issue tracker, but I have no clue what happened to it.

 -Matt





 On Mon, Jun 6, 2011 at 8:44 AM, lambda daku lambdad...@gmail.com wrote:

 Hi,

 I have a Restlet application running on jetty usiing https (with client
 side
 authn). The required behavior is to intercept the client request and
 extract
 the DN on the server side (in-bound), on which the authorization will take
 place. Whereby the DN/x.509 would be matched against some external entity
 (ldap) where the DN/x.509 certs are stored.

 Is there any standard way to add interceptors on the client as well as on
 the server side to authorize the user based on a particular DN/x.509 or
 any
 other credential?

 Thanks
 Daku



 --
 View this message in context:
 http://restlet-discuss.1400322.n2.nabble.com/fine-grained-authorization-based-on-DN-X-509-tp6444949p6444949.html
 Sent from the Restlet Discuss mailing list archive at Nabble.com.

 --

 http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2759025




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

Re: fine grained authorization based on DN/X.509

2011-06-06 Thread Matt Kennedy
And that was the wrong link, sorry:
http://wiki.restlet.org/docs_2.0/13-restlet/27-restlet/46-restlet.html

On Mon, Jun 6, 2011 at 2:21 PM, Matt Kennedy stinkym...@gmail.com wrote:

 Sorry, forgot to include the link:
 http://wiki.restlet.org/docs_1.1/13-restlet/27-restlet/46-restlet.html


 On Mon, Jun 6, 2011 at 2:20 PM, Matt Kennedy stinkym...@gmail.com wrote:

 There are two steps here, authenticating the client cert, and authorizing
 the user, which correspond to the org.restlet.routing.filter.Authenticator
 and org.restlet.routing.filter.Authorizer classes. These sit in front of the
 resource you are controlling access to.  In the cases of client
 certificates, the authenticator is really merely checking for the existence
 of client certs available on the connection, the SSL layer has already
 verified them and stashed them where restlet can access them, which is:
 getRequest().getAttributes().get(org.restlet.https.clientCertificates),
 which gives you a list (usually of length 1) of
 java.security.cert.X509Certificate objects I think.

 You can use that to get the DN, and then I would put that in a field of
 the restlet User object or a custom subclass thereof.  Then when it gets to
 your authorizer, you use the DN you pulled off the cert to query an LDAP to
 determine if the user can do what they are attempting or not.

 This is a good place to start research.  I could have sworn that at one
 point Bruno Harbulot had posted a patch for a ClientCertAuthenticator.java
 to the issue tracker, but I have no clue what happened to it.

 -Matt





 On Mon, Jun 6, 2011 at 8:44 AM, lambda daku lambdad...@gmail.com wrote:

 Hi,

 I have a Restlet application running on jetty usiing https (with client
 side
 authn). The required behavior is to intercept the client request and
 extract
 the DN on the server side (in-bound), on which the authorization will
 take
 place. Whereby the DN/x.509 would be matched against some external entity
 (ldap) where the DN/x.509 certs are stored.

 Is there any standard way to add interceptors on the client as well as on
 the server side to authorize the user based on a particular DN/x.509 or
 any
 other credential?

 Thanks
 Daku



 --
 View this message in context:
 http://restlet-discuss.1400322.n2.nabble.com/fine-grained-authorization-based-on-DN-X-509-tp6444949p6444949.html
 Sent from the Restlet Discuss mailing list archive at Nabble.com.

 --

 http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2759025





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

Re: Using the simple framework in Restlet

2011-05-05 Thread Matt Kennedy
It should be as simple as having
$RESTLET_HOME/lib/org.restlet.ext.simple.jar and
$RESTLET_HOME/lib/org.simpleframework_N.N/org.simpleframework.jar on your
classpath.

On Thu, May 5, 2011 at 7:20 AM, Steve Ferris steve.fer...@forgerock.comwrote:

 Hi,

 I cannot work out how to tell my standalone Restlet application to the use
 the Simple framework as it's chosen server connector. Is this some method I
 have to call or property to set?

 I am using maven and have included the correct dependency.

 thanks
 Steve

 --

 http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2730537


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

Re: Fine grained authorization

2011-04-19 Thread Matt Kennedy
You would typically call isInRole() in the ServerResource methods that you
override to determine if a particular user can perform some action.  You may
also want to look at the MethodAuthorizer if you want to allow some users
access to all the HTTP methods, but restrict others to GET  POST for
example.  That way your annotated methods don't have to have authorization
code in them, they simply won't be called if the user isn't allowed to call
them by the MethodAuthorizer

-Matt

On Fri, Apr 15, 2011 at 1:57 AM, Ishaaq Chandy ish...@gmail.com wrote:

 Hi all,

 Am using Restlet 2.0.6.

 Trying to figure out how to implement fine grained authorization on my
 Resources. The authorization checks need to be instance-specific.

 According to
 http://wiki.restlet.org/docs_2.0/13-restlet/27-restlet/46-restlet/113-restlet.html,
 I should be able to leverage ServerResource.isInRole() for this. However, I
 can't see how this works even if I implement that method as I see nothing in
 the Restlet source code that actually calls it other that some old
 deprecated jaxrs code.

 Suggestions?

 Ishaaq


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

Re: Auditing function

2011-04-12 Thread Matt Kennedy
I've done something similar in the past.  Rather than rely on the restlet
access logging service, I collected all the data I needed in an object as
the request was processed.  After the request completed, I spun off another
thread to write to the log object to the database. If the database wasn't
available, I did backup logging to a file. I _think_ I did this in the
confines of wither log4j or slf4j, but I can't remember.

On Sun, Apr 3, 2011 at 8:31 PM, Paul Morris pmor...@nmh.org wrote:

 I've been looking into this since my initial post and want to add a couple
 of thoughts to clarify my intention here. I found the LogService Restlet
 class which looks very robust but I need to customize some of the logging
 here for auditing and compliance purposes (i.e. identify the user based on
 querying a session server using a token) so I think I'm looking at something
 homegrown. But again, I'd like to implement some way to sort of copy the
 request on the way in and copy the response on the way out, parse through
 those copies (perhaps in another thread) to break them out cleanly into a
 database.

 --

 http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2716636


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

Re: Retrying requests

2010-05-05 Thread Matt Kennedy
I usually do this sort of thing in the ServerResource itself.  Just wrap the 
problematic lines in the code you just provided only replace the call to 
super.handle with whatever calls throw the exception.  Are you doing something 
in particular that makes this a bad strategy?

-Matt


On May 5, 2010, at 8:45 PM, Jean-Philippe Steinmetz wrote:

 Hello everyone,
 
 I have a restlet resource that sometimes produces an exception during 
 processing. Since the exception is the fault of the server and not the fault 
 of the client I would like to retry the request. When an exception occurs I 
 get rolled back all the way to the Finder. In the Finder's handle function 
 i'd like to attempt to retry processing of the request when I see these 
 exceptions. Here's an example of the Finder I would like to implement.
 
 @Override
 public void handle(Request request, Response response)
 {
 int count = 0;
 while (count  MAX_RETRIES)
 {
 try
 {
 super.handle(request, response);
 break;
 } catch (MyException e) {
 count++;
 }
 }
 }
 
 The behavior i'm seeing, however, is that once the exception is caught the 
 response is immediately sent back to the client and retry processing ceases. 
 If this is expected behavior how would I go about making this happen?
 
 Jean-Philippe

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

Re: Retrying requests

2010-05-05 Thread Matt Kennedy
You can probably save yourself a lot of work by inserting an extra level of 
inheritance. It is a pain to throw in try-catch blocks all over the place, but 
if you think about it you might be able to put your try loop in a new 
superclass to your resources and get the same functionality.  It is usually 
fairly easy to change around your inheritance hierarchy and change some method 
names, especially if you have a nice refactoring helper like Eclipse.


-Matt


On May 5, 2010, at 9:06 PM, Jean-Philippe Steinmetz wrote:

 I just tested that scenario out and it works. Unfortunately though the way 
 it's all coded up so far requires a lot more code refactoring to edit each 
 resource than it would be to handle it in the Finder itself. Albeit it would 
 probably be more correct. Just trying to save myself some time =)
 
 On Wed, May 5, 2010 at 5:56 PM, Matt Kennedy stinkym...@gmail.com wrote:
 I usually do this sort of thing in the ServerResource itself.  Just wrap the 
 problematic lines in the code you just provided only replace the call to 
 super.handle with whatever calls throw the exception.  Are you doing 
 something in particular that makes this a bad strategy?
 
 -Matt
 
 
 
 On May 5, 2010, at 8:45 PM, Jean-Philippe Steinmetz wrote:
 
 Hello everyone,
 
 I have a restlet resource that sometimes produces an exception during 
 processing. Since the exception is the fault of the server and not the fault 
 of the client I would like to retry the request. When an exception occurs I 
 get rolled back all the way to the Finder. In the Finder's handle function 
 i'd like to attempt to retry processing of the request when I see these 
 exceptions. Here's an example of the Finder I would like to implement.
 
 @Override
 public void handle(Request request, Response response)
 {
 int count = 0;
 while (count  MAX_RETRIES)
 {
 try
 {
 super.handle(request, response);
 break;
 } catch (MyException e) {
 count++;
 }
 }
 }
 
 The behavior i'm seeing, however, is that once the exception is caught the 
 response is immediately sent back to the client and retry processing ceases. 
 If this is expected behavior how would I go about making this happen?
 
 Jean-Philippe
 


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

Re: What to do about sessions?

2010-04-20 Thread Matt Kennedy
Dj,

I'm glad you asked this. I've really lucked out so far and have always worked 
in an environment that uses client certificates for authentication.  The 
identity of the user is established on every single connection, and I never 
have to worry about it.  But in the near future, I'm going to have to solve the 
same problem that you're looking at now.

You make some astute observations, HTTP_BASIC is only safe over HTTPS, which is 
very limiting, especially when deploying to GAE.  HTTP_DIGEST has some poorly 
understood compatibility problems with different HTTP clients, furthermore, it 
isn't what GAE uses natively.

It seems that for the GAE edition in particular it would be nice to have an 
Authenticator that could integrate with the GAE APIs.  I'm sure if it isn't 
done by the time I have to tackle that project that I'll wind up writing one.  
Does the restlet team have any specific advice for creating a subclass of 
Authenticator that can get the Google account identity? Specifically a way to 
use a restlet to write the login example given on this link: 
http://code.google.com/appengine/docs/java/users/overview.html

-Matt


On Apr 20, 2010, at 11:37 AM, dj wrote:

 Hey Stephen,
 
 Ok so I get that sessions shouldn't be supported by rest, totally fine with 
 that. I'm confused about how to use basic auth then instead, if that's the 
 preferred method.
 
 If we use basic auth, then we need to send the username and password as plain 
 text, right? This could be fixed by using https. 
 
 But this also implies that every rest call made must supply username:password 
 in the request, right?
 
 In that case, then in order to protect the user, every rest call should be 
 done using https. Is that correct?
 
 Thanks
 
 --
 http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2590591

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

Re: Representation for multiple types?

2010-01-24 Thread Matt Kennedy
Can you just use the sample code you provide below, only create a subclass of 
Representation that takes your serializer as the argument, maybe along with the 
mime type? Something like:

public class MyVariableRepresentation extends Representation
{
  Serializer serializer;
  public MyVariableRepresentation(MediaType type, Serializer variantSerializer)
  {
super(type);
this.serializer = variantSerializer;
  }
  //Then override write method or something to call your serializer to do the 
serializing.

}

So your sample code becomes:

public class MyResource extends Resource
{
public MapMediaType,Serializer map;

public Representation represent(Variant variant) throws ResourceException
{
Serializer serializer = map.get(variant.getMediaType());
if (serializer == null)
throw new 
ResourceException(Status.CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE);
return new MyVariableRepresentation(variant.getMediaType(), 
serializer.encode(data)); // ??
}
}

Does this work?


On Jan 22, 2010, at 6:27 PM, Jean-Philippe Steinmetz wrote:

 Sure. With our particular use case we specify a map of media types to data 
 serializers in spring as a hash map. We then inject this map into each 
 resource. When the map is set in the class we then add all the media types 
 specified as map keys as acceptable variants. When the represent() function 
 is called we use the provided media type to retrieve the associated 
 serializer, throwing an unsupported media type error if the variant has no 
 corresponding serializer. We then serialize our data and send it back to the 
 client. It's the sending it back to the client part is where I am stuck. As 
 there is no default Representation class that I can merely pass in any object 
 type to whether it be string, bye array, etc.
 
 Here is an example of the Resource class.
 
 public class MyResource extends Resource
 {
 public MapMediaType,Serializer map;
 
 public Representation represent(Variant variant) throws ResourceException
 {
 Serializer serializer = map.get(variant.getMediaType());
 if (serializer == null)
 throw new 
 ResourceException(Status.CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE);
 return new Representation(serializer.encode(data)); // ??
 }
 }
 
 Here is an example of our spring applicationContext.xml.
 
 beans
 ...
 util:map id=map map-class=java.util.HashMap
 entry
 keyutil:constant 
 static-field=org.restlet.data.MediaType.APPLICATION_FLASH//key
 ref local=amfSerializer/
 /entry
 entry
 keyutil:constant 
 static-field=org.restlet.data.MediaType.APPLICATION_JSON//key
 ref local=jsonSerializer/
 /entry
 entry
 keyutil:constant 
 static-field=org.restlet.data.MediaType.APPLICATION_XML//key
 ref local=xmlSerializer/
 /entry
 /util:map
 
 bean name=/my/resource id=myResource autowire=byName 
 scope=prototype
   class=com.restlets.MyResource
 property name=map ref=map/
 /bean
 ...
 /beans
 
 On Fri, Jan 22, 2010 at 3:07 PM, Matt Kennedy stinkym...@gmail.com wrote:
 I'm not a Spring user, so maybe that's why it isn't clear to me what you're 
 asking.  Can you try phrasing this question a different way?  I think I know 
 the answer to your problem because I've always had to deal with multiple 
 media types for the same resource, but I'm not sure I understand the problem. 
  Can you walk through a use-case?
 
 
 On Jan 22, 2010, at 6:00 PM, Jean-Philippe Steinmetz wrote:
 
 Thank you for the quick reply. This certainly would resolve the issue but it 
 doesn't really offer the kind of solution I was hoping for. With this 
 solution i'd still have to do a mapping of media type to some representation 
 which is what I am trying to avoid. The thought was that there is a 
 Representation that just outputs the message body regardless of whatever 
 media type variant is set for it. That way I don't have to make a mapping of 
 media type to anything.
 
 On Fri, Jan 22, 2010 at 1:27 PM, Matt Kennedy stinkym...@gmail.com wrote:
 I can't remember what 1.1.6's API looks like, but I do something like this 
 with the 2.0 API.  Basically, in the Resource's constructor, I use someting 
 like:
 
 getVariants().add(new MyXMLRepresentation(this))
 getVariants().add(new MyJSONRepresentation(this))
 
 
 Each of those My* classes are a subclass of Representation, and the write() 
 method is overridden to produce the custom media type.  I pass the Resource 
 object to the custom representation so that I have access to the resource 
 during the write method.  Also important is that in the constructor, you 
 call the super constructor with the MediaType and resource as arguments, ex:
 
 //Constructor
 public MyJSONRepresentation(Resource res)
 {
  super(MediaType.APPLICATION_JSON, res);
 }
 
 I know something like this can be done with the 1.1.6 API

Re: Representation for multiple types?

2010-01-22 Thread Matt Kennedy
I can't remember what 1.1.6's API looks like, but I do something like this with 
the 2.0 API.  Basically, in the Resource's constructor, I use someting like:

getVariants().add(new MyXMLRepresentation(this))
getVariants().add(new MyJSONRepresentation(this))


Each of those My* classes are a subclass of Representation, and the write() 
method is overridden to produce the custom media type.  I pass the Resource 
object to the custom representation so that I have access to the resource 
during the write method.  Also important is that in the constructor, you call 
the super constructor with the MediaType and resource as arguments, ex:

//Constructor
public MyJSONRepresentation(Resource res)
{
  super(MediaType.APPLICATION_JSON, res);
}

I know something like this can be done with the 1.1.6 API because I was using 
it before I ported to 2.0, but now I can't find the 1.1.6 code. It probably 
isn't too different.

On Jan 22, 2010, at 3:50 PM, Jean-Philippe Steinmetz wrote:

 Hello all,
 
 We're using restlet 1.1.6 and for all our resources we want to support a 
 dynamic set of media types. We do this in our Spring configuration by setting 
 up a list of acceptable media types. My question is if there is a 
 Representation class I can use that will essentially accept any type of data 
 I push into it? For instance we support HTML, XML, JSON and AMF3 therefore 
 most of the time it's a string based representation but in the case of AMF3 
 it is binary (byte array). So far the only way I see it is to make a switch 
 statement in our resource class for each media type but this pretty much 
 defeats the purpose of specifying supported media types in the application 
 configuration.
 
 Jean-Philippe

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


Re: Representation for multiple types?

2010-01-22 Thread Matt Kennedy
I'm not a Spring user, so maybe that's why it isn't clear to me what you're 
asking.  Can you try phrasing this question a different way?  I think I know 
the answer to your problem because I've always had to deal with multiple media 
types for the same resource, but I'm not sure I understand the problem.  Can 
you walk through a use-case?


On Jan 22, 2010, at 6:00 PM, Jean-Philippe Steinmetz wrote:

 Thank you for the quick reply. This certainly would resolve the issue but it 
 doesn't really offer the kind of solution I was hoping for. With this 
 solution i'd still have to do a mapping of media type to some representation 
 which is what I am trying to avoid. The thought was that there is a 
 Representation that just outputs the message body regardless of whatever 
 media type variant is set for it. That way I don't have to make a mapping of 
 media type to anything.
 
 On Fri, Jan 22, 2010 at 1:27 PM, Matt Kennedy stinkym...@gmail.com wrote:
 I can't remember what 1.1.6's API looks like, but I do something like this 
 with the 2.0 API.  Basically, in the Resource's constructor, I use someting 
 like:
 
 getVariants().add(new MyXMLRepresentation(this))
 getVariants().add(new MyJSONRepresentation(this))
 
 
 Each of those My* classes are a subclass of Representation, and the write() 
 method is overridden to produce the custom media type.  I pass the Resource 
 object to the custom representation so that I have access to the resource 
 during the write method.  Also important is that in the constructor, you call 
 the super constructor with the MediaType and resource as arguments, ex:
 
 //Constructor
 public MyJSONRepresentation(Resource res)
 {
  super(MediaType.APPLICATION_JSON, res);
 }
 
 I know something like this can be done with the 1.1.6 API because I was using 
 it before I ported to 2.0, but now I can't find the 1.1.6 code. It probably 
 isn't too different.
 
 On Jan 22, 2010, at 3:50 PM, Jean-Philippe Steinmetz wrote:
 
  Hello all,
 
  We're using restlet 1.1.6 and for all our resources we want to support a 
  dynamic set of media types. We do this in our Spring configuration by 
  setting up a list of acceptable media types. My question is if there is a 
  Representation class I can use that will essentially accept any type of 
  data I push into it? For instance we support HTML, XML, JSON and AMF3 
  therefore most of the time it's a string based representation but in the 
  case of AMF3 it is binary (byte array). So far the only way I see it is to 
  make a switch statement in our resource class for each media type but this 
  pretty much defeats the purpose of specifying supported media types in the 
  application configuration.
 
  Jean-Philippe
 
 --
 http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2441312


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

Re: Applying multiple security scheme's to a uri

2010-01-11 Thread Matt Kennedy
Are you using the 2.0 API?

You can subclass the Authenticator and override the authenticate() method.  
That gives you access to the Request object, you should then be able to check 
the user-agent and do custom authentication.

Authenticator is a filter, so you will have to call setNext() to specify the 
next resource in the chain, either an instance of an Authorizer, or your 
restlet usually.

-Matt

On Jan 11, 2010, at 9:44 AM, webp...@tigris.org wrote:

 Hello,
 
 Given the user-agent property, is it possible to apply different security 
 scheme's to a given uri?
 
 i.e. when using a browser apply basic or digest security, but when using any 
 other 'client', use a custom security scheme.
 
 Right now, my authentication is setup once-off in the 'createInboundRoot' 
 method. But this method is never invoked again after that.
 
 Is there a hook/method i can use to specify which scheme to use based on the 
 user agent?
 
 Regards,
 --KD
 
 --
 http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2436294

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


Re: Redirection?

2009-12-28 Thread Matt Kennedy
I guess I'm not clear on your motivation for trying to accomplish this on the 
server.  The easy way to do a redirect to another page if you want the 
original page to be displayed for a set period of time is to return html that 
has a special meta tag in the head section. See 
http://en.wikipedia.org/wiki/Meta_refresh for examples.  You can put an 
animated gif in for the countdown, or write some javascript to do the countdown.

If you want this to be an official HTTP redirect, for example a 301, 302, 303, 
307 status code, then you can set that status code in the response object and 
set the entity to be some html that will do your refresh to the new URL, plus 
the countdown.  Be careful if you choose to go with 301 or 302 as the response 
code, read IETF RFC 2626 for details.

-Matt

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


Re: Redirection?

2009-12-28 Thread Matt Kennedy
RFC 2616  :-)  http://www.ietf.org/rfc/rfc2616.txt  (2626 is the Y2K RFC)

Woops.  Hm, next time I should probably copy/paste the link instead of 
fat-fingering the name huh?

Rob is right about everything else here too, I should have made it more clear 
that the meta-refresh trick is hardly optimal as the wikipedia entry nicely 
states.  It sounded like the countdown part was really important to you though, 
but the combination of a redirect status code and the meta-refresh header may 
give you really inconsistent results. Do you know if you have the luxury of 
your client base only using a particular user agent?

If you decide the countdown is that important, you may have to forgo HTTP 
correctness and leave the status at 200.  Despite it's deprecated status, the 
meta-refresh at this moment still works in all the browsers I have experience 
with if it isn't also contending with a refresh directive. You can definitely 
use it to get your delayed redirect effect.

-Matt

On Dec 28, 2009, at 2:18 PM, Rob Heittman wrote:

 RFC 2616  :-)  http://www.ietf.org/rfc/rfc2616.txt  (2626 is the Y2K RFC)
 
 Sopasakis -- as HTTP itself doesn't have a means of specifying a delay before 
 a redirect, you won't get consistent behavior across every HTTP compliant 
 client or library.  Most user-agents will act immediately on an HTTP redirect 
 status code (3xx) and ignore the entity, but supplying an HTML entity with 
 the meta refresh tag may have the desired effect for some user-agents.
 
 The usual convention is to enclose a short HTML entity with a 3xx redirect, 
 something like this:
 
 htmlheadtitleMoved/title/headbody
 Please click this link if you are not automatically redirected to: a 
 href=${new-location}${new-location}/a
 scriptwindow.location.href=$[new-location};/script
 /body
 
 You can doctor up some variants of this using the meta refresh or Javascript 
 timeouts, but I suspect getting consistent behavior across basic HTTP clients 
 like curl and regular browsers like Firefox will be a challenge, since you're 
 operating at the HTML/JS level and not really the HTTP level.  If you find a 
 great solution, please post it back!
 
 - Rob
 
 On Mon, Dec 28, 2009 at 1:42 PM, Matt Kennedy stinkym...@gmail.com wrote:
 If you want this to be an official HTTP redirect, for example a 301, 302, 
 303, 307 status code, then you can set that status code in the response 
 object and set the entity to be some html that will do your refresh to the 
 new URL, plus the countdown.  Be careful if you choose to go with 301 or 302 
 as the response code, read IETF RFC 2626 for details.

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

Re: how to set up client certificate in restlet 1.1.4 for HTTPS?

2009-12-16 Thread Matt Kennedy
Here's the server code I use, my keys/certs may be set up a little
differently from yours though, but this code supports client cert handshakes
using browser clients and curl clients.  In this case, the CAs that sign the
client certs are stored in /etc/pki/ca.jks along with the CA that signed
that ewallet.p12 file. Unfortunately, I don't have any restlet client code
to send you, but you can try testing by setting up a client cert in Firefox.

static void setUpSSL(Context workingCtx)
{
System.setProperty('javax.net.ssl.trustStore','/etc/pki/ca.jks');
System.setProperty('javax.net.ssl.trustStorePassword',
System.getenv('TRUSTSTORE_PASS'));
workingCtx.getParameters().add(sslContextFactory,
org.restlet.ext.ssl.PkixSslContextFactory);
workingCtx.getParameters().add(keystorePath,
/etc/pki/wallets/${System.getenv('VIRTUAL_HOST')}/ewallet.p12);
workingCtx.getParameters().add(keystorePassword,
System.getenv('KEYSTORE_PASS'));
workingCtx.getParameters().add(keystoreType, PKCS12);
workingCtx.getParameters().add(keyPassword,
System.getenv('KEY_PASS'));
workingCtx.getParameters().add(certAlgorithm, SunX509);
}

On Wed, Dec 16, 2009 at 11:06 AM, webp...@tigris.org wrote:

 Hi,

 I'm trying to use the Simple HTTPS library to set up a HTTPS connection
 with mutual PKI authentication, after successful server-only authentication.

 For the server-only authentication, I created a JKS keystore and modified
 the client/server samples in
 src\org.restlet.example\org\restlet\example\book\restlet\ch11\{BasicHttpsServer.java,BasicHttpsClient.java}
 to load that store.
 The client GET request returned the 200 OK.

 For the mutual authentication, the BasicHttpsServer.java becomes:

System.setProperty(javax.net.ssl.trustStore,
 keystoreFile.getAbsolutePath());
System.setProperty(javax.net.ssl.trustStorePassword, changeit);

// Component declaring only one HTTPS server connector.
Component component = new Component();
Server server = component.getServers().add(Protocol.HTTPS, 8182);
component.getDefaultHost().attach(/helloWorld, restlet);

// Update server's context with keystore parameters.
server.getContext().getParameters().add(keystorePath,
 keystoreFile.getAbsolutePath());
server.getContext().getParameters().add(keystorePassword,
 changeit);
server.getContext().getParameters().add(keyPassword, server);
server.getContext().getParameters().add(needClientAuthentication,
 true);


 and the BasicHttpsClient.java becomes:

System.setProperty(javax.net.ssl.trustStore,
 keystoreFile.getAbsolutePath());
System.setProperty(javax.net.ssl.trustStorePassword, changeit);

Component component = new Component();
Client client = component.getClients().add(Protocol.HTTPS);
client.getContext().getParameters().add(keystorePath,
 keystoreFile.getAbsolutePath());
client.getContext().getParameters().add(keystorePassword,
 changeit);
client.getContext().getParameters().add(keyPassword, server);

 which is very similar to the server. I used the same jks keystore file for
 both client and server to make sure they have the same CA. However, the
 client GET request returns this error status:

 Communication Error (1001) - Software caused connection abort: recv failed

 I also tried to load client side keystore with these:

System.setProperty(javax.net.ssl.keyStore,
 keystoreFile.getAbsolutePath());
System.setProperty(javax.net.ssl.keyStorePassword, changeit);

 But I got an error status:
 Communication Error (1001) - Default SSL context init failed: Cannot
 recover key

 I suspect the client would not find the key from the keystore because Java
 does not provide such property javax.net.ssl.keyPassword.

 Does anyone know what is wrong?

 For mutual authentication, how do I set up the trustStore on the server
 side, and how do I set up the keystore on the client side?

 Thanks a lot.

 Li

 --

 http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2430830


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

Re: Unauthenticated access returns 204.

2009-12-09 Thread Matt Kennedy
I've always thought that 401 Not Authorized was poorly chosen wording, 
because it really says the same thing as 403 Forbidden.  However, the 
requirement that a 401 status also MUST send a WWW-Authenticate header I think 
in practice has led 401 to really mean Not Authenticated and 403 to really 
mean Not Authorized. Whereas in the description of 403 in rfc2616 section 10 
explicitly states that Authentication will not help, which implies that 
either no authentication is possible, the user is simply trying to do something 
the server doesn't want done, or it implies that the user is in fact 
authenticated, and the server is saying the authenticated user isn't authorized 
to do that.

So where does that leave us?  I guess I think that the abstract implementation 
of Authenticator should not simply return 204 to the client if Authentication 
has been set to be required, and a concrete subclass has returned false in the 
authenticate() method.  It is OK, because it does in fact stop the filter, but 
I think it could be a little bit easier on the programmer implementing the 
concrete subclass.  Perhaps setting the status to 403 is more appropriate in 
this case.  Anyway, I trust the restlet team's judgement here, but if you 
decide to keep the behavior as it is, then I encourage you to document clearly 
that the unauthenticated() method will also need to be overridden in subclasses 
in order to produce behavior that results in a 401 or 403 upon returning false 
from the authenticate() method.  I would be happy to look at possible 
implementations of changing the default behavior if it is something the restlet 
team thinks would be worthwhile.

The good news is that as far as my current project goes, I have custom 
subclasses of Authenticators and Authorizers working very well and I really 
like the new security architecture, I'm just trying to figure out if this 
particular aspect of the behavior is as simple as it could be.

Thanks for your time,
Matt

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


Re: Unauthenticated access returns 204.

2009-12-08 Thread Matt Kennedy
Stephan, I did call a 204 an error, didn't I?  I should know better.  

I have done some digging and I think I see what's going on. The 
unauthenticated() method in the abstract Authenticator class never sets 
CLIENT_ERROR_UNAUTHORIZED in the response object.  I don't know whether it 
should or not. It makes subclassing Authenticator slightly easier if it does 
set that status.  It seems to me that if authentication is not optional, and it 
gets as far as the unauthenticated() method, then in addition to setting any 
challengeResponse.authenticated property to false and the 
clientInfo.authenticated property to false, the method can go ahead and set the 
status in the response object as well. Otherwise, anybody writing a subclass of 
Authenticator will have to subclass the unauthenticated() method as well in 
order to return a 401.  Which is completely fine, it just isn't as simple.  I'm 
going to get a checkout of svn tomorrow and I'll see if I can make this change 
without breaking anything and submit the code if everything works OK.

-Matt



On Dec 5, 2009, at 8:16 AM, Stephan Koops wrote:

 Hi Matt,
 
 maybe the reason is, that the status is set to 204, if there is no 
 entity (by Restlet). This must onky be done, if status is 200. Maybe 
 this check is missing. Try to check it with the debugger.
 
 BTW: 204 is not an error, it means ok, but no entity available.
 
 best regards
   Stephan
 
 Matt Kennedy schrieb:
 I'm trying to implement a custom authenticator class and I'm a little 
 stumped by the behavior so far.  When I override the authenticate() method 
 to always return false, I get back an HTTP 204 error.  However, if I have it 
 always return true, then the request goes through correctly, so I think I 
 have everything wired up the right way.  Based on my reading of the 
 available documentation, if authentication is set as required in the 
 Authenticator subclass (which is the default setting), then a 401 response 
 should be sent.  Is this a bug?  Or am I missing a required step in my 
 subclass implementation?
 
 Thanks,
 Matt
 
 The following illustrates the problem (in Groovy):
 
 import org.restlet.*;
 import org.restlet.data.*;
 import org.restlet.security.Authenticator;
 import org.restlet.representation.*;
 
 class TestAuthenticator extends Authenticator
 {
  @Override 
  public TestAuthenticator(Context ctx){ super(ctx); }
 
  @Override
  protected boolean authenticate(Request request, Response response)
  {
return false;
//return true;
  }
 }
 
 class TestRestlet extends Restlet
 {
  @Override
  public void handle(Request request, Response response) 
  {
response.setEntity(new StringRepresentation(hello, world\n, 
 MediaType.TEXT_PLAIN));
  }
 }
 
 def component = new Component();
 Server http = component.servers.add(Protocol.HTTP, 8181);
 component.clients.add(Protocol.FILE);
 Context workingCtx = http.context;
 def guard = new TestAuthenticator(workingCtx);
 def restlet = new TestRestlet();
 guard.setNext(restlet);
 component.defaultHost.attach(guard);
 component.start();
 
 --
 http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2426801
 
 
 --
 http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2427447

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

Unauthenticated access returns 204.

2009-12-04 Thread Matt Kennedy
I'm trying to implement a custom authenticator class and I'm a little stumped 
by the behavior so far.  When I override the authenticate() method to always 
return false, I get back an HTTP 204 error.  However, if I have it always 
return true, then the request goes through correctly, so I think I have 
everything wired up the right way.  Based on my reading of the available 
documentation, if authentication is set as required in the Authenticator 
subclass (which is the default setting), then a 401 response should be sent.  
Is this a bug?  Or am I missing a required step in my subclass implementation?

Thanks,
Matt

The following illustrates the problem (in Groovy):

import org.restlet.*;
import org.restlet.data.*;
import org.restlet.security.Authenticator;
import org.restlet.representation.*;

class TestAuthenticator extends Authenticator
{
  @Override 
  public TestAuthenticator(Context ctx){ super(ctx); }

  @Override
  protected boolean authenticate(Request request, Response response)
  {
return false;
//return true;
  }
}

class TestRestlet extends Restlet
{
  @Override
  public void handle(Request request, Response response) 
  {
response.setEntity(new StringRepresentation(hello, world\n, 
MediaType.TEXT_PLAIN));
  }
}

def component = new Component();
Server http = component.servers.add(Protocol.HTTP, 8181);
component.clients.add(Protocol.FILE);
Context workingCtx = http.context;
def guard = new TestAuthenticator(workingCtx);
def restlet = new TestRestlet();
guard.setNext(restlet);
component.defaultHost.attach(guard);
component.start();

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


Re: file extension changes on PUT

2009-11-19 Thread Matt Kennedy
Thierry,

This work-around is perfect for my current needs, thanks.

-Matt

On Nov 19, 2009, at 4:29 AM, Thierry Boileau wrote:

 Hello Matt,
 
 the current directory is based on a mapping between extensions and media 
 types (see the javadoc of the method MetadataService#addCommonExtensions).
 At this time, the extensions jpe, jpg, jpeg are all mapped with 
 the media type MediaType.IMAGE_JPEG, with a preference for the first 
 one. This can be updated by calling the #addExtension(String, Metadata, 
 boolean) method.
 This mapping does clearly not define a bijection, which leads to your 
 reported errors, in case the served directory contains already files 
 with unpreferred extensions such as jpg and jpeg.
 I've entered an issue for this: 
 http://restlet.tigris.org/issues/show_bug.cgi?id=953.
 
 Best regards,
 Thierry Boileau
 
 I have found some behavior that I think is incorrect when a jpeg is 
 PUT to a Directory.  I wrote a test server in groovy and a client in 
 curl to illustrate the problem, see below.  In summary, when a jpeg 
 image is PUT into a Directory resource with a URL like 
 http://host:port/tmp.jpg, the file extension gets changed to .jpe.  A 
 subsequent retrieval of the same URL does work, but directory listings 
 show the wrong file name.  Similarly, and the reason this is a 
 problem for me, other programs that run on the server need to deal 
 with the files with the same name that users PUT as the resource 
 name.  In this case, I need users to be able to overwrite a file 
 called tmp.jpg that already exists in the directory. Instead, I wind 
 up with two files, tmp.jpg and tmp.jpe.  When the user subsequently 
 request http://host:port/tmp.jpg immediately after they perform a PUT, 
 they get the original image back, not the one that they just PUT to 
 the system to replace the original.
 
 I suspect this might happen with other media types that have multiple 
 valid extensions.
 
 I am testing against 2.0m5 for jse.  I tried to test this with a 
 recent checkout from svn, but building yielded some gwt errors I don't 
 know how to work around.
 
 Is this a configuration problem on my end?  Or could this be a bug?
 
 Thanks for your time,
 Matt
 
 //Groovy test server, I can rewrite this is java if necessary.
 import org.restlet.*;
 import org.restlet.resource.Directory;
 import org.restlet.data.Protocol;
 
 class TestDirApp extends Application
 {
  @Override
  public Restlet createInboundRoot()
  {
def dir = new Directory(getContext(), 'file:///tmp')
dir.modifiable = true;
//dir.negotiateContent = false; //NB have tried this both ways
println(Negotiating: ${dir.isNegotiateContent()});
dir.listingAllowed = true;
return dir;
  }
 }
 
 def component = new Component();
 Server http = component.servers.add(Protocol.HTTP, 8181);
 component.clients.add(Protocol.FILE);
 Context workingCtx = http.context;
 def app = new TestDirApp();
 component.defaultHost.attach(app);
 component.start();
 
 
 #curl client
 curl -i --request PUT --data-binary @tmp.jpg --header Content-Type: 
 image/jpeg http://localhost:8181/tmp.jpg;
 HTTP/1.1 201 The request has been fulfilled and resulted in a new 
 resource being created
 Content-Length: 0
 Date: Tue, 17 Nov 2009 16:23:00 GMT
 Accept-Ranges: bytes
 Server: Restlet-Framework/2.0m5
 Connection: close
 
 
 --
 http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2419969

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


Re: Router in servelet not routing to correct resource

2009-10-22 Thread Matt Stromske
!DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN
html
head
  meta content=text/html;charset=ISO-8859-1 http-equiv=Content-Type
/head
body bgcolor=#ff text=#00
Thanks.nbsp; That did it.nbsp; I think I'm losing it because I thought I tried
that and it didn't work.nbsp; br
Thanks again,br
Mattbr
br
Matt Kennedy wrote:
blockquote cite=mid:682073e5-25b8-47b9-970e-182d4990e...@gmail.com
 type=cite
  pre wrap=I'm not 100% sure based on that description, but try setting 
your  
second router line to:

router.attach(/test1)


On Oct 21, 2009, at 1:19 PM, Matt Stromske wrote:

  /pre
  blockquote type=cite
pre wrap=Hello,

I can't figure out why my router isn't routing to the correct  
resource.  It always seems to route to the default route.  I have 2  
routes:
   router.attachDefault(DefaultResource.class);
router.attach(/gpsh/test1,TestResource.class);

My servlet container mapping:
lt;url-patterngt;/gpsh/*lt;/url-patterngt;


When I attempt to go to /gpsh/test1, I end up going to the default  
route.

Any idea how I can get the routing corrected?

Thanks,
Matt

--
a class=moz-txt-link-freetext 
href=http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2409873;http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447amp;dsMessageId=2409873/a
/pre
  /blockquote
  pre wrap=!
--
a class=moz-txt-link-freetext 
href=http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2409935;http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447amp;dsMessageId=2409935/a
  /pre
/blockquote
br
pre class=moz-signature cols=72-- 

Matt Stromske
Software Engineer
Singlewire Software, LLC
a class=moz-txt-link-abbreviated 
href=http://www.singlewire.com;www.singlewire.com/a
--
608.298.1020
a class=moz-txt-link-abbreviated 
href=mailto:matt.strom...@singlewire.com;matt.strom...@singlewire.com/a
/pre
/body
/html

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


Router in servelet not routing to correct resource

2009-10-21 Thread Matt Stromske
Hello,
  
I can't figure out why my router isn't routing to the correct resource.  It 
always seems to route to the default route.  I have 2 routes:
router.attachDefault(DefaultResource.class);
router.attach(/gpsh/test1,TestResource.class);

My servlet container mapping:
url-pattern/gpsh/*/url-pattern
   

When I attempt to go to /gpsh/test1, I end up going to the default route.

Any idea how I can get the routing corrected?

Thanks,
Matt

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


Re: Router in servelet not routing to correct resource

2009-10-21 Thread Matt Kennedy
I'm not 100% sure based on that description, but try setting your  
second router line to:

router.attach(/test1)


On Oct 21, 2009, at 1:19 PM, Matt Stromske wrote:

 Hello,

 I can't figure out why my router isn't routing to the correct  
 resource.  It always seems to route to the default route.  I have 2  
 routes:
router.attachDefault(DefaultResource.class);
 router.attach(/gpsh/test1,TestResource.class);

 My servlet container mapping:
 url-pattern/gpsh/*/url-pattern


 When I attempt to go to /gpsh/test1, I end up going to the default  
 route.

 Any idea how I can get the routing corrected?

 Thanks,
 Matt

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

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


Client (HTTP) and query encoding of space characters

2009-10-01 Thread Matt Stromske
Hello,  I'm using a Client with the HTTP protocol.  I'm sending a GET with a 
query and I noticed that space characters are encoded to + (plus) signs.  I 
would like them encoded to %20 instead.  Is there a way to do this?

Thanks,
Matt

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


Extracting XML from Representation from POST

2009-09-22 Thread Matt Stromske
Hello,
  How do you extract the XML from a POST request?  I've tried using the input 
stream of the representation in conjunction with a SAXBuilder (JDOM) object, 
but that doesn't seem to work.  Then, I tried 'Form' and got a little further.  
I noticed the Form was populated.  How can you pull names/values from the Form?

Thanks,
Matt

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


Setting POST parameters

2009-09-11 Thread Matt Stromske
Hello, 

How do you set POST parameters in the body of the message?

Thanks,
Matt

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


RE: Possible GAE Client issue.

2009-06-30 Thread Matt
Thanks for your response. Bug report added.

Cheers,
Matt


jlouvel wrote:
 
 Hi guys,
 
 By default, we leverage the HttpURLConnection class which has been
 reimplemented on top of URLFetcher so this should work.
 
 Thierry will finish his work on automated Restlet editions next week or so
 and we'll be able to resolve such issue more quickly and precisely.
 
 For now, I suggest to enter a bug report.
 
 Best regards,
 Jerome Louvel
 --
 Restlet ~ Founder and Lead developer ~ http://www.restlet.org
 Noelios Technologies ~ Co-founder ~ http://www.noelios.com
 
 
 -Message d'origine-
 De : news [mailto:n...@ger.gmane.org] De la part de Philippe Marschall
 Envoyé : vendredi 26 juin 2009 07:14
 À : discuss@restlet.tigris.org
 Objet : Re: Possible GAE Client issue.
 
 Matt wrote:
 Hi there,
 
 I'm getting the following error whenever I attempt to use the client
 class
 from within the GAE.
 
 Client client = new Client(Protocol.HTTP);
 Response response = client.get(http://www.google.com;);
 
 Internal Connector Error (1002) - access denied
 (java.net.SocketPermission
 www.google.com resolve)
 
 NB: I'm not using anything other than the default provided by restlet
 i.e.
 I'm not using apache's HttpClient.
 
 I've updated the gae jar to be the latest snapshot as of yesterday but
 I'm
 still getting this problem.
 
 Any suggestions? Or is it a potential bug? 
 
 You're not allowed to open sockets on GAE/J.
 
 Cheers
 Philippe
 
 --
 http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=23655
 93
 
 --
 http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2366277
 
 

-- 
View this message in context: 
http://n2.nabble.com/Possible-GAE-Client-issue.-tp3151643p3185766.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


GAE + Restlet issue

2009-06-29 Thread Matt
 started.

Any ideas? Or could this be a possible bug?

Thanks in advance,
Matt

-- 
View this message in context: 
http://n2.nabble.com/GAE-%2B-Restlet-issue-tp3178764p3178764.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


Designing restlet applications

2009-06-15 Thread Matt
Hi there,

I though I would ask you all a couple of questions about designing Restlet
applications.

I want to use the minimal number of resources that perform operations on
Users and display them in different ways using Freemarker.

So I might have some routes like:

router.attach(/users, UsersResource.class);
router.attach(/user/{id}, UserResource.class);

That should handle the basic stuff.

Now I'll need to support the following:

Displaying a user, adding a user and editing a user. 

Now for each of these things I might need to do slightly different things.

Display a user -- Load the user -- display with view.ftl
Add a user -- Sets some defaults -- display with add.ftl
Edit a user -- Load the user --- display with edit.ftl

I can see that I could end up with additional routes like this:

router.attach(/users/add, UserAddResource.class) 
router.attach(/user/i{id}/edit, UserEditResource.class)  

I don't really want to d this if I can avoid it.

Any suggestions on how I can avoid doing the above?

Thanks in advance,
Matt
-- 
View this message in context: 
http://n2.nabble.com/Designing-restlet-applications-tp3084513p3084513.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


Setting Status from the write method of a Representation

2009-06-12 Thread Matt Kennedy
In order to support streaming writes of large ResultSets from a database, I am 
deferring execution of my query until the write() method of my Representations. 
 The resource is responsible for configuring the query string and handling 
connection issues with the DB, but if there is a problem with the URL which 
results in some bad sql, and an exception is thrown inside the write method, 
the server always returns a 500 response even though I have subclassed 
StatusService and it works for exceptions thrown in the Resource.

Is this expected behavior?  Are there suggestions on how I can set an error 
status if an exception occurs in a representation?

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


Re: restlet server NoSuchMethodError

2009-06-05 Thread Matt Stromske
I just realized I am using an old version of Tomcat (4.1) and the 
servlet spec for that version of Tomcat does not have support the 
'getLocalAddr' method.   Darn it.



Stephan Koops wrote:
 Hi Matt,

 looks like that the JARs are from different Restlet versions.

 best regards
Stephan

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

-- 
Matt Stromske
Software Engineer
Singlewire Software, LLC
www.singlewire.com
--
608.298.1020
matt.strom...@singlewire.com

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


Re: Restlet 2.0 M3 released

2009-05-28 Thread Matt
Hi Jerome,

I think I might have found a small issue effecting the Directory class since
upgrading from M2 - M3.

If I view my website in Safari and reload it the served statically files
(css/js/images etc) by the directory class now seem to throw 405 errors.

Even if type in the full URL to the file in safari I get a 405. 

If I revert back to 1.2-M2 again these problems go away.

Matt

PS: Thanks for all your hard work. Great product.



jlouvel wrote:
 
 Hi all,
 
  
 
 Restlet 2.0 M3 has just been kicked out:
 
 http://blog.noelios.com/2009/05/27/restlet-2-0-m3-released/
 
  
 
 We hope you will like it and strongly recommend upgrading from 1.2 M2 as
 it
 provides more stability, especially on the new APIs front (resource and
 security) and includes fresh JARs for all supported editions (GWT, GAE and
 Android).
 
  
 
 Best regards,
 Jerome Louvel
 --
 Restlet ~ Founder and Lead developer ~  http://www.restlet.org/
 http://www.restlet.org
 Noelios Technologies ~ Co-founder ~  http://www.noelios.com/
 http://www.noelios.com
 
 --
 http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2355707
 

-- 
View this message in context: 
http://n2.nabble.com/Restlet-2.0-M3-released-tp2980083p2990789.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


Freemarker CLAP and jarfiles.

2009-05-22 Thread Matt
Hi there,

I've got a small issue that I'm trying to resolve. 

I'm using Freemarker to access templates stored within the classpath hence
I'm using the CLAP protocol. 

I can run my application fine through the IDE but when I attempt to run it
as a jarred application if fails to find any of the templates. I get the
following:

server$ java -jar myapplication.jar 127.0.0.1 8080

May 23, 2009 4:29:11 PM org.restlet.ext.grizzly.GrizzlyServerHelper start
INFO: Starting the Grizzly [HTTP] server
0 [Grizzly-WorkerThread(0)] DEBUG freemarker.cache  - Could not find
template in cache, creating new one; id=[home.html[en_US,MacRoman,parsed] ]
May 23, 2009 4:29:17 PM org.restlet.ext.freemarker.TemplateRepresentation
getTemplate
WARNING: Unable to get the template home.html. Error message: Template
home.html not found.
May 23, 2009 4:29:17 PM org.restlet.engine.LogFilter afterHandle
INFO: 2009-05-2316:29:17127.0.0.1   -   127.0.0.1   
8080GET /   -   200 -   -   101
http://localhost:8080   Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US;
rv:1.9.0.10) Gecko/2009042315 Firefox/3.0.10-
May 23, 2009 4:29:17 PM org.restlet.ext.freemarker.TemplateRepresentation
write
WARNING: Unable to write the template representation. No template found.

Even though home.html is actually in the jarfile.

I've got the usual stuff set up:

 getConnectorService().getServerProtocols().add(Protocol.HTTP);
 getConnectorService().getClientProtocols().add(Protocol.CLAP);

This is how I've setup my Freemarker configuration.

public enum Freemarker {
INSTANCE;

private Configuration configuration = null;

private Freemarker() {
configuration = new Configuration();
configuration.setClassForTemplateLoading(Freemarker.class, ../..);
configuration.setObjectWrapper(new DefaultObjectWrapper());
configuration.setDateFormat( dd, );
configuration.setDateTimeFormat( dd,  hh:mm:ss);
configuration.setTimeFormat(hh:mm:ss);
configuration.setNumberFormat(0);
configuration.setWhitespaceStripping(false);
configuration.setBooleanFormat(On,Off);
configuration.addAutoImport(layout, core/ui/layouts.html);
configuration.addAutoImport(form, core/ui/form.html);
configuration.setURLEscapingCharset(UTF-8);
}

public TemplateRepresentation getTemplate(String name) {
return new TemplateRepresentation(name + .html, configuration,
MediaType.TEXT_HTML);
}

public Representation getTemplate(String name, Object object) {
return new TemplateRepresentation(name + .html, configuration,
object, MediaType.TEXT_HTML);
}
}

And in my code I access templates like this

class UsersResource extends ServerResource {

  @Get() 
  public Representation doGet() {
return Freemarker.INSTANCE.getTemplate(users/ui/users);
  }
}

Any ideas about what I might be doing wrong?

Thanks in advance,
Matt

PS: I've built my application using the 1.2-SNAPSHOT.
-- 
View this message in context: 
http://n2.nabble.com/Freemarker-CLAP-and-jarfiles.-tp2960919p2960919.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


Re: Tomcat not shutting down with Restlet

2009-05-14 Thread Matt Stromske




I found the problem: a pilot error on my part.  Not sure what I was
sniffing the day I implemented it, but I had put in a server component
that started up upon Tomcat initialization.  I think it "found" its way
in when I  was testing the Restlet standalone java app and ported it to
a servlet.  Anyway, the server wasn't getting shut down when Tomcat was
shutting down.  So I simply removed it.  

Thanks for all the advice.

Matt

Jerome Louvel wrote:

  Hi Matt,

One way to check from where the issue comes is to trim your application to
the strict minimum and check if you still observer this issue.

In such case, please open a defect report and attach the same applications
with steps to reproduce the issue and we'll look at it.

Best regards,
Jerome Louvel
--
Restlet ~ Founder and Lead developer ~ http://www.restlet.org
Noelios Technologies ~ Co-founder ~ http://www.noelios.com




-Message d'origine-
De : Michael McCallum [mailto:gho...@xtra.co.nz] 
Envoyé : mardi 12 mai 2009 01:08
À : discuss@restlet.tigris.org
Objet : Re: Tomcat not shutting down with Restlet

On Tue, 12 May 2009 06:47:53 Matt Stromske wrote:
  
  
Still no reply on this yet.  Anyone out there with some advice?

Thanks,
Matt

--


  
  http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=21951
79
  
  
check to see you have not spawned non daemon threads... or thread pool
executors not shut down...

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


-- 
Matt Stromske
Software Engineer
Singlewire Software, LLC
www.singlewire.com
--
608.298.1020
matt.strom...@singlewire.com






Freemarker extension minor addition

2009-04-27 Thread Matt
Hi,

At present in the Freemarker TemplateRepresentation class if you
_incorrectly_ specify the name of a template you'll eventually get a
NullPointerException when the write(OutputStream) method is invoked.

Ideally I'd like to be able to check if the template has been found or not
so that I could potentially respond with a 404 or whatever.

So could we have a method like isTemplateLoaded() or something similar added
to the TemplateRepresentation class to support this?

Cheers,
Matt
-- 
View this message in context: 
http://n2.nabble.com/Freemarker-extension-minor-addition-tp2729880p2729880.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


Re: securing the whole application

2009-04-27 Thread Matt
Hi João,

Luckily Restlet makes this sort of thing really easy. 

All you need to do is make the Guard (or ChallengeGuard in M2) handle and
forward the requests once you've authenticated the user. I.e something like:

 public Restlet createRoot() {

Router securedRoute = new Router(getContext());

securedRouter.add(/users, UsersResource.class);
securedRouter.add(/user/{id}, UserResource.class);

Guard guard = new Guard(getContext(), ChallengeScheme.HTTP_BASIC,
whatever);
guard.setNext(securedRoute);
return guard;
  }

Hope that vaguely helps,
Matt


João Pereira wrote:
 
 Hi, 
 
 How to secure all the application instead of each route?
 
 if this seems to be a newbie question it's because I'm a newbie :)
 
 --
 http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=1946647
 
 

-- 
View this message in context: 
http://n2.nabble.com/securing-the-whole-application-tp2726872p2729929.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


RE: File upload - as stream

2009-03-10 Thread Matt
Thanks, for some reason I missed that when looking at the apache fileupload api.

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


File upload - as stream

2009-03-09 Thread Matt Rutherford
Hi.

Is there a way to receive a file element from an html form without storing
it to disk?

I will be storing the file directly into a DB so no need to have it on disk
anywhere.

Would be nice to just stream bytes to the LargeObject.write() Postgres JDBC
method.

Sorry if this is a silly question, I'm a (enthusiastic) beginner with this
stuff. Any guidance much appreciated.

Thanks!

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

help with spring/servlet integration and applicaiton modificaton

2009-01-04 Thread matt
Hi There-

I have been using restlet for a few weeks steady now and love it but now have a 
problem with spring and servlets and complete integration. I am using as a base 
the spring cvs repository pointed to on the wiki and using. Here is my 
situation, not sure if I am attacking it correctly or if i can.

I want to make modifications to my 'base application' that is used in my 
servlet with the spring router. For example suppose I have a base application 
like this:

// Extends Application
public HwApplication() {
super();
TunnelService ts = new TunnelService(true,true,true,true,true);
ts.setMediaTypeParameter(mt);
this.setTunnelService(ts);
}

Here is one of the variations of my applicationContext-router.xml file that I 
used. I thought this would work from the docs on the wiki.

bean id=application class=com.hw.rest.HwApplication
/bean

bean id=root class=org.restlet.ext.spring.SpringRouter
constructor-arg ref=application /
property name=attachments
map
entry key=/foo  
value=com.hw.rest.HwResource /
/map
/property
/bean

What happens is that when com.hw.rest.HwResource is used it does not have a 
handle to my application but a generic restlet application. I have tried a 
variety of things from the wiki examples and also the CVS repo and nothing 
seems to work. So in my use case I am not getting the tunneling or the media 
conversion i need via my custom application..

Somewhere something is not getting bound correctly. This is happening in the 
servlet situation only. I am digging around the code now the best I can to see 
where things get switched up. I obviously and more sure on the correct binding 
order.

If anybody has advice or an example from their own work that does this I am 
super appreciative!

matt

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


RE: Re: question about spring example and uri extension parsing/best practices.

2008-12-23 Thread matt
Thanks you guys for the response. I actually had a dumb config problem in 
accessing the repo so i got the spring example configs now and things seem ok.

I will try exploring the tunnel service as well. Hopefully I can get everything 
configured through spring/servlet container with injection. We have a goal of 
deploying all through a servlet container with jetty or tomcat so hopefully I 
can get it all working there. 

Thanks to you guys for the help. It was a great stepping point!!!

matt

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


question about spring example and uri extension parsing/best practices.

2008-12-22 Thread matt
Hi there

Firstly I love restlet and much thanks to the people who work on it and i have 
been able to get up to speed really quickly.

I have two questions. One is where to find a complete example of the 
spring-restlet integration. I tried the cvs repo on the wiki and for some 
reason could never get there?!?

The next and more important REST and url extension and return format? I am in 
the quandry of deciding to do my rest API via extension or an 'optional' 
argument. I have included a snippit of my spring config below...

i.e.

1) myapi/v1/company/1.xml (or rss, json) bla bla bla

2) a) myapi/v1/company/1 - default xml
 b) myapi/v1/company/1format=xml
 c) myapi/v1/company/1/format=xml
 
2a and 2c works right out of the box so to speak. However 1 and 2b break since 
they pass in 1.xml and 1format=xml in the company {id} param. I would like to 
make my urls at least work for 2b or possibly 1 as well. I was not sure if I 
had to define some special regex in my routes for each pattern or if there was 
a global way to do cush filtering/url munging with restlet. Or if I had to roll 
my own. My end goal is to switch the accepted varient type based on either uri 
extension or optional format=XXX but get some strange behaviour in the routing 
itself.

My same was pulled from the spring sample and works wonderully minus this 
extension parsing issue.

entry key=/company/{id}
bean 
class=org.restlet.ext.spring.SpringFinder
lookup-method 
name=createResource bean=companyResource /
/bean
/entry

// this would work for xml but I do not want to do this for // every extension
entry key=/company/{id}.xml

Thanks in advance..

matt

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


Re: Static files: no available connector for FILE

2008-11-16 Thread Matt
keke iamkeke at gmail.com writes:

 
 
 Have you add FILE protocol into your Component? Like 
 component.getClients.add(Protocol.FILE)

 On Sun, Nov 16, 2008 at 12:54 PM, Matt restdev at randomcreation.com 
 wrote:
 WARNING: No available server connector supports the required protocols: FILE 
 .
 Please add the JAR of a matching connector to your classpath.
 Which jar file contains the connector implementation for the FILE protocol?
 Here is what I'm including:
 org.restlet.jar
 com.noelios.restlet.jar
 com.noelios.restlet.ext.simple_3.1.jar
 org.simpleframework_3.1/org.simpleframework.jar
 
 
 -- Cheers,Keke-We paranoid love life
 

Yes, here is my Component initialization:

public class HTTPServer 
 {
   public static final String ROOT_URI = 
file:///Users/matt/Workspace/devster/src/client/js/;
   public static void main( String[] args ) throws Exception
   {
 Component component = new Component();
 component.getServers().add( Protocol.HTTP, 8182 );
 component.getServers().add( Protocol.FILE );
 
component.getDefaultHost().attach( /app, new App() );
component.getDefaultHost().attach( /files, 
 new 
Application(component.getServers().getContext().createChildContext()) {
  public Restlet createRoot()
  {
Directory path = new Directory(getContext(), ROOT_URI);
path.setListingAllowed( true );
return path;
  }

} );
 component.start();
   }
 }






Static files: no available connector for FILE

2008-11-15 Thread Matt
WARNING: No available server connector supports the required protocols: FILE .
Please add the JAR of a matching connector to your classpath.

Which jar file contains the connector implementation for the FILE protocol?
Here is what I'm including:

org.restlet.jar
com.noelios.restlet.jar
com.noelios.restlet.ext.simple_3.1.jar
org.simpleframework_3.1/org.simpleframework.jar






Re: restlet noob: getting the CLAP (right)

2008-07-14 Thread Matt Brennan
Rob Heittman rob.heittman at solertium.com writes:
 
 I enthusiastically recommend using a 1.1 milestone or snapshot for any new
development.  The javadoc for ServerServlet says how to set a custom Component.
 (just like setting a custom Application, basically)  But you can't do that in
1.0.  I think the need to add extra client connectors and such was exactly what
drove that improvement to ServerServlet.

Rob,
   thanks for your help. the switch to the milestone (1.1) builds did the trick

cheers,

  matt



restlet noob: getting the CLAP (right)

2008-07-09 Thread Matt Brennan
Hi there,
 I am just hacking up my first restlet app. I'm really impressed so 
far. 

In addition to some resources served RESTfully, i'd also like to serve some
static comment of the classpath... and so have been trying a bunch of things to
expose a dir on the classpath without success so far. Any help appreciated!

env: restlet as war in jetty container.

web.xml:

   !-- Application class name --
   context-param
  param-nameorg.restlet.application/param-name
  param-value
 au.com.internode.udr2d2.SimpleUsageApplication
  /param-value
   /context-param

   !-- Restlet adapter --
   servlet
  servlet-nameRestletServlet/servlet-name
  servlet-class
 com.noelios.restlet.ext.servlet.ServerServlet
  /servlet-class
   /servlet

   !-- Catch all requests --
   servlet-mapping
  servlet-nameRestletServlet/servlet-name
  url-pattern/*/url-pattern
   /servlet-mapping

Restlet:
 public synchronized Restlet createRoot() {

Router router = new Router(getContext());

// Defines a default route with the URL format.
router.attachDefault(UsageFormatResource.class);

// Create a directory able to expose a hierarchy of files
Directory directory = new Directory(getContext(), clap://images/);
router.attach(directory);

// And add the
Route route = router.attach(SimpleUsageResource.URI_FORMAT,
SimpleUsageResource.class);
route.getTemplate().setMatchingMode(Template.MODE_EQUALS);

return router;
  }

--

The basic behavior is that a request to load:

http://localhost:8280/udr2d2/images/ajax-loader.gif

returns the default UsageFormatResource.class.

I tried adding the Protocol.CLAP and got a message to the client and server
connector list (this was a bit mindless - i'm not sure which i need! certainly
not both). And got a log message about the classpath loader not being loaded.

I've googled around a fair bit, read through the tute, looked through the Java
doc and tried rearranging ordering when creating the router. And eventually
thought: time to post.

Any help appreciated! :-)

  mattb



Re: restlet noob: getting the CLAP (right)

2008-07-09 Thread Matt Brennan
Forgot to add: in the war, the images directory sits at the top like:

 + WEB-INF
 +++ WEB-INF/web.xml
 + images
 +++ images/ajax-loader.gif

cheers,

  matt

(sorry for a few typos in the post!)
 



Re: restlet noob: getting the CLAP (right)

2008-07-09 Thread Matt Brennan
Rob Heittman rob.heittman at solertium.com writes:
 
 Be sure to do this in your Component constructor or another appropriate spot:
 getClients().add(Protocol.CLAP);

Rob,
   thanks very much for your reply. At you'll note, I am extending Application
and launching this with ServletServlet. That is, I'm not explicitly creating a
Component. So I have two follow ups:

1. If I do create a Component, how do I set up web.xml to launch the Component.

alternately,

2. If I stick to Application and ServletServlet, where is the appropriate spot
to add the Protocol.CLAP... in the context directives of web.xml?
 
 Then you want something like:
 Directory directory = new Directory(getContext(), clap://system/images/);

Ok, thanks - I will experiment. And thanks too for the info on caching.

Still poring through the APIs, examples, recipies and googling. Hmmm...
 
BTW, I am using: 1.0.10 (vice testing or svn suck).

Thanks again!

  mattb





RE: Re: StreamClientCall and FH exhaustion

2008-03-27 Thread Matt Reynolds
I'll give it a shot.  It may be a bit, we've solved the problem by moving the 
Apache's HTTPClient.

 

I'll also create an alternate test.  The one I wrote uses our internal 
services; obviously not a good candidate for a standalone test.

 

Thanks for looking into this

 

From: Kevin Conaway [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, March 25, 2008 2:23 PM
To: discuss@restlet.tigris.org
Subject: Re: StreamClientCall and FH exhaustion

 

Thanks Jerome.

Matt, could you see if that solves your problem as well?  If possible, can you 
attach your test case to 439?

On Tue, Mar 25, 2008 at 5:20 PM, Jerome Louvel [EMAIL PROTECTED] wrote:


Hi Kevin,

Very nice work (as always). The patch is in SVN trunk with some slight
improvements (more getContentLength() refactoring). Added complete()
handling on SimpleCall as well.


Best regards,
Jerome

 -Message d'origine-
 De : Kevin Conaway [mailto:[EMAIL PROTECTED]

 Envoyé : mardi 25 mars 2008 21:18

 À : discuss@restlet.tigris.org
 Objet : Re: StreamClientCall and FH exhaustion

 Yes.  If the response is chunked, the stream won't get
 closed.  In general, its not a great idea to close a socket
 *stream with the intention of closing the socket.

 I'm going to attach a patch to 439 with the following fixes:

 1.) In StreamClientCall, the response entity representation
 is now wrapped with a WrapperRepresentation that will close
 the associated socket when release() is called

 2.) In HttpServerCall, a new method called complete() was
 added that is called after commit().  StreamServerCall
 implements this by:
  A.) Flushing the response output stream
  B.) Exhausting the request input stream
  C.) Closing the request socket

 We exhaust the request input stream in case the client is
 still writing a request entity to the socket.  If we close
 the socket without reading the entire request, the client
 would get IOExceptions while it is still writing

 3.) I also modified
 StreamServerHelper.getRequestEntityStream() and
 StreamClientCall.getResponseEntityStream() to always return a
 KeepAliveInputStream.  The raw stream should never be
 exposed to callers as they can (and most likely will) close
 it at will.  Closing the input/output stream of a socket
 closes the entire socket so it should be protected as much as
 possible.

 Kevin


 On Tue, Mar 25, 2008 at 4:08 PM, Jerome Louvel
 [EMAIL PROTECTED] wrote:



   Hi Kevin,

   The InputRepresentation.release() method currently
 closes the underlying
   stream. As we currently don't support persistent
 connections, the closing of
   the input stream should actually close the socket input
 stream and as a
   consequence the socket.

   Do you obtain results that suggest it isn't happening like this?


   Best regards,
   Jerome

-Message d'origine-
De : Kevin Conaway [mailto:[EMAIL PROTECTED]

Envoyé : lundi 24 mars 2008 18:47

À : discuss@restlet.tigris.org
Objet : Re: StreamClientCall and FH exhaustion
   
Assuming the response entity is NOT pre-fetched, what about
wrapping the InputRepresentation used to store the response
so that release() closes the associated client socket.
   
Is it safe to assume that the socket is no longer needed once
a user calls release() on the Response entity?
   
   
On 3/23/08, Kevin Conaway [EMAIL PROTECTED] wrote:
   
  Jerome, I think you misunderstood me.  I was suggesting
it might be useful to allow the client to tell Restlet to
read and store the response entity to be consumed later.
   
  If the response entity is read right away and stored,
there would be no need to keep the connection open and the
entire request/response cycle could be completed in
 short order.
   
   
   
  On Sun, Mar 23, 2008 at 2:28 PM, Jerome Louvel
[EMAIL PROTECTED] wrote:
   
   
   
  Hi Kevin,
   
  Why not, but what would be the use case for
making such a request? If a
  client application isn't interested in the
entity, it can always issue a
  HEAD request.
   
   
  Best regards,
  Jerome
   
   -Message d'origine-
   De : Kevin Conaway
 [mailto:[EMAIL PROTECTED]
   
   Envoyé : samedi 22 mars 2008 13:33
   
   À : discuss@restlet.tigris.org
   Objet : Re: StreamClientCall and FH exhaustion
  
   Would it make sense to add an option to the
Client or Request
   that specifies whether Restlet should
prefetch the Response
   entity?  If the response entity was
prefetched

StreamClientCall and FH exhaustion

2008-03-17 Thread Matt Reynolds
I have a question around the StreamClientCall code and socket use.

The setup :
We're using a single client (org.restlet.Client) instance through a
number of threads (more than 10 or so), and calling a service repeatedly
that has a 50ms round-trip time.  We're using M1 (moving to M2, but more
on that later).

The symptoms :
During a performance test, after 20 minutes or so, we run out of file
handles.  We used lsof and /proc to isolate the number of handles used,
and noticed they're mostly sockets.

I created a small test harness around our usage of Client to see what
happens.  When I run this client very fast (30 threads, no waiting), I
can reproduce the problem in less than 10 seconds (on my local linux
machine, albeit not the same).

Anyway, the exception thrown comes through
StreamClientCall.createSocket:80/sendRequest:211 .  In that code, I
notice that the socket is created, but never closed.  Following the code
paths, I notice that an OutputStream and InputStream and gotten and
passed around to other methods, that end up calling OS.close and
IS.close.  However, the code paths appear to be calling close on the
wrapper instances of the OS/IS, either ChunkedOutputStream(which doesn't
call the destination.close)/KeepAliveOutputStream(which, seemingly
obviously, has no close) or ChunkedInputStream(no underlying
close)/InputEntityStream(same).

So, it simply appears that the Client socket isn't being closed.  I'm
guessing it should be closed as part of the finally block, with a null
check and then a call to isClosed?  Anyway, please let me know if I
debugged this path correctly and, if possible, what I should do to get
around this.

Thanks,
Matt


Possible bug?

2007-11-20 Thread Matt Allen
I am getting the following after processing the put method in my resource class:

Nov 20, 2007 2:30:41 PM com.noelios.restlet.LogFilter afterHandle
INFO: 2007-11-2014:30:41144.212.217.191 -   -   3000
PUT
/v1/entitlements/6901.xml   -   204 0   62811078
http://amatt:3000   -   -
Nov 20, 2007 2:30:41 PM com.noelios.restlet.ext.simple.SimpleProtocolHandler 
handle
INFO: Exception while closing the Simple response's output stream
java.io.IOException: Stream closed
at 
simple.http.MonitoredInputStream.ensureOpen(MonitoredInputStream.java:184)
at simple.http.MonitoredInputStream.read(MonitoredInputStream.java:83)
at java.io.FilterInputStream.read(FilterInputStream.java:66)
at
com.noelios.restlet.ext.simple.SimpleProtocolHandler.handle(SimpleProtocol
Handler.java:75)
at simple.http.Dispatcher.run(Dispatcher.java:83)
at simple.util.process.Daemon.execute(Daemon.java:121)
at simple.util.process.Daemon.run(Daemon.java:106)

The put method is is as follows:
@Override
public void put(Representation entity) {
  System.out.println(here1:  + entity.getMediaType());
  System.out.println(web representation: );
  try  {
System.out.println(entity.getText());
  }  catch (Exception e)  {
e.printStackTrace();
  }
  getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
}

I some some posts that could potentially have been related, but they alluded to
a fix that was implemented.  Is this the same bug?  Can I solve it (correctly)
by simply removing the call to close in SimpleProtocolHandler?  Any feedback
would be appreciated.

Thank you,
Matt


posting xml

2007-08-06 Thread matt
Does anyone have an example they'd be willing to share demonstrating how to
properly post an xml document to a restlet service?  I've been unsuccessful so
far with the following, as well as several other alternatives.  

StringRepresentation represent = new StringRepresentation(xmlString,
MediaType.APPLICATION_XML);
Client client = new Client(Protocol.HTTP);
Response response =
client.post(http://127.0.0.1:8080/Resources/api/department;, represent);


In general, I have yet to see anything show up on the service side. And the
client side throws the following error when trying the above:

Unable to complete the HTTP call due to a communication error with the remote
server. socket closed.

Thanks,
matt