Rest and POST method

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
21 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Rest and POST method

Olivier Auverlot
Hi,

I continu my experiments with seaside-rest and I have a new problem. I can post XML data to the seaside server with the post method. I can detect the arrival of the data with the postXML event method.

postXML
    "I receive XML data with the POST method"
    <POST>
    <Consumes: 'text/xml'>
    <Path: '/postxml'>
   
    Transcript show: 'XML data detected'.



But... how to read the content of the request ?

Best regards
Olivier ;-)

www.auverlot.fr

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Rest and POST method

Philippe Marschall
2011/4/4 Olivier Auverlot <[hidden email]>:

> Hi,
>
> I continu my experiments with seaside-rest and I have a new problem. I can
> post XML data to the seaside server with the post method. I can detect the
> arrival of the data with the postXML event method.
>
> postXML
>     "I receive XML data with the POST method"
>     <POST>
>     <Consumes: 'text/xml'>
>     <Path: '/postxml'>
>
>     Transcript show: 'XML data detected'.
>
>
>
> But... how to read the content of the request ?

Yeah right, at the moment you can only inject GET fields and not POST
fields. So you have to access them through

    self requestContext request postFields

Cheers
Philippe
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Rest and POST method

Olivier Auverlot
Philippe, thank for your response.

ok, that works for the content type application/x-www-form-urlencoded but I need to receive xml data. With another content type like text/plain or text/xml, the data seems to be not parsed. postFields or rawBody are empty.

Best regards
Olivier ;-)
self requestContext request postFields

www.auverlot.fr
2011/4/4 Olivier Auverlot [hidden email]:
Hi,

I continu my experiments with seaside-rest and I have a new problem. I can
post XML data to the seaside server with the post method. I can detect the
arrival of the data with the postXML event method.

postXML
    "I receive XML data with the POST method"
    <POST>
    <Consumes: 'text/xml'>
    <Path: '/postxml'>

    Transcript show: 'XML data detected'.



But... how to read the content of the request ?
Yeah right, at the moment you can only inject GET fields and not POST
fields. So you have to access them through

    self requestContext request postFields

Cheers
Philippe
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Rest and POST method

Philippe Marschall
2011/4/4 Olivier Auverlot <[hidden email]>:
> Philippe, thank for your response.
>
> ok, that works for the content type application/x-www-form-urlencoded but I
> need to receive xml data. With another content type like text/plain or
> text/xml, the data seems to be not parsed. postFields or rawBody are empty.

I would expect #postFields to be empty since it can't be parsed as
application/x-www-form-urlencoded or multipart/form-data. Which server
do you use in which version? Do you have dump of the request?

Cheers
Philippe
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Rest and POST method

Olivier Auverlot
Hi Philippe,

I work with the Seaside One-Click image and the HTTP server is Comanche.

*******************************************************
First test: with form data
*******************************************************

-- the postForm method --------------------------------

postForm
<POST>
<Consumes: 'application/x-www-form-urlencoded'>
<Path: '/postform'>

     Transcript show: self requestContext request postFields.

-- REQUEST --------------------------------

POST /MonAppRest/postform HTTP/1.1
Content-Type: application/x-www-form-urlencoded

user=olivier&id=23

-- RESPONSE --------------------------------

HTTP/1.1 200 OK
Date: Tue, 05 Apr 2011 07:13:01 GMT
Connection: close
Server: KomHttpServer/7.1.3 (Mac OS)
Content-Type: text/html
Content-Length: 0

-- Result  --------------------------------
a WARequestFields('id'->'23' 'user'->'olivier')

*******************************************************
Second test: with XML data
*******************************************************

-- the postXML method --------------------------------

postXML
     "detection de l'envoi de données XML"
<POST>
<Consumes: 'text/xml'>
<Path: '/postxml'>

     self requestContext inspect.

     Transcript show: 'postXML'.

-- REQUEST --------------------------------

POST /MonAppRest/postxml HTTP/1.1
Content-Type: text/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<agent>
<nom>auverlot</nom>
</agent>

-- RESPONSE --------------------------------

HTTP/1.1 200 OK
Date: Tue, 05 Apr 2011 07:08:01 GMT
Connection: close
Server: KomHttpServer/7.1.3 (Mac OS)
Content-Type: text/html
Content-Length: 0

-- Result  --------------------------------
a WARequestFields()

WARequestFields is empty but it seems logical because that is not a form
that is submited. I tried to read data thru rawBody but it is empty also.

For my project, I need to exchange XML data and probably LDIF data. If
there are no solutions, I will be forced to use another programming
solution (perl or java) :-( D'OH!!!.

Do you think that it's possible to implement a mecanism to access of the
body of a request send with a POST method ?

Thank for your help.

Best regards
Olivier ;-)

www.auverlot.fr

Le 05/04/11 08:59, Philippe Marschall a écrit :

> 2011/4/4 Olivier Auverlot<[hidden email]>:
>> Philippe, thank for your response.
>>
>> ok, that works for the content type application/x-www-form-urlencoded but I
>> need to receive xml data. With another content type like text/plain or
>> text/xml, the data seems to be not parsed. postFields or rawBody are empty.
> I would expect #postFields to be empty since it can't be parsed as
> application/x-www-form-urlencoded or multipart/form-data. Which server
> do you use in which version? Do you have dump of the request?
>
> Cheers
> Philippe
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Rest and POST method

Philippe Marschall
2011/4/5 Olivier Auverlot <[hidden email]>:

> Hi Philippe,
>
> I work with the Seaside One-Click image and the HTTP server is Comanche.
>
> *******************************************************
> First test: with form data
> *******************************************************
>
> -- the postForm method --------------------------------
>
> postForm
> <POST>
> <Consumes: 'application/x-www-form-urlencoded'>
> <Path: '/postform'>
>
>    Transcript show: self requestContext request postFields.
>
> -- REQUEST --------------------------------
>
> POST /MonAppRest/postform HTTP/1.1
> Content-Type: application/x-www-form-urlencoded
>
> user=olivier&id=23
>
> -- RESPONSE --------------------------------
>
> HTTP/1.1 200 OK
> Date: Tue, 05 Apr 2011 07:13:01 GMT
> Connection: close
> Server: KomHttpServer/7.1.3 (Mac OS)
> Content-Type: text/html
> Content-Length: 0
>
> -- Result  --------------------------------
> a WARequestFields('id'->'23' 'user'->'olivier')
>
> *******************************************************
> Second test: with XML data
> *******************************************************
>
> -- the postXML method --------------------------------
>
> postXML
>    "detection de l'envoi de données XML"
> <POST>
> <Consumes: 'text/xml'>
> <Path: '/postxml'>
>
>    self requestContext inspect.
>
>    Transcript show: 'postXML'.
>
> -- REQUEST --------------------------------
>
> POST /MonAppRest/postxml HTTP/1.1
> Content-Type: text/xml; charset=utf-8
>
> <?xml version="1.0" encoding="UTF-8"?>
> <agent>
> <nom>auverlot</nom>
> </agent>
>
> -- RESPONSE --------------------------------
>
> HTTP/1.1 200 OK
> Date: Tue, 05 Apr 2011 07:08:01 GMT
> Connection: close
> Server: KomHttpServer/7.1.3 (Mac OS)
> Content-Type: text/html
> Content-Length: 0
>
> -- Result  --------------------------------
> a WARequestFields()
>
> WARequestFields is empty but it seems logical because that is not a form
> that is submited. I tried to read data thru rawBody but it is empty also.
>
> For my project, I need to exchange XML data and probably LDIF data. If there
> are no solutions, I will be forced to use another programming solution (perl
> or java) :-( D'OH!!!.
>
> Do you think that it's possible to implement a mecanism to access of the
> body of a request send with a POST method ?

It should already work ;-)
Can you set a break point in WAComancheRequestConverter >>
#requestBodyFor: and check why the decoding doesn't happen? It could
be because the Content-Length is missing in that case.

Cheers
Philippe
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Rest and POST method

Tobias Pape
In reply to this post by Olivier Auverlot

Am 2011-04-05 um 09:29 schrieb Olivier Auverlot:

> Hi Philippe,
>
> I work with the Seaside One-Click image and the HTTP server is Comanche.
>
> *******************************************************
> First test: with form data
> *******************************************************
>
> -- the postForm method --------------------------------
>
> postForm
> <POST>
> <Consumes: 'application/x-www-form-urlencoded'>
> <Path: '/postform'>
>
>    Transcript show: self requestContext request postFields.
>
> -- REQUEST --------------------------------
>
> POST /MonAppRest/postform HTTP/1.1
> Content-Type: application/x-www-form-urlencoded
>
> user=olivier&id=23
>
> -- RESPONSE --------------------------------
>
> HTTP/1.1 200 OK
> Date: Tue, 05 Apr 2011 07:13:01 GMT
> Connection: close
> Server: KomHttpServer/7.1.3 (Mac OS)
> Content-Type: text/html
> Content-Length: 0
>
> -- Result  --------------------------------
> a WARequestFields('id'->'23' 'user'->'olivier')
>
> *******************************************************
> Second test: with XML data
> *******************************************************
>
> -- the postXML method --------------------------------
>
> postXML
>    "detection de l'envoi de données XML"
> <POST>
> <Consumes: 'text/xml'>
> <Path: '/postxml'>
>
>    self requestContext inspect.


Probably you can try rawBody. It is used by SqueakSource3 in
a put request, where postFields are naturally  not available.:

putMap: fileName ofProject: projectName
        <PUT>
        <Path: '/{projectName}/{fileName}.mcm'>
        "… "
        | data |
        data := self requestContext request rawBody.
        "…"


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Rest and POST method

Olivier Auverlot
Hi Tobias,

I tried rawBody with the POST method but it returns a empty string if I
send XML data.

> Probably you can try rawBody. It is used by SqueakSource3 in
> a put request, where postFields are naturally  not available.:
>
> putMap: fileName ofProject: projectName
> <PUT>
> <Path: '/{projectName}/{fileName}.mcm'>
> "…"
> | data |
> data := self requestContext request rawBody.
> "…"
>
>
Olivier ;-)

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Rest and POST method

Olivier Auverlot
In reply to this post by Philippe Marschall
Le 05/04/11 09:55, Philippe Marschall a écrit :
> It should already work;-)
> Can you set a break point in WAComancheRequestConverter>>
> #requestBodyFor: and check why the decoding doesn't happen? It could
> be because the Content-Length is missing in that case.

Ok. It seem that the request is recognized as a POST method but
HttpRequest>>#rawPostContents returns '' when the datatype is "text/xml".

Olivier ;-)
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Rest and POST method

Philippe Marschall
2011/4/5 Olivier Auverlot <[hidden email]>:
> Le 05/04/11 09:55, Philippe Marschall a écrit :
>>
>> It should already work;-)
>> Can you set a break point in WAComancheRequestConverter>>
>> #requestBodyFor: and check why the decoding doesn't happen? It could
>> be because the Content-Length is missing in that case.
>
> Ok. It seem that the request is recognized as a POST method but
> HttpRequest>>#rawPostContents returns '' when the datatype is "text/xml".

Why? Does it check Content-Length?

Cheers
Philippe
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Rest and POST method

Olivier Auverlot
I added content-length to the HTTP header but with no effect.

POST /MonAppRest/postxml HTTP/1.1
Content-Type: text/xml; charset=utf-8
Content-Length: 75

<?xml version="1.0" encoding="UTF-8"?>
<agent>
<nom>auverlot</nom>
</agent>

Olivier ;-)

> 2011/4/5 Olivier Auverlot<[hidden email]>:
>> Le 05/04/11 09:55, Philippe Marschall a écrit :
>>> It should already work;-)
>>> Can you set a break point in WAComancheRequestConverter>>
>>> #requestBodyFor: and check why the decoding doesn't happen? It could
>>> be because the Content-Length is missing in that case.
>> Ok. It seem that the request is recognized as a POST method but
>> HttpRequest>>#rawPostContents returns '' when the datatype is "text/xml".
> Why? Does it check Content-Length?
>
> Cheers
> Philippe
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Rest and POST method

Philippe Marschall
2011/4/5 Olivier Auverlot <[hidden email]>:
> I added content-length to the HTTP header but with no effect.

Are you manually building the request? Can you check what the code
actually does?

Cheers
Philippe
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Rest and POST method

T. Edwin King
In reply to this post by Olivier Auverlot
> From: Olivier Auverlot <[hidden email]>
> Subject: Re: [Seaside] Rest and POST method
>
> Hi Philippe,
>
> I work with the Seaside One-Click image and the HTTP server is Comanche.
>
> *******************************************************
> First test: with form data
> *******************************************************
>
> -- the postForm method --------------------------------
>
> postForm
> <POST>
> <Consumes: 'application/x-www-form-urlencoded'>
> <Path: '/postform'>
>
>     Transcript show: self requestContext request postFields.
>
> -- REQUEST --------------------------------
>
> POST /MonAppRest/postform HTTP/1.1
> Content-Type: application/x-www-form-urlencoded
>
> user=olivier&id=23
>
> -- RESPONSE --------------------------------
>
> HTTP/1.1 200 OK
> Date: Tue, 05 Apr 2011 07:13:01 GMT
> Connection: close
> Server: KomHttpServer/7.1.3 (Mac OS)
> Content-Type: text/html
> Content-Length: 0
>
> -- Result  --------------------------------
> a WARequestFields('id'->'23' 'user'->'olivier')
>
> *******************************************************
> Second test: with XML data
> *******************************************************
>
> -- the postXML method --------------------------------
>
> postXML
>     "detection de l'envoi de données XML"
> <POST>
> <Consumes: 'text/xml'>
> <Path: '/postxml'>
>
>     self requestContext inspect.
>
>     Transcript show: 'postXML'.
>
> -- REQUEST --------------------------------
>
> POST /MonAppRest/postxml HTTP/1.1
> Content-Type: text/xml; charset=utf-8
>
> <?xml version="1.0" encoding="UTF-8"?>
> <agent>
> <nom>auverlot</nom>
> </agent>
>
> -- RESPONSE --------------------------------
>
> HTTP/1.1 200 OK
> Date: Tue, 05 Apr 2011 07:08:01 GMT
> Connection: close
> Server: KomHttpServer/7.1.3 (Mac OS)
> Content-Type: text/html
> Content-Length: 0
>
> -- Result  --------------------------------
> a WARequestFields()
>
> WARequestFields is empty but it seems logical because that is not a form
> that is submited. I tried to read data thru rawBody but it is empty also.
>
> For my project, I need to exchange XML data and probably LDIF data. If
> there are no solutions, I will be forced to use another programming
> solution (perl or java) :-( D'OH!!!.
>
> Do you think that it's possible to implement a mecanism to access of the
> body of a request send with a POST method ?
>
> Thank for your help.
>
> Best regards
> Olivier ;-)


I don't want to steer you away for using Seaside-REST (I've been
meaning to look into it myself) - but I've a solution where I just use
the Swazoo server instance for handling my REST endpoints right along
side of my Seaside app.  It's not as integrated a solution as using
only Seaside, but it might be a good fall-back for you in the time
being and it should work with any of the http servers (Swazoo, Zinc,
Commanche, et. al.)

Cheers,

Todd Edwin King
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Rest and POST method

Olivier Auverlot
In reply to this post by Philippe Marschall
For my tests, I used a tool named "HTTP Client" (http://ditchnet.org/httpclient/). It's a debugger for HTTP requests. But, I have also used the Rebol programming language for generate HTTP request. I don't think that the request is the problem.

It's perhaps my smalltalk code that is the problem :( Have you the possibilite to test a POST request with XML data with a equivalent configuration ?

Olivier

Le 5 avr. 2011 à 16:22, Philippe Marschall a écrit :

2011/4/5 Olivier Auverlot <[hidden email]>:
I added content-length to the HTTP header but with no effect.

Are you manually building the request? Can you check what the code
actually does?

Cheers
Philippe
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Rest and POST method

Olivier Auverlot
In reply to this post by Philippe Marschall
Philippe,

I supose that the guilty is HttpRequest>>#rawPostFields.

If #isPostRequest answers true and the content type is different of  
'application/x-www-form-urlencoded', it answers always ''.

Olivier ;-)
www.auverlot.fr



Le 05/04/11 15:54, Philippe Marschall a écrit :

> 2011/4/5 Olivier Auverlot<[hidden email]>:
>> Le 05/04/11 09:55, Philippe Marschall a écrit :
>>> It should already work;-)
>>> Can you set a break point in WAComancheRequestConverter>>
>>> #requestBodyFor: and check why the decoding doesn't happen? It could
>>> be because the Content-Length is missing in that case.
>> Ok. It seem that the request is recognized as a POST method but
>> HttpRequest>>#rawPostContents returns '' when the datatype is "text/xml".
> Why? Does it check Content-Length?
>
> Cheers
> Philippe
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Rest and POST method

Philippe Marschall
2011/4/6 Olivier Auverlot <[hidden email]>:
> Philippe,
>
> I supose that the guilty is HttpRequest>>#rawPostFields.
>
> If #isPostRequest answers true and the content type is different of
>  'application/x-www-form-urlencoded', it answers always ''.

Ah, that explains it. I guess you can just remove the check

 self contentType = MIMEDocument contentTypeFormData

I created an issue [1]

 [1] http://code.google.com/p/seaside/issues/detail?id=648

Cheers
Philippe
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Rest and POST method

Olivier Auverlot
I have modified the code with the following modifications :

HttpRequest>>#rawPostFields
     ^self propertyAt: #rawPostFields ifAbsentPut: [
         (self isPostRequest) ifTrue: [
             stream next: self contentLength
         ] ifFalse: [
             ''
         ].
     ]

Now, it seems ok. I can send GET or POST requests and send XML data. For
read this data, I use the rawBody propertie.

For example:

postXML
<POST>
<Consumes: 'text/xml'>
<Path: '/postxml'>
     Transcript show: self requestContext request rawBody.

Now, I must find a cool tool for parsing XML...

Olivier ;-)
www.auverlot.fr

> 2011/4/6 Olivier Auverlot<[hidden email]>:
>> Philippe,
>>
>> I supose that the guilty is HttpRequest>>#rawPostFields.
>>
>> If #isPostRequest answers true and the content type is different of
>>   'application/x-www-form-urlencoded', it answers always ''.
> Ah, that explains it. I guess you can just remove the check
>
>   self contentType = MIMEDocument contentTypeFormData
>
> I created an issue [1]
>
>   [1] http://code.google.com/p/seaside/issues/detail?id=648
>
> Cheers
> Philippe
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Rest and POST method

Philippe Marschall
2011/4/6 Olivier Auverlot <[hidden email]>:

> I have modified the code with the following modifications :
>
> HttpRequest>>#rawPostFields
>    ^self propertyAt: #rawPostFields ifAbsentPut: [
>        (self isPostRequest) ifTrue: [
>            stream next: self contentLength
>        ] ifFalse: [
>            ''
>        ].
>    ]
>
> Now, it seems ok. I can send GET or POST requests and send XML data. For
> read this data, I use the rawBody propertie.
>
> For example:
>
> postXML
> <POST>
> <Consumes: 'text/xml'>
> <Path: '/postxml'>
>    Transcript show: self requestContext request rawBody.
>
> Now, I must find a cool tool for parsing XML...

Magritte-XML ;-)

Cheers
Philippe
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Rest and POST method

Olivier Auverlot
To infinite... and beyond !

Le 06/04/11 14:38, Philippe Marschall a écrit :

> 2011/4/6 Olivier Auverlot<[hidden email]>:
>> I have modified the code with the following modifications :
>>
>> HttpRequest>>#rawPostFields
>>     ^self propertyAt: #rawPostFields ifAbsentPut: [
>>         (self isPostRequest) ifTrue: [
>>             stream next: self contentLength
>>         ] ifFalse: [
>>             ''
>>         ].
>>     ]
>>
>> Now, it seems ok. I can send GET or POST requests and send XML data. For
>> read this data, I use the rawBody propertie.
>>
>> For example:
>>
>> postXML
>> <POST>
>> <Consumes: 'text/xml'>
>> <Path: '/postxml'>
>>     Transcript show: self requestContext request rawBody.
>>
>> Now, I must find a cool tool for parsing XML...
> Magritte-XML ;-)
>
> Cheers
> Philippe
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Rest and POST method

NorbertHartl

Am 06.04.2011 um 14:53 schrieb Olivier Auverlot:

> To infinite... and beyond !
>
I hope this wasn't a complaint :) I really like your using of rawBody. For just sending XML it is a good idea. Most of the time I use multipart messages an there rawBody doesn't help. In absence of multipart/related handling I just define the part "root" as the default one that carries the XML and the other parts are referenced from there

If you like to try Magritte-XML you can take a short cut. Define

---
Object subclass: #User
        instanceVariableNames: 'fullName emailAddress password'
        classVariableNames: ''
        poolDictionaries: ''
        category: 'Imagined-Model'

getter/setter for the instance variables

User class>descriptionContainer
        ^ super descriptionContainer
                xmlElementName: 'user';
                yourself

User class>>descriptionFullName
        ^ MAStringDescription new
                accessor: #fullName;
                priority: 100;
                label: 'full name';
                beRequired;
                beXmlAttribute;
                yourself

User class>>descriptionEmailAddress
        ^ MAStringDescription new
                accessor: #emailAddress;
                priority: 110;
                label: 'email address';
                beRequired;
                beXmlAttribute;
                xmlAttributeName: 'email';
                yourself

User class>>descriptionPassword
        ^ MAStringDescription new
                accessor: #password;
                priority: 120;
                label: 'password';
                beRequired;
                beHidden;
                yourself

---

If you do

| user |
user := COUser new
   fullName: 'John Doe';
   emailAddress: '[hidden email]';
   password: 'fobar'.

User description toXml: user

you should get

'<user email="[hidden email]" fullName="John Doe"/>'

If you have only one description and you need easy printing than adding the following methods to your model objects might be feasible.

User>>xmlString
        ^ String streamContents: [:stream|
                self printXMLOn: stream  ]  

User>>printXMLOn: aStream
        aStream nextPutAll: (self description toXml: self)

Hope it helps,

Norbert

> Le 06/04/11 14:38, Philippe Marschall a écrit :
>> 2011/4/6 Olivier Auverlot<[hidden email]>:
>>> I have modified the code with the following modifications :
>>>
>>> HttpRequest>>#rawPostFields
>>>    ^self propertyAt: #rawPostFields ifAbsentPut: [
>>>        (self isPostRequest) ifTrue: [
>>>            stream next: self contentLength
>>>        ] ifFalse: [
>>>            ''
>>>        ].
>>>    ]
>>>
>>> Now, it seems ok. I can send GET or POST requests and send XML data. For
>>> read this data, I use the rawBody propertie.
>>>
>>> For example:
>>>
>>> postXML
>>> <POST>
>>> <Consumes: 'text/xml'>
>>> <Path: '/postxml'>
>>>    Transcript show: self requestContext request rawBody.
>>>
>>> Now, I must find a cool tool for parsing XML...
>> Magritte-XML ;-)
>>
>> Cheers
>> Philippe
>> _______________________________________________
>> seaside mailing list
>> [hidden email]
>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
12