JP
17 years agoNew Contributor
Remove empty child and parent tags
I'm looking to find a way to remove empty child & parent tags from a request. Whilst the option 'Remove empty content' gets rid of child elements, the parent element remains in the request.
Having looked around on the forum, I've followed the suggestion of using a request filter, and have managed to get an example filter working (shown below).
Can anyone help me to amend the filter so that it removes empty child & parent tags?
Any help would be appriciated...
---------------------------------
package soapui.demo
import com.eviware.soapui.SoapUI
import com.eviware.soapui.impl.wsdl.submit.transports.http.BaseHttpRequestTransport
import com.eviware.soapui.impl.wsdl.submit.RequestFilter
import com.eviware.soapui.impl.wsdl.WsdlRequest
import com.eviware.soapui.model.iface.Request
import com.eviware.soapui.model.iface.Response
import com.eviware.soapui.model.iface.SubmitContext
public class DemoRequestFilter implements RequestFilter
{
public void afterRequest( SubmitContext context, Response response )
{}
public void filterRequest( SubmitContext context, WsdlRequest wsdlRequest )
{
String content = (String) context.getProperty( BaseHttpRequestTransport.REQUEST_CONTENT )
if( content == null )
{
System.err.println( "Missing request content in context, skipping demofilter" )
}
else
{
System.out.println( "running demofilter" )
content = content.replaceAll( "<(.+)>--remove--", "" )
context.setProperty( BaseHttpRequestTransport.REQUEST_CONTENT, content )
}
}
}
Having looked around on the forum, I've followed the suggestion of using a request filter, and have managed to get an example filter working (shown below).
Can anyone help me to amend the filter so that it removes empty child & parent tags?
Any help would be appriciated...
---------------------------------
package soapui.demo
import com.eviware.soapui.SoapUI
import com.eviware.soapui.impl.wsdl.submit.transports.http.BaseHttpRequestTransport
import com.eviware.soapui.impl.wsdl.submit.RequestFilter
import com.eviware.soapui.impl.wsdl.WsdlRequest
import com.eviware.soapui.model.iface.Request
import com.eviware.soapui.model.iface.Response
import com.eviware.soapui.model.iface.SubmitContext
public class DemoRequestFilter implements RequestFilter
{
public void afterRequest( SubmitContext context, Response response )
{}
public void filterRequest( SubmitContext context, WsdlRequest wsdlRequest )
{
String content = (String) context.getProperty( BaseHttpRequestTransport.REQUEST_CONTENT )
if( content == null )
{
System.err.println( "Missing request content in context, skipping demofilter" )
}
else
{
System.out.println( "running demofilter" )
content = content.replaceAll( "<(.+)>--remove--", "" )
context.setProperty( BaseHttpRequestTransport.REQUEST_CONTENT, content )
}
}
}