Check Out the Latest News About SmartBear Connect
JOIN OUR WEEKLY CHALLENGE
API_Bloom_banner

API Bloom is a weekly prize-winning challenge in the Ready! API Community. Each week, we assign a task that you need to accomplish to become a winner. See the rules here.

THIS WEEK TASK
Give the biggest number of Solutions on the Ready! API forums
Top 3 contributors will get $50, $35, and $15 gift cards!

WEEK 1-12 WINNERS
@nmrao, @msiadak, @Debz, @richie, @Emil91, @PramodYadav, @jkrier, @sanj, @mbheeke, @Radford, @kmaster, @kbw

Want More?

Register to get access to exclusive content

Reply
Highlighted
Contributor
Posts: 34
Registered: ‎02-10-2012

setting content-type header for mockservice

Hi,
Iam a newbie to soapui.Iam trying to have a mockserver running as part of my soapui tests.This mockserver doesnt have any operations and so iam writing some groovy code inside onRequestScript

def queryString = mockRequest.getHttpRequest().getQueryString()
def httpResponse = mockRequest.httpResponse
httpResponse.addHeader("Content-Type","application/json")

mockRunner.returnFile(httpResponse,new File('response.json'))
return new com.eviware.soapui.impl.wsdl.mock.WsdlMockResult(mockRequest)

So i have a question
For some reasons,content-type is being set as text/javascript(I cant seem to override it using groovy code)?

I followed following article
http://www.soapui.org/Service-Mocking/m ... vices.html


Thanks
Contributor
Posts: 34
Registered: ‎02-10-2012

Re: setting content-type header for mockservice

An Update
I had a look at
http://www.soapui.org/xref/com/eviware/ ... ndler.html
And it seems like the mapping for json is "application/javascript"

suffixToContentType.put( "json", "text/javascript" );


Can you tell me how can i set application/json as content type?

Thanks
Staff
Posts: 8,810
Registered: ‎02-16-2009

Re: setting content-type header for mockservice

Hi,

I suggest you replace your call to mockRunner.returnFile with the actual source code of that method (at http://www.soapui.org/xref/com/eviware/ ... r.html#465) but with your desired content-type used instead.

Does that work?

regards!

/Ole
SmartBear Software
API_Bloom
Contributor
Posts: 34
Registered: ‎02-10-2012

Re: setting content-type header for mockservice

Hi,
I did got this as a workaround option but don't you think it makes sense to not set header of content type if its already set as part of script?

Thanks
Staff
Posts: 8,810
Registered: ‎02-16-2009

Re: setting content-type header for mockservice

Hi,

yes - I'll add this to our backlog - please consider submitting a fix though!

thanks,

/Ole
SmartBear Software
API_Bloom
Let's Meet in Boston