osdir.com
mailing list archive

Subject: RE: jython embedded in jboss - msg#00120

List: lang.jython.user

Date: Prev Next Index Thread: Prev Next Index
Hello,

The problem is that my classes can reside in deployed jars such as EJBs.

I can not give them at the startup classpath as I don't know them in advance.
But they are available in the Thread.currentThread().getContextClassLoader()
classloader.

As regards with changing the import logic, what piece of code can I look at?

Regards,

Joachim.


-----Original Message-----
From: Oti [mailto:ohumbel@xxxxxxxxx]
Sent: 22 October 2003 23:47
To: Stefan Baramov; jython-users@xxxxxxxxxxxxxxxxxxxxx
Cc: 'joachim.tremouroux@xxxxxxxxxxx'
Subject: RE: [Jython-users] jython embedded in jboss


Hello Stefan and Joachim,

my advice is to not mess around with class loaders as long as you can
avoid it.

I am successfully using embedded Jython in Jboss for a long time now.
The question is: where does your class com.foo.xx reside? I guess it is
inside a .jar file, and I further guess this .jar is not mentioned on
the classpath explicitly, instead it is referenced from a manifest
inside another .jar file.

The most easiest way for you to enable from com.foo import xx is to add
the .jar file explicitly to the classpath when starting Jboss, such as

java -classpath run.jar;[jar_containing_com.foo.xx];[rest_of_classpath]
org.jboss.Main [your_conf]

Another approach would be to change the import logic of Jython a bit
(which is what I have done), but this requires some coding inside
org.python.core.

Best wishes,
Oti.

--- Stefan Baramov <Stefan.Baramov@xxxxxxx> wrote:
> Well, this is a tough question. I do not know JBoss enough to give
> you a
> precise answer but here is what I do in eclipse plugin:
>
>
> PySystemState systemState = new PySystemState();
> result.path.insert(0, new PyString("C:/jython21/Lib")); // standard
> jython
> libraries
>
> systemState.setClassLoader(MyPlugin.class.getClassLoader()); // here
> you
> have to specified the class loader
> PyStringMap dictNamespace = new PyStringMap();
>
> // Init interpreter
> PythonInterpreter interp = new PythonInterpreter(dictNamespace,
> systemState);
>
> If this does not work, the only other options is to develop custom
> class
> loader. Good luck !
>
> - Stefan Baramov
>
> -----Original Message-----
> From: joachim.tremouroux@xxxxxxxxxxx
> [mailto:joachim.tremouroux@xxxxxxxxxxx]
> Sent: Wednesday, October 22, 2003 9:11 AM
> To: jython-users@xxxxxxxxxxxxxxxxxxxxx
> Subject: [Jython-users] jython embedded in jboss
>
>
> Hello,
>
> I try to use jython embedded in jboss.
> In my scripts I can use any object givent through the
> interp.set("foo",bar)
> method.
>
> However, I can't import anything in my scripts using
> from com.foo import xx
>
> How do I need to initialize the jython interpreter?
> I basically needs my scripts to be able to use all java packages
> visible
> with the current classloader.
>
> I have tried differents things:
>
> 1.
> PySystemState.initialize(
> new Properties(),
> new Properties(),
> null,
> Thread.currentThread().getContextClassLoader());
>
>
> 2.
> I also tried to retrieve all jars from the
> Thread.currentThread().getContextClassLoader() and pass them
> through the addJar method
>
> String[] cps =
> new CompilePath().getCompileClasspath(
>
> Thread.currentThread().getContextClassLoader());
>
> for (int i=0;i<cps.length;i++) {
> System.out.println("adding " + cps[i]);
>
> PySystemState.packageManager.addJar(cps[i],false);
> }
>
>
> The getCompileClassPath comes from Jboss for the integration of
> Tomcat:
>
>
> public String[] getCompileClasspath(ClassLoader loader) {
> HashSet tmp = new HashSet();
> ClassLoader cl = loader;
> while (cl != null) {
> URL[] urls = getClassLoaderURLs(cl);
> addURLs(tmp, urls);
> cl = cl.getParent();
> }
> String[] cp = new String[tmp.size()];
> tmp.toArray(cp);
> return cp;
> }
>
> protected URL[] getClassLoaderURLs(ClassLoader cl) {
> URL[] urls = {
> };
> try {
> Class returnType = urls.getClass();
> Class[] parameterTypes = {
> };
> Method getURLs = cl.getClass().getMethod("getURLs",
> parameterTypes);
> if
> (returnType.isAssignableFrom(getURLs.getReturnType())) {
> Object[] args = {
> };
> urls = (URL[]) getURLs.invoke(cl, args);
> }
> if (urls == null || urls.length == 0) {
> getURLs =
> cl.getClass().getMethod("getAllURLs", parameterTypes);
> if
> (returnType.isAssignableFrom(getURLs.getReturnType())) {
> Object[] args = {
> };
> urls = (URL[]) getURLs.invoke(cl,
> args);
> }
> }
> } catch (Exception ignore) {
> }
> return urls;
> }
>
> private void addURLs(Set urlSet, URL[] urls) {
> for (int u = 0; u < urls.length; u++) {
> URL url = urls[u];
> url =
> org.jboss.net.protocol.njar.Handler.njarToFile(url);
> urlSet.add(url.toExternalForm());
> }
> }
>
>
>
> None of these two methods give me results. Has anyone any idea of the
> correct initialisation method?
>
> Thanks in advance,
>
>
> Joachim.



-------------------------------------------------------
This SF.net email is sponsored by OSDN developer relations
Here's your chance to show off your extensive product knowledge
We want to know what you know. Tell us and you have a chance to win $100
http://www.zoomerang.com/survey.zgi?HRPT1X3RYQNC5V4MLNSV3E54


Was this page helpful?
Yes No
Thread at a glance:

Previous Message by Date: click to view message preview

Re: element name missing with SAX parse

Thanks! ----- Original Message ----- From: "Alan Kennedy" <jython-users@xxxxxxxxx> Cc: "Jython-Users" <jython-users@xxxxxxxxxxxxxxxxxxxxx> Sent: Wednesday, October 22, 2003 4:59 PM Subject: Re: [Jython-users] element name missing with SAX parse > [Tertius] > > The following code never executes the startElement method although > > there are elements present in the XML string. > > Only the characters method seems to be invoked. > > > > Am I missing something? > > Yes: namespace processing. > > AFAIK, namespace processing is enabled by default. So if you change your > start element handler to something like > > def startElementNS(self, name, qname, attrs): > print "name:", name > print "qname:", qname > print "attr:", attrs > return # <- this is redundant > > Then you'll find that you are correctly receiving the element calls. > > The other alternative is to disable namespace processing. I'm not sure > how to do this with xmlproc though. If you do disable namespace > processing, your "startElement" handlers will then be called. > > HTH, > > Alan. > > > > ------------------------------------------------------- > This SF.net email is sponsored by OSDN developer relations > Here's your chance to show off your extensive product knowledge > We want to know what you know. Tell us and you have a chance to win $100 > http://www.zoomerang.com/survey.zgi?HRPT1X3RYQNC5V4MLNSV3E54 > _______________________________________________ > Jython-users mailing list > Jython-users@xxxxxxxxxxxxxxxxxxxxx > https://lists.sourceforge.net/lists/listinfo/jython-users ------------------------------------------------------- This SF.net email is sponsored by OSDN developer relations Here's your chance to show off your extensive product knowledge We want to know what you know. Tell us and you have a chance to win $100 http://www.zoomerang.com/survey.zgi?HRPT1X3RYQNC5V4MLNSV3E54

Next Message by Date: click to view message preview

Re: handle oracle BLOB with zxJDBC DataHandler

It comes back as a byte array because there was no precedence in the Python DB API to return a BLOB. It is possible to write a custom DataHandler which will return a BLOB instance so that you can manipulate it. You can implement getPyObject() and return the appropriate wrapped Java instance so that you can access the BLOB as you would with JDBC. From what I remember I spent a lot of time trying to get Oracle's BLOBs to work correctly for me and I found it somewhat difficult mapping it into the Python DB API. I did a lot of work with Informix's CLOBs but always returned them as a large string so it lost a lot of the advantages of the CLOB datatype. In any case email if you need more help or want a better roadmap for what to do. thanks, brian On Wednesday, October 22, 2003, at 07:51 AM, whamle li wrote:   hello ,friends        For my question, i tried to simulate the example in zxJDBC documentation in interactive model,as below:        from com.ziclix.python.sql import zxJDBC    from com.ziclix.python.sql.handler import OracleDataHandler      zxJDBC.autocommit = 0     #settings   driver = 'oracle.jdbc.driver.OracleDriver'   url = 'jdbc:oracle:thin:@localhost:1521:mydb'   username, passwd = 'test', 'test'     #get connection and cursor   db = zxJDBC.connect(url,username,passwd,driver)   c = db.cursor()     #bind oracle handler   c.datahandler = OracleDataHandler(c.datahandler)     #try to insert a blob value c.execute("insert into table(BLOB_COL) values(?),['testString']," +                "{0:zxJDBC.BLOB}")     The last statement triggered a error of unsupported sql92 sign: 42: 0 [SQLCode: 17034], then i tried another way:   #insert an empty BLOB  c.execute('insert into table(BLOB_COL) values(EMPTY_BLOB())')   #get the empty blob to update c.execute("select BLOB_COL from table")   result = c.fetchone()[0]   unfortrenately, the result is not a BLOB but an array([],byte).   i think the focus of handling BLOB is getting a BLOB object, but how?   any advise,reference or example will be very helpful.   thank you in advance   regards                                  lee                       __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ------------------------------------------------------- This SF.net email is sponsored by: The SF.net Donation Program. Do you like what SourceForge.net is doing for the Open Source Community? Make a contribution, and help us add new features and functionality. Click here: http://sourceforge.net/donate/

Previous Message by Thread: click to view message preview

RE: jython embedded in jboss

Hello Stefan and Joachim, my advice is to not mess around with class loaders as long as you can avoid it. I am successfully using embedded Jython in Jboss for a long time now. The question is: where does your class com.foo.xx reside? I guess it is inside a .jar file, and I further guess this .jar is not mentioned on the classpath explicitly, instead it is referenced from a manifest inside another .jar file. The most easiest way for you to enable from com.foo import xx is to add the .jar file explicitly to the classpath when starting Jboss, such as java -classpath run.jar;[jar_containing_com.foo.xx];[rest_of_classpath] org.jboss.Main [your_conf] Another approach would be to change the import logic of Jython a bit (which is what I have done), but this requires some coding inside org.python.core. Best wishes, Oti. --- Stefan Baramov <Stefan.Baramov@xxxxxxx> wrote: > Well, this is a tough question. I do not know JBoss enough to give > you a > precise answer but here is what I do in eclipse plugin: > > > PySystemState systemState = new PySystemState(); > result.path.insert(0, new PyString("C:/jython21/Lib")); // standard > jython > libraries > > systemState.setClassLoader(MyPlugin.class.getClassLoader()); // here > you > have to specified the class loader > PyStringMap dictNamespace = new PyStringMap(); > > // Init interpreter > PythonInterpreter interp = new PythonInterpreter(dictNamespace, > systemState); > > If this does not work, the only other options is to develop custom > class > loader. Good luck ! > > - Stefan Baramov > > -----Original Message----- > From: joachim.tremouroux@xxxxxxxxxxx > [mailto:joachim.tremouroux@xxxxxxxxxxx] > Sent: Wednesday, October 22, 2003 9:11 AM > To: jython-users@xxxxxxxxxxxxxxxxxxxxx > Subject: [Jython-users] jython embedded in jboss > > > Hello, > > I try to use jython embedded in jboss. > In my scripts I can use any object givent through the > interp.set("foo",bar) > method. > > However, I can't import anything in my scripts using > from com.foo import xx > > How do I need to initialize the jython interpreter? > I basically needs my scripts to be able to use all java packages > visible > with the current classloader. > > I have tried differents things: > > 1. > PySystemState.initialize( > new Properties(), > new Properties(), > null, > Thread.currentThread().getContextClassLoader()); > > > 2. > I also tried to retrieve all jars from the > Thread.currentThread().getContextClassLoader() and pass them > through the addJar method > > String[] cps = > new CompilePath().getCompileClasspath( > > Thread.currentThread().getContextClassLoader()); > > for (int i=0;i<cps.length;i++) { > System.out.println("adding " + cps[i]); > > PySystemState.packageManager.addJar(cps[i],false); > } > > > The getCompileClassPath comes from Jboss for the integration of > Tomcat: > > > public String[] getCompileClasspath(ClassLoader loader) { > HashSet tmp = new HashSet(); > ClassLoader cl = loader; > while (cl != null) { > URL[] urls = getClassLoaderURLs(cl); > addURLs(tmp, urls); > cl = cl.getParent(); > } > String[] cp = new String[tmp.size()]; > tmp.toArray(cp); > return cp; > } > > protected URL[] getClassLoaderURLs(ClassLoader cl) { > URL[] urls = { > }; > try { > Class returnType = urls.getClass(); > Class[] parameterTypes = { > }; > Method getURLs = cl.getClass().getMethod("getURLs", > parameterTypes); > if > (returnType.isAssignableFrom(getURLs.getReturnType())) { > Object[] args = { > }; > urls = (URL[]) getURLs.invoke(cl, args); > } > if (urls == null || urls.length == 0) { > getURLs = > cl.getClass().getMethod("getAllURLs", parameterTypes); > if > (returnType.isAssignableFrom(getURLs.getReturnType())) { > Object[] args = { > }; > urls = (URL[]) getURLs.invoke(cl, > args); > } > } > } catch (Exception ignore) { > } > return urls; > } > > private void addURLs(Set urlSet, URL[] urls) { > for (int u = 0; u < urls.length; u++) { > URL url = urls[u]; > url = > org.jboss.net.protocol.njar.Handler.njarToFile(url); > urlSet.add(url.toExternalForm()); > } > } > > > > None of these two methods give me results. Has anyone any idea of the > correct initialisation method? > > Thanks in advance, > > > Joachim. ------------------------------------------------------- This SF.net email is sponsored by OSDN developer relations Here's your chance to show off your extensive product knowledge We want to know what you know. Tell us and you have a chance to win $100 http://www.zoomerang.com/survey.zgi?HRPT1X3RYQNC5V4MLNSV3E54

Next Message by Thread: click to view message preview

Generating Pydoc or Javadoc for Jython

Hi, Has anyone had any success generating Pydoc or Javadoc from Jython source code? Of course, the response I'm really hoping for is something like: "Yes, it's really simple. Just follow these steps..." Other helpful responses include: "It's not currently possible. Here's why..." "I failed, too." (demonstrates the need for improvement here) "Generate docs? What kind of nut are you?" (helps set priorities) Thanks, Curt ------------------------------------------------------- This SF.net email is sponsored by OSDN developer relations Here's your chance to show off your extensive product knowledge We want to know what you know. Tell us and you have a chance to win $100 http://www.zoomerang.com/survey.zgi?HRPT1X3RYQNC5V4MLNSV3E54
Sign up for updates to this mailing list. email:
Loading Comments...
Home | News | Patents | Sitemap | FAQ | advertise

Advertising by