cancel
Showing results for 
Search instead for 
Did you mean: 

Turning off "Accept compressed responses from host" programmatically

SOLVED
Highlighted
Contributor

Turning off "Accept compressed responses from host" programmatically

Hi, I am trying to write an integration test in Java using SoapUI and the following code is able to do that:

 

            // create new project
            WsdlProject project = new WsdlProject();

            // import WSDL
            WsdlInterface wsdl = WsdlInterfaceFactory.importWsdl(project, endpoint.getWsdlUrl(), true)[0];

            // get desired operation
            WsdlOperation operation = wsdl.getOperationByName(operationName);

            // create a new empty request for that operation
            WsdlRequest request = operation.addNewRequest("My request");
            //WsdlRequest request = operation.getRequestAt(0);
            request.setEndpoint(endpoint.getEndpoint());

            // generate the request content from the schema
            request.setRequestContent(operation.createRequest(true));

            // submit the request
            WsdlSubmitContext submitContext = new WsdlSubmitContext(request);
            WsdlSubmit submit = request.submit(submitContext, false);

            // wait for the response
            Response response = submit.getResponse();

            //	validate the response
            String content = response.getContentAsString();
            System.out.println(content);

 

But when I look at the content, it is scrambled. The following 2 posts suggests that the solution is to turn off "Accept compressed responses from host":

https://community.smartbear.com/t5/SoapUI-NG/soapui-unable-to-parse-responses-with-XML-embedded-as-s...

https://community.smartbear.com/t5/SoapUI-Open-Source/Getting-unrecognized-character-on-webservice-r...

 

But I need to do this programmatically, not from the UI. How can I achieve the same programmatically?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: Turning off "Accept compressed responses from host" programmatically

Any way here it is to change the settings

 

//Change value what is needed for you true or false
boolean value = false;
SoapUI.getSettings().setBoolean(HttpSettings.RESPONSE_COMPRESSION, value);


Regards,
Rao.

View solution in original post

8 REPLIES 8
Highlighted
Community Hero

Re: Turning off "Accept compressed responses from host" programmatically

I think it is one time configuration using preferences.


Regards,
Rao.
Highlighted
Contributor

Re: Turning off "Accept compressed responses from host" programmatically

What do you mean by "one time configuration using preferences"? I need to get this working in code, not the GUI.

 

The best solution would be to be able to decode the response, which is gzip. I have tried the following alternatives, but they all result in 'java.util.zip.ZipException: Not in GZIP format':

 

GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(((WsdlSinglePartHttpResponse) response).getRawResponseBody()));
GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(response.getRawResponseData()));
GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(response.getContentAsString().getBytes()));

 

Does anyone have code that either turns off the ability to accept compressed responses, or that can decompress a compressed response?

Highlighted
Contributor

Re: Turning off "Accept compressed responses from host" programmatically

In case the content is base64 encoded, I even tried

String zippedBase64Str = response.getContentAsString();
byte[] bytes = Base64.decodeBase64(zippedBase64Str);
GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(bytes));

But the result is the same - "Not in GZIP format"

 

Highlighted
Community Hero

Re: Turning off "Accept compressed responses from host" programmatically

Highlighted
Contributor

Re: Turning off "Accept compressed responses from host" programmatically

@nmrao, you keep pointing to the GUI. My question is about the API, not the GUI. I don't have any issues running accessing services from the GUI, but I struggle to decode the response from Java/Groovy code when using SoapUI as an API.

Highlighted
Community Hero

Re: Turning off "Accept compressed responses from host" programmatically

If you make the changes in the preferences, the settings are saved in the soapui-settings.xml file. If you use this settings file while executing(does not have to use UI, at least, you would know what change is required in xml if the preferences are change ), then you have do not have make any additional changes to handle this.



Regards,
Rao.
Highlighted
Community Hero

Re: Turning off "Accept compressed responses from host" programmatically

Any way here it is to change the settings

 

//Change value what is needed for you true or false
boolean value = false;
SoapUI.getSettings().setBoolean(HttpSettings.RESPONSE_COMPRESSION, value);


Regards,
Rao.

View solution in original post

Highlighted
Contributor

Re: Turning off "Accept compressed responses from host" programmatically

Thank you, that was exactly the line of code I was looking for!

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors