Brian Hawkins | 2 Jan 2005 14:15

calling methods in scripts

I'm embedding groovy into a java application I'm witting and here is my 
problem.

In the script I want to define a method like so:
def hello(name) {
    println("hello "+name)
}

Now in my java code after I have evaluated the script that defines the 
above method I want to call that method from the java code.  I'm 
guessing the way to do it is:
groovyShell.evaluate("hello(\"Brian\")");

But alas it is not working.  I'm using the same groovy shell as when I 
evaluated the first script so the binding is the same.

Any help here would be appreciated.

Brian

Phil Wilson | 3 Jan 2005 00:13
Picon

How to pass parameters to Groovlets

Hi all,

I've written a very simple Groovlet based on the information on
http://groovy.codehaus.org/Groovlets but don't seem to be able to pass
a parameter through to the page.

With a traditional servlet or JSP I'd be able to add ?key=value to the
end of the URL and access the value using request.getParameter(key).

If I type hello.groovy?mykey=myvalue into the address bar of the
browser it doesn't even get as far as my code, instead throwing:

groovy.lang.MissingPropertyException: No such property: mykey for
class: groovy.lang.Binding
	groovy.lang.Binding.getVariable(Binding.java:88)
	groovy.servlet.GroovyServlet.service(GroovyServlet.java:145)

Any help gladly received.

Thanks,

Phil

Michael Schuerig | 3 Jan 2005 09:53
Picon
Gravatar

Groovy for JMX?


Programming plain JMX can be somewhat unwieldy. Luckily, for making an 
application manageable, there are very helpful support classes -- I 
recently discovered the offerings in the Spring framework's CVS 
sandbox. Now, having manageable applications, it would be nice to be 
able to actually manage them equally easily from scripts.

What makes programming JMX directly an unpleasurable experience is that 
JMX basically contains its own object model that can be accessed only 
indirectly through ObjectNames and some very general meta-methods. From 
what I know of Groovy, I take it to be possible to map between JMX 
objects/methods and Groovy objects/methods.

Has anyone tried this or can give hints of how to approach this? So far, 
I've only been a very casual Groovy user.

Michael

--

-- 
Michael Schuerig                             Those who call the shots
mailto:michael@...              Are never in the line of fire
http://www.schuerig.de/michael/           --Ani DiFranco, Not So Soft

phkim | 3 Jan 2005 13:24
Picon

Re: How to pass parameters to Groovlets

Hi Phil

I recommend to you the site:
http://groovlet-examples.dev.java.net/

You can find there
groovy-1.0-beta-6-c2.jar and etc.

Kim

> Hi all,
> 
> I've written a very simple Groovlet based on the information on
> http://groovy.codehaus.org/Groovlets but don't seem to be able to pass
> a parameter through to the page.
> 
> With a traditional servlet or JSP I'd be able to add ?key=value to the
> end of the URL and access the value using request.getParameter(key).
> 
> If I type hello.groovy?mykey=myvalue into the address bar of the
> browser it doesn't even get as far as my code, instead throwing:
> 
> groovy.lang.MissingPropertyException: No such property: mykey for
> class: groovy.lang.Binding
> 	groovy.lang.Binding.getVariable(Binding.java:88)
> 	groovy.servlet.GroovyServlet.service(GroovyServlet.java:145)
> 
> Any help gladly received.
> 
> Thanks,
(Continue reading)

Guillaume Laforge | 3 Jan 2005 13:43
Gravatar

Re: How to pass parameters to Groovlets

Hi Kim,

What are exactly the changes you made in Groovlet?
Are the changes like what Boris Gruschko's recent patch contains?
(see GROOVY-686).

--
Guillaume Laforge
http://glaforge.free.fr/weblog

phkim@... wrote:
> Hi Phil
> 
> I recommend to you the site:
> http://groovlet-examples.dev.java.net/
> 
> You can find there
> groovy-1.0-beta-6-c2.jar and etc.
> 
> Kim

Guillaume Laforge | 3 Jan 2005 15:05
Gravatar

Re: Groovy for JMX?

Hello Michael,

Michael Schuerig wrote:
> Programming plain JMX can be somewhat unwieldy. Luckily, for making an 
> application manageable, there are very helpful support classes -- I 
> recently discovered the offerings in the Spring framework's CVS 
> sandbox. Now, having manageable applications, it would be nice to be 
> able to actually manage them equally easily from scripts.
> 
> What makes programming JMX directly an unpleasurable experience is that 
> JMX basically contains its own object model that can be accessed only 
> indirectly through ObjectNames and some very general meta-methods. From 
> what I know of Groovy, I take it to be possible to map between JMX 
> objects/methods and Groovy objects/methods.

Groovy's metaprogramming facilities make it a breathe :-)

> Has anyone tried this or can give hints of how to approach this? So far, 
> I've only been a very casual Groovy user.

I think we've alread got in CVS what you're looking for.
Look at the source of GroovyMBean:
http://cvs.groovy.codehaus.org/viewrep/~raw,r=1.3/groovy/groovy/groovy-core/src/main/groovy/util/GroovyMBean.java

I've never tried it, but from what I see, you should easily be able to 
talk to an MBean in a pretty natural way, with something (untested) like:

import javax.management.*

// get the instance of the MBeanServercConnection from somewhere...
(Continue reading)

Guillaume Laforge | 3 Jan 2005 15:58
Gravatar

Re: [ANN] Scriptom: COM Scripting in Groovy

Salut Cédric,

Cedric Beust wrote:
> This would be very useful, and as a proof of concept, I would love to see a
> BrowserHelperObject implemented in Groovy (for those of you not familiar
> with BHO's, they are pieces of code that receive events from Internet
> Explorer and that can query value from IE, such as the content of the page
> just loaded, access to its DOM, etc...).

A BHO is a pretty neat idea for showing how to wire event handling 
between Groovy and ActiveX/COM components!
I'm almost there, but not yet :-)
In CVS Head, I've added support for event handling, but there are still 
some problems with Groovy and/or with some components, such as the one 
from Internet Explorer.
The idea is that we can write:

myComponent.events.OnLoad = { println "loading" }
myComponent.events.Quit   = { println "quit" }
myComponent.events.listen() // to wire everything

That's pretty weird: it works from a Java file evaluating a Groovy 
script with GroovyShell.evaluate(myScript). But with groovy 
myScript.groovy, it just hangs the JVM.

Is it a problem with class loaders, or something else, I have no clue at 
the moment.

When doing that from java, with Internet Explorer, I have another problem:

(Continue reading)

Michael Schuerig | 3 Jan 2005 16:37
Picon
Gravatar

Re: Groovy for JMX?

On Monday 03 January 2005 15:05, Guillaume Laforge wrote:

> Michael Schuerig wrote:
> > Programming plain JMX can be somewhat unwieldy. Luckily, for making
> > an application manageable, there are very helpful support classes
> > -- I recently discovered the offerings in the Spring framework's
> > CVS sandbox. Now, having manageable applications, it would be nice
> > to be able to actually manage them equally easily from scripts.
> >
> > What makes programming JMX directly an unpleasurable experience is
> > that JMX basically contains its own object model that can be
> > accessed only indirectly through ObjectNames and some very general
> > meta-methods. From what I know of Groovy, I take it to be possible
> > to map between JMX objects/methods and Groovy objects/methods.
>
> Groovy's metaprogramming facilities make it a breathe :-)

I hope so.

> > Has anyone tried this or can give hints of how to approach this? So
> > far, I've only been a very casual Groovy user.
>
> I think we've alread got in CVS what you're looking for.
> Look at the source of GroovyMBean:

Not quite. In the meantime I've developed a slightly better idea of what 
I actually want. How about something syntactically roughly like this

JMX.withConnection(serviceURL) { |jmx|

(Continue reading)

Tarun Ramakrishna | 3 Jan 2005 17:39
Picon

Groovy Shell - any way to keep the statements in buffer after execution ?

Hi all,

I am brand new to groovy - just started on it today. Its just
wonderful to try out proof-of-concept code in the shell. But, if there
is a way to avoid losing the statements after an 'execute/go'
statement, it would truly rock.

Thanks,
Tarun

Jeremy Rayner | 3 Jan 2005 17:54
Picon
Gravatar

Re: Groovy Shell - any way to keep the statements in buffer after execution ?

Hi Tarun,
  I wrote an alternate command line shell, which provides a command history
using up/down arrows, see if you find it any better...

  http://grash.javanicus.com/

Welcome to groovy-land,

jez.

On Mon, 3 Jan 2005 22:09:45 +0530, Tarun Ramakrishna
<lenkite@...> wrote:
> Hi all,
> 
> I am brand new to groovy - just started on it today. Its just
> wonderful to try out proof-of-concept code in the shell. But, if there
> is a way to avoid losing the statements after an 'execute/go'
> statement, it would truly rock.
> 
> Thanks,
> Tarun
> 

--

-- 
http://javanicus.com/blog2


Gmane