[omniORB] How to connect and call C++/Qt client and Java Server

Juaci Monteiro de Carvalho juacimc at yahoo.com.br
Fri Nov 27 11:47:04 GMT 2009


    Hi all,
    I'm programming in C++/Qt. Today I intend to use C++/Qt just to 
client and Java to server using glassfish and DB PostgreSQL.
    This example(1) in java (client and server), it's working.  
    I'm searching a solution to mix this two technologies(C++/Qt and 
Java server).
    I did a bean class to return a little message(java)

    Ex 1: server

package br.com.cadastro;

import java.util.List;
import javax.ejb.Stateless;

/**
 *
 * @author juaci
 */
@Stateless
public class CadastroBean implements CadastroRemote, CadastroLocal {

    public String getName() {
        return "<<<<<<<<<<    My first test..... >>>>>>>>>>>>>>>>";
    }
}


Ex 2: client C++/Qt

1 - How can I pass the parameter using this command line to test this 
code below?
    Command line:   ./cliente corbaname:iiop:localhost:3700/NameService

2 - The name of package in java  is  "br.com.cadastro.CadastroRemote".
      I would like adjust the command line above calling my package and 
to fix this piece of code below.

        CosNaming::Name name;
        name.length(1);
        name[0].id = CORBA::string_dup("CadastroRemote");
        // name[0].id = CORBA::string_dup("br.com.cadastro.CadastroRemote");
        name[0].kind = CORBA::string_dup("");


#include "CadastroRemote.h"
#include <iostream>
#include <CORBA.h>
#include <Naming.hh>
using namespace std;
int main(int argc, char ** argv)
{
try {
    // init ORB
    CORBA::ORB_ptr orb = CORBA::ORB_init(argc, argv);
    // resolve service
    CadastroRemote_ptr cadastro = 0;
    try {
        CORBA::Object_var ns_obj = 
orb->resolve_initial_references("NameService");
        if (!CORBA::is_nil(ns_obj)) {
        CosNaming::NamingContext_ptr nc = 
CosNaming::NamingContext::_narrow(ns_obj);
        CosNaming::Name name;
        name.length(1);
        name[0].id = CORBA::string_dup("CadastroRemote");
        // name[0].id = 
CORBA::string_dup("br.com.estante.cadastro.CadastroRemote");
        name[0].kind = CORBA::string_dup("");
        CORBA::Object_ptr obj = nc->resolve(name);
        if (!CORBA::is_nil(obj)) {
            cadastro = CadastroRemote::_narrow(obj);
        }
    }
    } catch (CosNaming::NamingContext::NotFound &) {
        cerr << "not found" << endl;
    } catch (CosNaming::NamingContext::InvalidName &) {
        cerr << "invalid name" << endl;
    } catch (CosNaming::NamingContext::CannotProceed &) {
        cerr << "cannot proceed" << endl;
    }

    if (!CORBA::is_nil(cadastro)) {
        char * server = cadastro->getNome();
        cout << "answer from: " << server << endl;
        CORBA::string_free(server);
    }

    // destroy ORB
    orb->destroy();
    } catch (CORBA::UNKNOWN) {}
}

// EOF



    If I made a mistake with codes please correct me.
    Someone has another better idea I appreciate your help.
    Thanks.

__________________________________________________
Faça ligações para outros computadores com o novo Yahoo! Messenger 
http://br.beta.messenger.yahoo.com/ 




More information about the omniORB-list mailing list