You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by nojonojo <n0...@yahoo.com> on 2009/02/03 22:22:12 UTC

restlet response content type and return code


Is there a way to set the content type and return code on the response sent
by the Restlet component?  Looking at the code, it's clear that the answer
is "no" for the content type - you get either text/plain or text/xml (no
chance for application/JSON or anything else user-defined).

Thanks.

Nolan
-- 
View this message in context: http://www.nabble.com/restlet-response-content-type-and-return-code-tp21819209s22882p21819209.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: restlet response content type and return code

Posted by William Tam <em...@gmail.com>.
Fix has been committed to trunk and 1.5.x branch.

On Tue, Feb 3, 2009 at 6:00 PM, William Tam <em...@gmail.com> wrote:
> That would make sense.   Will get it fixed.  Thanks for your patch.
> https://issues.apache.org/activemq/browse/CAMEL-1312
>
>
> On Tue, Feb 3, 2009 at 5:16 PM, nojonojo <n0...@yahoo.com> wrote:
>>
>> I'll go so far as to suggest a change that would enable both of these.  In
>> the DefaultRestletBinding class, the populateRestletResponseFromExchange
>> method could start like this:
>>
>>        public void populateRestletResponseFromExchange(Exchange exchange,
>>
>>        Response response) {
>>
>>                Object body = exchange.getOut().getBody();
>>
>>                MediaType mediaType = null;
>>
>>                String contentType = (String) exchange.getOut().getHeader(
>>                                CONTENT_TYPE_HEADER);
>>
>>                if (contentType != null) {
>>                        mediaType = MediaType.valueOf(contentType);
>>                }
>>
>>                if (mediaType == null) {
>>                  if (body instanceof String) {
>>
>>                  mediaType = MediaType.TEXT_PLAIN;
>>
>>                  } else if (body instanceof StringSource || body instanceof DOMSource)
>>                  {
>>
>>                  mediaType = MediaType.TEXT_XML;
>>
>>                  }
>>                }
>>
>>                String responseCodeHeader = (String) exchange.getOut().getHeader(
>>                                RESPONSE_STATUS_CODE_HEADER);
>>
>>                if (responseCodeHeader != null) {
>>                        response.setStatus(Status.valueOf(Integer
>>                                        .parseInt(responseCodeHeader)));
>>                }
>>
>> ... (rest of method is as before)
>>
>> In this case, headers could be set that would indicate what content type /
>> status code to use, and the current behavior would be retained if not
>> specified.
>>
>>
>> nojonojo wrote:
>>>
>>>
>>> Is there a way to set the content type and return code on the response
>>> sent by the Restlet component?  Looking at the code, it's clear that the
>>> answer is "no" for the content type - you get either text/plain or
>>> text/xml (no chance for application/JSON or anything else user-defined).
>>>
>>> Thanks.
>>>
>>> Nolan
>>>
>>
>> --
>> View this message in context: http://www.nabble.com/restlet-response-content-type-and-return-code-tp21819209s22882p21820115.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
>

Re: restlet response content type and return code

Posted by William Tam <em...@gmail.com>.
That would make sense.   Will get it fixed.  Thanks for your patch.
https://issues.apache.org/activemq/browse/CAMEL-1312


On Tue, Feb 3, 2009 at 5:16 PM, nojonojo <n0...@yahoo.com> wrote:
>
> I'll go so far as to suggest a change that would enable both of these.  In
> the DefaultRestletBinding class, the populateRestletResponseFromExchange
> method could start like this:
>
>        public void populateRestletResponseFromExchange(Exchange exchange,
>
>        Response response) {
>
>                Object body = exchange.getOut().getBody();
>
>                MediaType mediaType = null;
>
>                String contentType = (String) exchange.getOut().getHeader(
>                                CONTENT_TYPE_HEADER);
>
>                if (contentType != null) {
>                        mediaType = MediaType.valueOf(contentType);
>                }
>
>                if (mediaType == null) {
>                  if (body instanceof String) {
>
>                  mediaType = MediaType.TEXT_PLAIN;
>
>                  } else if (body instanceof StringSource || body instanceof DOMSource)
>                  {
>
>                  mediaType = MediaType.TEXT_XML;
>
>                  }
>                }
>
>                String responseCodeHeader = (String) exchange.getOut().getHeader(
>                                RESPONSE_STATUS_CODE_HEADER);
>
>                if (responseCodeHeader != null) {
>                        response.setStatus(Status.valueOf(Integer
>                                        .parseInt(responseCodeHeader)));
>                }
>
> ... (rest of method is as before)
>
> In this case, headers could be set that would indicate what content type /
> status code to use, and the current behavior would be retained if not
> specified.
>
>
> nojonojo wrote:
>>
>>
>> Is there a way to set the content type and return code on the response
>> sent by the Restlet component?  Looking at the code, it's clear that the
>> answer is "no" for the content type - you get either text/plain or
>> text/xml (no chance for application/JSON or anything else user-defined).
>>
>> Thanks.
>>
>> Nolan
>>
>
> --
> View this message in context: http://www.nabble.com/restlet-response-content-type-and-return-code-tp21819209s22882p21820115.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>

Re: restlet response content type and return code

Posted by nojonojo <n0...@yahoo.com>.
I'll go so far as to suggest a change that would enable both of these.  In
the DefaultRestletBinding class, the populateRestletResponseFromExchange
method could start like this:

	public void populateRestletResponseFromExchange(Exchange exchange,

	Response response) {

		Object body = exchange.getOut().getBody();

		MediaType mediaType = null;

		String contentType = (String) exchange.getOut().getHeader(
				CONTENT_TYPE_HEADER);

		if (contentType != null) {
			mediaType = MediaType.valueOf(contentType);
		}

                if (mediaType == null) {
		  if (body instanceof String) {
	
	 	  mediaType = MediaType.TEXT_PLAIN;
		
		  } else if (body instanceof StringSource || body instanceof DOMSource)
		  {
		
		  mediaType = MediaType.TEXT_XML;
		
		  }
                }

		String responseCodeHeader = (String) exchange.getOut().getHeader(
				RESPONSE_STATUS_CODE_HEADER);

		if (responseCodeHeader != null) {
			response.setStatus(Status.valueOf(Integer
					.parseInt(responseCodeHeader)));
		}

... (rest of method is as before)

In this case, headers could be set that would indicate what content type /
status code to use, and the current behavior would be retained if not
specified.


nojonojo wrote:
> 
> 
> Is there a way to set the content type and return code on the response
> sent by the Restlet component?  Looking at the code, it's clear that the
> answer is "no" for the content type - you get either text/plain or
> text/xml (no chance for application/JSON or anything else user-defined).
> 
> Thanks.
> 
> Nolan
> 

-- 
View this message in context: http://www.nabble.com/restlet-response-content-type-and-return-code-tp21819209s22882p21820115.html
Sent from the Camel - Users mailing list archive at Nabble.com.