[Seaside] Zinc-Seaside: Problem with POSTing UTF-8 JSON

Sven Van Caekenberghe sven at stfx.eu
Wed Jun 26 22:01:58 UTC 2013


Hi Tomas,

On 26 Jun 2013, at 22:46, Tomas Kukol <tomas.kukol at gmail.com> wrote:

> Unbelievable, this code with Czech characters and MIME type set to text/json works well:
> 
> GPRestfulHandler(WARestfulHandler)>>czechTestReal
> 	<get>
> 	<path: 'czechTestReal'>
> 	<produces: 'text/json; charset=utf-8'>
> 	^ 'Czech is in Czech čeština.' asJson
> 
> This code with Czech characters and MIME type set to application/json throws an error.
> 
> GPRestfulHandler(WARestfulHandler)>>czechTestReal
> 	<get>
> 	<path: 'czechTestReal'>
> 	<produces: 'application/json; charset=utf-8'>
> 	^ 'Czech is in Czech čeština.' asJson
> 
> There is difference only in produces - text/json vs. application/json, but there are probably different stream - text vs. binary.

Great that you found it !

Indeed, consider:

(WAMimeType fromString: 'text/json') isBinary. false
(WAMimeType fromString: 'application/json') isBinary. true

(ZnMimeType fromString: 'text/json') isBinary. false
(ZnMimeType fromString: 'application/json') isBinary. false

I made an explicit exception for application/json in ZnMimeType ;-)

Sven

> Tomas
> 
> On Wed, Jun 26, 2013 at 10:35 PM, Tomas Kukol <tomas.kukol at gmail.com> wrote:
> Hello, guys. Thanks for a great help.
> 
> I created these methods to check it:
> 
> GPRestfulHandler(WARestfulHandler)>>executeResult: aRouteResult
> 	| result |
> 	self requestContext
> 		respond: [ :response | 
> 			result := aRouteResult sendMessageTo: self.
> 			response document: result mimeType: aRouteResult seasideMimeType ]
> 
> 1) First one with simple Czech string:
> 
> GPRestfulHandler(WARestfulHandler)>>czechTestReal
> 	<get>
> 	<path: 'czechTestReal'>
> 	<produces: 'application/json; charset=utf-8'>
> 	^ 'Czech is in Czech čeština.' asJson
> 
> 2) Second one with simple ascii string:
> 
> GPRestfulHandler(WARestfulHandler)>>czechTestReal
> 	<get>
> 	<path: 'czechTestReal'>
> 	<produces: 'application/json; charset=utf-8'>
> 	^ 'Czech is in Czech cestina.' asJson
> 
> 1) In first case in executeResult: method in result variable is WideString 'Czech is in Czech čeština.'
> 
> I can see on the screen this error although I have WAException filter set to WAWalbackErrorHandler.
> Error: Improper store into indexable object
> 2) In second case in executeResult: method in result variable is ByteString 'Czech is in Czech cestina.'
> I can see on the screen expected result:
> "Czech is in Czech cestina."
> So, there must be somewhere a difference between ByteString and WideString conversion. I located the problem (thrown error) in this method:
> ZnZincServerAdaptor>>responseFrom: aRequestContext
> 
> 
> 
> 	| partialHeaders cookies fullHeaders seasideResponse contents entity contentType |
> 
> 
> 
> 	seasideResponse := aRequestContext response.
> 
> 
> 
> 	partialHeaders := seasideResponse headers.
> 
> 
> 
> 	cookies := seasideResponse cookies.
> 
> 
> 
> 	fullHeaders := ZnHeaders defaultResponseHeaders.
> 
> 
> 
> 	partialHeaders keysAndValuesDo: [ :key :value |
> 
> 
> 
> 		fullHeaders at: key put: value ].
> 
> 
> 
> 	cookies do: [ :each |
> 		fullHeaders at: 'Set-Cookie' add: each oldNetscapeString.
> 		fullHeaders at: 'Set-Cookie2' add: each rfc2965String ].
> 	contentType := seasideResponse contentType greaseString.
> 	contents := seasideResponse contents. "<------------------------ HERE is the error signalled"
> 	entity := (ZnEntity bytes: contents) contentType: contentType; yourself.
> 	^ ZnResponse new
> 		statusLine: (ZnStatusLine code: seasideResponse status);
> 
> 
> 
> 		headers: fullHeaders;
> 		entity: entity;
> 		yourself
> 
> 
> 
> 
> Regards,
> 
> 
> 
> Tomas
> 
> 
> On Wed, Jun 26, 2013 at 7:28 PM, Sven Van Caekenberghe <sven at stfx.eu> wrote:
> 
> On 26 Jun 2013, at 18:47, Philippe Marschall <philippe.marschall at gmail.com> wrote:
> 
> > On Wed, Jun 26, 2013 at 6:37 PM, Sven Van Caekenberghe <sven at stfx.eu> wrote:
> >> Tomas,
> >>
> >> I am not sure what one is supposed to return from #getUsers.
> >>
> >> Naively, I would guess just a [Wide]String with the <produces: 'application/json; charset=utf-8'> telling the Seaside-REST framework to do the right thing, but I just don't know.
> >
> > Yes it does/should, see
> >
> > WARestfulHandler/Filter >> #executeResult:
> 
> I see. Tomas, can you trace in there and see what happens in your case ?
> 
> > Cheers
> > Philippe
> > _______________________________________________
> > seaside mailing list
> > seaside at lists.squeakfoundation.org
> > http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
> 
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
> 
> 
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside



More information about the seaside mailing list