Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@herberthamaral
Created June 28, 2010 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herberthamaral/455872 to your computer and use it in GitHub Desktop.
Save herberthamaral/455872 to your computer and use it in GitHub Desktop.
"""
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