Forum Discussion

Desmond_Cassidy's avatar
Desmond_Cassidy
Contributor
18 years ago

Interpreting Spaces as against null in String input

Hi,
  I have a requirement to pass spaces in a SoapUI request string. The server code needs to distinguish between a null value and a trimmed string which is empty; logic being that a null indicates no change to the DB stored value whilst an empty string would indicate that the DB value should in fact be cleared (or nullified).
  Now if I put spaces into the Form in the SoapUI request then it gets converted (or translated to XML) as a null. In fact the value in XML looks like
  xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

The easiest way around this is to put XXX in the string and then in the XML replace this by spaces...then execute the request.

Now from the 'big picture' I can 'see' why it was developed in such a way as spaces are indeed not visible so this may be deemed as causing more problems than it solves.

ANy suggestion for a workaround so that my Test Cases run whilst interpreting spaces as just that. One suggestion of an enhancement (if indeed spaces are possible to be input from the 'form screen') might be to 'lightly highlight' text as it is entered into the text box thus spaces would get highlighted and a difference would be seen against an intended null value to be passed.

Regards,

Desmond.

16 Replies

  • omatzura's avatar
    omatzura
    Super Contributor
    Hi!

    of course, add the following import to the beginning of the file:

    import com.eviware.soapui.impl.wsdl.WsdlRequest;

    to see if that helps better..

    regards!

    /Ole
    eviware.com
  • Hi Ole,
        unfortunately there still seems to be a problem....

    First here is my code in the scripts




     
        listenerClass="com.eviware.soapui.support.scripting.listeners.ScriptRequestFilter"
        groovyClass="soapui.demo.DemoRequestFilter"
        listenerInterface="com.eviware.soapui.impl.wsdl.submit.RequestFilter"/>
       




    ==============================================

    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 abstract 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 )
    }
    }
    }


    ==================================================

    I took it one step at a time and for each Request submitted I get 2 errors returned....the actual request with the '--remove--' doesn;t seem to be any more different that the previous errors


    Cheers,

    Dezzz.

    ==================================================

    2008-10-07 13:31:35,049 ERROR [errorlog] java.lang.InstantiationException
    java.lang.InstantiationException
    at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.lang.Class.newInstance0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at com.eviware.soapui.support.scripting.listeners.AbstractScriptListener.syncClass(SourceFile:32)
    at com.eviware.soapui.support.scripting.listeners.ScriptRequestFilter.filterRequest(SourceFile:31)
    at com.eviware.soapui.impl.wsdl.submit.transports.http.HttpClientRequestTransport.sendRequest(HttpClientRequestTransport.java:120)
    at com.eviware.soapui.impl.wsdl.WsdlSubmit.run(WsdlSubmit.java:118)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    2008-10-07 13:31:46,772 ERROR [errorlog] java.lang.InstantiationException
    java.lang.InstantiationException
    at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.lang.Class.newInstance0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at com.eviware.soapui.support.scripting.listeners.AbstractScriptListener.syncClass(SourceFile:32)
    at com.eviware.soapui.support.scripting.listeners.ScriptRequestFilter.afterRequest(SourceFile:19)
    at com.eviware.soapui.impl.wsdl.submit.transports.http.HttpClientRequestTransport.sendRequest(HttpClientRequestTransport.java:170)
    at com.eviware.soapui.impl.wsdl.WsdlSubmit.run(WsdlSubmit.java:118)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
  • Oooops...I tried changing in the Listener the Listener class...




     
        listenerClass="com.eviware.soapui.support.scripting.listeners.ScriptRequestFilter"
        groovyClass="soapui.demo.DemoRequestFilter"
        listenerInterface="com.eviware.soapui.impl.wsdl.WsdlRequest"/>
       



    No errors but rejects --remove-- as an invalid code...

    Cheers,

    Dezzz
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi!

    hm.. how do you mean? Are you getting some kind of error message?

    regards!

    /Ole
    eviware.com
  • The error is my service respondimg with invalid code '--remove--'...which means its not replacing it...

    However I noticed the following in the small SoapUI-Pro window..

    Configuring log4j from [jar:file:/D:/Program%20Files/eviware/soapUI-Pro-2.0.2/li
    b/soapui-2.0.2.jar!/soapui-log4j.xml]
    16:48:26,505 INFO  [DefaultSoapUICore] initialized soapui-settings from [D:\Prog
    ram Files\eviware\soapUI-Pro-2.0.2\bin\soapui-settings.xml]
    16:48:26,557 INFO  [SoapUIProGroovyScriptEngineFactory] Initializing scripts fol
    der [D:\Program Files\eviware\soapUI-Pro-2.0.2\bin\scripts]
    16:48:26,926 INFO  [SoapUIProGroovyScriptEngineFactory] 5 classes loaded
    16:48:26,928 INFO  [DefaultSoapUICore] Adding listeners from [D:\Program Files\e
    viware\soapUI-Pro-2.0.2\bin\listeners\demo-listeners.xml]
    Error initializing Listener: java.lang.RuntimeException: Listener interface: com
    .eviware.soapui.impl.wsdl.WsdlRequest must be an interface
    16:48:27,537 INFO  [WorkspaceImpl] Loading workspace from [D:\Users\Desmond\defa
    ult-soapui-workspace.xml]
    16:48:28,027 INFO  [WsdlProject] Loaded project from [file:/F:/%23%23%23%20Conne
    ction%20Data/Testing/TimeSlices/QA%20Supplied/Product%20TimeSlice%20Component_Un
    itType-soapui-project.xml]
    16:48:29,573 INFO  [DefaultSoapUICore] Adding actions from [D:\Program Files\evi
    ware\soapUI-Pro-2.0.2\bin\actions\demo-actions.xml]
    Exception in thread "main" java.lang.IllegalArgumentException: No enum const cla
    ss com.eviware.soapui.lic.LicenseType.professional
            at java.lang.Enum.valueOf(Unknown Source)
            at com.eviware.soapui.lic.LicenseType.valueOf(SourceFile:11)
            at com.eviware.soapui.lic.LicenseData.getType(SourceFile:148)
            at com.eviware.soapui.SoapUIPro.checkLicense(SourceFile:175)
            at com.eviware.soapui.SoapUIPro.main(SourceFile:132)