How to call back to C via JNI in Java started from C?

Hi!
This problem might seem outlandish, but I have not been able to find any other method to reach my goal. The situation is the following.
There is a C++ program I intend to interface with a piece of Java code, called the manager. The C++ code invokes a VM, starts a Java glue code, that connects to the manager via RMI. This works fine. The glue code, however, can be called from the manager, via RMI as well. The problem is, that these calls should in turn call functions in the C++ code, that originally started the Java glue code. JNI can only load a library, but this is not what I want to do now. I want to somehow connect back to the C code that started the Java code. Is this possible at all?
Thanks for your help,
Ambrus

What you want to do is not too tough, but there will be some details to be worked through. In particular, you have to figure out how to make your "callback" get from your "glue" code back into your C++.
1. Calling back out is from java to C is pretty easy. There is a JNI function for registering a native method with the JVM. Here is an example of the registration code:
// See if the service interface class is known.
javaClass = javaEnv->FindClass("JavaInterfaceObject");
if (javaClass != 0) {
//Register a native method to place java server messages in the service log.
// Define the service logger native method.
JNINativeMethod methods[] = {
{"addToMessageLog", "(Ljava/lang/String;)V", Java_addToMessageLog}
// Register the method with the jvm.
javaEnv->RegisterNatives(javaClass, methods, 1);
     javaEnv->ExceptionClear();     // Just in case not found.
     return TRUE;
2. You have to define the native method:
* Native method - callback to place java server messages in the service log.
JNIEXPORT void JNICALL Server::Java_addToMessageLog(JNIEnv * javaEnv, jclass javaClass, jstring javaMsg) {
     jboolean     isCopy;
     const char* msg = javaEnv->GetStringUTFChars(javaMsg, &isCopy);
     Server::theServer->logger->addToMessageLog((char*)msg);
     if (isCopy)
          javaEnv->ReleaseStringUTFChars(javaMsg, msg);
3. The real headache is that this is C code, not C++. In other words, if you really need to call into C++, then you need to seed your callback so that it has a pointer to the appropriate C++ object.

Similar Messages

  • How to call a shell script via ODI

    Hi,
    I need suggestion on following issues:
    1) How to call a shell script via ODI?.. I tried using OSCommand utility .inspite of the execution being successful the data is not written into the new file in the desired format. After processing new file is created in the mentioned location but its empty.
    2) I'm calling a procedure in ODI to load data into my fact. But once the fact gets loaded i want to update the log details (num of rows processed,num of rows inserted,num of rows rejected etc) in my log table. I'm planning to use a proc for updating but need to know from where can i find these details. Is there a table in work rep which gives me these info like how we get if we execute an interface.?
    Please help me out.. Its urgent
    Regards
    Surabhi

    Hello,
    Question 1 appears a little vague, please elaborate. If you're looking to capture a return value from the command execution, you will need to pipe the return value to a file, then read from there.
    The execution information is stored in the SNP_STEP_LOG table in the Work Repository. You will need to do a series of joins to retrieve the exact table that was updated. Good luck with this...

  • How to call backing bean method from java script

    Hi,
    I would like to know how to call backing bean method from java script.
    I am aware of serverListener and [AjaxAutoSuggest article|http://www.oracle.com/technology/products/jdev/tips/mills/AjaxAutoSuggest/AjaxAutoSuggest.html]
    but i am running in to some issues with [AjaxAutoSuggest article|http://www.oracle.com/technology/products/jdev/tips/mills/AjaxAutoSuggest/AjaxAutoSuggest.html]
    regarding which i asked for help in other thread with subject ....Question on AjaxAutoSuggest article (Ajax Transactions Using ADF and J...)
    The reason why i posted is ( though i realise both are duplicates) .. that threads looks as a specific question to that article hence i would like to ask the quantified problem is asked in this thread.
    So could any please letme know how to call backing bean method from java script
    Thanks
    Murali
    Edited by: mchepuri on Oct 24, 2009 6:17 PM
    Edited by: mchepuri on Oct 24, 2009 6:20 PM

    Hello,
    May know how to submit a button autoamtically on onload of page with clicking a welcome alert box. the submit button has managed button too to show a message on console using SOP.
    the problem is.
    1. before loading the page a javascript comes on which i clicked ok
    2. the page gets loaded and the button is there which gets automatically clicked and the managed bean associated with prints a message on console using SOP.
    I m trying to do this through server listener and click listener. the code is(adf jspx page)
    <?xml version='1.0' encoding='UTF-8'?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <f:view>
    <af:document id="d1" binding="#{backingBeanScope.backing_check4.d1}">
    <af:form id="f1" binding="#{backingBeanScope.backing_check4.f1}">
    <af:commandButton text="commandButton 1"
    binding="#{backingBeanScope.backing_check4.cb1}"
    id="cb1" action="#{beanCheck4.submit1}"/>
    <af:clientListener type="click" method="delRow"/>
    <af:serverListener type= "jsServerListener"
    method="#{backingBeanScope.backing_check4.submit1}"/>
    <f:facet name="metaContainer">
    <af:resource type ="javascript">
    x=confirm("hi");
    // if(x){
    delRow = function(event){
    AdfCustomEvent.queue(event.getSource(), "jsServerListener", {}, false);
    return true;
    </af:resource>
    </f:facet>
    </af:form>
    </af:document>
    </f:view>
    <!--oracle-jdev-comment:auto-binding-backing-bean-name:backing_check4-->
    </jsp:root>
    the backing bean code is -----
    public class classCheck4 {
    public classCheck4() {
    public String submit1() {
    System.out.println("hello");
    return null;
    }

  • Pages IPad: how to  'Find' occurrence of a word in a range starting from somewhere in the middle of document to the end. It seems that 'Find' feature always defaults to finding the word from the start of the document. Thanks

    Pages IPad: how to  'Find' occurrence of a word in a range starting from somewhere in the middle of document to the end. It seems that 'Find' feature always defaults to finding the word from the start of the document. Thanks

    Pages IPad: how to  'Find' occurrence of a word in a range starting from somewhere in the middle of document to the end. It seems that 'Find' feature always defaults to finding the word from the start of the document. Thanks

  • How to call Backing Bean method from href tag in JSF. -- URGENT

    Hi guys,
    i am new to JSF. i want one option. how to call a backing bean method from href.
    I searched a lot. i found one component <commandLink>, but i cann't use <commandLink> i have to use only href which is client instructions.
    If anyone knows pls help me. Its Urgent. If u can, give me the code also.
    Suggestions will be appreciated.
    Thanks
    Rajesh

    You can make use of the constructor of the backing bean or the @PostConstruct annotation if you want to use managed properties.
    You may get some ideas out of this: [http://balusc.blogspot.com/2006/06/communication-in-jsf.html].

  • HT1766 hi, how to call back the back up when its has been overwrite with the new one?

    hi, i was tried to back up and restore my iphone 5 and then update to the latest version with my mac itunes, unfortunately my iphone 5 hang in the middle and it reback-up and overwrite the previous one and i didnt know how com it will overwrite the old one with the new back up, which means all my datas gone, how am i going to call back them?

    You don't unless you keep regular backups of your computer in which case you can restore previous backup files.

  • How to call Back end Bean method on Refresh (F5 from i.e.)

    I am very much new to JSF. I tried hard learning it. But I am not able to achive one thing.
    Question :
    How do we set some value in Back end bean when user presses F5(refresh from i.e)
    I have some root tag as given below. I tried checking properties of a4j:form but nothing seems to be releveant.
    <ui:composition>
         <rich:panel>
              <a4j:form id="FirstForm">
    I am kind of stuck with one week. Please provide help.

    Pasting the entire sample code. Here bBean is singleton.
    <ui:composition>
         <rich:panel>
              <a4j:form id="FirstForm">
         <table id="table" width="100%">
                        <tr>
                             <td style="margin-top: 8px;" class="fieldLabel" nowrap="nowrap"
                                  align="left" width="15%">
                             <p><h:outputText value="Option Name :">
                             </h:outputText> <span class="requiredField">*</span></p>
                             </td>
                             <td style="margin-top: 8px; width: 120px" class="fieldLabel"
                                  nowrap="nowrap" align="left"><rich:comboBox id="combo"
                                  value="#{bBean.selectedOption}"
                                  enableManualInput="false">
                                  <f:selectItems value="#{bBean.getAllOptions}" />
                                  <a4j:support event="onchange"
                                       reRender="FirstForm" BypassUpdates="false"
                                       ajaxSingle="true"" />
                             </rich:comboBox></td>
                        </tr>
                   </table>
              </a4j:form>
         </rich:panel>
    </ui:composition>
    </html>

  • How to call a CORBA Object in a 3rd Party ORB from a EJB

    Hello
    I found a few articles on the web how to call EJBs for example from C++.
    However, I want to do the inverse. I want to resolve an Object (implemented in C++, using OmniORB) via COS-Naming and invoke it from a EJB. I can write a simple Java Client which does this without a problem. But as soon as I try to do the same in EJB I get the following:
    [#|2004-11-09T10:48:16.848+0100|WARNING|sun-appserver-pe8.0.0_01|javax.enterprise.resource.corba._DEFAULT_.rpc.transport|_ThreadID=12;|"IOP00710209: (INTERNAL) Unable to create listener thread on the specific port"
    org.omg.CORBA.INTERNAL: vmcid: SUN minor code: 209 completed: No
    at com.sun.corba.ee.impl.logging.ORBUtilSystemException.createListenerFailed(ORBUtilSystemException.java:3142)
    at com.sun.corba.ee.impl.logging.ORBUtilSystemException.createListenerFailed(ORBUtilSystemException.java:3160)
    at com.sun.corba.ee.impl.legacy.connection.SocketFactoryAcceptorImpl.initialize(SocketFactoryAcceptorImpl.java:60)
    at com.sun.corba.ee.impl.transport.CorbaTransportManagerImpl.getAcceptors(CorbaTransportManagerImpl.java:190)
    at com.sun.corba.ee.impl.transport.CorbaTransportManagerImpl.addToIORTemplate(CorbaTransportManagerImpl.java:207)
    at com.sun.corba.ee.spi.oa.ObjectAdapterBase.initializeTemplate(ObjectAdapterBase.java:104)
    I think there is somehow a conflict because the SUN Appserver also uses CORBA. My Code looks like this:
    String[] a = null;
    Properties props = new Properties();
    final String CORBA_HOST = "arcos";
    final String ORB_INITIAL_PORT = "2809";
    props.put("org.omg.CORBA.ORBInitialPort", ORB_INITIAL_PORT);
    props.put("org.omg.CORBA.ORBInitialHost", CORBA_HOST);
    org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(a, props);
    So I thought this might be because there is already a ORB initialised. So I replaced the last line with
    org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init();
    Which should give me an ORB instance. However I get the following exception:
    [#|2004-11-09T11:51:59.206+0100|WARNING|sun-appserver-pe8.0.0_01|javax.enterprise.system.stream.err|_ThreadID=15;|
    org.omg.CORBA.NO_IMPLEMENT: vmcid: SUN minor code: 201 completed: No
    at com.sun.corba.ee.impl.logging.ORBUtilSystemException.genericNoImpl(ORBUtilSystemException.java:7085)
    at com.sun.corba.ee.impl.logging.ORBUtilSystemException.genericNoImpl(ORBUtilSystemException.java:7107)
    at com.sun.corba.ee.impl.orb.ORBSingleton.resolve_initial_references(ORBSingleton.java:311)
    at com.ascom.util.CorbaNaming.resolve(CorbaNaming.java:26)
    at com.ascom.fxm.FileManager.<init>(FileManager.java:46)
    at com.ascom.srv.file.web.FileImporterImpl.importFile(FileImporterImpl.java:146)
    Any ideas? Thank you very much in advance.
    Oliver Jaun

    Perhaps you could take a look at the following document and see if it meets your needs:
    http://java.sun.com/j2se/1.4.2/docs/guide/rmi-iiop/interop.html

  • How to call a method written in user control (ascx file) from javascript

    Hi to All,
    I have one scenario where I need to call a method written in user control (.ascx.cs file) from javascript (ascx file). I tried below code but it is not working,  I found later it works only for aspx or asmx file , is it true ?? 
    Code: 
    $.ajax({
                type: "POST",
                url: "ViewSearch/SetServerSessionText",
                data: "{'name':'" + searchText + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                error: function () {
                    alert("error");
    Can anyone please tell me how to call ascx.cs  code from javascript ??
    Thanks in Advance !!!

    yes that is true, ajax calls can only be made to an endpoint like aspx pages/web service, basically anything that can return a http response etc. User Control can be embedded inside of aspx pages.

  • JNI, run Java methodes from C++

    I'm trying to understand the JNI for a while, but can't realy figure out how to run a java methode from a C++ code.
    (I've managed to do the oposit; run a C++ methode from Java, but that is not what I need.)
    The thing is that I have a C++ program wich outputs a jpg picture. And I have a Java program wich is using this picture. (Picture size is from 2 - 4KB)
    My temparary (not good) solution for making the picture available for the java code is to have the C program save it to a file, and then make the java program read the file once in a while.
    What I would like is to have the C++ to call the methode updatePicture(byte[] newJPEG) in my javacode. How do I do this?
    Parts of the C++ sourcecode:
    void CExCameraView::OnTimer(UINT nIDEvent){
    static int timercount=0;
         CExCameraDoc* pDoc = GetDocument();
         timercount+=pDoc->mycameraconfig->RefreshInterval ;
         if (timercount<pDoc->mycameraconfig->LoadOverHeads )
              return;
         else
              timercount=pDoc->mycameraconfig->LoadOverHeads;
         ASSERT_VALID(pDoc);
    //grab one image and save it to a jpeg file
    // here I'd like to call the java updatePicture methode (not save as file)
         pDoc->GrabSaveNext(pDoc->myconfig->cmsTimeOut);
    And parts of the java code:
    class ImageHandler {
    JpegImage jpegImage; // class JpegImage extends Image
    public ImageHandler() {
    jpegImage = new jpegImage();
    setParameters();
    public updatePicture(byte[] newJPEG) {
    setImage(newJPEG);
    // lots of other methods
    Pete
    "If we knew what it was we were doing, it would
    not be called research, would it? [Einstein]"

    Well, you seem to be defining a C program with some imbedded java, or a java program with some native C methods. So which is it?
    o If it is a C program, then you have two things to do (with respect to java):
    - Start a java JVM.
    - During your processing, periodically call into your JVM to process data made available by your C program.
    o If it is a java program, then what you want to do -- I guess - is call a native method to start up an asynchronous (C) process, then have that asynchronous
    process periodically call back into java to process results.
    Overview of JNI (which you need to flesh out with some further study):
    o There is the socalled invocation API, which is used to get java started.
    o There is the definition of java native methods, which are then implemented in a C library (DLL on Windows), which library is loaded up at runtime by the java program, allowing the native methods to be called.
    o There are JNI methods available from C that allow you to look up objects and methods, and invoke those java methods.
    Two references:
    o Essential JNI by Rob Gordon.
    o www.swig.org

  • How to call business rules scripts via Java API

    Hi
    I have a problem. I have some scripts (business rules in essbase) that can be seen thru Administration Services Console under Business Rules folder. How can I execute these script using Provider Services (via Java API to EssBase interface)?

    hi
    i look too java api sample for "HBR Lounch"
    you can try found example in EAS folder
    C:\Hyperion\AdminServices\AppServer\InstalledApps\Tomcat\5.0.28\eas\webapps\hbrlauncher\MC_LaunchWindow.jsp
    please back, if you will have resolution :)

  • How to call backing bean method when user tabs out of af:inputListOfValues field

    Hi,
    I am using jdev 11.1.2.4.
    I want to call a backing bean method based on the value selected in the af:inputListOfValues field.
    The requirement is similar as Frank Nimphius-Oracle has demonstrated here  https://blogs.oracle.com/jdevotnharvest/entry/how_to_notify_the_server but with Input List of Values component.
    The fields I want to call method from is
    <af:inputListOfValues id="appealNameId"
                          popupTitle="Search and Select: #{bindings.AppealName.hints.label}"
                          value="#{bindings.AppealName.inputValue}"
                          label="#{bindings.AppealName.hints.label}"
                          model="#{bindings.AppealName.listOfValuesModel}"
                          required="#{bindings.AppealName.hints.mandatory}"
                          columns="#{bindings.AppealName.hints.displayWidth}"
                          shortDesc="#{bindings.AppealName.hints.tooltip}"
                          binding="#{backingBeanScope.backing_Donation.appealNameId}"
                          autoSubmit="true" clientComponent="false">
                          <f:validator binding="#{bindings.AppealName.validator}"/>
                          <af:autoSuggestBehavior suggestedItems="#{backingBeanScope.backing_Donation.onSuggestAppeal}"/>
                          <af:clientListener method="onBlurTxtField" type="blur"/>
    </af:inputListOfValues>
    <af:serverListener type="onBlurNotifyServer"
                       method="#{backingBeanScope.backing_Donation.onBlurNotify}"/>
    as you can see,  af:serverListener is outside the af:inputListOfValues which probably is the reason its not executing this method?
    public void onBlurNotify(ClientEvent clientEvent) {
       // get a hold of the input text component
       RichSelectOneChoice inputTxt =  (RichSelectOneChoice) clientEvent.getComponent();
       //do some work on it here (e.g. manipulating its readOnly state)
       //Get access to the payload
       Map  parameters = clientEvent.getParameters();
       System.out.println("SubmittedValue = "+parameters.get("submittedValue"));
       System.out.println("LocalValue =  "+parameters.get("localValue"));
    I've tried to put serverListener tag inside the <af:inputListOfValues> but getting below error
    "Server Listener is not valid child of Input List of Values"
    any ideas please?
    thanks

    As first, check to see that you are using correct type for af:serverListener (thet one you are queue in the javaScript onBlurTxtField function)
    If still does not work, go to directly to the page source code, and put af:serverListener "by hand", as a child for af:inputListOfValues.
    Because it is possible that these messages are false alarm...

  • How to call back a sent mail

    I have sent a mail and want to recall it , how can I do that ?

    that is not a good news , thanks a lot for your quick answer
    Have a lovely sunday
    susanne

  • How to call Backing bean method from JS

    I want to call commandlink action from JS,
    I'm trying document.getElementById('formPageInfo:btnCreateQuote').click() in javascript.
    But it is not working any ideas around?
    Code is for commandlink : <h:commandLink action="#{ManagedController.businessListActions.createNewQuote}" accesskey="C" title="Start Quote" id="btnCreateQuote"> <h:outputText value="Start Quote" /></h:commandLink>
    Any help/Suggestions around?

    I think that not exist a specific way to do it with jsf. Maybe you should ask in other forum more related with javascript, as a tip, if you can use jQuery in your environment, jQuery.trigger() can simulate a click on a button or command link. I have used it with a h:commnadLink and worked fine.

  • How to call function in included dll file through java application.

    Hi All,
    i am trying to create an java application which call c# functions using JNI. i am completed with the code and it is running fine when i tried to run from netbeans IDE. But when i tried from Calculator.jar file, first time it throws this error:
    F:\JavaProjects\Calculator\dist>Java -jar Calculator.jar
    Exception in thread "main" java.lang.UnsatisfiedLinkError: no CSharpClient in java.library.path
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.loadLibrary0(Unknown Source)
    at java.lang.System.loadLibrary(Unknown Source)
    at calculator.CalculatorApp.<clinit>(CalculatorApp.java:20)
    After that i included that dll file in the cuurent directory. And compiled and tried to run, it throws an unexpected error:
    F:\JavaProjects\Calculator\dist>Java -jar Calculator.jar
    *# An unexpected error has been detected by Java Runtime Environment:*
    *# Internal Error (0xe0434f4d), pid=2640, tid=3700*
    *# Java VM: Java HotSpot(TM) Client VM (1.6.0_02-b06 mixed mode, sharing)*
    *# Problematic frame:*
    *# C [kernel32.dll+0x12a5b]*
    *# An error report file with more information is saved as hs_err_pid2640.log*
    *# If you would like to submit a bug report, please visit:*
    *# http://java.sun.com/webapps/bugreport/crash.jsp*
    Anyone have idea how to solve this error.
    Thanks in advance.

    This error is created whenever things go sour on the native side. The first thing you can try, and I assume you are using a Java<->C++<->C# bridge which includes two dlls, one created by C++ and another by C#. Is to make sure that the C# dll is compiled using /t:module switch during compilation.
    If you are using VS2008, or VS2005, you can add a post build syntax like:
    csc /t:module /out:"$(ProjectDir)$(OutDir)YourModule.dll" "$(ProjectDir)YourCSfile.cs"
    Hope this helps! If not, ensure first that the native code works by creating a native test app for it.

Maybe you are looking for

  • Set Intermediary bank in DME

    Dear all, I need to set an intermediary bank in DME. I see that there are fileds from FPAYHX-BNKN1, BNKN2, BNKN3 that can be used for intermediary bank account, but all these fields are empty in REGUP and REGUH table. How are these fields populated,

  • I need help sorting out how Web services work

    I'm getting pretty darn confused with all the new terms I have to learn to develop a web service. I want to deploy a simple java based web service on an IIS/ServletExec machine. To do so the documentation says I have to instal WSDP on the machine. Wi

  • Customize daily email alerts for low storage on drive on server

    Hey, Hi, All, Thanks for the fantastic discussions, information, advice here. Great stuff. We have a server that sends email alerts for low storage on the file server. And we like those. But it is alerting us to low storage on the TimeMachine drive.

  • XSQL and 8.0.5

    Does anyone have XSQL running with 8.0.5? null

  • XML slideshow with preloader bar

    I'm using the following code to create a simple slideshow: import fl.transitions.Tween; import fl.transitions.easing.*; import fl.transitions.TweenEvent; var my_speed:Number; var my_count:Number; var my_images:XMLList; var my_loaders_array:Array=[];