[groovy-user] Code works in Java but not in Groovy

14 views
Skip to first unread message

Grey, Lee

unread,
Dec 2, 2010, 7:48:56 PM12/2/10
to us...@groovy.codehaus.org
I'm trying to use Groovy with SonicMQ's APIs, but I've run into a situation where I cannot make a successful call from Groovy, although the same call works fine from Java.
 
At first, I was obviously just trying to make the API call from Groovy:
 
def mff = new MFMgmtBeanFactory()
mff.connect('Domain1', url, usr, pwd)
List<String> containers = mff.list("/Containers/")
 
[This would be a lot easier if Copy worked from the GroovyConsole Output panel.]
 
When running this, I get, among other things, java.io.StreamCorruptedException: invalid type code: 01
 
But I determined that the same basic code written in Java works fine.  So, I figured I would sidestep the issue by creating a Java library that I could call from Groovy.  But that Java library, which I've tried calling from both Java and from Groovy, works in one but not the other.  The calls made by Java succeed.  The calls made by Groovy fail.
 
So I'm left wondering if there's something different in the JVMs, although there's no good reason I know of that these API calls wouldn't work in any compatible JVM.  Even if there is a difference, why would Groovy not be able to make the call?
 
I can, of course, provide the code, but it's unlikely you're going to have SonicMQ.  And I don't think this is a source code problem.  What is it about Groovy or the Groovy environment that prevents this call from succeeding, both directly and indirectly?
 
Thanks for any insights,
Lee Grey
 

Hamlet DArcy

unread,
Dec 3, 2010, 1:39:58 AM12/3/10
to us...@groovy.codehaus.org
Do you have a stack trace?

--
Hamlet D'Arcy
hamlet...@canoo.com

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Grey, Lee

unread,
Dec 3, 2010, 11:50:44 AM12/3/10
to us...@groovy.codehaus.org
Thanks for your reply, Hamlet.

Yes, there's a long stacktrace, but I can't copy it from GroovyConsole, unless there is a trick to copying from the Output pane.

Thanks,
Lee

Andy Goodspeed

unread,
Dec 3, 2010, 11:56:49 AM12/3/10
to us...@groovy.codehaus.org
No trick - highlight what you want and press CTL-C.

BTW, are you sure that you have the classpath for the GroovyConsole set up to support what you are trying to do? That is one common problem...

Andrew Goodspeed

"...we have normality, I repeat we have normality. Anything you still can’t cope with is therefore your own problem." -Douglas Adams (Trillian)



"Grey, Lee" <Lee....@ncr.com>

12/03/2010 11:51 AM

Please respond to
us...@groovy.codehaus.org

To
"us...@groovy.codehaus.org" <us...@groovy.codehaus.org>
cc
Subject
RE: [groovy-user] Code works in Java but not in Groovy


Tim Yates

unread,
Dec 3, 2010, 12:03:56 PM12/3/10
to us...@groovy.codehaus.org
Just checked, and I can't copy the output on my Mac :-/

Cédric CHAMPEAU

unread,
Dec 3, 2010, 12:07:13 PM12/3/10
to us...@groovy.codehaus.org
I have the problem too on Ubuntu. Seems to be Java related. Here's how I do it : CTRL+C, then paste in a basic editor (gedit on Ubuntu). It works because this editor doesn't manage rich text. Then I copy it from the editor to whatever I need. Overkill, but it works.

Le 03/12/2010 18:03, Tim Yates a �crit�:
Just checked, and I can't copy the output on my Mac :-/

On 3 December 2010 16:56, Andy Goodspeed <AGood...@cfglife.com> wrote:
No trick - highlight what you want and press CTL-C.

BTW, are you sure that you have the classpath for the GroovyConsole set up to support what you are trying to do? That is one common problem...

Andrew Goodspeed

"...we have normality, I repeat we have normality. Anything you still can�t cope with is therefore your own problem." -Douglas Adams (Trillian)



"Grey, Lee" <Lee....@ncr.com>

12/03/2010 11:51 AM

Please respond to
us...@groovy.codehaus.org

To
"us...@groovy.codehaus.org" <us...@groovy.codehaus.org>
cc

Subject
RE: [groovy-user] Code works in Java but not in Groovy







Thanks for your reply, Hamlet.

Yes, there's a long stacktrace, but I can't copy it from GroovyConsole, unless there is a trick to copying from the Output pane.

Thanks,
Lee




--

C�dric�CHAMPEAU
Responsable du d�veloppement logiciel

Des�moteurs�qui�comprennent�votre�m�tier

pablomar

unread,
Dec 3, 2010, 12:16:42 PM12/3/10
to us...@groovy.codehaus.org
I got the same problem even on windows xp. I had to copy the text to notepad or pspad and then copy/paste it on a email for example


On Fri, Dec 3, 2010 at 12:07 PM, Cédric CHAMPEAU <cedric....@lingway.com> wrote:
I have the problem too on Ubuntu. Seems to be Java related. Here's how I do it : CTRL+C, then paste in a basic editor (gedit on Ubuntu). It works because this editor doesn't manage rich text. Then I copy it from the editor to whatever I need. Overkill, but it works.

Le 03/12/2010 18:03, Tim Yates a écrit :
Just checked, and I can't copy the output on my Mac :-/

On 3 December 2010 16:56, Andy Goodspeed <AGood...@cfglife.com> wrote:
No trick - highlight what you want and press CTL-C.

BTW, are you sure that you have the classpath for the GroovyConsole set up to support what you are trying to do? That is one common problem...

Andrew Goodspeed

"...we have normality, I repeat we have normality. Anything you still can’t cope with is therefore your own problem." -Douglas Adams (Trillian)



"Grey, Lee" <Lee....@ncr.com>

12/03/2010 11:51 AM

Please respond to
us...@groovy.codehaus.org

To
"us...@groovy.codehaus.org" <us...@groovy.codehaus.org>
cc

Subject
RE: [groovy-user] Code works in Java but not in Groovy







Thanks for your reply, Hamlet.

Yes, there's a long stacktrace, but I can't copy it from GroovyConsole, unless there is a trick to copying from the Output pane.

Thanks,
Lee




--

Cédric CHAMPEAU
Responsable du développement logiciel

Des moteurs qui comprennent votre métier


signature.gif

Grey, Lee

unread,
Dec 3, 2010, 12:19:45 PM12/3/10
to us...@groovy.codehaus.org
Fair enough.  I guess it's the paste into Outlook that doesn't work.  Here it is, pasted into Notepad++ and then copied from there and pasted into Outlook.  (Software is weird.)
 
 
Exception thrown
Dec 3, 2010 12:00:50 PM org.codehaus.groovy.runtime.StackTraceUtils sanitize
 
WARNING: Sanitizing stacktrace:
 
com.sonicsw.mf.mgmtapi.runtime.ProxyRuntimeException
 
 at com.sonicsw.mf.jmx.client.DirectoryServiceProxy.listFSAll(DirectoryServiceProxy.java:1611)
 
 at com.sonicsw.mx.config.impl.ConfigServer.list(ConfigServer.java:1083)
 
 at com.sonicsw.ma.mgmtapi.config.impl.AbstractMgmtBeanFactory.list(AbstractMgmtBeanFactory.java:312)
 
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 
 at java.lang.reflect.Method.invoke(Method.java:597)
 
 at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:229)
 
 at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52)
 
 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
 
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
 
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
 
 at mgmt.run(mgmt.groovy:19)
 
 at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:264)
 
 at groovy.lang.GroovyShell.run(GroovyShell.java:513)
 
 at groovy.lang.GroovyShell.run(GroovyShell.java:170)
 
 at groovy.lang.GroovyShell$run$0.call(Unknown Source)
 
 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
 
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
 
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:132)
 
 at groovy.ui.Console$_runScriptImpl_closure16.doCall(Console.groovy:890)
 
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 
 at java.lang.reflect.Method.invoke(Method.java:597)
 
 at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
 
 at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
 
 at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:273)
 
 at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)
 
 at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
 
 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44)
 
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
 
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:149)
 
 at groovy.ui.Console$_runScriptImpl_closure16.doCall(Console.groovy)
 
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 
 at java.lang.reflect.Method.invoke(Method.java:597)
 
 at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
 
 at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
 
 at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:273)
 
 at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)
 
 at groovy.lang.Closure.call(Closure.java:276)
 
 at groovy.lang.Closure.call(Closure.java:271)
 
 at groovy.lang.Closure.run(Closure.java:354)
 
 at java.lang.Thread.run(Thread.java:662)
 
Caused by...
 
java.io.StreamCorruptedException: invalid type code: 01
 
 at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1355)
 
 at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1946)
 
 at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1870)
 
 at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
 
 at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
 
 at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
 
 at java.util.HashMap.readObject(HashMap.java:1030)
 
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 
 at java.lang.reflect.Method.invoke(Method.java:597)
 
 at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974)
 
 at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1848)
 
 at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
 
 at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
 
 at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1666)
 
 at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1322)
 
 at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
 
 at com.sonicsw.mf.comm.jms.ConnectorClient.unpackResponse(ConnectorClient.java:1598)
 
 at com.sonicsw.mf.comm.jms.ConnectorClient.invoke(ConnectorClient.java:874)
 
 at com.sonicsw.mf.comm.jms.ConnectorClient.invoke(ConnectorClient.java:637)
 
 at com.sonicsw.mf.jmx.client.JMSConnectorClient.invoke(JMSConnectorClient.java:846)
 
 at com.sonicsw.mf.jmx.client.JMSConnectorClient.invoke(JMSConnectorClient.java:803)
 
 at com.sonicsw.mf.jmx.client.DirectoryServiceProxy.listFSAll(DirectoryServiceProxy.java:1604)
 
 at com.sonicsw.mx.config.impl.ConfigServer.list(ConfigServer.java:1083)
 
 at com.sonicsw.ma.mgmtapi.config.impl.AbstractMgmtBeanFactory.list(AbstractMgmtBeanFactory.java:312)
 
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 
 at java.lang.reflect.Method.invoke(Method.java:597)
 
 at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:229)
 
 at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52)
 
 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
 
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
 
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
 
 at mgmt.run(mgmt.groovy:19)
 
 at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:264)
 
 at groovy.lang.GroovyShell.run(GroovyShell.java:513)
 
 at groovy.lang.GroovyShell.run(GroovyShell.java:170)
 
 at groovy.lang.GroovyShell$run$0.call(Unknown Source)
 
 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
 
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
 
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:132)
 
 at groovy.ui.Console$_runScriptImpl_closure16.doCall(Console.groovy:890)
 
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 
 at java.lang.reflect.Method.invoke(Method.java:597)
 
 at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
 
 at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
 
 at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:273)
 
 at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)
 
 at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
 
 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44)
 
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
 
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:1
49)
 
 at groovy.ui.Console$_runScriptImpl_closure16.doCall(Console.groovy)
 
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 
 at java.lang.reflect.Method.invoke(Method.java:597)
 
 at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
 
 at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
 
 at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:273)
 
 at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)
 
 at groovy.lang.Closure.call(Closure.java:276)
 
 at groovy.lang.Closure.call(Closure.java:271)
 
 at groovy.lang.Closure.run(Closure.java:354)
 
 at java.lang.Thread.run(Thread.java:662)
Dec 3, 2010 12:00:51 PM org.codehaus.groovy.runtime.StackTraceUtils sanitize
 
WARNING: Sanitizing stacktrace:
 
com.sonicsw.ma.mgmtapi.config.MgmtException: Failed to list  - null
 
 at com.sonicsw.ma.mgmtapi.config.impl.AbstractMgmtBeanFactory.list(AbstractMgmtBeanFactory.java:333)
 
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 
 at java.lang.reflect.Method.invoke(Method.java:597)
 
 at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:229)
 
 at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52)
 
 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
 
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
 
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
 
 at mgmt.run(mgmt.groovy:19)
 
 at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:264)
 
 at groovy.lang.GroovyShell.run(GroovyShell.java:513)
 
 at groovy.lang.GroovyShell.run(GroovyShell.java:170)
 
 at groovy.lang.GroovyShell$run$0.call(Unknown Source)
 
 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
 
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
 
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:132)
 
 at groovy.ui.Console$_runScriptImpl_closure16.doCall(Console.groovy:890)
 
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 
 at java.lang.reflect.Method.invoke(Method.java:597)
 
 at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
 
 at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
 
 at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:273)
 
 at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)
 
 at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
 
 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44)
 
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
 
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:149)
 
 at groovy.ui.Console$_runScriptImpl_closure16.doCall(Console.groovy)
 
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 
 at java.lang.reflect.Method.invoke(Method.java:597)
 
 at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
 
 at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
 
 at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:273)
 
 at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)
 
 at groovy.lang.Closure.call(Closure.java:276)
 
 at groovy.lang.Closure.call(Closure.java:271)
 
 at groovy.lang.Closure.run(Closure.java:354)
 
 at java.lang.Thread.run(Thread.java:662)
 
Caused by: com.sonicsw.mf.mgmtapi.runtime.ProxyRuntimeException
 
 at com.sonicsw.mf.jmx.client.DirectoryServiceProxy.listFSAll(DirectoryServiceProxy.java:1611)
 
 at com.sonicsw.mx.config.impl.ConfigServer.list(ConfigServer.java:1083)
 
 at com.sonicsw.ma.mgmtapi.config.impl.AbstractMgmtBeanFactory.list(AbstractMgmtBeanFactory.java:312)
 
 at mgmt.run(mgmt.groovy:19)
 
com.sonicsw.ma.mgmtapi.config.MgmtException: Failed to list  - null
 
 at com.sonicsw.ma.mgmtapi.config.impl.AbstractMgmtBeanFactory.list(AbstractMgmtBeanFactory.java:333)
 
 at mgmt.run(mgmt.groovy:19)
 
Caused by: com.sonicsw.mf.mgmtapi.runtime.ProxyRuntimeException
 
 at com.sonicsw.mf.jmx.client.DirectoryServiceProxy.listFSAll(DirectoryServiceProxy.java:1611)
 
 at com.sonicsw.mx.config.impl.ConfigServer.list(ConfigServer.java:1083)
 
 at com.sonicsw.ma.mgmtapi.config.impl.AbstractMgmtBeanFactory.list(AbstractMgmtBeanFactory.java:312)
 
 ... 1 more
 
 
This is the script:
 

def

url = 'tcp://localhost:2506'

def

usr = 'Administrator'

def

pwd = 'Administrator'

import

com.sonicsw.mf.jmx.client.*

import

com.sonicsw.mf.mgmtapi.runtime.*

import

com.sonicsw.mq.mgmtapi.runtime.*

import

javax.management.*

 

import

com.sonicsw.mf.mgmtapi.config.*

import

com.sonicsw.mq.mgmtapi.config.*

import

com.sonicsw.ma.mgmtapi.config.*

import

main.JavaUtil

def

mff = new MFMgmtBeanFactory()

mff.connect('Domain1', url, usr, pwd)

List<String> containers = mff.list("/Containers/") 

 

The call to mff.list above is mgmt.groovy:19, where the API call fails. 

Thanks,
Lee

From: Andy Goodspeed [mailto:AGood...@cfglife.com]
Sent: Friday, December 03, 2010 11:57 AM
To: us...@groovy.codehaus.org

Subject: RE: [groovy-user] Code works in Java but not in Groovy

Andy Goodspeed

unread,
Dec 3, 2010, 12:19:53 PM12/3/10
to us...@groovy.codehaus.org
It sounds like a lot of folks have a paste problem, but copy works fine! ;-)

Andrew Goodspeed

"...we have normality, I repeat we have normality. Anything you still can’t cope with is therefore your own problem." -Douglas Adams (Trillian)



pablomar <pablo.dani...@gmail.com>

12/03/2010 12:17 PM

Please respond to
us...@groovy.codehaus.org

To
us...@groovy.codehaus.org
cc
Subject
Re: [groovy-user] Code works in Java but not in Groovy


Grey, Lee

unread,
Dec 3, 2010, 12:34:54 PM12/3/10
to us...@groovy.codehaus.org
The previous script was the direct call to the API from Groovy.
 
Here is a script that calls my Java class which makes the calls to the SonicMQ API.  This Java class works as expected when called from a Java program, but results in an exception when called from Groovy.

def

url = 'tcp://localhost:2506'

def

usr = 'Administrator'

def

pwd = 'Administrator'

import

com.sonicsw.mf.jmx.client.*

import

com.sonicsw.mf.mgmtapi.runtime.*

import

com.sonicsw.mq.mgmtapi.runtime.*

import

javax.management.*

import

com.sonicsw.mf.mgmtapi.config.*

import

com.sonicsw.mq.mgmtapi.config.*

import

com.sonicsw.ma.mgmtapi.config.*

import

main.JavaUtil

println

JavaUtil

def

mff = JavaUtil.getMFMgmtBean(url, usr, pwd, 'Domain1')

def

clist = JavaUtil.getContainers(mff, "/Containers/")

println

clist.size()
And here is the resulting output:

class main.JavaUtil
in getContainers
Exception in getContainers
com.sonicsw.ma.mgmtapi.config.MgmtException: Failed to list  - null
 at com.sonicsw.ma.mgmtapi.config.impl.AbstractMgmtBeanFactory.list(AbstractMgmtBeanFactory.java:333)
 at main.JavaUtil.getContainers(JavaUtil.java:29)
 at main.JavaUtil$getContainers.call(Unknown Source)

 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)
 at mgmt.run(mgmt.groovy:18)

 at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:264)
 at groovy.lang.GroovyShell.run(GroovyShell.java:513)
 at groovy.lang.GroovyShell.run(GroovyShell.java:170)
 at groovy.lang.GroovyShell$run$1.call(Unknown Source)

 at groovy.ui.Console$_runScriptImpl_closure16.doCall(Console.groovy:890)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
 at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
 at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:273)
 at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)
 at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:149)
 at groovy.ui.Console$_runScriptImpl_closure16.doCall(Console.groovy)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
 at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
 at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:273)
 at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:886)
 at groovy.lang.Closure.call(Closure.java:276)
 at groovy.lang.Closure.call(Closure.java:271)
 at groovy.lang.Closure.run(Closure.java:354)
 at java.lang.Thread.run(Thread.java:662)
Caused by: com.sonicsw.mf.mgmtapi.runtime.ProxyRuntimeException
 at com.sonicsw.mf.jmx.client.DirectoryServiceProxy.listFSAll(DirectoryServiceProxy.java:1611)
 at com.sonicsw.mx.config.impl.ConfigServer.list(ConfigServer.java:1083)
 at com.sonicsw.ma.mgmtapi.config.impl.AbstractMgmtBeanFactory.list(AbstractMgmtBeanFactory.java:312)
 ... 34 more
Exception thrown
Dec 3, 2010 12:26:07 PM org.codehaus.groovy.runtime.StackTraceUtils sanitize
 
WARNING: Sanitizing stacktrace:
 
java.lang.NullPointerException: Cannot invoke method size() on null object
  ...
 
Is there anything I can print out from the environment that might help get to the bottom of this?  It is counter to everything I know about Groovy for it to get a different result from Java.  Aside from my own needs on my project, this seems like something that needs to be understood and resolved.
 
Thanks,
Lee

From: Grey, Lee
Sent: Friday, December 03, 2010 12:20 PM

Peter Niederwieser

unread,
Dec 4, 2010, 12:31:48 PM12/4/10
to us...@groovy.codehaus.org

Sounds like the problem is environment-based (e.g. different class loader or
class path setup). I'd try to run both the Groovy and the Java version with
the same 'java' command (in the Groovy case you have to add the Groovy Jar
to the class path).

Cheers,
Peter
--
View this message in context: http://groovy.329449.n5.nabble.com/Code-works-in-Java-but-not-in-Groovy-tp3290286p3292321.html
Sent from the groovy - user mailing list archive at Nabble.com.

Grey, Lee

unread,
Dec 6, 2010, 4:11:35 PM12/6/10
to us...@groovy.codehaus.org
So, it turns out that the API calls work fine when I run the program from a groovy command-line. It's actually been GroovyConsole's environment that was the problem all along.

Is there any way to view, compare, and reconfigure GroovyConsole's environment, so I can get it to work the way the java and groovy commands do? It's the ideal tool for working with an API to get the calls right.

Thanks,
Lee

Reply all
Reply to author
Forward
0 new messages