Develop and Test Script Filters

You can test scripts as you development them by using the filter results API and passing it a social contact id. Doing this will run the filter on the social contact and return the results in XML, along with the output of any logs or exceptions output by the script.

Note

Errors can result if an editor such as Notepad is used to edit a script written in a language containing multi-byte characters. Eclipse and Notepad++ are the most reliable editors to use for editing scripts.

The procedure to test script filters during development is as follows:

Procedure


Step 1

Run a Campaign results GET to obtain a social contact link. Each <entry> has a <link rel="socialcontact" href="socialcontactRefURL">.

Step 2

Run a Filters Get List to obtain the refURL of the script filter you want to test.

Step 3

Run a Filter Results GET and add the refURL of the social contact as a parameter.

Example:

https://<ServerIP>:<Port>/ccp-webapp/ccp/filter/

103105/results?socialContact=

https://<ServerIP>:<Port>/ccp-webapp/ccp/socialcontact/

AB1C35141000013200000F450A568DD2.

Step 4

Enter that URL in the address bar of a browser to view the XML filter result.

Example:

The < logBuffer> is all the output from the script, including logging and exceptions.

 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
- <FilterResult>
<logBuffer>
Bad script. 
Security rules violation exception: startup failed: 
General error during canonicalization: 
Indirect import checks prevents 
usage of expression java.lang.SecurityException: 
Indirect import checks prevents usage of expression 
at org.codehaus.groovy.control.customizers.
SecureASTCustomizer$SecuringCode
Visitor.assertExpressionAuthorized
(SecureASTCustomizer.java:682) 
at org.codehaus.groovy.control.customizers.
SecureASTCustomizer
$SecuringCodeVisitor.visitConstructorCallExpression
SecureASTCustomizer.java:845) 
at org.codehaus.groovy.ast.expr.
ConstructorCallExpression.visit
(ConstructorCallExpression.java:43)
at org.codehaus.groovy.control.customizers.
SecureASTCustomizer
$SecuringCodeVisitor.visitThrowStatement
(SecureASTCustomizer.java:804)
at org.codehaus.groovy.ast.stmt.ThrowStatement.visit
(ThrowStatement.java:41)
at org.codehaus.groovy.control.customizers.
SecureASTCustomizer
$SecuringCodeVisitor.visitBlockStatement
(SecureASTCustomizer.java:705)
at org.codehaus.groovy.ast.stmt.BlockStatement.
visit(BlockStatement.java:69)
at org.codehaus.groovy.control.customizers.
SecureASTCustomizer.call
(SecureASTCustomizer.java:549)
at org.codehaus.groovy.control.CompilationUnit.
applyToPrimaryClassNodes
(CompilationUnit.java:957)
at org.codehaus.groovy.control.CompilationUnit.
doPhaseOperation
(CompilationUnit.java:542) 
at org.codehaus.groovy.control.CompilationUnit.
processPhaseOperations
(CompilationUnit.java:520)
at org.codehaus.groovy.control.CompilationUnit.
compile(CompilationUnit.java:497)
at groovy.lang.GroovyClassLoader.doParseClass
(GroovyClassLoader.java:306)
at groovy.lang.GroovyClassLoader.parseClass
(GroovyClassLoader.java:287)
at groovy.util.GroovyScriptEngine$ScriptClassLoader.
parseClass
(GroovyScriptEngine.java:197)
at groovy.lang.GroovyClassLoader.parseClass
(GroovyClassLoader.java:267)
at groovy.lang.GroovyClassLoader.parseClass
(GroovyClassLoader.java:214)
at groovy.util.GroovyScriptEngine.loadScriptByName
(GroovyScriptEngine.java:470)
at groovy.util.GroovyScriptEngine.createScript
(GroovyScriptEngine.java:539)
at groovy.util.GroovyScriptEngine.run
(GroovyScriptEngine.java:526)
at com.cisco.ccbu.ccp.filter.ScriptFilter.
executeFilterOnSocialContact
(ScriptFilter.java:148)
at com.cisco.ccbu.ccp.filter.FilterManager.
executeGenericFilter
(FilterManager.java:688)
at com.cisco.ccbu.ccp.filter.FilterManager.
applyFilterOnSocialContact
(FilterManager.java:497)
at com.cisco.ccbu.ccp.filter.FilterManager.
applyFilterOnSocialContact
(FilterManager.java:413) 
at com.cisco.ccbu.ccp.filter.FilterSubsystem.
executeFilterOnSocialContact
(FilterSubsystem.java:356)
at com.cisco.ccbu.ccp.filter.FilterSubsystem.
handleFilterSocialContactRequest
(FilterSubsystem.java:334)
at com.cisco.ccbu.ccp.filter.FilterSubsystem.
handleMessage
(FilterSubsystem.java:130)
at com.cisco.ccbu.ccp.filter.messaging.FilterMsgHandler.
handleMessage
(FilterMsgHandler.java:22)
at com.cisco.ccbu.infra.msg.BaseMessage$Handler.
handleMessageInternal
(BaseMessage.java:1197)
at com.cisco.ccbu.infra.msg.BaseMessage$Handler.
handleMessage
(BaseMessage.java:1175)
at com.cisco.ccbu.infra.msg.MSGHolder.handleImpl
(MSGHolder.java:322)
at com.cisco.ccbu.infra.msg.MSGDispatcher$Hook.handle
(MSGDispatcher.java:2976)
at com.cisco.ccbu.infra.msg.MSGDispatcher$DispatchRunnable.
handleMessage
(MSGDispatcher.java:3232)
at com.cisco.ccbu.infra.msg.MSGDispatcher$DispatchRunnable.run
(MSGDispatcher.java:3262)
at com.cisco.ccbu.infra.threads.InstrumentedRunnable.run
(InstrumentedRunnable.java:88)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask
(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run
(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619) 
at com.cisco.ccbu.infra.threads.ThreadPoolThread.run
(ThreadPoolThread.java:164) 
Caused by: java.lang.SecurityException: Importing
[java.lang.NullPointerException] is not allowed 
at org.codehaus.groovy.control.customizers.SecureASTCustomizer.
assertImportIsAllowed
(SecureASTCustomizer.java:574) 
at org.codehaus.groovy.control.customizers.SecureASTCustomizer.
access$800
(SecureASTCustomizer.java:121) 
at org.codehaus.groovy.control.customizers.SecureASTCustomizer
$SecuringCodeVisitor.assertExpressionAuthorized
(SecureASTCustomizer.java:664) ... 38 more 1 error
</logBuffer>

<refURL>
 https://[ServerIP]:[Port]/ccp-webapp/ccp/
 filter/103105/results</refURL>
<result>100</result>
<socialContact>
 https://[ServerIP]:[Port]/ccp-webapp/ccp/socialcontact/
 AB1C35141000013200000F450A568DD2
</socialContact>
</FilterResult>