異常org.omg.CORBA.BAD_PARAM ()解決方法猜想

小聲bb:這個是在我寫一個corba博客的時候偶然發現的,百度後發現不少人遇到這個錯誤而且還有些沒有被解決,由於我沒有實際遇到這個問題,所以此處只是對這個錯誤及解決方法的一些分析猜想,希望能對你有所幫助。如果有錯請不要罵我quq


這個錯誤是在idl文件下生成的包中的一個文件的函數內被拋出。

我的idl文件是這樣的

module sample{
interface HelloWorld{ 
wstring sayHello();   
};  
};

在它生成的sample包中有一個HelloWorldHelper.java文件(文件的所有代碼請見最後),裏面有一個narrow(),具體內容如下:

public static sample.HelloWorld narrow (org.omg.CORBA.Object obj)
  {
    if (obj == null)
      return null;
    else if (obj instanceof sample.HelloWorld)
      return (sample.HelloWorld)obj;
    else if (!obj._is_a (id ()))
      throw new org.omg.CORBA.BAD_PARAM ();
    else
    {
      org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate ();
      sample._HelloWorldStub stub = new sample._HelloWorldStub ();
      stub._set_delegate(delegate);
      return stub;
    }
  }

在第二個else if中,判斷如果(!obj._is_a (id ()))則拋出這個org.omg.CORBA.BAD_PARAM ()異常,而id()這個函數也是在HelloWorldHelper.java中被定義的

id()的內容是

public static String id ()
  {
    return _id;
  }

而_id是在HelloWorldHelper.java中一開始被定義的

  private static String  _id = "IDL:sample/HelloWorld:1.0";//IDL:接口數字語言

所以這個異常的錯誤原因可能是生成id失敗或者爲空。

同時我在stackflow上看到有人也遇到了這個問題,https://stackoverflow.com/questions/28851733/apache-camel-update-route-through-jmx-throws-org-omg-corba-bad-param,他是在博客的服務器端更新時遇到的這個問題,回答的那個人說他是在本地跑的就沒有報這個錯(不失爲一種解決辦法?/發抖),他說在本地跑Camel就會拋出一個異常,但是不能再客戶端加載。異常爲

Caused by: java.lang.ClassNotFoundException: org.apache.camel.FailedToCreateRouteException (no security manager: RMI class loader disabled)

以下是HelloWorldHelper.java的源代碼

package sample;


/**
* sample/HelloWorldHelper.java .
* 由IDL-to-Java 編譯器 (可移植), 版本 "3.2"生成
* 從HelloWorld.idl
* 2019年5月25日 星期六 上午10時02分35秒 CST
*/

abstract public class HelloWorldHelper
{
  private static String  _id = "IDL:sample/HelloWorld:1.0";

  public static void insert (org.omg.CORBA.Any a, sample.HelloWorld that)
  {
    org.omg.CORBA.portable.OutputStream out = a.create_output_stream ();
    a.type (type ());
    write (out, that);
    a.read_value (out.create_input_stream (), type ());
  }

  public static sample.HelloWorld extract (org.omg.CORBA.Any a)
  {
    return read (a.create_input_stream ());
  }

  private static org.omg.CORBA.TypeCode __typeCode = null;
  synchronized public static org.omg.CORBA.TypeCode type ()
  {
    if (__typeCode == null)
    {
      __typeCode = org.omg.CORBA.ORB.init ().create_interface_tc (sample.HelloWorldHelper.id (), "HelloWorld");
    }
    return __typeCode;
  }

  public static String id ()
  {
    return _id;
  }

  public static sample.HelloWorld read (org.omg.CORBA.portable.InputStream istream)
  {
    return narrow (istream.read_Object (_HelloWorldStub.class));
  }

  public static void write (org.omg.CORBA.portable.OutputStream ostream, sample.HelloWorld value)
  {
    ostream.write_Object ((org.omg.CORBA.Object) value);
  }

  public static sample.HelloWorld narrow (org.omg.CORBA.Object obj)
  {
    if (obj == null)
      return null;
    else if (obj instanceof sample.HelloWorld)
      return (sample.HelloWorld)obj;
    else if (!obj._is_a (id ()))
      throw new org.omg.CORBA.BAD_PARAM ();
    else
    {
      org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate ();
      sample._HelloWorldStub stub = new sample._HelloWorldStub ();
      stub._set_delegate(delegate);
      return stub;
    }
  }

  public static sample.HelloWorld unchecked_narrow (org.omg.CORBA.Object obj)
  {
    if (obj == null)
      return null;
    else if (obj instanceof sample.HelloWorld)
      return (sample.HelloWorld)obj;
    else
    {
      org.omg.CORBA.portable.Delegate delegate = ((org.omg.CORBA.portable.ObjectImpl)obj)._get_delegate ();
      sample._HelloWorldStub stub = new sample._HelloWorldStub ();
      stub._set_delegate(delegate);
      return stub;
    }
  }

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章