header
header
Main Menu
Home
Eviware Store
Downloads
Products
News
Forum
Eviware Blog
Search
FAQs
Customer Area
Support
Documentation
Tutorials
CookBook
Downloads
Forum
Login Form
Welcome, Guest. Please login or register.
January 09, 2009, 01:00:47 am
Username: Password:
Login with username, password and session length

Forgot your password?
 
Interpreting Spaces as against null in String input
Welcome, Guest. Please login or register.
January 09, 2009, 01:00:47 am
Home Help Search Login Register
News: The Forums are up! Welcome to eviware.

+  Eviware Forum
|-+  soapUI
| |-+  soapUI
| | |-+  Interpreting Spaces as against null in String input
« previous next »
Pages: [1] 2 Print
Author Topic: Interpreting Spaces as against null in String input  (Read 1135 times)
Desmond Cassidy
Newbie
*
Posts: 25


« on: June 04, 2008, 11:14:08 am »

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.
Logged
omatzura
Administrator
Hero Member
*****
Posts: 1,666


« Reply #1 on: June 04, 2008, 01:43:59 pm »

Hi Desmond..

I knew this was coming :-)

I guess we could add an option to the editor for this, something in the line of "keep spaces in form fields"? (Although this wouldn't allow you to enter an empty string, which would still be interpreted as null).

Your suggestion with the XXX content is otherwise in use together with an outgoing request filter that removes the content (or the entire element) when a node contains XXX.. If you're interested I can post the code for this extension here..

regards!

/Ole
eviware.com
Logged
Desmond Cassidy
Newbie
*
Posts: 25


« Reply #2 on: June 05, 2008, 11:46:51 am »

Hi Ole,
    Many thanks for the reply...

From what you are saying, if this filter was in place then the XXX would get reduced to an empty string - I have checked this in SoapUI and INDEED this WOULD be a good solution. So for want of a better 'code' - if we advise QA that a content of CLEAR-CONTENT will in fact transmit an empty string rather than a null then this would indeed do the trick...

SO, YES PLEASE...Ole....please post the code for the extension !!!

Best regards and THANKS..

Desmond.
Logged
omatzura
Administrator
Hero Member
*****
Posts: 1,666


« Reply #3 on: June 09, 2008, 10:20:56 pm »

Hi Desmond,

ok, here goes (this is for soapUI Pro only):

The extension goes into a file called DemoRequestFilter.groovy in the soapUI Pro\bin\scripts folder:

Code:
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.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, Request 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--</(\\1)>", "" )
  context.setProperty( BaseHttpRequestTransport.REQUEST_CONTENT, content )
  }
  }
 }

As you can see the filter removes all elements containing "--remove--".

Put the following into a file called demo-listeners.xml in the bin\listeners folder:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<tns:soapui-listeners xmlns:tns="http://eviware.com/soapui/config">

  <tns:listener id="DemoRequestFilter"
    listenerClass="com.eviware.soapui.support.scripting.listeners.ScriptRequestFilter"
    groovyClass="soapui.demo.DemoRequestFilter"
    listenerInterface="com.eviware.soapui.impl.wsdl.submit.RequestFilter"/>
   
</tns:soapui-listeners>

Good Luck!

regards,

/Ole
eviware.com

Logged
Desmond Cassidy
Newbie
*
Posts: 25


« Reply #4 on: October 02, 2008, 03:07:59 pm »

Hi OLe...sorry I didn't pick this reply up at the time...

I implemented the two files...but nothing has been changed on the outgoing request..iy still has '--remove--'....do I need to specify something in the request to utilize them - I  imagine at the Listener end first Huh

Cheers,

Dezzz.
Logged
Desmond Cassidy
Newbie
*
Posts: 25


« Reply #5 on: October 02, 2008, 06:40:05 pm »

Just noticed in the SoapUI Erro log

2008-10-02 19:24:00,816 ERROR [errorlog] java.lang.ClassNotFoundException: soapui.demo.DemoRequestFilter
java.lang.ClassNotFoundException: soapui.demo.DemoRequestFilter
   at java.net.URLClassLoader$1.run(Unknown Source)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.net.URLClassLoader.findClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClass(Unknown Source)
   at java.lang.ClassLoader.loadClassInternal(Unknown Source)
   at java.lang.Class.forName0(Native Method)
   at java.lang.Class.forName(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 com.eviware.soapui.impl.wsdl.WsdlSubmit.submitRequest(WsdlSubmit.java:78)
   at com.eviware.soapui.impl.wsdl.WsdlRequest.submit(WsdlRequest.java:387)
   at com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep.run(WsdlTestRequestStep.java:276)
   at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner.run(WsdlTestCaseRunner.java:185)
   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)
Logged
omatzura
Administrator
Hero Member
*****
Posts: 1,666


« Reply #6 on: October 02, 2008, 11:41:14 pm »

Hi,

hm, are you running from SVN or the latest build? This is nothing to worry about, it just says that the demo-listeners.xml file specified a listener that isn't available..

regards,

/Ole
eviware.com
Logged
omatzura
Administrator
Hero Member
*****
Posts: 1,666


« Reply #7 on: October 03, 2008, 09:49:01 am »

Hi again,

after restarting soapUI, do you see the following message in the soapui log:

Adding listeners from [...\bin\listeners\demo-listeners.xml]

?

regards,

/Ole
eviware.com
Logged
Desmond Cassidy
Newbie
*
Posts: 25


« Reply #8 on: October 03, 2008, 04:24:30 pm »

Hi Ole..

I closed down SoapUI AFTER CLOISNG all projects, deleted the soapui logs and restarted SoapUI

First the soapui.log

2008-10-03 17:21:24,263 INFO  [DefaultSoapUICore] initialized soapui-settings from [D:\Program Files\eviware\soapUI-Pro-2.0.2\bin\soapui-settings.xml]
2008-10-03 17:21:24,315 INFO  [SoapUIProGroovyScriptEngineFactory] Initializing scripts folder [D:\Program Files\eviware\soapUI-Pro-2.0.2\bin\scripts]
2008-10-03 17:21:24,652 ERROR [SoapUI] An error occured [startup failed, D:\Program Files\eviware\soapUI-Pro-2.0.2\bin\scripts\DemoRequestFilter.groovy: 10: Can't have an abstract method in a non-abstract class. The class 'soapui.demo.DemoRequestFilter' must be declared abstract or the method 'void filterRequest(com.eviware.soapui.model.iface.SubmitContext, com.eviware.soapui.impl.wsdl.WsdlRequest)' must be implemented.
 @ line 10, column 8.
   public class DemoRequestFilter implements RequestFilter
          ^

1 error
], see error log for details
2008-10-03 17:21:24,654 ERROR [errorlog] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, D:\Program Files\eviware\soapUI-Pro-2.0.2\bin\scripts\DemoRequestFilter.groovy: 10: Can't have an abstract method in a non-abstract class. The class 'soapui.demo.DemoRequestFilter' must be declared abstract or the method 'void filterRequest(com.eviware.soapui.model.iface.SubmitContext, com.eviware.soapui.impl.wsdl.WsdlRequest)' must be implemented.
 @ line 10, column 8.
   public class DemoRequestFilter implements RequestFilter
          ^

1 error

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, D:\Program Files\eviware\soapUI-Pro-2.0.2\bin\scripts\DemoRequestFilter.groovy: 10: Can't have an abstract method in a non-abstract class. The class 'soapui.demo.DemoRequestFilter' must be declared abstract or the method 'void filterRequest(com.eviware.soapui.model.iface.SubmitContext, com.eviware.soapui.impl.wsdl.WsdlRequest)' must be implemented.
 @ line 10, column 8.
   public class DemoRequestFilter implements RequestFilter
          ^

1 error

   at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:296)
   at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:912)
   at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:436)
   at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:271)
   at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyClassLoader.syncExternalClasses(SourceFile:112)
   at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyClassLoader.<init>(SourceFile:40)
   at com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory.<init>(SourceFile:24)
   at com.eviware.soapui.SoapUIPro$SoapUIProCore.getExtensionClassLoader(SourceFile:518)
   at com.eviware.soapui.DefaultSoapUICore.init(DefaultSoapUICore.java:84)
   at com.eviware.soapui.SoapUIPro$SoapUIProCore.<init>(SourceFile:510)
   at com.eviware.soapui.SoapUIPro.a(SourceFile:151)
   at com.eviware.soapui.SoapUIPro.main(SourceFile:130)
2008-10-03 17:21:24,698 INFO  [SoapUIProGroovyScriptEngineFactory] 5 classes loaded
2008-10-03 17:21:24,700 INFO  [DefaultSoapUICore] Adding listeners from [D:\Program Files\eviware\soapUI-Pro-2.0.2\bin\listeners\demo-listeners.xml]
2008-10-03 17:21:24,713 INFO  [DefaultSoapUICore] Adding listener [class com.eviware.soapui.support.scripting.listeners.ScriptRequestFilter]
2008-10-03 17:21:25,383 INFO  [WorkspaceImpl] Loading workspace from [D:\Users\Desmond\default-soapui-workspace.xml]
2008-10-03 17:21:26,269 INFO  [WsdlProject] Loaded project from [file:/F:/%23%23%23%20Connection%20Data/Testing/TimeSlices/QA%20Supplied/Product%20Timeslice%20Group_GenericUnitType_Inventory-soapui-project.xml]
2008-10-03 17:21:28,469 INFO  [DefaultSoapUICore] Adding actions from [D:\Program Files\eviware\soapUI-Pro-2.0.2\bin\actions\demo-actions.xml]


Now the error log

2008-10-03 17:21:24,654 ERROR [errorlog] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, D:\Program Files\eviware\soapUI-Pro-2.0.2\bin\scripts\DemoRequestFilter.groovy: 10: Can't have an abstract method in a non-abstract class. The class 'soapui.demo.DemoRequestFilter' must be declared abstract or the method 'void filterRequest(com.eviware.soapui.model.iface.SubmitContext, com.eviware.soapui.impl.wsdl.WsdlRequest)' must be implemented.
 @ line 10, column 8.
   public class DemoRequestFilter implements RequestFilter
          ^

1 error

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, D:\Program Files\eviware\soapUI-Pro-2.0.2\bin\scripts\DemoRequestFilter.groovy: 10: Can't have an abstract method in a non-abstract class. The class 'soapui.demo.DemoRequestFilter' must be declared abstract or the method 'void filterRequest(com.eviware.soapui.model.iface.SubmitContext, com.eviware.soapui.impl.wsdl.WsdlRequest)' must be implemented.
 @ line 10, column 8.
   public class DemoRequestFilter implements RequestFilter
          ^

1 error

   at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:296)
   at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:912)
   at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:436)
   at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:271)
   at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyClassLoader.syncExternalClasses(SourceFile:112)
   at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyClassLoader.<init>(SourceFile:40)
   at com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory.<init>(SourceFile:24)
   at com.eviware.soapui.SoapUIPro$SoapUIProCore.getExtensionClassLoader(SourceFile:518)
   at com.eviware.soapui.DefaultSoapUICore.init(DefaultSoapUICore.java:84)
   at com.eviware.soapui.SoapUIPro$SoapUIProCore.<init>(SourceFile:510)
   at com.eviware.soapui.SoapUIPro.a(SourceFile:151)
   at com.eviware.soapui.SoapUIPro.main(SourceFile:130)
Logged
omatzura
Administrator
Hero Member
*****
Posts: 1,666


« Reply #9 on: October 03, 2008, 10:14:41 pm »

Hi,

oh, sorry, my fault; try changing the method declarations in the code to use WsdlRequest instead of Request as the request argument type (in the com.eviware.soapui.impl.wsdl.submit package)..

does that help?

regards!

/Ole
eviware.com
Logged
Desmond Cassidy
Newbie
*
Posts: 25


« Reply #10 on: October 06, 2008, 10:54:26 am »

Hi Ole...I tried amending the code but wasn't sure WHERE you meant me to amend it...

The method to me means....

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--</(\\1)>", "" )
          context.setProperty( BaseHttpRequestTransport.REQUEST_CONTENT, content )
       }
    }

If So....the error now is

2008-10-06 11:52:46,409 INFO  [DefaultSoapUICore] initialized soapui-settings from [D:\Program Files\eviware\soapUI-Pro-2.0.2\bin\soapui-settings.xml]
2008-10-06 11:52:46,540 INFO  [SoapUIProGroovyScriptEngineFactory] Initializing scripts folder [D:\Program Files\eviware\soapUI-Pro-2.0.2\bin\scripts]
2008-10-06 11:52:47,053 ERROR [SoapUI] An error occured [startup failed, D:\Program Files\eviware\soapUI-Pro-2.0.2\bin\scripts\DemoRequestFilter.groovy: 16: unable to resolve class WsdlRequest
 @ line 16, column 52.
   quest( SubmitContext context, WsdlReques
                                 ^

1 error
], see error log for details
2008-10-06 11:52:47,055 ERROR [errorlog] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, D:\Program Files\eviware\soapUI-Pro-2.0.2\bin\scripts\DemoRequestFilter.groovy: 16: unable to resolve class WsdlRequest
 @ line 16, column 52.
   quest( SubmitContext context, WsdlReques
                                 ^

1 error

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, D:\Program Files\eviware\soapUI-Pro-2.0.2\bin\scripts\DemoRequestFilter.groovy: 16: unable to resolve class WsdlRequest
 @ line 16, column 52.
   quest( SubmitContext context, WsdlReques
                                 ^

1 error

Cheers,

Dezzz
Logged
omatzura
Administrator
Hero Member
*****
Posts: 1,666


« Reply #11 on: October 06, 2008, 08:41:50 pm »

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
Logged
Desmond Cassidy
Newbie
*
Posts: 25


« Reply #12 on: October 07, 2008, 12:45:14 pm »

Hi Ole,
    unfortunately there still seems to be a problem....

First here is my code in the scripts

<?xml version="1.0" encoding="UTF-8"?>
<tns:soapui-listeners xmlns:tns="http://eviware.com/soapui/config">

  <tns:listener id="DemoRequestFilter"
          listenerClass="com.eviware.soapui.support.scripting.listeners.ScriptRequestFilter"
          groovyClass="soapui.demo.DemoRequestFilter"
          listenerInterface="com.eviware.soapui.impl.wsdl.submit.RequestFilter"/>   
   
</tns:soapui-listeners>



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

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--</(\\1)>", "" )
          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)
Logged
Desmond Cassidy
Newbie
*
Posts: 25


« Reply #13 on: October 07, 2008, 12:51:44 pm »

Oooops...I tried changing in the Listener the Listener class...

<?xml version="1.0" encoding="UTF-8"?>
<tns:soapui-listeners xmlns:tns="http://eviware.com/soapui/config">

  <tns:listener id="DemoRequestFilter"
          listenerClass="com.eviware.soapui.support.scripting.listeners.ScriptRequestFilter"
          groovyClass="soapui.demo.DemoRequestFilter"
          listenerInterface="com.eviware.soapui.impl.wsdl.WsdlRequest"/>   
   
</tns:soapui-listeners>


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

Cheers,

Dezzz
Logged
omatzura
Administrator
Hero Member
*****
Posts: 1,666


« Reply #14 on: October 07, 2008, 01:28:13 pm »

Hi!

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

regards!

/Ole
eviware.com
Logged
Pages: [1] 2 Print 
« previous next »
Jump to:  


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
header header
header
header