Discussion:
[omniORB] How to connect and call C++/Qt client and Java Server
Juaci Monteiro de Carvalho
2009-11-27 19:44:24 UTC
Permalink
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/
techy_bolek
2009-11-30 13:02:21 UTC
Permalink
I've no idea what are you trying to do. Firstly, you say you want to connect
a C++ client to Java server but you throw a C++ server code. Secondly, my
assumption was that the you were using CORBA but I see a J2EE 3.0 session
bean in your Java code.
Post by Juaci Monteiro de Carvalho
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;
/**
*
*/
@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/
_______________________________________________
omniORB-list mailing list
http://www.omniorb-support.com/mailman/listinfo/omniorb-list
--
View this message in context: http://old.nabble.com/How-to-connect-and-call-C%2B%2B-Qt-client-and-Java-Server-tp26542605p26562807.html
Sent from the OmniORB - User mailing list archive at Nabble.com.
Juaci Monteiro de Carvalho
2009-12-01 01:36:17 UTC
Permalink
Ok, thanks for your help.
I'm beginner, I was thinking that code (Corba) would be to use for client.
It's possible you send me an example C++ Corba for client and using
javaEE5 (server)?
This I'm trying to do.
Post by techy_bolek
I've no idea what are you trying to do. Firstly, you say you want to connect
a C++ client to Java server but you throw a C++ server code. Secondly, my
assumption was that the you were using CORBA but I see a J2EE 3.0 session
bean in your Java code.
Post by Juaci Monteiro de Carvalho
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;
/**
*
*/
@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/
_______________________________________________
omniORB-list mailing list
http://www.omniorb-support.com/mailman/listinfo/omniorb-list
__________________________________________________
Faça ligações para outros computadores com o novo Yahoo! Messenger
http://br.beta.messenger.yahoo.com/
techy_bolek
2009-12-03 05:44:39 UTC
Permalink
Not sure if my previous message was accepted so here it is again.
Ok, my bad, your C++ code actually does show a piece of a CORBA client code.
First, you should know that CORBA is a platform-independent technology. This
means your client does not care what whether your server is Java, C++ or
whatever - as long as they two speak CORBA they can talk to each other
through CORBA.
That being said, what you need is a CORBA C++ client, assuming that you have
your CORBA server correctly implemented. Have you tested your server with
other clients yet?
You should be able to find an example in any CORBA tutorial. You got the
initial steps handled, whereby you set the ORB parameters and connect to the
remote object. I have not validated your code that thoroughly but it looks
good at a first glance.
Post by Juaci Monteiro de Carvalho
Ok, thanks for your help.
I'm beginner, I was thinking that code (Corba) would be to use for client.
It's possible you send me an example C++ Corba for client and using
javaEE5 (server)?
This I'm trying to do.
Post by techy_bolek
I've no idea what are you trying to do. Firstly, you say you want to connect
a C++ client to Java server but you throw a C++ server code. Secondly, my
assumption was that the you were using CORBA but I see a J2EE 3.0 session
bean in your Java code.
Post by Juaci Monteiro de Carvalho
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;
/**
*
*/
@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/
_______________________________________________
omniORB-list mailing list
http://www.omniorb-support.com/mailman/listinfo/omniorb-list
__________________________________________________
Fa?a liga??es para outros computadores com o novo Yahoo! Messenger
http://br.beta.messenger.yahoo.com/
_______________________________________________
omniORB-list mailing list
http://www.omniorb-support.com/mailman/listinfo/omniorb-list
--
View this message in context: http://old.nabble.com/How-to-connect-and-call-C%2B%2B-Qt-client-and-Java-Server-tp26542605p26618696.html
Sent from the OmniORB - User mailing list archive at Nabble.com.
techy_bolek
2009-11-30 23:51:34 UTC
Permalink
Ok, my bad, your C++ code actually does show a piece of a CORBA client code.
First, you should know that CORBA is a platform-independent technology. This
means your client does not care what whether your server is Java, C++ or
whatever - as long as they two speak CORBA they can talk to each other
through CORBA.
That being said, what you need is a CORBA C++ client, assuming that you have
your CORBA server correctly implemented. Have you tested your server with
other clients yet?
You should be able to find an example in any CORBA tutorial. You got the
initial steps handled, whereby you set the ORB parameters and connect to the
remote object. I have not validated your code that thoroughly but it looks
good at a first glance.
Post by Juaci Monteiro de Carvalho
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;
/**
*
*/
@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/
_______________________________________________
omniORB-list mailing list
http://www.omniorb-support.com/mailman/listinfo/omniorb-list
--
View this message in context: http://old.nabble.com/How-to-connect-and-call-C%2B%2B-Qt-client-and-Java-Server-tp26542605p26578926.html
Sent from the OmniORB - User mailing list archive at Nabble.com.
Duncan Grisby
2009-12-07 23:48:42 UTC
Permalink
Post by Juaci Monteiro de Carvalho
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)
From what you've posted, it looks like you are trying to talk to J2EE
server using C++ code, via RMI-over-IIOP. Although that is theoretically
possible, it is not something that's a good idea unless you are a real
expert in CORBA generally and the C++ mapping in particular because the
way the Java-to-IDL mapping uses CORBA makes everything hopelessly
complex. It would appear that you are not such an expert...

The sensible approach to doing what you want is to define your own
simple IDL interface for the Java server, then talk to that with C++.
That will make everything comprehensible and will work much better.

Cheers,

Duncan.
--
-- Duncan Grisby --
-- ***@grisby.org --
-- http://www.grisby.org --
Juaci Monteiro de Carvalho
2009-12-08 17:26:07 UTC
Permalink
Please, someone can send me an example or explain me.
How to connect?
1 - Client C++.
2 - Java Server.

Thanks.
Post by Duncan Grisby
Post by Juaci Monteiro de Carvalho
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)
From what you've posted, it looks like you are trying to talk to J2EE
server using C++ code, via RMI-over-IIOP. Although that is theoretically
possible, it is not something that's a good idea unless you are a real
expert in CORBA generally and the C++ mapping in particular because the
way the Java-to-IDL mapping uses CORBA makes everything hopelessly
complex. It would appear that you are not such an expert...
The sensible approach to doing what you want is to define your own
simple IDL interface for the Java server, then talk to that with C++.
That will make everything comprehensible and will work much better.
Cheers,
Duncan.
__________________________________________________
Fa?a liga??es para outros computadores com o novo Yahoo! Messenger
http://br.beta.messenger.yahoo.com/

Loading...