Forum Discussion
Unibet_Support
14 years agoContributor
Hi,
Here is the code.
When i did that from HTTP test step i get content type as null.
I think its better if you could set this up locally and try to return a json/or any other file for that matter and see if the content type is being set.
Iam using soapui-pro 4.5.1
Thanks
Here is the code.
When i did that from HTTP test step i get content type as null.
I think its better if you could set this up locally and try to return a json/or any other file for that matter and see if the content type is being set.
Iam using soapui-pro 4.5.1
Thanks
<con:onRequestScript>
import org.apache.commons.lang.StringUtils
import java.util.logging.Level
import java.util.logging.Logger
import org.apache.commons.io.IOUtils
def logger = Logger.getLogger( this.getClass().getName() );
def queryString = mockRequest.getHttpRequest().getQueryString()
def testfilesdir = context.expand( '${#Project#testfilesdir}' )
def httpStatusCode = javax.servlet.http.HttpServletResponse.SC_OK
String mockServerResponseDir = "testfilesdir/responsefrommockserver/"
String responseFileName = "filenotfound";
if(StringUtils.contains(queryString,"term=PSV")){
responseFileName = "response.json";
}else if(StringUtils.contains(queryString,"term=UNKNOWN")){
responseFileName = "notfound.json";
httpStatusCode = javax.servlet.http.HttpServletResponse.SC_NOT_FOUND
}
def httpResponse = mockRequest.httpResponse
def fileInputStream= this.getClass().getClassLoader().getParent().getResourceAsStream(mockServerResponseDir
+ responseFileName)
httpResponse.setStatus(httpStatusCode)
def length = IOUtils.copy(fileInputStream, httpResponse.getOutputStream())
httpResponse.setContentLength( ( int )length )
httpResponse.setContentType( 'application/json' )
fileInputStream.close()
return new com.eviware.soapui.impl.wsdl.mock.WsdlMockResult(mockRequest)
</con:onRequestScript>