tags:

views:

203

answers:

1

Hi,

I've created a new custom JSON codec for OpenRasta which works fine.

I need to pass arguments to the codec's write method when the handler is executed but cannot find any documentation on how to do it.

I notice in the implemented WriteTo method, there is a string[] codecParameters parameter, however no idea how to pass them in.

Anyone come accross this problem before? Thanks

+2  A: 

Hey,

the codec parameters are per-request. They're intended to be used together with (for example) the PathSegmentAsParameterUriDecorator.

For example, if you enable that decorator, the path /resource;segment will be treated as /resource by openrasta, and a parameter will be created with the "segment" value, and passed to the codec.

If you wish to pass information to the codec from the handler, there's nothing there, as architecturally it goes against the design of OpenRasta, which specifically prevents handlers and codecs from talking to each others.

If you wish to pass configuration data to your codec, you use the Configuration property from the ICodec interface, which will be filled with whatever object you have provided at configuration time.

You provide the configuration object either through the paramter in the .TranscodedBy(object configuration) method, or if you do custom registration using the configuration metamodel, bu adding the configuration to your Configuration property on CodecModel (which incidently is used in the ResourceModel object created by the fluent API).

Do you have a specific scenario I can help with?

serialseb
Hi serialseb.Thanks for the answer, very helpful. Unfortunately it doesnt solve my issue but maybe you know a workaround.My scenario is:I want to pass back some information in the HTTP response headers. I do not have access to the response stream within the handler, only in the codec.At the moment I am having to return a DTO (containing the header fields' data) from the handler, and then extract it in the codec and put it in the response headers.This works, but I would be interested if there is any way of modifying the HTTP response packet in the handler.Thanks!
joeweoj
it depends what the header is. If it's an entity header, it's quite fine to deduct it from the DTO returned by the handler, as the DTO *is* the entity. That said, it depends if the entity header in question can be deducted or if it's an opaque value (in which case you may be making the response less transparent).That said, you do have access to headers in your handler. Not that you should do it, but just take a dependency on IResponse in the handler and use the Entity.Headers property.
serialseb