Re: Examples of Tanuki wrapper usage with a Restlet application

2011-03-31 Thread Tal Liron
You can check out the daemon support page for Prudence (which is based 
on Restlet):

http://threecrickets.com/prudence/manual/daemon/

Prudence comes with working configuration files for Tanuki's Wrapper and 
for YAJSW. It comes with Apache Commons Daemon ready to run, with a 
rather sophisticated bash and Windows script.

-Tal

On 03/31/2011 01:53 PM, Fabian Mandelbaum wrote:
> Hello,
>
> I'd like to know if there's some examples (and where are them, of
> course) on using Tanuki's wrapper to 'control' (startup, shutdown) a
> Restlet application.
>
> I'm currently using a 'main' class which sets my Application instance,
> starts needed services, and starts the Application, together with a
> shutdown hook to shut itself down when:
> 1) the user hits Ctrl+C on the console where my app is running; or
> 2) a POST is gotten on /system/control/shutdown
>
> and am having problems with dangling Java processes left around and
> not really 'clean' shutdown.
>
> I'm using the Jetty server connector.
>
> Any ideas/help is appreciated. Thanks in advance.
>

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


Examples of Tanuki wrapper usage with a Restlet application

2011-03-31 Thread Fabian Mandelbaum
Hello,

I'd like to know if there's some examples (and where are them, of
course) on using Tanuki's wrapper to 'control' (startup, shutdown) a
Restlet application.

I'm currently using a 'main' class which sets my Application instance,
starts needed services, and starts the Application, together with a
shutdown hook to shut itself down when:
1) the user hits Ctrl+C on the console where my app is running; or
2) a POST is gotten on /system/control/shutdown

and am having problems with dangling Java processes left around and
not really 'clean' shutdown.

I'm using the Jetty server connector.

Any ideas/help is appreciated. Thanks in advance.

-- 
Fabián Mandelbaum
IS Engineer

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


Re: Setting the keystore password for SSL

2011-03-31 Thread Tal Liron
I can confirm that this is also true for Restlet 2.0.6. The blog 
announcement indicated that Jetty was upgraded, but I guess this 
happened only in the 2.1 branch. Jetty 7.3 does not work in Restlet 2.0.

-Tal

On 03/18/2011 03:09 PM, John Karp wrote:
> I found the problem. Apparently restlet-jse-2.0.5 does not work with 
> jetty-7.3.1. I had to downgrade jetty to version 7.2.2, and then SSL worked.
>
> Should I file a bug?
>
> -John
>
> --
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2712441

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


Re: Different @Post: xml, json and java String

2011-03-31 Thread Tim Peierls
Thank you, Fabian! This is the kind of thing that should go into the wiki
(and the book!). It seems like dozens of people have run into the same
situation, and it could all be avoided by saying this clearly up front.

--tim

On Thu, Mar 31, 2011 at 12:17 PM, Fabian Mandelbaum
wrote:

> *That's because Restlet's content negotiation algorithm "prefers" the
> 'generic' @Get annotation over the more 'specific' @Get(MEDIA_TYPE)
> ones.
> *
> You'll have to decide which are the representations you plan to return
> in the response, which is the 'default' one, and do something like
> this (assuming JSON is the desired 'default'):
>
> @Get("json")
> public JsonRepresentation toJSON() {
>  // Build up and return JSON here
> }
>
> @Get("xml")
> public XmlRepresentation toXML() {
>  // Build up and return XML here
> }
>
> // Other @Get(SPECIFIC_MEDIA_TYPE) here without a @Get annotated
> method that doesn't specify the media type it will handle back
>
> Hope this helps,
>
> good luck.
>
> On Thu, Mar 31, 2011 at 12:35 PM, Daniele Dellafiore
>  wrote:
> > I've tried with the @Get
> >
> >@Get("json")
> >public JsonRepresentation represent() {
> >   return new JsonRepresentation(new JSONArray(find()));
> >}
> >
> >public List find() {
> >   return getApplication().getSubscriptionService().findTenants();
> >}
> >
> > without the @Get on the second method, works:
> >
> > clientResource.get(JsonRepresentation.class);
> >
> > If I add the annotation, the request arrives to find() method, and fails
> to
> > return a Json.
> >
> >
> > On Wed, Mar 23, 2011 at 11:23 AM, Thierry Boileau
> >  wrote:
> >>
> >> Hello Daniele,
> >>
> >> >What if the parameter is a Map or a generic POJO?
> >> the parameters of the annotation deal with the content negotiation
> >> feature, that is to say a choice made according to the media type of the
> >> sent entity, the parameter type of the Java method, and the conversion
> >> capability of the application (in a few words : the available
> converters).
> >> If the representation of the POJO or MAP is available in JSON format,
> the
> >> @Post("json") methoed will be chosen.
> >>
> >> > If I remove the annotation from the first method, everything works.
> >> > There is a notation to say to the first method he is waiting for a
> >> > String class?
> >> As there is competition between converters, I guess the default
> converter
> >> should be chosen only if any other available converter does not match
> (see
> >> this RFE http://restlet.tigris.org/issues/show_bug.cgi?id=1093).
> >> As a workaround, or as a matter of test, can you test to put the
> >> @Post("json") method before the other one in the code of your class?
> >>
> >> Best regards,
> >> Thierry Boileau
> >>
> >>
> >>> that works, I did not think about it, even if it's in the book :)
> >>> but is not documented in the API.
> >>>
> >>> What if the parameter is a Map or a generic POJO?
> >>>
> >>> On Wed, Mar 23, 2011 at 12:07 AM, Fabian Mandelbaum
> >>>  wrote:
> 
>  Hello Daniele,
> 
>  @Post("txt")
> 
>  should accept strings. Test it though ;-)
> 
>  On Tue, Mar 22, 2011 at 1:07 PM, Daniele Dellafiore <
> ilde...@gmail.com>
>  wrote:
>  > Hi.
>  >
>  > I built a server resource with a
>  >
>  >@Post
>  >public void request(final String email) { }
>  >
>  > that works great with the restlet client. With a real form I have
> two
>  > options: json/xml, say json, or post parameters.
>  >
>  > Json, I just add
>  >
>  >@Post("json")
>  >public void xml(final Representation representation) { ...}
>  >
>  > in which parse the email from the json and call the request(String
>  > email) so
>  > I do not duplicate code.
>  > There is a problem here: the application/json  post does not end in
>  > the
>  > @Post("json"), everything falls in the first @Post.
>  > If I remove the annotation from the first method, everything works.
>  >
>  > There is a notation to say to the first method he is waiting for a
>  > String
>  > class?
>  >
>  > Thanks.
>  > --
>  > Daniele Dellafiore
>  > http://danieledellafiore.net
>  >
> 
> 
> 
>  --
>  Fabián Mandelbaum
>  IS Engineer
> 
>  --
> 
> 
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2713282
> >>>
> >>
> >
> >
>
>
>
> --
> Fabián Mandelbaum
> IS Engineer
>
> --
>
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2715672
>

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

Re: Different @Post: xml, json and java String

2011-03-31 Thread Fabian Mandelbaum
That's because Restlet's content negotiation algorithm "prefers" the
'generic' @Get annotation over the more 'specific' @Get(MEDIA_TYPE)
ones.

You'll have to decide which are the representations you plan to return
in the response, which is the 'default' one, and do something like
this (assuming JSON is the desired 'default'):

@Get("json")
public JsonRepresentation toJSON() {
 // Build up and return JSON here
}

@Get("xml")
public XmlRepresentation toXML() {
 // Build up and return XML here
}

// Other @Get(SPECIFIC_MEDIA_TYPE) here without a @Get annotated
method that doesn't specify the media type it will handle back

Hope this helps,

good luck.

On Thu, Mar 31, 2011 at 12:35 PM, Daniele Dellafiore
 wrote:
> I've tried with the @Get
>
>    @Get("json")
>    public JsonRepresentation represent() {
>   return new JsonRepresentation(new JSONArray(find()));
>    }
>
>    public List find() {
>   return getApplication().getSubscriptionService().findTenants();
>    }
>
> without the @Get on the second method, works:
>
> clientResource.get(JsonRepresentation.class);
>
> If I add the annotation, the request arrives to find() method, and fails to
> return a Json.
>
>
> On Wed, Mar 23, 2011 at 11:23 AM, Thierry Boileau
>  wrote:
>>
>> Hello Daniele,
>>
>> >What if the parameter is a Map or a generic POJO?
>> the parameters of the annotation deal with the content negotiation
>> feature, that is to say a choice made according to the media type of the
>> sent entity, the parameter type of the Java method, and the conversion
>> capability of the application (in a few words : the available converters).
>> If the representation of the POJO or MAP is available in JSON format, the
>> @Post("json") methoed will be chosen.
>>
>> > If I remove the annotation from the first method, everything works.
>> > There is a notation to say to the first method he is waiting for a
>> > String class?
>> As there is competition between converters, I guess the default converter
>> should be chosen only if any other available converter does not match (see
>> this RFE http://restlet.tigris.org/issues/show_bug.cgi?id=1093).
>> As a workaround, or as a matter of test, can you test to put the
>> @Post("json") method before the other one in the code of your class?
>>
>> Best regards,
>> Thierry Boileau
>>
>>
>>> that works, I did not think about it, even if it's in the book :)
>>> but is not documented in the API.
>>>
>>> What if the parameter is a Map or a generic POJO?
>>>
>>> On Wed, Mar 23, 2011 at 12:07 AM, Fabian Mandelbaum
>>>  wrote:

 Hello Daniele,

 @Post("txt")

 should accept strings. Test it though ;-)

 On Tue, Mar 22, 2011 at 1:07 PM, Daniele Dellafiore 
 wrote:
 > Hi.
 >
 > I built a server resource with a
 >
 >    @Post
 >    public void request(final String email) { }
 >
 > that works great with the restlet client. With a real form I have two
 > options: json/xml, say json, or post parameters.
 >
 > Json, I just add
 >
 >    @Post("json")
 >    public void xml(final Representation representation) { ...}
 >
 > in which parse the email from the json and call the request(String
 > email) so
 > I do not duplicate code.
 > There is a problem here: the application/json  post does not end in
 > the
 > @Post("json"), everything falls in the first @Post.
 > If I remove the annotation from the first method, everything works.
 >
 > There is a notation to say to the first method he is waiting for a
 > String
 > class?
 >
 > Thanks.
 > --
 > Daniele Dellafiore
 > http://danieledellafiore.net
 >



 --
 Fabián Mandelbaum
 IS Engineer

 --

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



-- 
Fabián Mandelbaum
IS Engineer

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


Re: Different @Post: xml, json and java String

2011-03-31 Thread Daniele Dellafiore
I've tried with the @Get

   @Get("json")
   public JsonRepresentation represent() {
  return new JsonRepresentation(new JSONArray(find()));
   }

   public List find() {
  return getApplication().getSubscriptionService().findTenants();
   }

without the @Get on the second method, works:

clientResource.get(JsonRepresentation.class);

If I add the annotation, the request arrives to find() method, and fails to
return a Json.


On Wed, Mar 23, 2011 at 11:23 AM, Thierry Boileau <
thierry.boil...@noelios.com> wrote:

> Hello Daniele,
>
>
> >What if the parameter is a Map or a generic POJO?
> the parameters of the annotation deal with the content negotiation feature,
> that is to say a choice made according to the media type of the sent entity,
> the parameter type of the Java method, and the conversion capability of the
> application (in a few words : the available converters).
> If the representation of the POJO or MAP is available in JSON format, the
> @Post("json") methoed will be chosen.
>
>
> > If I remove the annotation from the first method, everything works.
> > There is a notation to say to the first method he is waiting for a String
> class?
> As there is competition between converters, I guess the default converter
> should be chosen only if any other available converter does not match (see
> this RFE http://restlet.tigris.org/issues/show_bug.cgi?id=1093).
> As a workaround, or as a matter of test, can you test to put the
> @Post("json") method before the other one in the code of your class?
>
> Best regards,
> Thierry Boileau
>
>
>
> that works, I did not think about it, even if it's in the book :)
>> but is not documented in the API.
>>
>> What if the parameter is a Map or a generic POJO?
>>
>>
>> On Wed, Mar 23, 2011 at 12:07 AM, Fabian Mandelbaum <
>> fmandelb...@gmail.com> wrote:
>>
>>> Hello Daniele,
>>>
>>> @Post("txt")
>>>
>>> should accept strings. Test it though ;-)
>>>
>>> On Tue, Mar 22, 2011 at 1:07 PM, Daniele Dellafiore 
>>> wrote:
>>> > Hi.
>>> >
>>> > I built a server resource with a
>>> >
>>> >@Post
>>> >public void request(final String email) { }
>>> >
>>> > that works great with the restlet client. With a real form I have two
>>> > options: json/xml, say json, or post parameters.
>>> >
>>> > Json, I just add
>>> >
>>> >@Post("json")
>>> >public void xml(final Representation representation) { ...}
>>> >
>>> > in which parse the email from the json and call the request(String
>>> email) so
>>> > I do not duplicate code.
>>> > There is a problem here: the application/json  post does not end in the
>>> > @Post("json"), everything falls in the first @Post.
>>> > If I remove the annotation from the first method, everything works.
>>> >
>>> > There is a notation to say to the first method he is waiting for a
>>> String
>>> > class?
>>> >
>>> > Thanks.
>>> > --
>>> > Daniele Dellafiore
>>> > http://danieledellafiore.net
>>> >
>>>
>>>
>>>
>>> --
>>> Fabián Mandelbaum
>>> IS Engineer
>>>
>>> --
>>>
>>> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2713282
>>>
>>
>>
>

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

RE: First character of XML document gets eaten on POST

2011-03-31 Thread Jerome Louvel
Hi Bryan,

That's strange as a similar bug was fixed in 2.0.5. From changes log:

   - Fixed bug causing first entity byte to be eaten if the connection
 wasn't persisting. Reported by Sebastien Gaide and Olivier Miel.

Would you mind providing a small test case to reproduce/fix/verify?

Best regards,
Jerome
--
Restlet ~ Founder and Technical Lead ~ http://www.restlet.o​rg
Noelios Technologies ~ http://www.noelios.com



-Message d'origine-
De : Bryan Hunt [mailto:bh...@mac.com] 
Envoyé : jeudi 31 mars 2011 01:03
À : discuss@restlet.tigris.org
Objet : First character of XML document gets eaten on POST

I'm using Restlet 2.0.5 and I'm seeing the first character of an XML document 
being eaten on a POST.  I'm sending the entity:



and if I print out the entity inside my post function, I get

?xml version="1.0" encoding="UTF-8"?>

which would explain why the DomRepresentation.getDocument() is failing.  If I 
pad the entity with a leading space, it seems to work.

Bryan

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

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


RE: HTML decoration for Directory

2011-03-31 Thread Jerome Louvel
Hi Meb,

 

If you are referring to index HTML pages, you can override the following 
methods:

 

 

 getIndexRepresentation( 

 Variant variant,  

 ReferenceList indexContent)

getIndexVariants 

 (ReferenceList 

  indexContent)

 

Best regards,
Jerome
--
Restlet ~ Founder and Technical Lead ~   
http://www.restlet.o​rg
Noelios Technologies ~   http://www.noelios.com

 

 

 

De : Marc-Elian Bégin [mailto:m...@sixsq.com] 
Envoyé : jeudi 24 mars 2011 19:09
À : discuss@restlet.tigris.org
Objet : HTML decoration for Directory

 

Hi,

 

Is there a way to decorate/control the HTML used by Director class responses?

 

Thanks,

 

Meb

 

 

_
Marc-Elian Bégin
Co-Founder
SixSq, Geneva, Switzerland
m...@sixsq.com
+41 77 44 68 119
twitter: lemeb
www.sixsq.com 

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

All URLs 404 with JAX-RS on GAE

2011-03-31 Thread Ellen Spertus
I'm using JAX-RS in Restlet 2.0.5 on GAE 1.4.2 in Eclipse 3.6.1, and none of my 
paths are recognized.  Specifically, the only requests that are successful are 
to "http://localhost:8080";.  I modeled my code after the tutorial at 
"http://wiki.restlet.org/docs_2.0/13-restlet/28-restlet/57-restlet.html";.  When 
trying to debug this, I added a RuntimeException to the constructor for my 
class MyJaxRsApplication, which appears to never get executed.

Here is my web.xml file:

  
http://java.sun.com/xml/ns/j2ee";  
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";  
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee  
 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd";>  
   first steps servlet  
 
 
  org.restlet.ext.jaxrs.JaxRsApplication  

 jaxrs.MyJaxRsApplication  

 
  
 
 
  RestletServlet  

 org.restlet.ext.servlet.ServerServlet  

 
  
 
 
  RestletServlet  
  /*  
 
  

Here is MyJaxRsApplication.java:

package jaxrs;

import org.restlet.Context;
import org.restlet.ext.jaxrs.JaxRsApplication;

public class MyJaxRsApplication extends JaxRsApplication {

public MyJaxRsApplication(Context context) {
super(context);
this.add(new ExampleApplication());
throw new RuntimeException("Made it to MyJaxRsApplication");
}
}

Any advice on how to fix my configuration or debug this problem?

Thanks.

Ellen

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


Re: Cross Domain JQUERY POST Attempt

2011-03-31 Thread Ian Dunlop
Hello,

I remember having to tell restlet to allow cross domain posts using a specific 
route for a crossdomain.xml file like this:

private static final String CLIENT_ACCESS_POLICY = "/crossdomain.xml";
router.attach(CLIENT_ACCESS_POLICY, ClientAccessPolicy.class);
and having the route defined like the code below.  In this one localhost ie 
127.0.0.1 is allowed to post.  This code was written back in the early days of 
restlet 2 so might be a bit out of date now.

import java.io.IOException;
import java.util.logging.Level;
import org.apache.log4j.Logger;


import org.restlet.data.MediaType;
import org.restlet.ext.xml.DomRepresentation;


import org.restlet.representation.Representation;
import org.restlet.representation.Variant;



import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;


import org.w3c.dom.Document;

import org.w3c.dom.Element;

public class ClientAccessPolicy extends ServerResource {

private static final String LOGGER_NAME = "org.mortbay.log";
private static Logger logger = 
Logger.getLogger(ClientAccessPolicy.class);


@Get("xml")
public Representation accessAllowed(Variant variant) {

logger.info("client access");

if (MediaType.TEXT_XML.equals(variant.getMediaType())) {

try {

DomRepresentation representation = new 
DomRepresentation(

MediaType.TEXT_XML);

// Generate a DOM document representing the 
list of

// items.

Document d = representation.getDocument();

Element accesspolicy = 
d.createElement("cross-domain-policy");

d.appendChild(accesspolicy);

Element crossdomainaccess = d

.createElement("allow-access-from");
crossdomainaccess.setAttribute("domain", 
"127.0.0.1");
crossdomainaccess.setAttribute("secure", 
"false");


accesspolicy.appendChild(crossdomainaccess);

d.normalizeDocument();

// Returns the XML representation of this 
document.

return representation;

} catch (IOException e) {

e.printStackTrace();

}

}

return null;

}

}


Cheers,

Ian

On 29 Mar 2011, at 22:33, Jason Richards wrote:

> I have been trying to do a JSON post request with jquery to a restlet 
> service. Every the post is attempted it shows up on the server as an HTML 
> Options request with an error of 405. From what I have read this is a problem 
> with Cross Domain scripting. How do you do a post to the restlet built in 
> server with javascript or jQuery?
> 
> --
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2715100

Ian Dunlop
myGrid Team
School of Computer Science
University of Manchester

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

Restlet Framework version 2.1 M3 and 2.0.6 released

2011-03-31 Thread Jerome Louvel
Hi everyone,

 

Two new releases today! For additional details, please read our blog posts:

http://blog.noelios.com/2011/03/31/restlet-framework-2-1-m3-and-2-0-6-released/

http://blog.noelios.com/2011/03/31/restlet-framework-unifies-voip-and-web-applications/

 

Best regards,
Jerome
--
Restlet ~ Founder and Technical Lead ~   
http://www.restlet.o​rg
Noelios Technologies ~   http://www.noelios.com

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