Created
June 28, 2010 13:58
-
-
Save herberthamaral/455872 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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