引发 CORBA 异常:未找到

Posted

技术标签:

【中文标题】引发 CORBA 异常:未找到【英文标题】:CORBA exception raised: NotFound 【发布时间】:2020-06-10 15:49:53 【问题描述】:

您好,我正在尝试使用 docker 实现简单的客户端/服务器 CORBA 应用程序。这是 Print.idl 代码:

module Test

  interface Printer
  
    void print();
  ;
;

这是客户端代码:

#include <iostream>

#include "PrintC.h"

int main(int argc, char** argv) 
    try 
        CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
        CORBA::Object_var po = orb->string_to_object("corbaname::nameservice/NameService#test/Printer");
        Test::Printer_var p = Test::Printer::_narrow(po.in());
        p->print();
        orb->destroy();
     catch (CORBA::Exception const& e) 
        std::cerr << "CORBA exception raised: " << e._name() << ": " << e._info().c_str() << '\n';
    
    return 0;

这是服务器代码:

#include <iostream>

#include <orbsvcs/CosNamingC.h>

#include "PrintS.h"

class Implement_Printer : public POA_Test::Printer 
public:
    void print() 
        std:: cout << "Hello World\n";
    
;

int main(int argc, char** argv) 
    try 
        CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
        CORBA::Object_var object = orb->resolve_initial_references("RootPOA");
        PortableServer::POA_var poa = PortableServer::POA::_narrow(object.in());
        PortableServer::POAManager_var poa_manager = poa->the_POAManager();
        poa_manager->activate();

        Implement_Printer p;    
        Test::Printer_var printer_object = p._this();   
        object = orb->string_to_object("corbaloc::nameservice/NameService");
        CosNaming::NamingContextExt_var naming_context =
        CosNaming::NamingContextExt::_narrow(object.in());
        CosNaming::Name_var name;
        name = naming_context->to_name("test/Printer");
        naming_context->rebind(name.in(), printer_object.in());

        orb->run();

        poa->destroy(1, 1);
        orb->destroy();
     catch (CORBA::Exception const& e) 
        std::cerr << "CORBA exception raised: " << e;
    
    return 0;

这里是 docker-compose.yml :

version: '3.2'
services:
  serveur:
    image: serveur
    networks:
      - corba
    depends_on:
    - nameservice
  client:
    image: client
    networks:
      - corba
    depends_on:
    - nameservice
    - serveur
  nameservice:
    image: omninames
    networks:
      - corba
networks:
  corba:
    driver: bridge

这里是 docker-compose up 的日志:

nameservice_1  | omniNames: (0) 2020-06-10 15:47:16.221353: Data file: '/var/lib/omniorb/omninames-13afbf6c0191.dat'.
nameservice_1  | omniNames: (0) 2020-06-10 15:47:16.221588: Starting omniNames for the first time.
nameservice_1  | omniNames: (0) 2020-06-10 15:47:16.222368: Wrote initial data file '/var/lib/omniorb/omninames-13afbf6c0191.dat'.
nameservice_1  | omniNames: (0) 2020-06-10 15:47:16.222446: Read data file '/var/lib/omniorb/omninames-13afbf6c0191.dat' successfully.
nameservice_1  | omniNames: (0) 2020-06-10 15:47:16.222496: Root context is IOR:010000002b00000049444c3a6f6d672e6f72672f436f734e616d696e672f4e616d696e67436f6e746578744578743a312e300000010000000000000070000000010102000e0000003139322e3136382e3230382e3200f90a0b0000004e616d6553657276696365000300000000000000080000000100000000545441010000001c0000000100000001000100010000000100010509010100010000000901010003545441080000008400e15e01000001
nameservice_1  | omniNames: (0) 2020-06-10 15:47:16.222546: Checkpointing Phase 1: Prepare.
nameservice_1  | omniNames: (0) 2020-06-10 15:47:16.222634: Checkpointing Phase 2: Commit.
nameservice_1  | omniNames: (0) 2020-06-10 15:47:16.222783: Checkpointing completed.
serveur_1      | CORBA exception raised: NotFound (IDL:omg.org/CosNaming/NamingContext/NotFound:1.0)
corba_docker_serveur_1 exited with code 139
corba_docker_client_1 exited with code 139

根据文档,错误是由于“无法找到名称或其组件之一。如果由于绑定已存在或绑定类型错误而引发此异常,则 rest_of_name 的成员异常的长度为 1。”

这段代码的灵感来自https://github.com/cromo/multicontainer-corba/

【问题讨论】:

【参考方案1】:

感谢 Wireshark,我获得了有关该错误的更多信息。 wireshark

因此它似乎取代了:

name = naming_context->to_name("test/Printer")

通过

name = naming_context->to_name("Printer")

有效。 (客户端代码也是一样)

【讨论】:

以上是关于引发 CORBA 异常:未找到的主要内容,如果未能解决你的问题,请参考以下文章

Appdomain.Load(AssemblyName) 引发文件未找到异常

Spring-boot,无法自动装配类。未找到默认构造函数引发异常

ojdbc14外部jar文件引发未找到异常[重复]

vb.net制作的Excel文件 未捕获通过反射调用的方法而引发的异常

在 Django REST 中引发异常

Android:未找到类运行时异常 - 仅发布版本