I want to play around with NekoHtml, in Groovy. I thought of adding it via Grape.
I tried this way :
#GrabResolver(root="http://net.sourceforge.nekohtml/nekohtml")
in my Groovy code.
But it is throwing an error like this :
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
/home/anto/Groovy/webScrape/webFetch.groovy: 3: unexpected token: # line 3, column 1.
The NekoHtml can be found in Maven over here.
Edit:
Now I have a code like this :
#Grab('net.sourceforge.nekohtml:nekohtml:1.9.15')
import org.cyberneko.html.parsers.SAXParser
def url = 'http://java.sun.com'
def html = new XmlSlurper(new org.cyberneko.html.parsers.SAXParser()).parse(url)
def bolded = html.'**'.findAll{ it.name() == 'B' }
def out = bolded.A*.text().collect{ it.trim() }
out.removeAll([''])
out[2..5].each{ println it }
which throws the error like this :
Caught: java.lang.NoClassDefFoundError: org/apache/xerces/parsers/AbstractSAXParser
java.lang.NoClassDefFoundError: org/apache/xerces/parsers/AbstractSAXParser
Caused by: java.lang.ClassNotFoundException: org.apache.xerces.parsers.AbstractSAXParser
Couldn't able to figure out what this error states.
Thanks in advance.
Have you tried:
#Grab('net.sourceforge.nekohtml:nekohtml:1.9.15')
Then it should resolve from maven
Related
I have the following models setup:
class Cluster(models.Model):
name = models.CharField(...)
...
class ResourceRequest(Process):
cluster = models.ForeignKey('Cluster')
def clean(self, ...):
if self.cluster.name == 'abc':
...
And when I try to post to:
http://pmas-local:8000/workflow/api/tasks/vm_request/resourcerequest/start/
it complains that ResourceRequest has no cluster.
Stacktrace shows if self.cluster.name == 'abc': caused the problem.
The error is not related to django-viewflow. That's standard django error for a foreign key field, which means that self.cluster is None.
Groovy RestClient throw the following Error when Getting the List of Object
this is the code
List<Code> codeList = restClient.get(path:"codes",headers: [Accept: 'application/json'])
Exception in thread "main" org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'groovyx.net.http.HttpResponseDecorator#7526515b' with class 'groovyx.net.http.HttpResponseDecorator' to class 'java.util.List'
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:360)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:599)
After changing the code like below ,its working fine
def codeList = restClient.get(path:"codes",headers: [Accept: 'application/json'])
List<Code> codes = codeList.data
Trying to use the commons-vfs sync ant task from Groovy. Solved most of the things, but still having some issues. Here is my groovy script:
#Grapes([
#Grab(group='org.apache.commons', module='commons-vfs2', version='2.0'),
#Grab(group='com.jcraft', module='jsch', version='0.1.53'),
#GrabConfig(systemClassLoader = true)
])
import groovy.xml.NamespaceBuilder
import groovy.io.FileType
localRootDir = 'forUpdateSite'
updateServer = 'some.remote.server.com'
remoteRootDir = '/var/www/directory'
println("Syncing files from ${localRootDir} to ${updateServer} ${remoteRootDir}");
def ant = new AntBuilder()
def vfs = NamespaceBuilder.newInstance(ant, 'antlib:org.apache.commons.vfs2.tasks')
def remoteURI = "sftp://username:{FAKEENCRYPTEDPASSWORD}#${updateServer}${remoteRootDir}"
vfs.sync (destdir: remoteURI) {
src() {
file: localRootDir
}
}
At this point the only thing I am missing is how to specify the local directory and files. This example gives me this stack trace:
Syncing files from forUpdateSite to some.remote.server.com /var/www/directory
Caught: : No source file specified.
: No source file specified.
at org.apache.commons.vfs2.tasks.AbstractSyncTask.addConfiguredSrc(AbstractSyncTask.java:149)
at org.apache.tools.ant.IntrospectionHelper$AddNestedCreator.istore(IntrospectionHelper.java:1469)
at org.apache.tools.ant.IntrospectionHelper$AddNestedCreator.store(IntrospectionHelper.java:1463)
at org.apache.tools.ant.IntrospectionHelper$Creator.store(IntrospectionHelper.java:1370)
at org.apache.tools.ant.UnknownElement.handleChild(UnknownElement.java:582)
at org.apache.tools.ant.UnknownElement.handleChildren(UnknownElement.java:349)
at org.apache.tools.ant.UnknownElement.configure(UnknownElement.java:201)
at org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:163)
at syncToUpdateSite.run(syncToUpdateSite.groovy:53)
Turned out to be pretty simple:
#Grapes([
#Grab(group='org.apache.commons', module='commons-vfs2', version='2.0'),
#Grab(group='com.jcraft', module='jsch', version='0.1.53'),
#GrabConfig(systemClassLoader = true)
])
import groovy.xml.NamespaceBuilder
import groovy.io.FileType
localRootDir = 'forUpdateSite'
updateServer = 'some.remote.server.com'
remoteRootDir = '/var/www/directory'
println("Syncing files from ${localRootDir} to ${updateServer} ${remoteRootDir}");
def ant = new AntBuilder()
def vfs = NamespaceBuilder.newInstance(ant, 'antlib:org.apache.commons.vfs2.tasks')
def remoteURI = "sftp://username:{FAKEENCRYPTEDPASSWORD}#${updateServer}${remoteRootDir}"
vfs.sync (destdir: remoteURI,
src: localRootDir)
Note that you have to include the jsch module with #Grab for the sftp URL parsing to work. I was getting the stack trace below before I included that.
Caught: : Badly formed URI "sftp://username:***#some.remote.server.com/var/www/directory".
: Badly formed URI "sftp://username:***#some.remote.server.com/var/www/directory".
at org.apache.commons.vfs2.tasks.AbstractSyncTask.execute(AbstractSyncTask.java:227)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at syncToUpdateSite.run(syncToUpdateSite.groovy:52)
Caused by: org.apache.commons.vfs2.FileSystemException: Badly formed URI "sftp://username:***#some.remote.server.com/var/www/directory".
at org.apache.commons.vfs2.provider.url.UrlFileProvider.findFile(UrlFileProvider.java:91)
at org.apache.commons.vfs2.impl.DefaultFileSystemManager.resolveFile(DefaultFileSystemManager.java:713)
at org.apache.commons.vfs2.impl.DefaultFileSystemManager.resolveFile(DefaultFileSystemManager.java:649)
at org.apache.commons.vfs2.impl.DefaultFileSystemManager.resolveFile(DefaultFileSystemManager.java:636)
at org.apache.commons.vfs2.tasks.VfsTask.resolveFile(VfsTask.java:56)
at org.apache.commons.vfs2.tasks.AbstractSyncTask.handleFiles(AbstractSyncTask.java:247)
at org.apache.commons.vfs2.tasks.AbstractSyncTask.execute(AbstractSyncTask.java:218)
... 3 more
Caused by: java.net.MalformedURLException: unknown protocol: sftp
at org.apache.commons.vfs2.provider.url.UrlFileProvider.findFile(UrlFileProvider.java:72)
... 9 more
I am receiving this null pointer exception and not sure how to resolve/debug it. The script contains a class with two methods. Code is doing what it is supposed to do. Any pointers on geeting started to resolve this?
java.lang.NullPointerException
at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:154)
at com.eviware.soapui.model.testsuite.TestStep$run.call(Unknown Source)
at Script48.run(Script48.groovy:22)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:92)
at com.eviware.soapui.impl.wsdl.teststeps.assertions.basic.GroovyScriptAssertion.assertScript(GroovyScriptAssertion.java:116)
at com.eviware.soapui.impl.wsdl.teststeps.assertions.basic.GroovyScriptAssertion.internalAssertResponse(GroovyScriptAssertion.java:128)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion.assertResponse(WsdlMessageAssertion.java:150)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequest.assertResponse(WsdlTestRequest.java:176)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep.propertyChange(WsdlTestRequestStep.java:339)
at com.eviware.soapui.impl.wsdl.support.assertions.AssertionsSupport.propertyChange(AssertionsSupport.java:79)
at java.beans.PropertyChangeSupport.fire(Unknown Source
Script looks like this.
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner
import com.eviware.soapui.support.types.StringToObjectMap
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext
context.setProperty("searchChange", new searchChange())
class searchChange{
def search(a,b,TCRunner){
def search_TestCase = TCRunner.testCase.testSuite.getTestCaseByName("TestCaseName")
search_TestCase.setPropertyValue("a", a)
search_TestCase.setPropertyValue("b", b)
search_TestCase.run(new com.eviware.soapui.support.types.StringToObjectMap(), false)
}
def runner(tCase,mExchange){
new WsdlTestCaseRunner( tCase, new StringToObjectMap() );
}
}
When using the above class,the line(groovy:22) in code that throws exception is
scripts.testCases["Library"].testSteps["Lib"].run(context.getTestRunner(),context)
In a soapui groovy script test step I've this.
context.setProperty("searchA", new searchA());
class searchA{
def testRunner
def searchA(testRunner){
this.testRunner=testRunner
}
def search(a,b){
def search_TestCase = testRunner.testCase.testSuite.getTestCaseByName("Search")
search_TestCase.setPropertyValue("ABC", a)
search_TestCase.setPropertyValue("DEF", b)
search_TestCase.run(new com.eviware.soapui.support.types.StringToObjectMap(), false)
}
}
and in an assertion script in a different test suite I am calling the above code like this.
scripts = messageExchange.modelItem.testStep.testCase.testSuite.project.testSuites["Test"]
scripts.testCases["Lib123"].testSteps["TestLib123"].run(context.getTestRunner(),context)
context.searchA.search("value1","value2")
but this gives me error "can not get property testCase on null object". whats wrong here?
I am not seeing null object error now. The issue was that testRunner is not available in script assertion so we need to create it like this in script assertion and then pass it in the caller method.
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner
import com.eviware.soapui.support.types.StringToObjectMap
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext
testCase = messageExchange.modelItem.testStep.testCase
tcRunner = new WsdlTestCaseRunner( testCase, new StringToObjectMap() );
context.searchA.search("value1","value2",tcRunner)
This thread helped me.