1. /*
  2. * @(#)MessageBase.java 1.18 04/01/13
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.internal.iiop.messages;
  8. import java.io.IOException;
  9. import org.omg.CORBA.Principal;
  10. import org.omg.CORBA.INTERNAL;
  11. import org.omg.CORBA.MARSHAL;
  12. import org.omg.CORBA.CompletionStatus;
  13. import org.omg.IOP.TaggedProfile;
  14. import com.sun.corba.se.internal.iiop.ORB;
  15. import com.sun.corba.se.internal.core.GIOPVersion;
  16. import com.sun.corba.se.internal.core.ServiceContexts;
  17. import com.sun.corba.se.internal.core.IOR;
  18. import com.sun.corba.se.internal.ior.ObjectKey;
  19. import com.sun.corba.se.internal.ior.ObjectKeyFactory;
  20. import com.sun.corba.se.internal.ior.IIOPProfile;
  21. import com.sun.corba.se.internal.orbutil.ORBUtility;
  22. import com.sun.corba.se.internal.orbutil.MinorCodes;
  23. import com.sun.corba.se.internal.orbutil.ORBConstants;
  24. import com.sun.corba.se.internal.iiop.AddressingDispositionException;
  25. /**
  26. * This class acts as the base class for the various GIOP message types. This
  27. * also serves as a factory to create various message types. We currently
  28. * support GIOP 1.0, 1.1 and 1.2 message types.
  29. *
  30. * @author Ram Jeyaraman 05/14/2000
  31. * @version 1.0
  32. */
  33. public abstract class MessageBase implements Message {
  34. // This is only used when the giopDebug flag is
  35. // turned on.
  36. public byte[] giopHeader;
  37. // Static methods
  38. public static Message createFromStream(ORB orb, java.io.InputStream is)
  39. throws IOException {
  40. Message msg = null;
  41. boolean debug = orb.giopDebugFlag ;
  42. // Allocate a buffer just large enough for the GIOP header
  43. byte buf[] = new byte[GIOPMessageHeaderLength];
  44. readFully(is, buf, 0, GIOPMessageHeaderLength);
  45. if (debug) {
  46. ORBUtility.dprint("Message", "createFromStream: type is " + buf[7]);
  47. }
  48. // Sanity checks
  49. /*
  50. * check for magic corruption
  51. * check for version incompatibility
  52. * check if fragmentation is allowed based on mesg type.
  53. . 1.0 fragmentation disallowed; FragmentMessage is non-existent.
  54. . 1.1 only {Request, Reply} msgs maybe fragmented.
  55. . 1.2 only {Request, Reply, LocateRequest, LocateReply} msgs
  56. maybe fragmented.
  57. */
  58. int b1, b2, b3, b4;
  59. b1 = (buf[0] << 24) & 0xFF000000;
  60. b2 = (buf[1] << 16) & 0x00FF0000;
  61. b3 = (buf[2] << 8) & 0x0000FF00;
  62. b4 = (buf[3] << 0) & 0x000000FF;
  63. int magic = (b1 | b2 | b3 | b4);
  64. if (magic != GIOPBigMagic) {
  65. // If Magic is incorrect, it is an error.
  66. // ACTION : send MessageError and close the connection.
  67. throw new INTERNAL(MinorCodes.GIOP_MAGIC_ERROR,
  68. CompletionStatus.COMPLETED_MAYBE);
  69. }
  70. GIOPVersion orbVersion = orb.getGIOPVersion();
  71. if (debug) {
  72. ORBUtility.dprint("MessageBase", "Message GIOP version: "
  73. + buf[4] + '.' + buf[5]);
  74. ORBUtility.dprint("MessageBase", "ORB Max GIOP Version: "
  75. + orbVersion);
  76. }
  77. if ( (buf[4] > orbVersion.getMajor()) ||
  78. ( (buf[4] == orbVersion.getMajor()) && (buf[5] > orbVersion.getMinor()) )
  79. ) {
  80. // For requests, sending ORB should use the version info
  81. // published in the IOR or may choose to use a <= version
  82. // for requests. If the version is greater than published version,
  83. // it is an error.
  84. // For replies, the ORB should always receive a version it supports
  85. // or less, but never greater (except for MessageError)
  86. // ACTION : Send back a MessageError() with the the highest version
  87. // the server ORB supports, and close the connection.
  88. if ( buf[7] != GIOPMessageError ) {
  89. throw new INTERNAL(MinorCodes.GIOP_VERSION_ERROR,
  90. CompletionStatus.COMPLETED_MAYBE);
  91. }
  92. }
  93. AreFragmentsAllowed(buf[4], buf[5], buf[6], buf[7]);
  94. // create appropriate messages types
  95. switch (buf[7]) {
  96. case GIOPRequest:
  97. if (debug) {
  98. ORBUtility.dprint( "Message",
  99. "createFromStream: creating RequestMessage" ) ;
  100. }
  101. //msg = new RequestMessage(debug);
  102. if ( (buf[4] == 0x01) && (buf[5] == 0x00) ) { // 1.0
  103. msg = new RequestMessage_1_0(orb);
  104. } else if ( (buf[4] == 0x01) && (buf[5] == 0x01) ) { // 1.1
  105. msg = new RequestMessage_1_1(orb);
  106. } else if ( (buf[4] == 0x01) && (buf[5] == 0x02) ) { // 1.2
  107. msg = new RequestMessage_1_2(orb);
  108. } else {
  109. throw new INTERNAL(MinorCodes.GIOP_VERSION_ERROR,
  110. CompletionStatus.COMPLETED_MAYBE);
  111. }
  112. break;
  113. case GIOPLocateRequest:
  114. //msg = new LocateRequestMessage(debug);
  115. if ( (buf[4] == 0x01) && (buf[5] == 0x00) ) { // 1.0
  116. msg = new LocateRequestMessage_1_0(orb);
  117. } else if ( (buf[4] == 0x01) && (buf[5] == 0x01) ) { // 1.1
  118. msg = new LocateRequestMessage_1_1(orb);
  119. } else if ( (buf[4] == 0x01) && (buf[5] == 0x02) ) { // 1.2
  120. msg = new LocateRequestMessage_1_2(orb);
  121. } else {
  122. throw new INTERNAL(MinorCodes.GIOP_VERSION_ERROR,
  123. CompletionStatus.COMPLETED_MAYBE);
  124. }
  125. break;
  126. case GIOPCancelRequest:
  127. //msg = new CancelRequestMessage(debug);
  128. if ( (buf[4] == 0x01) && (buf[5] == 0x00) ) { // 1.0
  129. msg = new CancelRequestMessage_1_0();
  130. } else if ( (buf[4] == 0x01) && (buf[5] == 0x01) ) { // 1.1
  131. msg = new CancelRequestMessage_1_1();
  132. } else if ( (buf[4] == 0x01) && (buf[5] == 0x02) ) { // 1.2
  133. msg = new CancelRequestMessage_1_2();
  134. } else {
  135. throw new INTERNAL(MinorCodes.GIOP_VERSION_ERROR,
  136. CompletionStatus.COMPLETED_MAYBE);
  137. }
  138. break;
  139. case GIOPReply:
  140. //msg = new ReplyMessage(debug);
  141. if ( (buf[4] == 0x01) && (buf[5] == 0x00) ) { // 1.0
  142. msg = new ReplyMessage_1_0(orb);
  143. } else if ( (buf[4] == 0x01) && (buf[5] == 0x01) ) { // 1.1
  144. msg = new ReplyMessage_1_1(orb);
  145. } else if ( (buf[4] == 0x01) && (buf[5] == 0x02) ) { // 1.2
  146. msg = new ReplyMessage_1_2(orb);
  147. } else {
  148. throw new INTERNAL(MinorCodes.GIOP_VERSION_ERROR,
  149. CompletionStatus.COMPLETED_MAYBE);
  150. }
  151. break;
  152. case GIOPLocateReply:
  153. //msg = new LocateReplyMessage(debug);
  154. if ( (buf[4] == 0x01) && (buf[5] == 0x00) ) { // 1.0
  155. msg = new LocateReplyMessage_1_0(orb);
  156. } else if ( (buf[4] == 0x01) && (buf[5] == 0x01) ) { // 1.1
  157. msg = new LocateReplyMessage_1_1(orb);
  158. } else if ( (buf[4] == 0x01) && (buf[5] == 0x02) ) { // 1.2
  159. msg = new LocateReplyMessage_1_2(orb);
  160. } else {
  161. throw new INTERNAL(MinorCodes.GIOP_VERSION_ERROR,
  162. CompletionStatus.COMPLETED_MAYBE);
  163. }
  164. break;
  165. case GIOPCloseConnection:
  166. case GIOPMessageError:
  167. // REVISIT a MessageError may contain the highest version server
  168. // can support. In such a case, a new request may be made with the
  169. // correct version or the connection be simply closed. Note the
  170. // connection may have been closed by the server.
  171. //msg = new Message(debug);
  172. if ( (buf[4] == 0x01) && (buf[5] == 0x00) ) { // 1.0
  173. msg = new Message_1_0();
  174. } else if ( (buf[4] == 0x01) && (buf[5] == 0x01) ) { // 1.1
  175. msg = new Message_1_1();
  176. } else if ( (buf[4] == 0x01) && (buf[5] == 0x02) ) { // 1.2
  177. msg = new Message_1_1();
  178. } else {
  179. throw new INTERNAL(MinorCodes.GIOP_VERSION_ERROR,
  180. CompletionStatus.COMPLETED_MAYBE);
  181. }
  182. break;
  183. case GIOPFragment:
  184. //msg = new FragmentMessage(debug);
  185. if ( (buf[4] == 0x01) && (buf[5] == 0x00) ) { // 1.0
  186. // not possible (error checking done already)
  187. } else if ( (buf[4] == 0x01) && (buf[5] == 0x01) ) { // 1.1
  188. msg = new FragmentMessage_1_1();
  189. } else if ( (buf[4] == 0x01) && (buf[5] == 0x02) ) { // 1.2
  190. msg = new FragmentMessage_1_2();
  191. } else {
  192. throw new INTERNAL(MinorCodes.GIOP_VERSION_ERROR,
  193. CompletionStatus.COMPLETED_MAYBE);
  194. }
  195. break;
  196. default:
  197. if (debug)
  198. ORBUtility.dprint("Message", "createFromStream: fell off end!");
  199. // unknown message type ?
  200. // ACTION : send MessageError and close the connection
  201. throw new INTERNAL(MinorCodes.ILLEGAL_GIOP_MSG_TYPE,
  202. CompletionStatus.COMPLETED_MAYBE);
  203. }
  204. //
  205. // Initialize the generic GIOP header instance variables.
  206. //
  207. if ( (buf[4] == 0x01) && (buf[5] == 0x00) ) { // 1.0
  208. Message_1_0 msg10 = (Message_1_0) msg;
  209. msg10.magic = magic;
  210. msg10.GIOP_version = new GIOPVersion(buf[4], buf[5]);
  211. msg10.byte_order = (buf[6] == LITTLE_ENDIAN_BIT);
  212. msg10.message_type = buf[7];
  213. msg10.message_size = readSize(buf[8], buf[9], buf[10], buf[11],
  214. msg10.isLittleEndian()) +
  215. GIOPMessageHeaderLength;
  216. } else { // 1.1 & 1.2
  217. Message_1_1 msg11 = (Message_1_1) msg;
  218. msg11.magic = magic;
  219. msg11.GIOP_version = new GIOPVersion(buf[4], buf[5]);
  220. msg11.flags = buf[6];
  221. msg11.message_type = buf[7];
  222. msg11.message_size = readSize(buf[8], buf[9], buf[10], buf[11],
  223. msg11.isLittleEndian()) +
  224. GIOPMessageHeaderLength;
  225. }
  226. if (debug) {
  227. ORBUtility.dprint( "Message",
  228. "createFromStream: message construction complete." ) ;
  229. // For debugging purposes, save the 12 bytes of the header
  230. ((MessageBase)msg).giopHeader = buf;
  231. }
  232. return msg;
  233. }
  234. private static RequestMessage createRequest(
  235. ORB orb, GIOPVersion gv, int request_id,
  236. boolean response_expected, byte[] object_key, String operation,
  237. ServiceContexts service_contexts, Principal requesting_principal) {
  238. if (gv.equals(GIOPVersion.V1_0)) { // 1.0
  239. return new RequestMessage_1_0(orb, service_contexts, request_id,
  240. response_expected, object_key, operation, requesting_principal);
  241. } else if (gv.equals(GIOPVersion.V1_1)) { // 1.1
  242. return new RequestMessage_1_1(orb, service_contexts, request_id,
  243. response_expected, new byte[] { 0x00, 0x00, 0x00 },
  244. object_key, operation, requesting_principal);
  245. } else if (gv.equals(GIOPVersion.V1_2)) { // 1.2
  246. // Note: Currently we use response_expected flag to decide if the
  247. // call is oneway or not. Ideally, it is possible to expect a
  248. // response on a oneway call too, but we do not support it now.
  249. byte response_flags = 0x03;
  250. if (response_expected) {
  251. response_flags = 0x03;
  252. } else {
  253. response_flags = 0x00;
  254. }
  255. /*
  256. // REVISIT The following is the correct way to do it. This gives
  257. // more flexibility.
  258. if ((DII::INV_NO_RESPONSE == false) && response_expected) {
  259. response_flags = 0x03; // regular two-way
  260. } else if ((DII::INV_NO_RESPONSE == false) && !response_expected) {
  261. // this condition is not possible
  262. } else if ((DII::INV_NO_RESPONSE == true) && response_expected) {
  263. // oneway, but we need response for LocationForwards or
  264. // SystemExceptions.
  265. response_flags = 0x01;
  266. } else if ((DII::INV_NO_RESPONSE == true) && !response_expected) {
  267. // oneway, no response required
  268. response_flags = 0x00;
  269. }
  270. */
  271. TargetAddress target = new TargetAddress();
  272. target.object_key(object_key);
  273. return new RequestMessage_1_2(orb, request_id, response_flags,
  274. new byte[] { 0x00, 0x00, 0x00 }, target,
  275. operation, service_contexts);
  276. } else {
  277. throw new INTERNAL(MinorCodes.GIOP_VERSION_ERROR,
  278. CompletionStatus.COMPLETED_MAYBE);
  279. }
  280. }
  281. public static RequestMessage createRequest(
  282. ORB orb, GIOPVersion gv, int request_id, boolean response_expected,
  283. IOR ior, short addrDisp, String operation,
  284. ServiceContexts service_contexts, Principal requesting_principal) {
  285. if (addrDisp == KeyAddr.value) {
  286. // object key will be used for target addressing
  287. IIOPProfile profile = ior.getProfile();
  288. ObjectKey objKey = profile.getObjectKey();
  289. byte[] object_key = objKey.getBytes(orb);
  290. return createRequest(orb, gv, request_id, response_expected,
  291. object_key, operation, service_contexts,
  292. requesting_principal);
  293. }
  294. if (!(gv.equals(GIOPVersion.V1_2))) {
  295. // only object_key based target addressing is allowed for
  296. // GIOP 1.0 & 1.1
  297. throw new INTERNAL(
  298. "GIOP version error",
  299. MinorCodes.GIOP_VERSION_ERROR,
  300. CompletionStatus.COMPLETED_NO);
  301. }
  302. // Note: Currently we use response_expected flag to decide if the
  303. // call is oneway or not. Ideally, it is possible to expect a
  304. // response on a oneway call too, but we do not support it now.
  305. byte response_flags = 0x03;
  306. if (response_expected) {
  307. response_flags = 0x03;
  308. } else {
  309. response_flags = 0x00;
  310. }
  311. TargetAddress target = new TargetAddress();
  312. if (addrDisp == ProfileAddr.value) { // iop profile will be used
  313. IIOPProfile profile = ior.getProfile();
  314. target.profile(profile.getIOPProfile(orb));
  315. } else if (addrDisp == ReferenceAddr.value) { // ior will be used
  316. IORAddressingInfo iorInfo =
  317. new IORAddressingInfo(
  318. 0, // profile index
  319. ior.getIOPIOR(orb));
  320. target.ior(iorInfo);
  321. } else {
  322. // invalid target addressing disposition value
  323. throw new INTERNAL("Illegal target address disposition",
  324. MinorCodes.ILLEGAL_TARGET_ADDRESS_DISPOSITION,
  325. CompletionStatus.COMPLETED_NO);
  326. }
  327. return new RequestMessage_1_2(orb, request_id, response_flags,
  328. new byte[] { 0x00, 0x00, 0x00 }, target,
  329. operation, service_contexts);
  330. }
  331. public static ReplyMessage createReply(
  332. ORB orb, GIOPVersion gv, int request_id,
  333. int reply_status, ServiceContexts service_contexts, IOR ior) {
  334. if (gv.equals(GIOPVersion.V1_0)) { // 1.0
  335. return new ReplyMessage_1_0(orb, service_contexts, request_id,
  336. reply_status, ior);
  337. } else if (gv.equals(GIOPVersion.V1_1)) { // 1.1
  338. return new ReplyMessage_1_1(orb, service_contexts, request_id,
  339. reply_status, ior);
  340. } else if (gv.equals(GIOPVersion.V1_2)) { // 1.2
  341. return new ReplyMessage_1_2(orb, request_id, reply_status,
  342. service_contexts, ior);
  343. } else {
  344. throw new INTERNAL(MinorCodes.GIOP_VERSION_ERROR,
  345. CompletionStatus.COMPLETED_MAYBE);
  346. }
  347. }
  348. public static LocateRequestMessage createLocateRequest(
  349. ORB orb, GIOPVersion gv,
  350. int request_id, byte[] object_key) {
  351. if (gv.equals(GIOPVersion.V1_0)) { // 1.0
  352. return new LocateRequestMessage_1_0(orb, request_id, object_key);
  353. } else if (gv.equals(GIOPVersion.V1_1)) { // 1.1
  354. return new LocateRequestMessage_1_1(orb, request_id, object_key);
  355. } else if (gv.equals(GIOPVersion.V1_2)) { // 1.2
  356. TargetAddress target = new TargetAddress();
  357. target.object_key(object_key);
  358. return new LocateRequestMessage_1_2(orb, request_id, target);
  359. } else {
  360. throw new INTERNAL(MinorCodes.GIOP_VERSION_ERROR,
  361. CompletionStatus.COMPLETED_MAYBE);
  362. }
  363. }
  364. public static LocateReplyMessage createLocateReply(ORB orb, GIOPVersion gv,
  365. int request_id, int locate_status, IOR ior) {
  366. if (gv.equals(GIOPVersion.V1_0)) { // 1.0
  367. return new LocateReplyMessage_1_0(orb, request_id,
  368. locate_status, ior);
  369. } else if (gv.equals(GIOPVersion.V1_1)) { // 1.1
  370. return new LocateReplyMessage_1_1(orb, request_id,
  371. locate_status, ior);
  372. } else if (gv.equals(GIOPVersion.V1_2)) { // 1.2
  373. return new LocateReplyMessage_1_2(orb, request_id,
  374. locate_status, ior);
  375. } else {
  376. throw new INTERNAL(MinorCodes.GIOP_VERSION_ERROR,
  377. CompletionStatus.COMPLETED_MAYBE);
  378. }
  379. }
  380. public static CancelRequestMessage createCancelRequest(
  381. GIOPVersion gv, int request_id) {
  382. if (gv.equals(GIOPVersion.V1_0)) { // 1.0
  383. return new CancelRequestMessage_1_0(request_id);
  384. } else if (gv.equals(GIOPVersion.V1_1)) { // 1.1
  385. return new CancelRequestMessage_1_1(request_id);
  386. } else if (gv.equals(GIOPVersion.V1_2)) { // 1.2
  387. return new CancelRequestMessage_1_2(request_id);
  388. } else {
  389. throw new INTERNAL(MinorCodes.GIOP_VERSION_ERROR,
  390. CompletionStatus.COMPLETED_MAYBE);
  391. }
  392. }
  393. public static Message createCloseConnection(GIOPVersion gv) {
  394. if (gv.equals(GIOPVersion.V1_0)) { // 1.0
  395. return new Message_1_0(Message.GIOPBigMagic, false,
  396. Message.GIOPCloseConnection, 0);
  397. } else if (gv.equals(GIOPVersion.V1_1)) { // 1.1
  398. return new Message_1_1(Message.GIOPBigMagic, GIOPVersion.V1_1,
  399. FLAG_NO_FRAG_BIG_ENDIAN,
  400. Message.GIOPCloseConnection, 0);
  401. } else if (gv.equals(GIOPVersion.V1_2)) { // 1.2
  402. return new Message_1_1(Message.GIOPBigMagic, GIOPVersion.V1_2,
  403. FLAG_NO_FRAG_BIG_ENDIAN,
  404. Message.GIOPCloseConnection, 0);
  405. } else {
  406. throw new INTERNAL(MinorCodes.GIOP_VERSION_ERROR,
  407. CompletionStatus.COMPLETED_MAYBE);
  408. }
  409. }
  410. public static Message createMessageError(GIOPVersion gv) {
  411. if (gv.equals(GIOPVersion.V1_0)) { // 1.0
  412. return new Message_1_0(Message.GIOPBigMagic, false,
  413. Message.GIOPMessageError, 0);
  414. } else if (gv.equals(GIOPVersion.V1_1)) { // 1.1
  415. return new Message_1_1(Message.GIOPBigMagic, GIOPVersion.V1_1,
  416. FLAG_NO_FRAG_BIG_ENDIAN,
  417. Message.GIOPMessageError, 0);
  418. } else if (gv.equals(GIOPVersion.V1_2)) { // 1.2
  419. return new Message_1_1(Message.GIOPBigMagic, GIOPVersion.V1_2,
  420. FLAG_NO_FRAG_BIG_ENDIAN,
  421. Message.GIOPMessageError, 0);
  422. } else {
  423. throw new INTERNAL(MinorCodes.GIOP_VERSION_ERROR,
  424. CompletionStatus.COMPLETED_MAYBE);
  425. }
  426. }
  427. public static FragmentMessage createFragmentMessage(GIOPVersion gv) {
  428. // This method is not currently used.
  429. // New fragment messages are always created from existing messages.
  430. // Creating a FragmentMessage from InputStream is done in
  431. // createFromStream(..)
  432. return null;
  433. }
  434. public static int getRequestId(Message msg) {
  435. switch (msg.getType()) {
  436. case GIOPRequest :
  437. return ((RequestMessage) msg).getRequestId();
  438. case GIOPReply :
  439. return ((ReplyMessage) msg).getRequestId();
  440. case GIOPLocateRequest :
  441. return ((LocateRequestMessage) msg).getRequestId();
  442. case GIOPLocateReply :
  443. return ((LocateReplyMessage) msg).getRequestId();
  444. case GIOPCancelRequest :
  445. return ((CancelRequestMessage) msg).getRequestId();
  446. case GIOPFragment :
  447. return ((FragmentMessage) msg).getRequestId();
  448. }
  449. throw new INTERNAL(MinorCodes.ILLEGAL_GIOP_MSG_TYPE,
  450. CompletionStatus.COMPLETED_MAYBE);
  451. }
  452. public static void readFully(java.io.InputStream is, byte[] buf,
  453. int offset, int size) throws IOException {
  454. int n = 0;
  455. while (n < size) {
  456. int bytecount=0;
  457. bytecount = is.read(buf, offset + n, size - n);
  458. if (bytecount < 0)
  459. throw new IOException();
  460. n += bytecount;
  461. }
  462. }
  463. /**
  464. * Set a flag in the given buffer (fragment bit, byte order bit, etc)
  465. */
  466. public static void setFlag(byte[] buf, int flag) {
  467. buf[6] |= flag;
  468. }
  469. /**
  470. * Clears a flag in the given buffer
  471. */
  472. public static void clearFlag(byte[] buf, int flag) {
  473. buf[6] &= (0xFF ^ flag);
  474. }
  475. private static void AreFragmentsAllowed(byte major, byte minor, byte flag,
  476. byte msgType) {
  477. if ( (major == 0x01) && (minor == 0x00) ) { // 1.0
  478. if (msgType == GIOPFragment) {
  479. throw new INTERNAL(MinorCodes.FRAGMENTATION_DISALLOWED,
  480. CompletionStatus.COMPLETED_MAYBE);
  481. }
  482. }
  483. if ( (flag & MORE_FRAGMENTS_BIT) == MORE_FRAGMENTS_BIT ) {
  484. switch (msgType) {
  485. case GIOPCancelRequest :
  486. case GIOPCloseConnection :
  487. case GIOPMessageError :
  488. throw new INTERNAL(MinorCodes.FRAGMENTATION_DISALLOWED,
  489. CompletionStatus.COMPLETED_MAYBE);
  490. case GIOPLocateRequest :
  491. case GIOPLocateReply :
  492. if ( (major == 0x01) && (minor == 0x01) ) { // 1.1
  493. throw new INTERNAL(MinorCodes.FRAGMENTATION_DISALLOWED,
  494. CompletionStatus.COMPLETED_MAYBE);
  495. }
  496. break;
  497. }
  498. }
  499. return;
  500. }
  501. /**
  502. * Construct an ObjectKey from a byte[].
  503. *
  504. * @return ObjectKey the object key.
  505. */
  506. static ObjectKey extractObjectKey(byte[] objKey, ORB orb) {
  507. try {
  508. if (objKey != null) {
  509. ObjectKey objectKey = ObjectKeyFactory.get().
  510. create(orb, objKey);
  511. if (objectKey != null) {
  512. return objectKey;
  513. }
  514. }
  515. } catch (Exception e) {}
  516. // This exception is thrown if any exceptions are raised while
  517. // extracting the object key or if the object key is empty.
  518. throw new MARSHAL(MinorCodes.INVALID_OBJECT_KEY,
  519. CompletionStatus.COMPLETED_NO);
  520. }
  521. /**
  522. * Extract the object key from TargetAddress.
  523. *
  524. * @return ObjectKey the object key.
  525. */
  526. static ObjectKey extractObjectKey(TargetAddress target, ORB orb) {
  527. short orbTargetAddrPref = orb.getGIOPTargetAddressPreference();
  528. short reqAddrDisp = target.discriminator();
  529. switch (orbTargetAddrPref) {
  530. case ORBConstants.ADDR_DISP_OBJKEY :
  531. if (reqAddrDisp != KeyAddr.value) {
  532. throw new AddressingDispositionException(KeyAddr.value);
  533. }
  534. break;
  535. case ORBConstants.ADDR_DISP_PROFILE :
  536. if (reqAddrDisp != ProfileAddr.value) {
  537. throw new AddressingDispositionException(ProfileAddr.value);
  538. }
  539. break;
  540. case ORBConstants.ADDR_DISP_IOR :
  541. if (reqAddrDisp != ReferenceAddr.value) {
  542. throw new AddressingDispositionException(ReferenceAddr.value);
  543. }
  544. break;
  545. case ORBConstants.ADDR_DISP_HANDLE_ALL :
  546. break;
  547. default :
  548. throw new INTERNAL(
  549. "ORB target address preference in extractObjectKey is invalid",
  550. MinorCodes.ORB_TARGET_ADDR_PREFERENCE_IN_EXTRACT_OBJECTKEY_INVALID,
  551. CompletionStatus.COMPLETED_NO);
  552. }
  553. try {
  554. switch (reqAddrDisp) {
  555. case KeyAddr.value :
  556. byte[] objKey = target.object_key();
  557. if (objKey != null) { // AddressingDisposition::KeyAddr
  558. ObjectKey objectKey = ObjectKeyFactory.get().
  559. create(orb, objKey);
  560. if (objectKey != null) {
  561. return objectKey;
  562. }
  563. }
  564. break;
  565. case ProfileAddr.value :
  566. IIOPProfile iiopProfile = null;
  567. TaggedProfile profile = target.profile();
  568. if (profile != null) { // AddressingDisposition::ProfileAddr
  569. iiopProfile = new IIOPProfile(orb, profile);
  570. ObjectKey objectKey = iiopProfile.getObjectKey();
  571. if (objectKey != null) {
  572. return objectKey;
  573. }
  574. }
  575. break;
  576. case ReferenceAddr.value :
  577. IORAddressingInfo iorInfo = target.ior();
  578. if (iorInfo != null) { // AddressingDisposition::IORAddr
  579. profile = iorInfo.ior.profiles[iorInfo.selected_profile_index];
  580. iiopProfile = new IIOPProfile(orb, profile);
  581. ObjectKey objectKey = iiopProfile.getObjectKey();
  582. if (objectKey != null) {
  583. return objectKey;
  584. }
  585. }
  586. break;
  587. default : // this cannot happen
  588. // There is no need for a explicit exception, since the
  589. // TargetAddressHelper.read() would have raised a BAD_OPERATION
  590. // exception by now.
  591. break;
  592. }
  593. } catch (Exception e) {}
  594. // This exception is thrown if any exceptions are raised while
  595. // extracting the object key from the TargetAddress or if all the
  596. // the valid TargetAddress::AddressingDispositions are empty.
  597. throw new MARSHAL(MinorCodes.INVALID_OBJECT_KEY,
  598. CompletionStatus.COMPLETED_NO);
  599. }
  600. private static int readSize(byte b1, byte b2, byte b3, byte b4,
  601. boolean littleEndian) {
  602. int a1, a2, a3, a4;
  603. if (!littleEndian) {
  604. a1 = (b1 << 24) & 0xFF000000;
  605. a2 = (b2 << 16) & 0x00FF0000;
  606. a3 = (b3 << 8) & 0x0000FF00;
  607. a4 = (b4 << 0) & 0x000000FF;
  608. } else {
  609. a1 = (b4 << 24) & 0xFF000000;
  610. a2 = (b3 << 16) & 0x00FF0000;
  611. a3 = (b2 << 8) & 0x0000FF00;
  612. a4 = (b1 << 0) & 0x000000FF;
  613. }
  614. return (a1 | a2 | a3 | a4);
  615. }
  616. static void nullCheck(Object obj) {
  617. if (obj == null) {
  618. throw new org.omg.CORBA.MARSHAL(0,
  619. org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);
  620. }
  621. }
  622. public void callback(com.sun.corba.se.internal.iiop.MessageMediator m)
  623. throws java.io.IOException
  624. {
  625. m.handleInput(this);
  626. }
  627. }