how do i decode, change, then re-encode a CORBA IOR file (Visibroker) in my Java client code?

二次信任 提交于 2019-12-11 17:55:01

问题


I am writing code to ingest the IOR file generated by the team responsible for the server and use it to bind my client to their object. Sounds easy, right?

For some reason a bit beyond my grasp (having to do with firewalls, DMZs, etc.), the value for the server inside the IOR file is not something we can use. We have to modify it. However, the IOR string is encoded.

What does Visibroker provide that will let me decode the IOR string, change one or more values, then re-encode it and continue on as normal?

I've already looked into IORInterceptors and URL Naming but I don't think either will do the trick.

Thanks in advance!


回答1:


When you feel like you need to hack an IOR, resist the urge to do so by writing code and whatnot to mangle it to your liking. IORs are meant to be created and dictated by the server that contains the referenced objects, so the moment you start mucking around in there, you're kinda "voiding your warranty".

Instead, spend your time finding the right way to make the IOR usable in your environment by having the server use an alternative hostname when it generates them. Most ORBs offer such a feature. I don't know Visibroker's particular configuration options at all, but a quick Google search revealed this page that shows a promising value:

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.

Hope that helps.




回答2:


Long time ago I wrote IorParser for GNU Classpath, the code is available. It is a normal parser written being aware about the format, should not "void a warranty" I think. IOR contains multiple tagged profiles that are encapsulated very much like XML so we could parse/modify profiles that we need and understand and leave the rest untouched.

The profile we need to parse is TAG_INTERNET_IOP. It contains version number, host, port and object key. Code that reads and writes this profile can be found in gnu.IOR class. I am sorry this is part of the system library and not a nice piece of code to copy paste here but it should not be very difficult to rip it out with a couple of dependent classes.

This question has been repeatedly asked as CORBA :: Get the client ORB address and port with use of IIOP




回答3:


Use the FixIOR tool (binary) from jacORB to patch the address and port of an IOR. Download the binary (unzip it) and run:

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

The tool will override the content of the IOR file with the 'patched' IOR

You can use IOR Parser to check the resulting IOR and compare it to your original IOR




回答4:


Use this function to change the IOR. pass stringified IOR as first argument.

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.

}

Hope this works for you.



来源:https://stackoverflow.com/questions/4900422/how-do-i-decode-change-then-re-encode-a-corba-ior-file-visibroker-in-my-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!