Jython can not use lxml library - java

I'm trying to use zeep library to provide soap call in python code and its okay it works when I try to run with python. Then, I'm trying to use jython to run this code (i need jython because next step will be on the server that uses jython to compile) and when I try to install lxml for jython it gives me this error:
error:Compiling extensions is not supported on Jython
When I search for this situation, I found that jython doesn't support c based libraries.
So, there is a solution with jython-jni bridge but I couldn't understand how to be.
Is there another solution? Or can you give me an obvious example?

I couldn't achieve to implement jni but i created a new layer between jython and server.I mean, i made a REST call from jython compiler and this call listens my server for soap call and it worked.

Related

Using the original python packages instead of the jython packages

I am trying to create a hybrid application with python back-end and java GUI and for that purpose I am using jython to access the data from the GUI.
I wrote code using a standard Python 3.7.4 virtual environment and it worked "perfectly". But when I try to run the same code on jython it doesn't work so it seems that in jython some packages like threading are overwritten with java functionality.
My question is how can I use the threading package for example from python but in jython environment?
Here is the error:
Exception in thread Thread-1:Traceback (most recent call last):
File "/home/dexxrey/jython2.7.0/Lib/threading.py", line 222, in _Thread__bootstrap
self.run()
self._target(*self._args, **self._kwargs)
Since you have already decoupled the application i.e using python for backend and java for GUI, why not stick to that and build in a communication layer between the backend and frontend, this layer could either be REST or any Messaging framework.
I think one issue you might be facing is that you are running on Jython 2.7.0 (~Python 2.7 compatible) but your code is written for CPython 3.7.4. So you might be facing Python 2 vs 3 issues.
The threading module in Jython is indeed different from CPython i.e. it is making use of JVM threading. However the intension is to be API compatible with Python 2.7 code so if it doesn't run that should be considered a bug.
My first suggestion would be try Jython 2.7.1 it contains many fixes over 2.7.0 https://www.jython.org/download however I suspect it still might not work. Check if your code runs on CPython 2.7 https://www.python.org/downloads/release/python-2716/ if it does then that sounds like a Jython bug. Open a ticket with details to reproduce at https://bugs.jython.org/

how to call .net dll in JMeter

Can we invoke .net dll in JMeter. I have a peice of code written in .net need to use its output in jmeter as a parameter. (I am trying to call .net writen code which generate a key in jmeter.) Can anyone please help?
If .net dll exposes the COM interface, java can talk to that. If you can do something in java, then JMeter can do that as well.
Check this library which cna access COM interface.
Check this as well for examples: http://danadler.com/jacob/
But is that something which can be done only in .net? If possible, create the lib in java.
There are following options ordered by my personal preferences perspective
Re-implement your .NET code in Java/Groovy using JSR223 Sampler
Compile your code into an executable binary and call it using OS Process Sampler
Use JSR223 Sampler mentioned in step 1 and a wrapper library like jni4net, but keep in mind that you will need a .NET Runtime (Windows with installed .NET Framework or Linux/MacOSX with installed Mono)

Run TypeScript compiler from Java

I am trying to run the TypeScript compiler from my Java application. To start, I am trying to figure out, whether I can run the compiler from command-line without Node.js:
$ jsc tsc.js
But this way I don't get any errors, nor help.
$ jsc tsc.js myscript.ts
Will get me nowhere.
It is easy to run js code directly from java (and I am hoping to run the compiler in this way), but is it possible to run TypeScript compiler without node.js?
EDIT:
I confirm the same behaviour with rhino.
I have a project, Typescript4j that does precisely this.
It runs the Typescript compiler wrapped within Rhino.
I'm using it successfully within Bakehouse, and a non-trivial Typescript application.
Looking at the source code, the tsc command invokes a JS script tsc.js, which has 2 backends: Node.js and Windows Scripting Host. If any other JavaScript server supports reading and writing to a file system (like Rhino with RingoJS), it should be able to run the TypeScript compiler tsc.js.
Moreover, there is a fork of TypeScript compiler which claims to directly run on Rhino. So you could invoke Rhino directly from Java, without installing node.js.
what you want to do is jsc node_modules/typescript/lib/tsc.js file1.ts, but unfortunately that won't work with engines different than node.js.
What will work (or at least works in the browser), is using TypeScript Compiler API, instead of trying to use the CLI (you will have to program). In the browser, you do this by loading the file node_modules/typescript/typescript.js and then you have access to the compiler API (https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API) via the global ts. Here you have an example of how to transpile a ts string to js using the compiler API: https://typescript-api-playground.glitch.me/#example=Transpiling-a-single-file
Good luck
The TypeScript compiler is implemented in TypeScript, and can be used in any JavaScript host.
You may need to specify the full path to tsc.js

Use python library in java code

There is some library called pymorphy written in python. Unfortunately, for java there is not any library with the similar functionality - natural language processing for Russian lang. So I need to invoke some methods of pymorphy library from Java code.
First I've tried to solve this problem with Jython. But I've spent 2 days and the goal was not accomplished because python modules cdb, bsddb3, sqlite are written in C and they will not work with Jython.
Now I want to run some python light-weight server with pymorphy for handling request from Java code.
How could I implement this kind of java-python interaction with the maximum production performance? Or is there more simple way to call python from java?
Try Jepp, "Java Embedded Python". http://jepp.sourceforge.net/
I haven't used it beyond small projects, but it works as advertised, allowing one to call CPython transparently from Java. If you have the opposite problem, needing to call Java from CPython, definitely check out JPype. I've used it extensively and it works very well.
I think these libraries (cdb, bsddb3, sqlite) has a jython implementation in https://code.google.com/p/django-jython/ check it out

Java Wrapper to Perl/Python code

I have to deploy some Web Services on a server that only supports the Java ones, but some of them will be done using perl or python. I want to know if is possible to develop a Java wrapper to call a specific code written in perl or python. So, I want to have all the Web Services in Java, but some of them will call some code using other languages.
Thanks in advance.
Regards,
Ukrania
This depends heavily upon your needs. If Jython is an option for the Python code (it isn't always 100% compatible), then it is probably the best option there. Otherwise, you will need to use Java's Process Builder to call the interpretters directly and return the results on their output stream. This will not be fast (but then again, Jython isn't that fast either, relative to regular Java code), but it is an extremely flexible solution.
For the Python part of it you can use Jython to run Python code right from your Java virtual machine. It'll integrate fully with your Java code as a bonus.
For Perl, use Inline::Java. There are several options for integrating the code; you can call a separate process or you can use an embedded interpreter.
For Python you can use the Java Scripting API.
A Perl implementation is sadly still missing.
There's something I used a while back called Jython which allows you to execute Python code from Java. It was a little quirky, but I got it to do what I needed.
http://www.jython.org

Categories