Hi
On 14/10/12 11:40, Mickael Marrache wrote:
Hi again

I have a question about returning responses to HTTP requests in the context of 
a RESTful web service.

This is my method declaration in the WADL:

<method id="saveA" name="PUT">
    <request>
       <representation mediaType="application/xml" element="ns1:A" />
    </request>
    <response status="200">
        <param name="header1" style="header" type="xsd:string" />
    </response>
</method>

After generating the code, I get the following method signature:

public void saveA(AType atype);


Does the method is generated as expected ? (referring to your other email re PUT method)

If the PUT operation performed well, I would like to return an HTTP response 
with status code 200 and an HTTP header containing a certain value. This is 
indicated in the WADL, but I don't see anything in the code. Since the method 
saveA doesn't return anything, where is the right place to customize the 
response (i.e. setting the desired status code and header)?

Typically a Response would be returned from the method in such cases, built like this:

Response.status(myStatus).header(key, value).build();

I wonder if the generator should generate 'Response' by default in such cases, where no response representation is expected...Or this should be configurable at least, I'll look into it.

In meantime, add ResponseHandler filter (on CXF 2.6.x) or ContainerResponseFilter (on CXF 2.7.0) and add a required header from there...

Also, what if for a given request, different responses may be returned 
according to how the operation  performed? Should I add multiple responses in 
the method element (in the WADL)?

At the moment the simplest thing to do is to

<response status="200 400 401">

etc

Creating multiple responses is also valid but as far as the code generation is concerned, it won't make any difference, given that at the code level the relevant exceptions are all runtime ones. However, it can be better for the reader of WADL because you can attach specific descriptions to different response elements...

Cheers, Sergey


Thanks,
Mickael



--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Reply via email to