Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
"""
Exemplo simples de uso do JNDI com o Jython.
Nota: coloque os seguintes JARs no CLASSPATH:
jboss-4.2.2.GA\client\jnp-client.jar
jboss-4.2.2.GA\client\jboss-client.jar;
jboss-4.2.2.GA\client\jboss-common-client.jar
Coloca-los no sys.path *NÃO* vai funcionar :)
"""
from java.util import *
from javax.naming import *
from java.lang import *
class Registra:
def __init__(self):
env = Properties()
env.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory")
env.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces")
env.put("java.naming.provider.url", "jnp://localhost:1099")
jndiContext = InitialContext(env)
jndiContext.rebind("mensagem","Ola JNDI !!!")
jndiContext.close()
class Recupera:
def __init__(self):
env = Properties()
env.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory")
env.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces")
env.put("java.naming.provider.url", "jnp://localhost:1099")
jndiContext = InitialContext(env)
teste = str(jndiContext.lookup("mensagem"))
print "Mensagem: "+teste
jndiContext.close()
Registra()
Recupera()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.