users@jersey.java.net

[Jersey] Re: custom object or Response

From: DiFrango, Ronald (CONT) <"DiFrango,>
Date: Fri, 20 Feb 2015 10:46:01 -0500

The things is if you Return a “Response” object, then you are “polluting” your service code with boilerplate Jersey code to send back the response object, hence why we never do it, because Jersey does that just fine for us.

As to your question on our filters, it pretty simple but here you go, as you can see on a response, we check the incoming request method to see if it’s a POST and if the response will be a success, we change the status to Created, aka 201.

public class CreatedHttpStatusFilter implements ContainerResponseFilter {
    /*
     * (non-Javadoc)
     *
     * @see javax.ws.rs.container.ContainerResponseFilter#filter(javax.ws.rs.container.ContainerRequestContext,
     * javax.ws.rs.container.ContainerResponseContext)
     */
    @Override
    public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
            throws IOException {
        if (responseContext.getStatus() == Response.Status.OK.getStatusCode()
                && requestContext.getMethod() == HttpMethod.POST) {
            responseContext.setStatusInfo(Status.CREATED);
        }
    }
}


From: Paul Blakeley [mailto:Paul.Blakeley_at_lifestylegroup.co.uk]
Sent: Friday, February 20, 2015 10:38 AM
To: users_at_jersey.java.net
Subject: [Jersey] Re: custom object or Response

It maybe doesn’t help when from a domain class to Response, but has to be more generic when going from single class to a list.

From: Mikael Ståldal [mailto:mikael.staldal_at_appearnetworks.com]
Sent: 20 February 2015 15:32
To: users_at_jersey.java.neting<mailto:users_at_jersey.java.neting>
Subject: [Jersey] Re: custom object or Response

I don't understand how using Response will avoid any coupling, since you will wrap your domain classes in the Response anyway.

On Fri, Feb 20, 2015 at 4:27 PM, Martynas Jusevičius <martynas_at_graphity.org<mailto:martynas_at_graphity.org>> wrote:
In my opinion Response is more generic, and that is an advantage. Your
domain classes such as Customer are likely to change over time. Using
Response allows you to avoid coupling those with your HTTP-level code.

On Fri, Feb 20, 2015 at 3:47 PM, Mikael Ståldal
<mikael.staldal_at_appearnetworks.com<mailto:mikael.staldal_at_appearnetworks.com>> wrote:
> I would recommend to return a plain custom object, unless you need to set
> any response metadata (HTTP response status or headers).
>
> On Fri, Feb 20, 2015 at 3:08 PM, Paul Blakeley
> <Paul.Blakeley_at_lifestylegroup.co.uk<mailto:Paul.Blakeley_at_lifestylegroup.co.uk>> wrote:
>>
>> Hi,
>>
>> I use restful services quite a lot these days. But one of
>> my colleges was questioning whether when returning a response from a service
>> should you return a custom object or wrap the object in the Response. I
>> thought wrapping any custom object in a Response was the right thing to do.
>> He seemed to think otherwise! It would be good to get some idea on what is
>> the right way, if there is one? Or to get the advantages/disadvantages of
>> either way? I have provided examples below of either way just to clarify.
>>
>>
>>
>> @GET
>>
>> @Produces({ MediaType.APPLICATION_JSON })
>>
>> public Response getCustomers() {
>>
>> ...
>>
>> }
>>
>>
>>
>> @GET
>>
>> @Produces({ MediaType.APPLICATION_JSON })
>>
>> public List<Customer> getCustomers() {
>>
>> ...
>>
>> }
>>
>> Assurant Solutions - The new name for Lifestyle Services Group.
>>
>> This e-mail message and all attachments transmitted with it may contain
>> legally privileged and/or confidential information intended solely for the
>> use of the addressee(s). If the reader of this message is not the intended
>> recipient, you are hereby notified that any reading, dissemination,
>> distribution, copying, forwarding or other use of this message or its
>> attachments is strictly prohibited. If you have received this message in
>> error, please notify the sender immediately and delete this message and all
>> copies and backups thereof.
>>
>> In the UK, Assurant Solutions is a trading name for each of the following
>> companies: Assurant Group Limited, registered in England no. 3264846;
>> Lifestyle Services Group Limited, registered in England no. 5114385;
>> Assurant General Insurance Limited, registered in England No. 2341082;
>> Assurant Life Limited, registered in England no. 3264844; Assurant Services
>> (UK) Limited, registered in England no. 2515130; Assurant Direct Limited,
>> registered in England no. 5399683; Assurant Intermediary Limited, registered
>> in England no. 4019801 The UK branch of Assurant Services Limited,
>> registered in England no. FC028217.
>>
>> The registered office for all the companies noted above is Assurant House,
>> 6-12 Victoria Street, Windsor, Berkshire, SL4 1EN.
>>
>> Lifestyle Services Group Limited is authorised and regulated by the
>> Financial Conduct Authority under register number 315245. Assurant General
>> Insurance Limited is authorised by the Prudential Regulation Authority and
>> regulated by the Financial Conduct Authority and the Prudential Regulation
>> Authority under register number 202735. Assurant Life Limited is authorised
>> by the Prudential Regulation Authority and regulated by the Financial
>> Conduct Authority and the Prudential Regulation Authority under register
>> number 203060. Assurant Direct Limited is an appointed representative of
>> Assurant Intermediary Limited, which is authorised and regulated by the
>> Financial Conduct Authority under register number 311243.
>>
>> You can check this information on the Financial Services Register at
>> http://www.fca.org.uk/register or by calling 0800 111 6768.
>
>
>
>
> --
> Mikael Ståldal
> Chief Software Architect
> Appear
> Phone: +46 8 545 91 572<tel:%2B46%208%20545%2091%20572>
> Email: mikael.staldal_at_appearnetworks.com<mailto:mikael.staldal_at_appearnetworks.com>



--
Mikael Ståldal
Chief Software Architect
Appear
Phone: +46 8 545 91 572
Email: mikael.staldal_at_appearnetworks.com<mailto:mikael.staldal_at_appearnetworks.com>

Assurant Solutions - The new name for Lifestyle Services Group.

This e-mail message and all attachments transmitted with it may contain legally privileged and/or confidential information intended solely for the use of the addressee(s). If the reader of this message is not the intended recipient, you are hereby notified that any reading, dissemination, distribution, copying, forwarding or other use of this message or its attachments is strictly prohibited. If you have received this message in error, please notify the sender immediately and delete this message and all copies and backups thereof.

In the UK, Assurant Solutions is a trading name for each of the following companies: Assurant Group Limited, registered in England no. 3264846; Lifestyle Services Group Limited, registered in England no. 5114385; Assurant General Insurance Limited, registered in England No. 2341082; Assurant Life Limited, registered in England no. 3264844; Assurant Services (UK) Limited, registered in England no. 2515130; Assurant Direct Limited, registered in England no. 5399683; Assurant Intermediary Limited, registered in England no. 4019801 The UK branch of Assurant Services Limited, registered in England no. FC028217.

The registered office for all the companies noted above is Assurant House, 6-12 Victoria Street, Windsor, Berkshire, SL4 1EN.

Lifestyle Services Group Limited is authorised and regulated by the Financial Conduct Authority under register number 315245. Assurant General Insurance Limited is authorised by the Prudential Regulation Authority and regulated by the Financial Conduct Authority and the Prudential Regulation Authority under register number 202735. Assurant Life Limited is authorised by the Prudential Regulation Authority and regulated by the Financial Conduct Authority and the Prudential Regulation Authority under register number 203060. Assurant Direct Limited is an appointed representative of Assurant Intermediary Limited, which is authorised and regulated by the Financial Conduct Authority under register number 311243.

You can check this information on the Financial Services Register at http://www.fca.org.uk/register or by calling 0800 111 6768.
________________________________________________________

The information contained in this e-mail is confidential and/or proprietary to Capital One and/or its affiliates. The information transmitted herewith is intended only for use by the individual or entity to which it is addressed. If the reader of this message is not the intended recipient, you are hereby notified that any review, retransmission, dissemination, distribution, copying or other use of, or taking of any action in reliance upon this information is strictly prohibited. If you have received this communication in error, please contact the sender and delete the material from your computer.