requestContext and extra data in the output

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

requestContext and extra data in the output

Brian Tabone
My question is about extra data I am seeing when using the
requestContext to send back JSon data for a web service.

I am using Seaside 3.0 in Pharo 1.1

My renderContentOn:html method is:

renderContentOn: html
        | resultDictionary |
        self requestContext
                respond: [:response |
                        resultDictionary := Dictionary new.
                        createError isNil
                                ifTrue: [resultDictionary at: #listName put: listName.
                                        resultDictionary at: #listUUID put: todoList uuid asString]
                                ifFalse: [resultDictionary at: #error put: createError class asString.
                                        resultDictionary at: #reason put: createError asString].
                        response contentType: 'application/json'.
                        response nextPutAll: resultDictionary asJson].

When I call the url for this web service, I get (here is the verbose
output from curl)

curl -v http://localhost:8081/createList
* About to connect() to localhost port 8081 (#0)
*   Trying 127.0.0.1... connected
* Connected to localhost (127.0.0.1) port 8081 (#0)
> GET /createList HTTP/1.1
> User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3
> Host: localhost:8081
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Mon, 22 Nov 2010 21:17:48 GMT
< Connection: close
< Server: KomHttpServer/7.1.3 (Mac OS)
< Content-type: application/json
< Content-length: 465
<
* Closing connection #0
<!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>Seaside</title><meta http-equiv="Content-Type"
content="text/html;charset=utf-8"/><meta
http-equiv="Content-Script-Type"
content="text/javascript"/></head><body
onload="onLoad()">{"reason":"MessageNotUnderstood: receiver of
\"asSymbol\" is nil","error":"MessageNotUnderstood"}

Long story short, How do I get rid of the <html header data that is in
the buffer before I get a hold of the response to put my JSon data in
the stream? Should I re-initialize the response with a fresh buffer?

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

Re: requestContext and extra data in the output

Philippe Marschall
2010/11/22 Brian Tabone <[hidden email]>:

> My question is about extra data I am seeing when using the
> requestContext to send back JSon data for a web service.
>
> I am using Seaside 3.0 in Pharo 1.1
>
> My renderContentOn:html method is:
>
> renderContentOn: html
>        | resultDictionary |
>        self requestContext
>                respond: [:response |
>                        resultDictionary := Dictionary new.
>                        createError isNil
>                                ifTrue: [resultDictionary at: #listName put: listName.
>                                        resultDictionary at: #listUUID put: todoList uuid asString]
>                                ifFalse: [resultDictionary at: #error put: createError class asString.
>                                        resultDictionary at: #reason put: createError asString].
>                        response contentType: 'application/json'.
>                        response nextPutAll: resultDictionary asJson].
>
> When I call the url for this web service, I get (here is the verbose
> output from curl)
>
> curl -v http://localhost:8081/createList
> * About to connect() to localhost port 8081 (#0)
> *   Trying 127.0.0.1... connected
> * Connected to localhost (127.0.0.1) port 8081 (#0)
>> GET /createList HTTP/1.1
>> User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3
>> Host: localhost:8081
>> Accept: */*
>>
> < HTTP/1.1 200 OK
> < Date: Mon, 22 Nov 2010 21:17:48 GMT
> < Connection: close
> < Server: KomHttpServer/7.1.3 (Mac OS)
> < Content-type: application/json
> < Content-length: 465
> <
> * Closing connection #0
> <!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>Seaside</title><meta http-equiv="Content-Type"
> content="text/html;charset=utf-8"/><meta
> http-equiv="Content-Script-Type"
> content="text/javascript"/></head><body
> onload="onLoad()">{"reason":"MessageNotUnderstood: receiver of
> \"asSymbol\" is nil","error":"MessageNotUnderstood"}
>
> Long story short, How do I get rid of the <html header data that is in
> the buffer before I get a hold of the response to put my JSon data in
> the stream? Should I re-initialize the response with a fresh buffer?

Nope. You're in the render phase, you should render HTML. If you want
to return JSON you can do that in the callback phase. If you're
building a web service you shouldn't use components at all.

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: requestContext and extra data in the output

Brian Tabone
Philippe,

Yes, I see now after reading the manual a little closer this evening, that what I wanted was a WARequestHandler. Once I moved to using that, my problems were solved. Thanks for the feedback

-Brian

Sent from my iPhone

On Nov 22, 2010, at 11:32 PM, Philippe Marschall <[hidden email]> wrote:

> 2010/11/22 Brian Tabone <[hidden email]>:
>> My question is about extra data I am seeing when using the
>> requestContext to send back JSon data for a web service.
>>
>> I am using Seaside 3.0 in Pharo 1.1
>>
>> My renderContentOn:html method is:
>>
>> renderContentOn: html
>>        | resultDictionary |
>>        self requestContext
>>                respond: [:response |
>>                        resultDictionary := Dictionary new.
>>                        createError isNil
>>                                ifTrue: [resultDictionary at: #listName put: listName.
>>                                        resultDictionary at: #listUUID put: todoList uuid asString]
>>                                ifFalse: [resultDictionary at: #error put: createError class asString.
>>                                        resultDictionary at: #reason put: createError asString].
>>                        response contentType: 'application/json'.
>>                        response nextPutAll: resultDictionary asJson].
>>
>> When I call the url for this web service, I get (here is the verbose
>> output from curl)
>>
>> curl -v http://localhost:8081/createList
>> * About to connect() to localhost port 8081 (#0)
>> *   Trying 127.0.0.1... connected
>> * Connected to localhost (127.0.0.1) port 8081 (#0)
>>> GET /createList HTTP/1.1
>>> User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3
>>> Host: localhost:8081
>>> Accept: */*
>>>
>> < HTTP/1.1 200 OK
>> < Date: Mon, 22 Nov 2010 21:17:48 GMT
>> < Connection: close
>> < Server: KomHttpServer/7.1.3 (Mac OS)
>> < Content-type: application/json
>> < Content-length: 465
>> <
>> * Closing connection #0
>> <!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>Seaside</title><meta http-equiv="Content-Type"
>> content="text/html;charset=utf-8"/><meta
>> http-equiv="Content-Script-Type"
>> content="text/javascript"/></head><body
>> onload="onLoad()">{"reason":"MessageNotUnderstood: receiver of
>> \"asSymbol\" is nil","error":"MessageNotUnderstood"}
>>
>> Long story short, How do I get rid of the <html header data that is in
>> the buffer before I get a hold of the response to put my JSon data in
>> the stream? Should I re-initialize the response with a fresh buffer?
>
> Nope. You're in the render phase, you should render HTML. If you want
> to return JSON you can do that in the callback phase. If you're
> building a web service you shouldn't use components at all.
>
> 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: requestContext and extra data in the output

Julian Fitzell-2
In reply to this post by Philippe Marschall
On Tue, Nov 23, 2010 at 5:32 AM, Philippe Marschall
<[hidden email]> wrote:
> 2010/11/22 Brian Tabone <[hidden email]>:
>> Long story short, How do I get rid of the <html header data that is in
>> the buffer before I get a hold of the response to put my JSon data in
>> the stream? Should I re-initialize the response with a fresh buffer?
>
> Nope. You're in the render phase, you should render HTML. If you want
> to return JSON you can do that in the callback phase. If you're
> building a web service you shouldn't use components at all.

I think that's a bit strong. Components are perfectly valid for an
application that returns non-HTML (take the RSS examples). However,
the Application/Session code is all pretty geared around returning
HTML.

As long as you're using a non-streaming response, you could certainly
clear the contents in the buffer, however Philippe is right that the
normal pattern would be to do this in a callback. You could do
something like:

html anchor
  callback: [ self requestContext returnResponse: [ :response | ...
your code here ... ] ];
  with: 'foo'

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