tracker issue : CF-3376486

select a category, or use search below
(searches all categories and all time range)
Title:

restSetResponse with a header can cause an error.

| View in Tracker

Status/Resolution/Reason: Closed/Fixed/

Reporter/Name(from Bugbase): Raymond Camden / Raymond Camden (Raymond Camden)

Created: 12/03/2012

Components: REST Services

Versions: 10.0

Failure Type:

Found In Build/Fixed In Build: Final / 287253

Priority/Frequency: Normal / Few users will encounter

Locale/System: English / Windows 7 64-bit

Vote Count: 0

I'm using restSetResponse to return a custom XML string. Ie, I don't want the built in XML serialization. This worked fine:

	remote void function sayHelloEvening() httpMethod="get" restPath="/custom" {
		var result = {};
			result.status=201;

			result.content = "<person><name>#variables.data.name#</name><age>#variables.data.age#</age><likes>";
			for(var i=1; i<arrayLen(variables.data.likes); i++) {
				result.content &= "<like>#variables.data.likes[i]#</like>";
			}
			result.content &= "</likes></person>";

			restSetResponse(result);

	}

But I noticed that the browser didn't recognize that it was XML. I remembered that I could set a header:

			result.headers["content-type"] = "application/xml";

And as soon as I did this, I got this error in the Application log:

"Error","ajp-bio-8012-exec-1","12/03/12","09:57:31","RestPreso","java.lang.String cannot be cast to javax.ws.rs.core.MediaType The specific sequence of files included or processed is: C:\websites\webroot\restpreso\services\custom.cfc'' "

It appears as if CF is assuming I've got an XML object. But CF should not assume that. My result is a string, not an XML variable. CF shouldn't even care what I return. If I say I'm returning XML let me worry about it being valid XML.

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3376486

External Customer Info:
External Company:  
External Customer Name: cfjedimaster
External Customer Email:  
External Test Config: My Hardware and Environment details:

Attachments:

Comments:

I should add, even doing this: result.content = xmlparse(result.content) doesn't help. To be clear, I am NOT saying this should work. It should work as is, but there ya go.
Comment by External U.
17056 | December 03, 2012 10:32:20 AM GMT
workaround: <cfset myMediaType=CreateObject("java","javax.ws.rs.core.MediaType").valueOf("application/xml;charset=UTF-8")> <cfset response=structNew()> <cfset response.status=200> <cfset response.content=ret> <cfset response.headers=structNew()> <cfset response.headers["Content-Type"] = myMediaType>
Comment by External U.
17057 | December 13, 2013 07:24:42 PM GMT
Verified with the latest dev build(#289665)
Comment by HariKrishna K.
17058 | April 07, 2014 01:06:46 AM GMT