Help with Seaside, RESTful service, json and curl

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

Help with Seaside, RESTful service, json and curl

Santiago Cardoso Geller-3
Hi everybody.
I'm trying to learn how to create a restful service by following seaside's book. I implemented method #createJson as indicate in this page:
http://book.seaside.st/book/advanced/restful/matching/content-type

I'm using curl to simulate a REST client.

curl -H "Content-Type: text/json" -d '{"title":"Check out latest Seaside"}' http://localhost:8080/todo-api

But the method fails here:
JSJsonParser parse: self requestContext request rawBody

The body received from the request is always an empty string.

Does anybody have any experience with this? I'd appreciate some help.

Thanks and regards,
Santiago

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Help with Seaside, RESTful service, json and curl

Santiago Cardoso Geller-3
Ok, I found something (maybe wrong?) in SstHttpServletRequest>>#getPostFieldsString method.

-------------------------
SstHttpServletRequest>>#getPostFieldsString
    "Answer a String built from multipart fields for a post request"
    | answer |
   
     answer := ''.
    self isPostRequest ifTrue: [
        (self getContentTypeOrDefault sameAs: HttpContentTypeFormData ) ifTrue: [ answer :=  self contents asString ].
        (self getContentTypeOrDefault sameAs: HttpContentTypeMultipart) ifTrue: [ answer := self multiPostFields ]].
   
    ^answer
-------------------------

The body should be the result of evaluate: self contents asString
but self getContentTypeOrDefault is 'application/json' and HttpContentTypeFormData  is 'application/x-www-form-urlencoded'. So,
neither of the two conditions is met and answer variable keeps '' until the end of the method execution.

So my question is:
How can I determine if the answer that I need is self contents asString even when the getContentType of the request is different from

'application/x-www-form-urlencoded'?

Now I changed the method as follows:

------------------
getPostFieldsString
    "Answer a String built from multipart fields for a post request"
    | answer |
   
     answer := ''.
    self isPostRequest ifTrue: [
        (self getContentTypeOrDefault sameAs: HttpContentTypeMultipart)
            ifTrue: [ answer := self multiPostFields ]
            ifFalse: [ answer :=  self contents asString ]].
   
    ^answer
------------------

Could this be a permanent fix?



El jueves, 25 de junio de 2015, 1:27:26 (UTC-3), Santiago Cardoso Geller escribió:
Hi everybody.
I'm trying to learn how to create a restful service by following seaside's book. I implemented method #createJson as indicate in this page:
<a href="http://book.seaside.st/book/advanced/restful/matching/content-type" target="_blank" rel="nofollow" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fbook.seaside.st%2Fbook%2Fadvanced%2Frestful%2Fmatching%2Fcontent-type\46sa\75D\46sntz\0751\46usg\75AFQjCNE-GKrUtDXXlEUWwrAGsCEgaMzvvg';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fbook.seaside.st%2Fbook%2Fadvanced%2Frestful%2Fmatching%2Fcontent-type\46sa\75D\46sntz\0751\46usg\75AFQjCNE-GKrUtDXXlEUWwrAGsCEgaMzvvg';return true;">http://book.seaside.st/book/advanced/restful/matching/content-type

I'm using curl to simulate a REST client.

curl -H "Content-Type: text/json" -d '{"title":"Check out latest Seaside"}' <a href="http://localhost:8080/todo-api" target="_blank" rel="nofollow" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Flocalhost%3A8080%2Ftodo-api\46sa\75D\46sntz\0751\46usg\75AFQjCNEJGrx3kaiTBe_4QqAejic36BSveg';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Flocalhost%3A8080%2Ftodo-api\46sa\75D\46sntz\0751\46usg\75AFQjCNEJGrx3kaiTBe_4QqAejic36BSveg';return true;">http://localhost:8080/todo-api

But the method fails here:
JSJsonParser parse: self requestContext request rawBody

The body received from the request is always an empty string.

Does anybody have any experience with this? I'd appreciate some help.

Thanks and regards,
Santiago

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Help with Seaside, RESTful service, json and curl

John O'Keefe-3
Hello Santiago -

Thank you for your analysis. I believe you are correct, but we will need to do a little more checking. I have opened case 52228 for this problem and will post back here with the final resolution. In the meantime, please let us know if your change does not completely correct the situation.

Regards, John

On Friday, June 26, 2015 at 12:40:27 AM UTC-4, Santiago Cardoso Geller wrote:
Ok, I found something (maybe wrong?) in SstHttpServletRequest>>#getPostFieldsString method.

-------------------------
SstHttpServletRequest>>#getPostFieldsString
    "Answer a String built from multipart fields for a post request"
    | answer |
   
     answer := ''.
    self isPostRequest ifTrue: [
        (self getContentTypeOrDefault sameAs: HttpContentTypeFormData ) ifTrue: [ answer :=  self contents asString ].
        (self getContentTypeOrDefault sameAs: HttpContentTypeMultipart) ifTrue: [ answer := self multiPostFields ]].
   
    ^answer
-------------------------

The body should be the result of evaluate: self contents asString
but self getContentTypeOrDefault is 'application/json' and HttpContentTypeFormData  is 'application/x-www-form-urlencoded'. So,
neither of the two conditions is met and answer variable keeps '' until the end of the method execution.

So my question is:
How can I determine if the answer that I need is self contents asString even when the getContentType of the request is different from

'application/x-www-form-urlencoded'?

Now I changed the method as follows:

------------------
getPostFieldsString
    "Answer a String built from multipart fields for a post request"
    | answer |
   
     answer := ''.
    self isPostRequest ifTrue: [
        (self getContentTypeOrDefault sameAs: HttpContentTypeMultipart)
            ifTrue: [ answer := self multiPostFields ]
            ifFalse: [ answer :=  self contents asString ]].
   
    ^answer
------------------

Could this be a permanent fix?



El jueves, 25 de junio de 2015, 1:27:26 (UTC-3), Santiago Cardoso Geller escribió:
Hi everybody.
I'm trying to learn how to create a restful service by following seaside's book. I implemented method #createJson as indicate in this page:
<a href="http://book.seaside.st/book/advanced/restful/matching/content-type" rel="nofollow" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fbook.seaside.st%2Fbook%2Fadvanced%2Frestful%2Fmatching%2Fcontent-type\46sa\75D\46sntz\0751\46usg\75AFQjCNE-GKrUtDXXlEUWwrAGsCEgaMzvvg';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fbook.seaside.st%2Fbook%2Fadvanced%2Frestful%2Fmatching%2Fcontent-type\46sa\75D\46sntz\0751\46usg\75AFQjCNE-GKrUtDXXlEUWwrAGsCEgaMzvvg';return true;">http://book.seaside.st/book/advanced/restful/matching/content-type

I'm using curl to simulate a REST client.

curl -H "Content-Type: text/json" -d '{"title":"Check out latest Seaside"}' <a href="http://localhost:8080/todo-api" rel="nofollow" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Flocalhost%3A8080%2Ftodo-api\46sa\75D\46sntz\0751\46usg\75AFQjCNEJGrx3kaiTBe_4QqAejic36BSveg';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Flocalhost%3A8080%2Ftodo-api\46sa\75D\46sntz\0751\46usg\75AFQjCNEJGrx3kaiTBe_4QqAejic36BSveg';return true;">http://localhost:8080/todo-api

But the method fails here:
JSJsonParser parse: self requestContext request rawBody

The body received from the request is always an empty string.

Does anybody have any experience with this? I'd appreciate some help.

Thanks and regards,
Santiago

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Help with Seaside, RESTful service, json and curl

Santiago Cardoso Geller-3
Thank you John.
I don't know if another Content-Type may produce another issue. I assume that everything that is not multi-part, is the same for this method. I'm only playing with REST and JSON by now and the fix works. Maybe someone with a more complex web application could try the fix.

Regards,
Santiago

On Thu, Jul 2, 2015 at 9:27 AM, John O'Keefe <[hidden email]> wrote:
Hello Santiago -

Thank you for your analysis. I believe you are correct, but we will need to do a little more checking. I have opened case 52228 for this problem and will post back here with the final resolution. In the meantime, please let us know if your change does not completely correct the situation.

Regards, John


On Friday, June 26, 2015 at 12:40:27 AM UTC-4, Santiago Cardoso Geller wrote:
Ok, I found something (maybe wrong?) in SstHttpServletRequest>>#getPostFieldsString method.

-------------------------
SstHttpServletRequest>>#getPostFieldsString
    "Answer a String built from multipart fields for a post request"
    | answer |
   
     answer := ''.
    self isPostRequest ifTrue: [
        (self getContentTypeOrDefault sameAs: HttpContentTypeFormData ) ifTrue: [ answer :=  self contents asString ].
        (self getContentTypeOrDefault sameAs: HttpContentTypeMultipart) ifTrue: [ answer := self multiPostFields ]].
   
    ^answer
-------------------------

The body should be the result of evaluate: self contents asString
but self getContentTypeOrDefault is 'application/json' and HttpContentTypeFormData  is 'application/x-www-form-urlencoded'. So,
neither of the two conditions is met and answer variable keeps '' until the end of the method execution.

So my question is:
How can I determine if the answer that I need is self contents asString even when the getContentType of the request is different from

'application/x-www-form-urlencoded'?

Now I changed the method as follows:

------------------
getPostFieldsString
    "Answer a String built from multipart fields for a post request"
    | answer |
   
     answer := ''.
    self isPostRequest ifTrue: [
        (self getContentTypeOrDefault sameAs: HttpContentTypeMultipart)
            ifTrue: [ answer := self multiPostFields ]
            ifFalse: [ answer :=  self contents asString ]].
   
    ^answer
------------------

Could this be a permanent fix?



El jueves, 25 de junio de 2015, 1:27:26 (UTC-3), Santiago Cardoso Geller escribió:
Hi everybody.
I'm trying to learn how to create a restful service by following seaside's book. I implemented method #createJson as indicate in this page:
http://book.seaside.st/book/advanced/restful/matching/content-type

I'm using curl to simulate a REST client.

curl -H "Content-Type: text/json" -d '{"title":"Check out latest Seaside"}' http://localhost:8080/todo-api

But the method fails here:
JSJsonParser parse: self requestContext request rawBody

The body received from the request is always an empty string.

Does anybody have any experience with this? I'd appreciate some help.

Thanks and regards,
Santiago

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.