如何在我的Java客户端代码中解码,更改,然后重新编码CORBA IOR文件(Visibroker)?

时间:2011-02-04 16:32:58

标签: corba

我正在编写代码来摄取由负责服务器的团队生成的IOR文件,并使用它将我的客户端绑定到他们的对象。听起来很简单吧?

出于某种原因,我有点超出了我的掌握(与防火墙,DMZ等有关),IOR文件中服务器的价值不是我们可以使用的。我们必须修改它。但是,IOR字符串是编码的。

Visibroker提供哪些内容可让我解码IOR字符串,更改一个或多个值,然后对其进行重新编码并继续正常进行?

我已经研究过IORInterceptors和URL命名,但我认为不会有这样做。

提前致谢!

4 个答案:

答案 0 :(得分:2)

当你觉得你需要破解IOR时,通过编写代码以及根据自己的喜好来修改它来抵制这样做的冲动。 IOR是由包含引用对象的服务器创建和指定的,所以当你开始在那里乱逛时,你就有点“取消保修”。

相反,通过让服务器在生成它们时使用备用主机名,花时间找到使环境中的IOR可用的正确方法。大多数ORB都提供这样的功能。我根本不了解Visibroker的特定配置选项,但快速谷歌搜索显示this page显示了一个很有前景的价值:

vbroker.se.iiop_ts.host    
  Specifies the host name used by this server engine. 
  The default value, null, means use the host name from the system.

希望有所帮助。

答案 1 :(得分:1)

很久以前我为GNU Classpath写了IorParser,代码可用。这是一个正常的解析器写的知道格式,不应该“无效保修”我认为。 IOR包含多个标记的配置文件,这些配置文件非常类似于XML,因此我们可以解析/修改我们需要和理解的配置文件,并保持其余部分不受影响。

我们需要解析的个人资料是TAG_INTERNET_IOP。它包含版本号,主机,端口和对象键。可以在gnu.IOR类中找到读取和写入此配置文件的代码。我很抱歉这是系统库的一部分,并不是一个很好的代码来复制粘贴在这里,但是用一些依赖类来删除它应该不是很困难。

此问题一再被问及CORBA :: Get the client ORB address and port with use of IIOP

答案 2 :(得分:1)

使用jacORB中的FixIOR工具(二进制)来修补IOR的地址和端口。 Download the binary(解压缩)并运行:

fixior <new-address> <new-port> <ior-file>

该工具将使用'修补'IOR

覆盖IOR文件的内容

您可以使用IOR Parser检查生成的IOR并将其与原始IOR进行比较

答案 3 :(得分:-1)

使用此功能更改IOR。将字符串化的IOR作为第一个参数传递。

void hackIOR(const char* str, char* newIOR )
{
  size_t s = (str ? strlen(str) : 0);
  char temp[1000];
  strcpy(newIOR,"IOR:");
  const char *p = str;

  s = (s-4)/2;  // how many octets are there in the string
  p += 4;

  int i;

  for (i=0; i<(int)s; i++) {

    int j = i*2;
    char v=0;

    if (p[j] >= '0' && p[j] <= '9') {
      v = ((p[j] - '0') << 4);
    }
    else if (p[j] >= 'a' && p[j] <= 'f') {
      v = ((p[j] - 'a' + 10) << 4);
    }
    else if (p[j] >= 'A' && p[j] <= 'F') {
      v = ((p[j] - 'A' + 10) << 4);
    }
    else
      cout <<"invalid octet"<<endl;

    if (p[j+1] >= '0' && p[j+1] <= '9') {
      v += (p[j+1] - '0');
    }
    else if (p[j+1] >= 'a' && p[j+1] <= 'f') {
      v += (p[j+1] - 'a' + 10);
    }
    else if (p[j+1] >= 'A' && p[j+1] <= 'F') {
      v += (p[j+1] - 'A' + 10);
    }
    else
      cout <<"invalid octet"<<endl;
    temp[i]=v;
  }

  temp[i] = 0;

  // Now temp  has decoded IOR string. print it.
  // Replace the object ID in temp.
  // Encoded it back, with following code.

  int temp1,temp2;
  int l,k;

  for(k = 0, l = 4 ; k < s ; k++)
  {

      temp1=temp2=temp[k];

      temp1 &= 0x0F;

      temp2 = temp2 & 0xF0;

      temp2 = temp2 >> 4;

    if(temp2 >=0 && temp2 <=9)
    {
        newIOR[l++] = temp2+'0';
    }
    else if(temp2 >=10 && temp2 <=15)
    {
        newIOR[l++] = temp2+'A'-10;
    }

    if(temp1 >=0 && temp1 <=9)
    {
        newIOR[l++] = temp1+'0';
    }
    else if(temp1 >=10 && temp1 <=15)
    {
        newIOR[l++] = temp1+'A'-10;
    }
  }

  newIOR[l] = 0;

//new IOR is present in new variable newIOR.

}

希望这适合你。