Re: jython's convenience java methods
Oti <ohumbel <at> gmail.com>
2007-12-03 21:03:33 GMT
Marcel,
could you please provide a
dir(env)
I suspect that initialContext is not a setter/getter pair, but
something else, like in my example below.
Consider the following Java class with an unbalanced initialContext:
package st.extreme.jython;
public class Environment {
public Environment() {
}
public String initialContext;
public String getInitialContext() {
return "getInitialContext";
}
}
and then, after calling jython interpreter:
>>> from st.extreme.jython import Environment
>>> env = Environment()
>>> dir(env)
['__init__', 'class', 'equals', 'getClass', 'getInitialContext',
'hashCode', 'initialContext', 'notify', 'notifyAll', 'toString',
'wait']
>>> print env.getInitialContext()
getInitialContext
>>> print env.initialContext
None
>>> env.initialContext.someMethod()
>>> Traceback (innermost last):
File "<console>", line 1, in ?
AttributeError: 'NoneType' object has no attribute 'someMethod'
best wishes,
Oti.
On Dec 1, 2007 10:37 PM, marcel liker <m_liker <at> yahoo.com> wrote:
>
> ----- Original Message ----
> From: Charlie Groves <charlie.groves <at> gmail.com>
> To: marcel liker <m_liker <at> yahoo.com>
> Cc: jython-users <at> lists.sourceforge.net
> Sent: Saturday, December 1, 2007 4:06:44 PM
> Subject: Re: [Jython-users] jython's convenience java methods
>
> On Dec 1, 2007 11:57 AM, marcel liker <m_liker <at> yahoo.com> wrote:
> > Hi there,
> > I ran into an issue with Jython's "convenience" java methods.
> Consider this example:
> >
> > [mliker <at> jbox1 ~]$ ./rlwrap jython/jython
> > Jython 2.2.1 on java1.4.2_08
> > Type "copyright", "credits" or "license" for more information.
> >
> > >>> from weblogic.jndi import Environment
> > >>> server, user, password = 'server', 'user', 'password'
> > >>> env = Environment(providerUrl = 't3://' + server + ':80',
> securityPrincipal = user, securityCredentials = password)
> > >>>
> env.getInitialContext().lookup("javax.jms.QueueConnectionFactory")
> > weblogic.jms.client.JMSXAConnectionFactory <at> 1d226a7
> >
> > however:
> >
> > [mliker <at> box1 ~]$ ./rlwrap jython/jython
> >
> > Jython 2.2.1 on java1.4.2_08
> >
> > Type "copyright", "credits" or "license" for more information.
> >
> > >>> from weblogic.jndi import Environment
> > >>> server, user, password = 'server', 'user', 'password'
> >
> > >>> env = Environment(providerUrl = 't3://' + server + ':80',
> securityPrincipal = user, securityCredentials = password)
> > >>> env.initialContext.lookup("javax.jms.QueueConnectionFactory")
> > Traceback (innermost last):
> > File "<console>", line 1, in ?
> > AttributeError: 'NoneType' object has no attribute 'lookup'
>
> It strikes me as odd that this is complaining about NoneType not
> having lookup on it. If the bean accessors weren't being created,
> you'd get an AttributeError about the lack of initialContext on env.
> Is there anything that could be going on here to cause
> getInitialContext to return null just in this instance?
>
> [Marcel]
>
> [mliker <at> box1 ~]$ ./rlwrap jython/jython
> >>> from weblogic.jndi import Environment
> >>> server, user, password = 'server', 'user', 'password'
> >>> env = Environment(providerUrl = 't3://' + server + ':80', securityPrincipal = user,
securityCredentials = password)
> >>> ctx = env.initialContext
> >>> type(ctx)
> <type 'NoneType'>
> >>> ctx = env.getInitialContext()
> >>> dir(ctx)
> ['APPLET', 'AUTHORITATIVE', 'BATCHSIZE', 'CREATE_INTERMEDIATE_CONTEXTS',
'DELEGATE_ENVIRONMENT', 'DNS_URL', 'ENABLE_CALL_BY_REFERENCE', 'ENABLE_SERVER_AFFINITY',
'INITIAL_CONTEXT_FACTORY', 'LANGUAGE', 'OBJECT_FACTORIES', 'PIN_TO_PRIMARY_SERVER',
'PROVIDER_RJVM', 'PROVIDER_URL', 'REFERRAL', 'REPLICATE_BINDINGS', 'SECURITY_AUTHENTICATION',
'SECURITY_CREDENTIALS', 'SECURITY_PRINCIPAL', 'SECURITY_PROTOCOL', 'SSL_CLIENT_CERTIFICATE',
'SSL_CLIENT_KEY_PASSWORD', 'SSL_ROOT_CA_FINGERPRINTS', 'SSL_SERVER_NAME', 'STATE_FACTORIES',
'URL_PKG_PREFIXES', 'addToEnvironment', 'bind', 'class', 'clone', 'close', 'composeName',
'createSubcontext', 'destroySubcontext', 'enableLogoutOnClose', 'env', 'environment',
'equals', 'finalize', 'getClass', 'getEnvironment', 'getNameInNamespace', 'getNameParser', 'getN
ode', 'getRemoteDelegate', 'hashCode', 'kernelId', 'list', 'listBindings', 'log', 'loginThread',
'lookup', 'lookupLink', 'nameInNamespace', 'node', 'notify', 'notifyAll',
> 'readExternal', 'rebind', 'registerNatives', 'remoteDelegate', 'removeFromEnvironment',
'rename', 'serialVersionUID', 'toString', 'translateException', 'unbind', 'wait', 'writeExternal']
> >>> type(ctx)
> <type 'javainstance'>
>
>
>
> Your console
> output makes it seem like that's impossible, but it's the first thing
> I want to be sure of. Would it be hard for me to set this up locally
> or have you seen this anywhere else?
>
> [Marcel]
>
> I do not remember that I saw this before. If you would like to reproduce it you would need:
> - Weblogic Server 8.1 sp5 installed and running
> - for jython put the $BEA_HOME/weblogic81/server/lib/weblogic.jar on your classpath
> - use the same java version as the one used to run Weblogic Server
>
> > If somebody could also shed some light on how does jython provide
> these "convenience" methods as I have come across instances where not all
> java methods would have a jython "convenience" method
>
> It's based off of JavaBean properties:
> http://jython.org/Project/userguide.html#javabean-properties
> Essentially, if an object x has a getBlah method that returns a
> String, it can be accessed as x.blah and if it has a setBlah(String)
> method, it can be set with x.blah = 'whatever'. If the get method
> takes an argument, or if the setter returns something, they won't be
> exposed as a field since they're not JavaBeans.
>
> [Marcel]
>
> Thanks for the info Charlie
>
> Charlie
>
>
>
>
>
> Be smarter than spam. See how smart SpamGuard is at giving junk email the boot with the All-new Yahoo! Mail.
Click on Options in Mail and switch to New Mail today or register for free at http://mail.yahoo.ca
>
>
> -------------------------------------------------------------------------
> SF.Net email is sponsored by: The Future of Linux Business White Paper
> from Novell. From the desktop to the data center, Linux is going
> mainstream. Let it simplify your IT future.
> http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
> _______________________________________________
> Jython-users mailing list
> Jython-users <at> lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jython-users
>
-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell. From the desktop to the data center, Linux is going
mainstream. Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4