You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jerry Jalenak <Je...@LABONE.com> on 2004/06/21 16:11:56 UTC

[OT] Accessing Http Request with Groovy

Hi Guys - 

I know this is a little off topic, but the groovy mailing list doesn't seem
to be very active, and I need to track down an answer on this.  What I'm
trying to do is call a groovy script from a java class (an Action) and pass
over the current Http Request object.  Here's the calling Java code :

<snip>

	GroovyClassLoader groovyClassLoader = new
GroovyClassLoader(classLoader);
	Class groovyClass =
groovyClassLoader.parseClass(form.getValidationScript());

	GroovyObject groovyObject = (GroovyObject)
groovyClass.newInstance();
	Object[] args = {_request};
	validated = ((Boolean) groovyObject.invokeMethod("run",
args)).booleanValue();

</snip>

And here's the (very basic) groovy script :

<snip>

	import javax.servlet.http.HttpServletRequest;
	public class Validate {
		public Boolean run(HttpServletRequest request) {
			println("queryString is " +
request.getQueryString());
			return new Boolean(true);
		}
	}

</snip>

When I run this I'm getting the following error :

java.lang.NoClassDefFoundError:
org/apache/coyote/tomcat5/CoyoteRequestFacade
	
gjdk.org.apache.coyote.tomcat5.CoyoteRequestFacade_GroovyReflector.invoke(Co
yoteRequestFacade_GroovyReflector.java)
	groovy.lang.MetaMethod.invoke(MetaMethod.java:110)
	groovy.lang.MetaClass.doMethodInvoke(MetaClass.java:1020)
	groovy.lang.MetaClass.invokeMethod(MetaClass.java:314)
	org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:139)
	
org.codehaus.groovy.runtime.InvokerHelper.invokeNoArgumentsMethod(InvokerHel
per.java:102)
	Validate.run(script1087827061572.groovy:4)
	gjdk.Validate_GroovyReflector.invoke(Validate_GroovyReflector.java)
	groovy.lang.MetaMethod.invoke(MetaMethod.java:110)
	groovy.lang.MetaClass.doMethodInvoke(MetaClass.java:1020)
	groovy.lang.MetaClass.invokeMethod(MetaClass.java:314)
	
gjdk.groovy.lang.MetaClass_GroovyReflector.invoke(MetaClass_GroovyReflector.
java)
	groovy.lang.MetaMethod.invoke(MetaMethod.java:110)
	groovy.lang.MetaClass.doMethodInvoke(MetaClass.java:1020)
	groovy.lang.MetaClass.invokeMethod(MetaClass.java:314)
	org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:139)
	
org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:10
6)
	Validate.invokeMethod(script1087827061572.groovy)
	org.appframework.controller.Controller.process(Controller.java:213)
	org.appframework.controller.Controller.doGet(Controller.java:104)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:810)

For some reason groovy is looking for the CoyoteRequestFacade, not the
normal javax.servlet.http.HttpServletRequest.  So, for all of you groovy
guru's out there, how can I do this?

Thanks!

Jerry Jalenak
Development Manager, Web Publishing
LabOne, Inc.
10101 Renner Blvd.
Lenexa, KS  66219
(913) 577-1496

jerry.jalenak@labone.com


This transmission (and any information attached to it) may be confidential and
is intended solely for the use of the individual or entity to which it is
addressed. If you are not the intended recipient or the person responsible for
delivering the transmission to the intended recipient, be advised that you
have received this transmission in error and that any use, dissemination,
forwarding, printing, or copying of this information is strictly prohibited.
If you have received this transmission in error, please immediately notify
LabOne at the following email address: securityincidentreporting@labone.com


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] Accessing Http Request with Groovy

Posted by Kris Schneider <kr...@dotech.com>.
How is "classLoader" obtained? Is it set to
Thread.currentThread().getContextClassLoader()?

Quoting Jerry Jalenak <Je...@LABONE.com>:

> Hi Guys - 
> 
> I know this is a little off topic, but the groovy mailing list doesn't seem
> to be very active, and I need to track down an answer on this.  What I'm
> trying to do is call a groovy script from a java class (an Action) and pass
> over the current Http Request object.  Here's the calling Java code :
> 
> <snip>
> 
> 	GroovyClassLoader groovyClassLoader = new
> GroovyClassLoader(classLoader);
> 	Class groovyClass =
> groovyClassLoader.parseClass(form.getValidationScript());
> 
> 	GroovyObject groovyObject = (GroovyObject)
> groovyClass.newInstance();
> 	Object[] args = {_request};
> 	validated = ((Boolean) groovyObject.invokeMethod("run",
> args)).booleanValue();
> 
> </snip>
> 
> And here's the (very basic) groovy script :
> 
> <snip>
> 
> 	import javax.servlet.http.HttpServletRequest;
> 	public class Validate {
> 		public Boolean run(HttpServletRequest request) {
> 			println("queryString is " +
> request.getQueryString());
> 			return new Boolean(true);
> 		}
> 	}
> 
> </snip>
> 
> When I run this I'm getting the following error :
> 
> java.lang.NoClassDefFoundError:
> org/apache/coyote/tomcat5/CoyoteRequestFacade
> 	
> gjdk.org.apache.coyote.tomcat5.CoyoteRequestFacade_GroovyReflector.invoke(Co
> yoteRequestFacade_GroovyReflector.java)
> 	groovy.lang.MetaMethod.invoke(MetaMethod.java:110)
> 	groovy.lang.MetaClass.doMethodInvoke(MetaClass.java:1020)
> 	groovy.lang.MetaClass.invokeMethod(MetaClass.java:314)
> 	org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:139)
> 	
> org.codehaus.groovy.runtime.InvokerHelper.invokeNoArgumentsMethod(InvokerHel
> per.java:102)
> 	Validate.run(script1087827061572.groovy:4)
> 	gjdk.Validate_GroovyReflector.invoke(Validate_GroovyReflector.java)
> 	groovy.lang.MetaMethod.invoke(MetaMethod.java:110)
> 	groovy.lang.MetaClass.doMethodInvoke(MetaClass.java:1020)
> 	groovy.lang.MetaClass.invokeMethod(MetaClass.java:314)
> 	
> gjdk.groovy.lang.MetaClass_GroovyReflector.invoke(MetaClass_GroovyReflector.
> java)
> 	groovy.lang.MetaMethod.invoke(MetaMethod.java:110)
> 	groovy.lang.MetaClass.doMethodInvoke(MetaClass.java:1020)
> 	groovy.lang.MetaClass.invokeMethod(MetaClass.java:314)
> 	org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:139)
> 	
> org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:10
> 6)
> 	Validate.invokeMethod(script1087827061572.groovy)
> 	org.appframework.controller.Controller.process(Controller.java:213)
> 	org.appframework.controller.Controller.doGet(Controller.java:104)
> 	javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
> 	javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
> 
> For some reason groovy is looking for the CoyoteRequestFacade, not the
> normal javax.servlet.http.HttpServletRequest.  So, for all of you groovy
> guru's out there, how can I do this?
> 
> Thanks!
> 
> Jerry Jalenak
> Development Manager, Web Publishing
> LabOne, Inc.
> 10101 Renner Blvd.
> Lenexa, KS  66219
> (913) 577-1496
> 
> jerry.jalenak@labone.com

-- 
Kris Schneider <ma...@dotech.com>
D.O.Tech       <http://www.dotech.com/>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org