DLL/TLB in Java<->DCOM communication - java

I have to write an OpenOffice add-on (in Java) which communicates with DCOM server of some closed-source application. The major problem is that, I don't have any documentation about server's Interfaces .
All I have is a VB/C++ SDK kit for the Application. SDK contain a library in dll and a bunch of *.tlb files. In SDK documentation there is an information, I can use java, but there is no example at all. I have read provided examples and it looks like all the communication wit DCOM goes through this dll.
Is there a way to somehow import such dll/tlb functions def directly to java, bypass dll and comunicate with DCOM or I have to write a C++ wrapper(dll)? What is the best way to do it?
Any hints are welcomed.

You can use a project like j-Interop for communication with (D)COM servers.

Related

android use pcap library

I have a general question according an android app, I need to use some pcap functionality in my android app. Because java does not give the possibility in raw packet injections and low layer programming (as far as I know, pls correct me if I'm wrong) so I was looking for an alternative. So far I found the following:
ANDROID NDK
JNETPCAP
Any suggestions which one I should use or does anyone have other suggestions?
The JNI Solution
You need to wrap the calls and the logic you need out of libpcap in C or C++ and expose the underlying functions through JNI (Java Native Interface) so your application can call native code in Java.
The documentation on JNI is pretty complete on internet, a lot of tutorials exists on this subject such as this one.
If you want to easily wrap native code in JNI you can use Swig which allow you to automatically generate JNI code based on your C/C++ native headers.
The obtained JNI code should be compiled using the Android NDK as a dynamic library (.so). This library is to be placed in your application package under libs/. You can then invoke System.loadLibrary(path_to_you_dynamic_library) to load all the symbols contained in the library and use them in Java.
Using a third-party library
If you're afraid of getting headaches while figuring out how to use JNI, you can look at this library which does the hard work for you, and provides an API to manipulate raw sockets in Java.
http://www.savarese.com/software/rocksaw/
You need to wrap the calls and the logic you need out of libpcap in C or C++ and expose the underlying functions through JNI (Java Native Interface) so your application can call native code in Java.
Or you need to get a library that's already done that, such as, err, umm, jNetPcap.
One problem you may have with any attempt to do packet capture on Android - or any other OS using the Linux kernel - is that, by default, the underlying kernel mechanism used by libpcap (PF_PACKET sockets) requires root privileges. If there's a way to run your code as root, or to give it CAP_NET_RAW and possibly CAP_NET_ADMIN privileges, it might be possible to make it work.

Android Apps using python

I found that Android development can be done through Python from the link http://www.linuxplanet.com/linuxplanet/tutorials/7157/1. My question is whether all the libraries that are available in Java are also available in python.
Any of you already started with python on Android if so please indicate links to help get our group up to speed.
No, not all the libraries have been exposed. You can look at the SL4A project on google-code for more information regarding the support it has.
Is this a complete API bridge, or are there restrictions?
BeanShell, JRuby, and Rhino basically give you a complete API bridge (you can invoke Java calls directly). See the documentation for those interpreters for instruction on how to accomplish this. Cross compiled languages like Lua are more restricted. They only have access to the APIs exposed through the RPC layer. See the API reference for a list of currently supported APIs. The RPC layer is easy to extend.

Php/Java Integration

Have you experience of integration of php and Java? I've written a class in Java "Hello". Now I want to call its method from php when I create an instance of this class from php with
$obj = new Java(Hello);
Then it gives me fatal error. I've tried many times to setup php ini variables etc but I couldn't find anything. Please advice me how can I set it up.
Thanks in advance
Reference: http://php.net/manual/en/book.java.php
Have a look at:
PHP-Java Bridge
The PHP/Java Bridge is an
implementation of a streaming,
XML-based network protocol, which can
be used to connect a native script
engine, for example PHP, Scheme or
Python, with a Java virtual machine.
It is up to 50 times faster than local
RPC via SOAP, requires less resources
on the web-server side. It is faster
and more reliable than direct
communication via the Java Native
Interface, and it requires no
additional components to invoke Java
procedures from PHP or PHP procedures
from Java.
Could it be you are just missing the quotes around the Java Class? Also make sure you actually do have a Java VM on the machine you are trying to run the code on and make sure you have properly set up the config options. Also, the Java extension is a PECL extension and has to be installed. It is not part of the native distribution. Furthermore, the extension is considered unmaintained and dead, so you might want to have a look at the JavaBridge suggested elsewhere. Zend Server also brings a JavaBridge.
Check out this article: http://www.devshed.com/c/a/PHP/Using-PHP-with-Java/
They say it's possible (and how to do it). I've never done it, so I can't vouch for it...
In my experience the best way to interact between Java and PHP is through a WebService layer. NuSoap for PHP is very good, and you can consume the webservice in Java to create a stub that will build the request/response object.
There are many ways few are:
PHP Java Bridge
Java Integration in PHP
Using web services to pass data in between like SOAP
Using simple HTTP data passage between Java and PHP see (facejar uses the same technique)
Client site script (AJAX)
If you are after security, use option 1 otherwise I prefer using option 4 which is a bit faster when it comes to performance.

How can I use Java to communicate to device through USB port?

I just recently learn Java and try to communicate to the device through USB port connection. I've have used C# with OpenNETCF which allows me to send file and retrieve file on the device through USB port; how can I achieve this with java?
I seearch on stackoverflow thread, How to communicate with a USB device under Windows and Java?, the comment made by christoffer is to hack the native code, but I don't quite which native code api that he referred to. RAPI, maybe?
The only USB API I could find for Windows is here. Seems as if it has limited functionality, but it might suit your needs. A more complete UNIX API is also available.
ETA: Found a link to the official Java USB implementation, but looks like the windows version is still in alpha.
The native code API I referred to was the Windows DDK, i.e. the Driver Development Kit. The modern version seem to be called Windows Driver Kit, so google for Windows WDK :)
There should be a few C samples on how to communicate with USB devices, and it should be pretty straightforward to write a JNI wrapper from those.
As a quick thought, you could use JNI, the Java Native Interface. I've never used it myself though.
I found this page that explains how to perform a communication between a microcontroller and a java application: http://javausbapi.blogspot.com/
The Best way I found to communicate with USB is through RxTx library.
You can find an example of the usage here:
http://www.snip2code.com/Snippet/1044/Java--read-from-USB-using-RXTX-library

Java or C++ API for Apache Drill

I want to access Drill through a programming interface. The Apache Drill documentation just mentions about its JAVA and C++ libraries for the client to connect but doesn't provide any documentation or example for the same.
http://drill.apache.org/faq/#what-clients-are-supported?
http://drill.apache.org/docs/architecture-introduction/#drill-clients
The closest thing which I was able to find on the forums/documentations was to connect through the drill-JDBC driver. But it defeats the purpose of what I want to do. Does anyone has any idea where I can find more about these APIs and if they are actually there?
They provide native C++ client.
Check querySubmitter example for more details.

Categories