Sorry i mix to many functions :) I read a second time the javadoc and i
discover you can't use both handlePut()  == lowerlevel
and put() == high level.

So i have another issue if something can give me a clue:
When i try to get my data form from the handlePut() or the handlePost() with
this code it works very well !:

@Override
    public void handlePut() {
        System.out.println(" handlePut()");
        Form form = getRequest().getEntityAsForm();
        String formId = form.getFirstValue("formId");
        System.out.println("=> formId = " + formId);
        super.handlePut();
    }

@Override
    public void handlePost() {
        System.out.println(" handlePost()");
        Form form = getRequest().getEntityAsForm();
        String formId = form.getFirstValue("formId");
        System.out.println("=> formId = " + formId);
        super.handlePut();
    }


But now when i try to use the default implementation with put() and post()
method with this code it fails ! :

I get this from this post
http://article.gmane.org/gmane.comp.java.restlet/2420/match=form+post (i
check the sample this is how it should work)

@Override
    public void post(Representation entity) {
        System.out.println(" post()");

        if (entity != null) {
            Form form = new Form(entity);  //throws error
            String id = form.getFirstValue("formId");
            System.out.println("=> formId = " + id);
        }
    }

@Override
    public void put(Representation entity) {
        System.out.println(" put()");
         if (entity != null) {
            Form form = new Form(entity);  //throws error
            String id = form.getFirstValue("formId");
            System.out.println("=> formId = " + id);
        }
    }

Aug 23, 2007 12:28:09 PM com.noelios.restlet.StatusFilter getStatus
SEVERE: Unhandled exception or error intercepted
java.lang.IllegalStateException: The Web form cannot be parsed as no fresh
content is available. If this entity has been already read once, caching of
the entity is required
    at com.noelios.restlet.util.FormUtils.parsePost(FormUtils.java:95)
    at com.noelios.restlet.Engine.parse(Engine.java:815)
    at org.restlet.data.Form.<init>(Form.java:73)
    at org.restlet.data.Form.<init>(Form.java:99)
    at com.webmd.restlet.rest.FormResource.post(FormResource.java:49)
    at org.restlet.resource.Resource.handlePost(Resource.java:479)


Somebody can explain in which case to use the handlePut() and the
put(Representation entity) ?

Thanks a lot for the reply

On 8/22/07, regis regis <[EMAIL PROTECTED]> wrote:
>
> Thanks a lot for the quick reply now it works very well.
> It was not clear.
> I hope it will help.
>
>
> But know i have a second problem , when i try to access to my data in the
> request object in a handlePut() or in handlePost() like this
>
> Form form = getRequest().getEntityAsForm();
> String value = form.getFirstValue("text");
> String method = form.getFirstValue ("method");
>
> if i doing getRequest().getEntityAsObject()  it returns a null ....
>
> I get this error, what does it mean ?
>
> java.lang.IllegalStateException: The Web form cannot be parsed as no fresh
> content is available. If this entity has been already read once, caching of
> the entity is required
>     at com.noelios.restlet.util.FormUtils.parsePost(FormUtils.java:95)
>     at com.noelios.restlet.Engine.parse(Engine.java:815)
>     at org.restlet.data.Form.<init>(Form.java:73)
>     at org.restlet.data.Form .<init>(Form.java:99)
>
>
> There is something i forgot.
>
> Thks a lot
>
> On 8/22/07, Jerome Louvel < [EMAIL PROTECTED]> wrote:
> >
> >
> > Hi Regis,
> >
> > There is a built-in service for that, based on a query parameter. See:
> > http://www.restlet.org/documentation/1.0/faq#19
> >
> > You have to put the parameter into the query string of the action's URI.
> > <form action="api/form?method=put" method="post" enctype="text/plain">
> >
> > Best regards,
> > Jerome
> >
> > > -----Message d'origine-----
> > > De : regis regis [mailto:[EMAIL PROTECTED]
> > > Envoyé : mercredi 22 août 2007 21:41
> > > À : [email protected]
> > > Objet : tunnelFilter in tomcat container - how ???
> > >
> > > Hi i try to implement in a tomcat container the
> > >
> > > => How can I make PUT or DELETE calls from browsers? i read
> > > the faq/mailing list but there is not a lot informations about that.
> > >
> > > So my goal it is pretty simple, a html page with a <form>
> > > which contain a <input type="hidden"> with the name="method"
> > > and value="put" (or "delete"), and call the associate method
> > > in a resource ( handlePut() or handleDelete() ).
> > >
> > > My problem it is i never go to the handlePut() ! But always
> > > to the handlePost().
> > > When i debug the application in the request object, in the
> > > method attribute it is always POST !!!
> > >
> > >
> > > So here my code :
> > >
> > > XHTML Page:
> > >
> > > <?xml version=" 1.0" encoding="UTF-8"?>
> > > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
> > > " http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd ">
> > > <html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
> > >     <head>
> > >         <title>form.xhtml</title>
> > >         <meta http-equiv="keywords"
> > > content="enter,your,keywords,here" />
> > >         <meta http-equiv="description" content="A short
> > > description of this page." />
> > >         <meta http-equiv="content-type" content="text/html;
> > > charset=ISO-8859-1" />
> > >
> > >         <base href=" http://localhost:8080/restlet/ "/>
> > >     </head>
> > >     <body>
> > >         <form action="api/form" method="post" enctype="text/plain">
> > >             <input type="text" name="text" />
> > >
> > >             <input  type="hidden" name="method" value="PUT"/>
> > >             <input  type="submit" name="ok" value="ok"/>
> > >         </form>
> > >
> > >     </body>
> > > </html>
> > >
> > >
> > > web.xml
> > >
> > > <web-app>
> > >
> > >   <!-- Your application class name -->
> > >   <context-param>
> > >      <param-name> org.restlet.application</param-name>
> > >      <param-value>com.webmd.restlet.app.RestApplication </param-value>
> > >   </context-param>
> > >
> > >   <servlet>
> > >      <servlet-name>RestServlet</servlet-name>
> > >
> > > <servlet-class>com.noelios.restlet.ext.servlet.ServerServlet</
> > > servlet-class>
> > >   </servlet>
> > >
> > >   <servlet-mapping>
> > >      <servlet-name>RestServlet</servlet-name>
> > >      <url-pattern>/api/*</url-pattern>
> > >   </servlet-mapping>
> > >
> > > </web-app>
> > >
> > >
> > > com/webmd/restlet/app/RestApplication.java
> > >
> > >
> > > public class RestApplication extends Application {
> > >
> > >     public RestApplication(Context context) {
> > >         //enable the tunnel service
> > >         TunnelService tunnelService = new TunnelService(true,
> > > true, true);
> > >         tunnelService.setMethodParameter ("method");
> > >         this.setTunnelService(tunnelService);
> > >
> > >     }
> > >
> > >     @Override
> > >     public Restlet createRoot() {
> > >         Router router = new Router(getContext());
> > >         router.attach(/form, FormResource.getClass());
> > >
> > >         TunnelFilter tunnelFilter = new TunnelFilter(this);
> > >         tunnelFilter.setContext(getContext());
> > >         tunnelFilter.setNext (router);
> > >
> > >         return tunnelFilter;
> > >     }
> > >
> > >     public void handle(Request request, Response response) {
> > >         try {
> > >             start();
> > >         } catch (Exception ee) {
> > >             ee.printStackTrace();
> > >         }
> > >         super.handle(request, response);
> > >     }
> > >
> > > }
> > >
> > > com/webmd/restlet/rest/FormResource .java;
> > >
> > > public class FormResource extends Resource {
> > >
> > >
> > >     @Override
> > >     public void init(Context context, Request request,
> > > Response response) {
> > >
> > >         System.out.println(" init()");
> > >         Form form = request.getEntityAsForm();
> > >
> > >         String value = form.getFirstValue("text");
> > >         String method = form.getFirstValue("method");
> > >
> > >         super.init (context, request, response);
> > >     }
> > >
> > > @Override
> > >     public boolean allowDelete() {
> > >         return true;
> > >     }
> > >
> > >     @Override
> > >     public boolean allowGet() {
> > >         return true;
> > >     }
> > >
> > >
> > >     @Override
> > >     public boolean allowPost() {
> > >         return true;
> > >     }
> > >
> > >
> > >     @Override
> > >     public boolean allowPut() {
> > >         return true;
> > >     }
> > >
> > >
> > >     @Override
> > >     public void handleDelete() {
> > >         System.out.println(" handleDelete()");
> > >         super.handleDelete();
> > >     }
> > >
> > >
> > >     @Override
> > >     public void handleGet() {
> > >         System.out.println(" handleGet()");
> > >         super.handleGet();
> > >     }
> > >
> > >
> > >     @Override
> > >     public void handlePost() {
> > >         System.out.println(" handlePost()");
> > >         super.handlePost();
> > >     }
> > >
> > >
> > >     @Override
> > >     public void handlePut() {
> > >         System.out.println (" handlePut()");
> > >         super.handlePut();
> > >     }
> > >
> > >     @Override
> > >     public Representation getRepresentation(Variant arg0) {
> > >         System.out.println("=> getRepresentation()");
> > >         return super.getRepresentation(arg0);
> > >     }
> > >
> > >
> > >     @Override
> > >     public void delete() {
> > >         System.out.println(" delete()");
> > >         super.delete ();
> > >     }
> > >
> > >
> > >
> > >     @Override
> > >     public void post(Representation arg0) {
> > >         System.out.println(" post()");
> > >         super.post(arg0);
> > >     }
> > >
> > >
> > >
> > >     @Override
> > >     public void put(Representation arg0) {
> > >         System.out.println(" put()");
> > >         super.put(arg0);
> > >     }
> > >
> > > }
> > >
> > > Thanks for the reply
> > >
> > >
> > >
> >
>
>

Reply via email to