1 18 package org.apache.geronimo.interop.rmi.iiop; 19 20 import java.io.ByteArrayInputStream ; 21 import java.io.ByteArrayOutputStream ; 22 import java.util.zip.GZIPInputStream ; 23 24 import org.apache.geronimo.interop.SystemException; 25 import org.apache.geronimo.interop.rmi.RmiTrace; 26 import org.apache.geronimo.interop.rmi.iiop.client.ClientNamingContext; 27 import org.apache.geronimo.interop.rmi.iiop.compiler.StubFactory; 28 import org.apache.geronimo.interop.util.ArrayUtil; 29 import org.apache.geronimo.interop.util.BigEndian; 30 import org.apache.geronimo.interop.util.ExceptionUtil; 31 import org.apache.geronimo.interop.util.LittleEndian; 32 import org.apache.geronimo.interop.util.ThreadContext; 33 import org.apache.geronimo.interop.util.UTF8; 34 import org.apache.geronimo.interop.util.UnsignedShort; 35 import org.omg.CORBA.TCKind ; 36 import org.omg.GIOP.LocateRequestHeader_1_0; 37 import org.omg.GIOP.LocateRequestHeader_1_0Helper; 38 import org.omg.GIOP.LocateRequestHeader_1_2; 39 import org.omg.GIOP.LocateRequestHeader_1_2Helper; 40 import org.omg.GIOP.MsgType_1_1; 41 import org.omg.GIOP.ReplyHeader_1_2Helper; 42 import org.omg.GIOP.RequestHeader_1_0; 43 import org.omg.GIOP.RequestHeader_1_0Helper; 44 import org.omg.GIOP.RequestHeader_1_1; 45 import org.omg.GIOP.RequestHeader_1_1Helper; 46 import org.omg.GIOP.RequestHeader_1_2; 47 import org.omg.GIOP.RequestHeader_1_2Helper; 48 import org.omg.GIOP.TargetAddress; 49 import org.omg.IOP.IOR ; 50 import org.omg.IOP.IORHelper ; 51 52 55 public class CdrInputStream extends org.omg.CORBA_2_3.portable.InputStream 56 { 57 58 public static CdrInputStream getInstance() 59 { 60 CdrInputStream input = new CdrInputStream(); 61 input.init(new byte[64], 0, DEFAULT_BUFFER_LENGTH, false); 62 return input; 63 } 64 65 public static CdrInputStream getInstance(byte[] buffer) 66 { 67 CdrInputStream input = new CdrInputStream(); 68 input.init(buffer, 0, buffer.length, false); 69 return input; 70 } 71 72 public static CdrInputStream getInstance(byte[] buffer, int offset, int length, boolean little) 73 { 74 CdrInputStream input = new CdrInputStream(); 75 input.init(buffer, offset, length, little); 76 return input; 77 } 78 79 public static CdrInputStream getInstanceForEncapsulation() 80 { 81 return getInstance(); 82 } 83 84 public static CdrInputStream getPooledInstance() 85 { 86 CdrInputStream input = null; 87 if (input == null) 88 { 89 input = getInstance(); 90 } 91 return input; 92 } 93 94 98 private static final int DEFAULT_BUFFER_LENGTH = 64; 99 100 private static final int MAXIMUM_POOLED_BUFFER_LENGTH = 1024; 101 102 private static boolean RMI_TRACE = true; 103 104 private static final byte[] EMPTY_BYTE_ARRAY = {}; 105 106 private GiopMessage _giopMessage; 107 108 private boolean _moreFragments; 109 110 private ClientNamingContext _namingContext; 111 112 private boolean _unaligned; 113 114 private byte[] _pooledBuffer; 115 116 private boolean _gzip; 117 118 122 byte[] _buffer; 123 124 int _offset; 125 126 int _length; 127 128 boolean _little; 129 130 134 public void init(byte[] buffer, int offset, int length, boolean little) 135 { 136 _buffer = buffer; 137 _offset = offset; 138 _length = length; 139 _little = little; 140 } 141 142 public void recycle() 143 { 144 reset(); 145 } 146 147 public void reset() 148 { 149 _offset = 0; 150 if (_buffer.length > MAXIMUM_POOLED_BUFFER_LENGTH) 151 { 152 _buffer = _pooledBuffer; 153 _pooledBuffer = null; 154 if (_buffer == null) 155 { 156 _buffer = new byte[DEFAULT_BUFFER_LENGTH]; 157 } 158 } 159 _length = _buffer.length; 160 _little = false; 161 _namingContext = null; 162 } 163 164 public void setUnaligned() 165 { 166 _unaligned = true; 167 } 168 169 public byte[] getBytes() 170 { 171 return ArrayUtil.getBytes(_buffer, 0, _length); 172 } 173 174 public byte[] getBuffer() 175 { 176 return _buffer; 177 } 178 179 public int getOffset() 180 { 181 return _offset; 182 } 183 184 public int getGiopVersion() 185 { 186 GiopMessage message = _giopMessage; 187 if (message == null) 188 { 189 throw new IllegalStateException (); 190 } 191 return message.giopVersion; 192 } 193 194 public void setGiopVersion(int giopVersion) 195 { 196 } 198 199 public void setLength(int length) 200 { 201 if (_buffer.length < length) 202 { 203 byte[] newBuffer = new byte[length]; 204 System.arraycopy(_buffer, 0, newBuffer, 0, 12); 205 pool(_buffer); 206 _buffer = newBuffer; 207 } 208 _length = length; 209 } 210 211 public ClientNamingContext getNamingContext() 212 { 213 return _namingContext; 214 } 215 216 public void setNamingContext(ClientNamingContext namingContext) 217 { 218 _namingContext = namingContext; 219 } 220 221 public void setEncapsulation(byte[] data) 222 { 223 _buffer = data; 224 _offset = 0; 225 _length = data.length; 226 _little = read_boolean(); 227 } 228 229 public boolean hasMoreData() 230 { 231 return _offset < _length; 232 } 233 234 242 public final void read_align(int alignment, int size) 243 { 244 if (_unaligned) 245 { 246 alignment = 1; 247 } 248 int mask = alignment - 1; 249 _offset += (alignment - (_offset & mask)) & mask; 250 if (_offset + size <= _length) 251 { 252 return; 253 } 254 else 255 { 256 throw new org.omg.CORBA.MARSHAL ("offset (" + _offset + ") + size (" 257 + size + ") > buffer length (" + _length + ")"); 258 } 259 } 260 261 264 public byte[] read_octet_sequence() 265 { 266 int n = read_long(); 267 if (n == 0) 268 { 269 return EMPTY_BYTE_ARRAY; 270 } 271 byte[] bytes = new byte[n]; 272 read_octet_array(bytes, 0, n); 273 return bytes; 274 } 275 276 public GiopMessage read_message() 277 { 278 return receive_message(null, null); 279 } 280 281 public GiopMessage receive_message(java.io.InputStream input, String url) 282 { 283 return receive_message(input, url, true); 284 } 285 286 public GiopMessage receive_message(java.io.InputStream input, String url, boolean readFragments) 287 { 288 GiopMessage message = _giopMessage; 289 if (message == null) 290 { 291 message = _giopMessage = new GiopMessage(); 292 } 293 if (input != null) 294 { 295 read(input, _buffer, 0, 12); 296 } 297 int m1 = read_octet(); 298 int m2 = read_octet(); 299 int m3 = read_octet(); 300 int m4 = read_octet(); 301 if (m1 != 'G' || m2 != 'I' || m3 != 'O' || m4 != 'P') 302 { 303 if (m1 == 'G' && m2 == 'Z' && m3 == 'I' && m4 == 'P') 304 { 305 _gzip = true; 306 } 307 else if ((m1 == 'P' || m1 == 'p') && (m2 == 'O' || m2 == 'o') && (m3 == 'S' || m3 == 's') && 308 (m4 == 'T' || m4 == 't')) 309 { 310 return receive_http_post_message(input, url); 311 } 312 else if( (m1 == 'G' || m1 == 'g') && (m2 == 'E' || m2 == 'e') && (m3 == 'T' || m3 == 't') && 313 m4 == ' ') 314 { 315 return receive_http_get_message(input, url); 316 } 317 else 318 { 319 throw new BadMagicException(m1 + "," + m2 + "," + m3 + "," + m4); 320 } 321 } 322 else 323 { 324 _gzip = false; 325 } 326 int v1 = read_octet(); 327 int v2 = read_octet(); 328 if (v1 != 1 || (v2 < 0 || v2 > 2)) { 330 throw new UnsupportedProtocolVersionException(v1 + "." + v2); 331 } 332 int giopVersion; 333 message.giopVersion = giopVersion = v2; 334 int flags = read_octet(); 335 _little = (flags & 1) != 0; 336 _moreFragments = (flags & 2) != 0; 337 int messageType = message.type = read_octet(); 338 int messageSize = message.size = read_ulong(); 339 _length = 12 + messageSize; 340 if (_moreFragments && _length % 8 != 0) 341 { 342 throw new org.omg.CORBA.MARSHAL ("GIOP Fragment: bad message size (not divisible by 8) = " + messageSize); 343 } 344 if (messageSize > 0 && input != null) 345 { 346 if (_buffer.length < _length) 347 { 348 byte[] newBuffer = new byte[_length]; 349 System.arraycopy(_buffer, 0, newBuffer, 0, 12); 350 pool(_buffer); 351 _buffer = newBuffer; 352 } 353 read(input, _buffer, 12, _length); 354 } 355 if (RMI_TRACE && url != null) 356 { 357 byte[] data = new byte[_length]; 358 System.arraycopy(_buffer, 0, data, 0, _length); 359 RmiTrace.receive(url, data); 360 } 361 if (_moreFragments && readFragments) 362 { 363 read_fragments(input, url); 364 } 365 switch (messageType) 366 { 367 case MsgType_1_1._Fragment: 368 break; 369 case MsgType_1_1._Request: 370 switch (giopVersion) 371 { 372 case GiopVersion.VERSION_1_0: 373 { 374 RequestHeader_1_0 req10 = RequestHeader_1_0Helper.read(this); 375 RequestHeader_1_2 req12 = new RequestHeader_1_2(); 376 req12.service_context = req10.service_context; 377 req12.request_id = req10.request_id; 378 req12.response_flags = (byte)(req10.response_expected ? 3 : 0); 379 req12.operation = req10.operation; 380 (req12.target = new TargetAddress()).object_key(req10.object_key); 381 message.request = req12; 382 } 383 break; 384 case GiopVersion.VERSION_1_1: 385 { 386 RequestHeader_1_1 req11 = RequestHeader_1_1Helper.read(this); 387 RequestHeader_1_2 req12 = new RequestHeader_1_2(); 388 req12.service_context = req11.service_context; 389 req12.request_id = req11.request_id; 390 req12.response_flags = (byte)(req11.response_expected ? 3 : 0); 391 req12.operation = req11.operation; 392 (req12.target = new TargetAddress()).object_key(req11.object_key); 393 message.request = req12; 394 } 395 break; 396 case GiopVersion.VERSION_1_2: 397 message.request = RequestHeader_1_2Helper.read(this); 398 if (_length > _offset) 399 { 400 read_align(8, 0); } 402 break; 403 } 404 if (_gzip) 405 { 406 unzip(); 407 } 408 break; 409 case MsgType_1_1._Reply: 410 message.reply = ReplyHeader_1_2Helper.read(this); 411 if (giopVersion >= GiopVersion.VERSION_1_2) 412 { 413 if (_length > _offset) 414 { 415 read_align(8, 0); } 417 } 418 if (_gzip) 419 { 420 unzip(); 421 } 422 break; 423 case MsgType_1_1._LocateRequest: 424 switch (giopVersion) 425 { 426 case GiopVersion.VERSION_1_0: 427 case GiopVersion.VERSION_1_1: 428 { 429 LocateRequestHeader_1_0 req10 = LocateRequestHeader_1_0Helper.read(this); 430 LocateRequestHeader_1_2 req12 = new LocateRequestHeader_1_2(); 431 req12.request_id = req10.request_id; 432 (req12.target = new TargetAddress()).object_key(req10.object_key); 433 message.locateRequest = req12; 434 } 435 break; 436 default: 437 message.locateRequest = LocateRequestHeader_1_2Helper.read(this); 438 } 439 break; 440 case MsgType_1_1._LocateReply: 441 throw new org.omg.CORBA.MARSHAL ("GIOP LocateReply: unexpected"); 443 default: 445 throw new org.omg.CORBA.NO_IMPLEMENT ("TODO: message type = " + messageType); 446 } 447 return message; 448 } 449 450 private GiopMessage receive_http_post_message(java.io.InputStream input, String url) 451 { 452 int ver = http_read_hiop_version(input); 453 454 boolean cLenRead = false; 456 int clen = 0, count; 457 458 while( (count = http_read_line(input, 0)) != 0) 459 { 460 if( (_buffer[0] == 'c' || _buffer[0] == 'C')) 461 { 462 String str = new String (_buffer, 0, count).toLowerCase(); 463 if(str.startsWith("content-length:")) 464 { 465 str = str.substring(15).trim(); 466 try 467 { 468 clen = java.lang.Integer.parseInt(str); 469 } 470 catch(Exception e) 471 { 472 throw new SystemException(e.toString()); 473 } 474 cLenRead = true; 475 } 476 } 477 } 478 479 if(!cLenRead) 480 { 481 throw new SystemException("HTTP Post: Missing content-length"); 482 } 483 484 java.io.InputStream msgInput = input; 485 if(ver == 1) 486 { 487 byte[] buffer = new byte[clen]; 488 read(input, buffer, 0, clen); 489 String data = new String (buffer, 8, buffer.length - 8); byte[] giopdata = org.apache.geronimo.interop.util.Base16Binary.fromString(data); 491 ByteArrayInputStream bi = new ByteArrayInputStream (giopdata); 492 msgInput = bi; 493 } 494 _offset = 0; 495 GiopMessage gm = receive_message(msgInput, url, false); 496 gm.httpTunneling = true; 497 gm.hiopVersion = ver; 498 return gm; 499 } 500 501 504 protected GiopMessage receive_http_get_message(java.io.InputStream input, String url) 505 { 506 508 int count = http_read_line(input, 12); 509 String str = new String (_buffer, 0, count); 510 int index = str.indexOf("/HIOP/1.0/"); 511 if(index == -1) 512 { 513 throw new SystemException("HTTP Tunnelling: HIOP version error"); 514 } 515 516 index += 10; 517 if( index >= count) 518 { 519 throw new SystemException("HTTP Tunneling: GET message error"); 520 } 521 522 byte[] giopdata = org.apache.geronimo.interop.util.Base16Binary.fromString(str.substring(index)); 523 ByteArrayInputStream bi = new ByteArrayInputStream (giopdata); 524 525 GiopMessage gm = receive_message(bi, url, false); 526 gm.httpTunneling = true; 527 gm.hiopVersion = 1; 528 return gm; 529 } 530 531 535 public GiopMessage receive_http_response(java.io.InputStream input, String url) 536 { 537 int count = http_read_line(input, 0); 539 String status = new String (_buffer, 0, count).toLowerCase(); 540 if(!status.startsWith("http/1.1") && !status.startsWith("http/1.0")) 541 { 542 throw new SystemException("HTTP response error"); 543 } 544 545 if(status.indexOf("200") == -1 || status.indexOf("ok") == -1) 546 { 547 throw new SystemException("HTTP response error"); 548 } 549 550 boolean cLenRead = false; 552 int clen = 0; 553 554 while( (count = http_read_line(input, 0)) != 0) 555 { 556 if( (_buffer[0] == 'c' || _buffer[0] == 'C')) 557 { 558 String str = new String (_buffer, 0, count).toLowerCase(); 559 if(str.startsWith("content-length:")) 560 { 561 str = str.substring(15).trim(); 562 try 563 { 564 clen = java.lang.Integer.parseInt(str); 565 } 566 catch(Exception e) 567 { 568 throw new SystemException(e.toString()); 569 } 570 cLenRead = true; 571 } 572 } 573 } 574 575 if(!cLenRead) 576 { 577 throw new SystemException("HTTP Post: Missing Content-Length"); 578 } 579 580 582 GiopMessage gm = receive_message(input, url, false); 583 gm.httpTunneling = true; 584 gm.hiopVersion = 2; 585 return gm; 586 } 587 588 591 private int http_read_hiop_version(java.io.InputStream input) 592 throws java.lang.NumberFormatException 593 { 594 int count = http_read_line(input, 12); 596 597 String str = new String (_buffer, 0, count); 598 int index, ver; 599 600 if((index = str.indexOf("HIOP")) == -1) 601 { 602 throw new SystemException("HTTP: Post Message - HIOP Version not specified"); 603 } 604 else 605 { 606 608 if((index + 8) > count) 609 { 610 throw new SystemException("HTTP: Post Message - Incorrect HIOP header"); 611 } 612 613 index += 5; 614 615 if(_buffer[index + 1] != '.' && _buffer[index + 2] != '0') 616 { 617 throw new SystemException("HTTP: Incorrect HIOP version"); 618 } 619 620 if(_buffer[index] == '1') 621 { 622 ver = 1; 623 } 624 else if (_buffer[index] == '2') 625 { 626 ver = 2; 627 } 628 else 629 { 630 throw new SystemException("HTTP: Incorrect HIOP version"); 631 } 632 } 633 return ver; 634 } 635 636 640 641 private int http_read_line(java.io.InputStream input, int offset) { 643 try 644 { 645 int b; 646 while ( (b = input.read()) != '\r' ) 647 { 648 if(b == -1) { 650 throw new SystemException("HTTP: read error"); 651 } 652 if(_buffer.length <= offset) 653 { 654 byte[] newbuffer = new byte[offset*2]; 655 System.arraycopy(_buffer, 0, newbuffer, 0, _buffer.length); 656 _buffer = newbuffer; 657 658 } 659 _buffer[offset++] = (byte)b; 660 } 661 662 b = input.read(); 664 if ( b != '\n' ) 665 { 666 throw new SystemException("HTTP CRLF combination missing"); 667 } 668 } 669 catch (java.io.IOException ex) 670 { 671 throw new SystemException(ex.toString()); 672 } 673 return offset; 674 } 675 676 680 public boolean read_boolean() 681 { 682 read_align(1, 1); 683 int b = _buffer[_offset++]; 684 if (b == 0) 685 { 686 return false; 687 } 688 else if (b == 1) 689 { 690 return true; 691 } 692 else 693 { 694 throw new org.omg.CORBA.MARSHAL ("read_boolean: value = " + b); 695 } 696 } 697 698 public char read_char() 699 { 700 read_align(1, 1); 701 return (char)_buffer[_offset++]; 702 } 703 704 public char read_wchar() 705 { 706 read_align(1, 3); 707 int size = (int)read_wchar_size(); 708 int value = (char)read_ushort_no_align_big_endian(); 709 _offset += 2; 710 boolean littleEndian = ((value & 0xffff) == 0xFFFE); 711 boolean bigEndian = ((value & 0xffff) == 0xFEFF); 712 boolean bomPresent = (littleEndian || bigEndian); 713 if ((bomPresent && size != 4) || (! bomPresent && size != 2)) 714 { 715 throw new org.omg.CORBA.MARSHAL ("wchar size = " + size 716 + (bomPresent ? " (BOM present)" : " (BOM absent)")); 717 } 718 if (littleEndian) 719 { 720 read_align(1, 2); 721 char ch = (char)read_ushort_no_align_little_endian(); 722 _offset += 2; 723 return ch; 724 } 725 else if (bigEndian) 726 { 727 read_align(1, 2); 728 char ch = (char)read_ushort_no_align_big_endian(); 729 _offset += 2; 730 return ch; 731 } 732 else 733 { 734 return (char)value; 736 } 737 } 738 739 public byte read_octet() 740 { 741 read_align(1, 1); 742 return _buffer[_offset++]; 743 } 744 745 public short read_short() 746 { 747 read_align(2, 2); 748 int oldOffset = _offset; 749 _offset += 2; 750 if (_little) 751 { 752 return LittleEndian.getShort(_buffer, oldOffset); 753 } 754 else 755 { 756 return BigEndian.getShort(_buffer, oldOffset); 757 } 758 } 759 760 public short read_ushort() 761 { 762 return read_short(); 763 } 764 765 public int read_long() 766 { 767 read_align(4, 4); 768 int oldOffset = _offset; 769 _offset += 4; 770 if (_little) 771 { 772 return LittleEndian.getInt(_buffer, oldOffset); 773 } 774 else 775 { 776 return BigEndian.getInt(_buffer, oldOffset); 777 } 778 } 779 780 public int read_ulong() 781 { 782 return read_long(); 783 } 784 785 public long read_longlong() 786 { 787 read_align(8, 8); 788 int oldOffset = _offset; 789 _offset += 8; 790 if (_little) 791 { 792 return LittleEndian.getLong(_buffer, oldOffset); 793 } 794 else 795 { 796 return BigEndian.getLong(_buffer, oldOffset); 797 } 798 } 799 800 public long read_ulonglong() 801 { 802 return read_longlong(); 803 } 804 805 public float read_float() 806 { 807 return Float.intBitsToFloat(read_ulong()); 808 } 809 810 public double read_double() 811 { 812 return Double.longBitsToDouble(read_ulonglong()); 813 } 814 815 public java.lang.String read_string() 816 { 817 int size = read_ulong(); 818 if (size < 1) { 820 throw new org.omg.CORBA.MARSHAL ("read_string: size = " + size); 821 } 822 read_align(1, size); 823 size--; 824 if (_buffer[_offset + size] != 0) 825 { 826 throw new org.omg.CORBA.MARSHAL ("read_string: missing NUL"); 827 } 828 String value = size == 0 ? "" : UTF8.toString(_buffer, _offset, size); 830 _offset += size + 1; return value; 832 } 833 834 public java.lang.String read_wstring() 835 { 836 int size = read_long(); 837 if (size == 0) 838 { 839 return ""; 840 } 841 read_align(2, size); 842 int numChars = size / 2; 843 boolean littleEndian = false; 844 read_align(1, 2); 845 int firstChar = (char)read_ushort_no_align_big_endian(); 846 _offset+=2; 847 char[] result; 848 int index = 0; 849 if (firstChar == 0xFEFF) 850 { 851 result = new char[--numChars]; 853 } 854 else if (firstChar == 0xFFFE) 855 { 856 result = new char[--numChars]; 858 littleEndian = true; 859 } 860 else 861 { 862 result = new char[numChars--]; 864 result[index++] = (char)firstChar; 865 } 866 read_align(1, 2 * numChars); 867 if (littleEndian) 868 { 869 for (int i = 0; i < numChars; i++) 870 { 871 result[index++] = (char)read_ushort_no_align_little_endian(); 872 _offset+=2; 873 } 874 } 875 else 876 { 877 for (int i = 0; i < numChars; i++) 878 { 879 result[index++] = (char)read_ushort_no_align_big_endian(); 880 _offset+=2; 881 } 882 } 883 return new String (result); 884 } 885 886 public void read_boolean_array(boolean[] value, int offset, int length) 887 { 888 for (int i = 0; i < length; i++) 889 { 890 value[offset + i] = read_boolean(); 891 } 892 } 893 894 public void read_char_array(char[] value, int offset, int length) 895 { 896 for (int i = 0; i < length; i++) 897 { 898 value[i] = read_char(); 899 } 900 } 901 902 public void read_wchar_array(char[] value, int offset, int length) 903 { 904 for (int i = 0; i < length; i++) 905 { 906 value[offset + i] = read_wchar(); 907 } 908 } 909 910 public void read_octet_array(byte[] value, int offset, int length) 911 { 912 read_align(1, length); 913 System.arraycopy(_buffer, _offset, value, offset, length); 914 _offset += length; 915 } 916 917 public void read_short_array(short[] value, int offset, int length) 918 { 919 for (int i = 0; i < length; i++) 920 { 921 value[offset + i] = read_short(); 922 } 923 } 924 925 public void read_ushort_array(short[] value, int offset, int length) 926 { 927 for (int i = 0; i < length; i++) 928 { 929 value[offset + i] = read_ushort(); 930 } 931 } 932 933 public void read_long_array(int[] value, int offset, int length) 934 { 935 for (int i = 0; i < length; i++) 936 { 937 value[offset + i] = read_long(); 938 } 939 } 940 941 public void read_ulong_array(int[] value, int offset, int length) 942 { 943 for (int i = 0; i < length; i++) 944 { 945 value[offset + i] = read_ulong(); 946 } 947 } 948 949 public void read_longlong_array(long[] value, int offset, int length) 950 { 951 for (int i = 0; i < length; i++) 952 { 953 value[offset + i] = read_longlong(); 954 } 955 } 956 957 public void read_ulonglong_array(long[] value, int offset, int length) 958 { 959 for (int i = 0; i < length; i++) 960 { 961 value[offset + i] = read_ulonglong(); 962 } 963 } 964 965 public void read_float_array(float[] value, int offset, int length) 966 { 967 for (int i = 0; i < length; i++) 968 { 969 value[offset + i] = read_float(); 970 } 971 } 972 973 public void read_double_array(double[] value, int offset, int length) 974 { 975 for (int i = 0; i < length; i++) 976 { 977 value[offset + i] = read_double(); 978 } 979 } 980 981 public org.omg.CORBA.Object read_Object() 982 { 983 IOR ior = IORHelper.read(this); 984 if (ior.profiles.length == 0) 985 { 986 return null; 987 } 988 ObjectRef stub = null; 989 if (ior.type_id.length() != 0) 990 { 991 String interfaceName = ""; 992 if (ior.type_id.startsWith("RMI:") && ior.type_id.endsWith(":0000000000000000")) 993 { 994 interfaceName = ior.type_id.substring(4, ior.type_id.length() - 17); 995 } 996 else if (ior.type_id.startsWith("IDL:") && ior.type_id.endsWith(":1.0")) 997 { 998 interfaceName = ior.type_id.substring(4, ior.type_id.length() - 4).replace('/', '.'); 999 } 1000 1001 if(interfaceName.startsWith("omg.org", 0)) 1003 { 1004 interfaceName = "org.apache.geronimo.interop" + interfaceName.substring(7); 1005 } 1006 Class remoteInterface = ThreadContext.loadClass(interfaceName); 1007 stub = StubFactory.getInstance().getStub(remoteInterface); 1008 } 1009 if (stub == null) 1010 { 1011 stub = ObjectRef._getInstance(); 1012 } 1013 stub.$setIOR(ior); 1014 stub.$setNamingContext(_namingContext); 1015 return stub; 1016 } 1017 1018 public org.omg.CORBA.TypeCode read_TypeCode() 1019 { 1020 return read_TypeCode(new java.util.HashMap ()); 1021 } 1022 1023 private org.omg.CORBA.TypeCode read_TypeCode(java.util.HashMap table) 1024 { 1025 int beforeKindOffset = _offset; 1026 int tk = read_ulong(); 1027 int afterKindOffset = _offset; 1028 org.apache.geronimo.interop.rmi.iiop.TypeCode tc; 1029 if (tk == 0xffffffff) 1030 { 1031 int offset = read_long(); 1033 Integer key = new Integer (afterKindOffset + offset); 1034 org.omg.CORBA.TypeCode ref = (org.omg.CORBA.TypeCode )table.get(key); 1035 if (ref == null) 1036 { 1037 throw new org.omg.CORBA.MARSHAL ("read_TypeCode: bad indirection: offset = " + offset); 1038 } 1039 tc = new org.apache.geronimo.interop.rmi.iiop.TypeCode(TCKind.tk_null); 1040 tc.indirection(ref); 1041 return tc; 1042 } 1043 tc = new org.apache.geronimo.interop.rmi.iiop.TypeCode(TCKind.from_int(tk)); 1044 table.put(new Integer (beforeKindOffset), tc); 1045 switch (tk) 1046 { 1047 case TCKind._tk_null: 1048 case TCKind._tk_void: 1049 case TCKind._tk_TypeCode: 1050 case TCKind._tk_any: 1051 case TCKind._tk_boolean: 1052 case TCKind._tk_char: 1053 case TCKind._tk_wchar: 1054 case TCKind._tk_octet: 1055 case TCKind._tk_short: 1056 case TCKind._tk_ushort: 1057 case TCKind._tk_long: 1058 case TCKind._tk_ulong: 1059 case TCKind._tk_longlong: 1060 case TCKind._tk_ulonglong: 1061 case TCKind._tk_float: 1062 case TCKind._tk_double: 1063 case TCKind._tk_longdouble: 1064 break; 1066 case TCKind._tk_fixed: 1067 tc.fixed_digits(read_ushort()); 1068 tc.fixed_scale(read_short()); 1069 break; 1070 case TCKind._tk_string: 1071 case TCKind._tk_wstring: 1072 tc.length(read_ulong()); 1073 break; 1074 case TCKind._tk_objref: 1075 case TCKind._tk_native: 1076 case TCKind._tk_abstract_interface: 1077 { 1078 boolean saveLittle = begin(); 1079 tc.id(read_string()); 1080 tc.name(read_string()); 1081 end(saveLittle); 1082 } 1083 break; 1084 case TCKind._tk_alias: 1085 case TCKind._tk_value_box: 1087 { 1089 boolean saveLittle = begin(); 1090 tc.id(read_string()); 1091 tc.name(read_string()); 1092 tc.content_type(read_TypeCode(table)); 1093 end(saveLittle); 1094 } 1095 break; 1096 case TCKind._tk_sequence: 1097 case TCKind._tk_array: 1098 { 1099 boolean saveLittle = begin(); 1100 tc.content_type(read_TypeCode(table)); 1101 tc.length(read_ulong()); 1102 end(saveLittle); 1103 } 1104 break; 1105 case TCKind._tk_enum: 1106 { 1107 boolean saveLittle = begin(); 1108 tc.id(read_string()); 1109 tc.name(read_string()); 1110 int count = read_ulong(); 1111 tc.member_count(count); 1112 for (int i = 0; i < count; i++) 1113 { 1114 tc.member_name(i, read_string()); 1115 } 1116 end(saveLittle); 1117 } 1118 break; 1119 case TCKind._tk_struct: 1120 case TCKind._tk_except: 1121 { 1122 boolean saveLittle = begin(); 1123 tc.id(read_string()); 1124 tc.name(read_string()); 1125 int count = read_ulong(); 1126 tc.member_count(count); 1127 for (int i = 0; i < count; i++) 1128 { 1129 tc.member_name(i, read_string()); 1130 tc.member_type(i, read_TypeCode(table)); 1131 } 1132 end(saveLittle); 1133 } 1134 break; 1135 case TCKind._tk_union: 1136 { 1137 boolean saveLittle = begin(); 1138 tc.id(read_string()); 1139 tc.name(read_string()); 1140 org.omg.CORBA.TypeCode dt = read_TypeCode(table); 1141 tc.discriminator_type(dt); 1142 int di = read_ulong(); 1143 int count = read_ulong(); 1144 tc.member_count(count); 1145 for (int i = 0; i < count; i++) 1146 { 1147 org.omg.CORBA.Any label = new org.apache.geronimo.interop.rmi.iiop.Any(); 1148 read_Any(label.create_output_stream(), dt); 1149 label.read_value(null, dt); 1150 tc.member_label(i, label); 1151 tc.member_name(i, read_string()); 1152 tc.member_type(i, read_TypeCode(table)); 1153 } 1154 tc.default_index(di); end(saveLittle); 1156 } 1157 break; 1158 case TCKind._tk_value: 1159 { 1160 boolean saveLittle = begin(); 1161 tc.id(read_string()); 1162 tc.name(read_string()); 1163 tc.type_modifier(read_short()); 1164 tc.concrete_base_type(read_TypeCode(table)); 1165 int count = read_ulong(); 1166 tc.member_count(count); 1167 for (int i = 0; i < count; i++) 1168 { 1169 tc.member_name(i, read_string()); 1170 tc.member_type(i, read_TypeCode(table)); 1171 tc.member_visibility(i, read_short()); 1172 } 1173 end(saveLittle); 1174 } 1175 break; 1176 default: 1177 throw new org.omg.CORBA.MARSHAL ("read_TypeCode: kind = " + tk); 1178 } 1179 return tc; 1180 } 1181 1182 public org.omg.CORBA.Any read_Any() 1183 { 1184 org.omg.CORBA.TypeCode tc = read_TypeCode(); 1185 org.omg.CORBA.Any value = new org.apache.geronimo.interop.rmi.iiop.Any(); 1186 org.omg.CORBA.portable.OutputStream os = value.create_output_stream(); 1187 read_Any(os, tc); 1188 value.read_value(os.create_input_stream(), tc); 1189 return value; 1190 } 1191 1192 public void read_Any(org.omg.CORBA.portable.OutputStream os, org.omg.CORBA.TypeCode tc) 1193 { 1194 try 1195 { 1196 int tk = tc.kind().value(); 1197 switch (tk) 1198 { 1199 case TCKind._tk_null: 1200 case TCKind._tk_void: 1201 break; 1202 case TCKind._tk_TypeCode: 1203 os.write_TypeCode(read_TypeCode()); 1204 break; 1205 case TCKind._tk_any: 1206 os.write_any(read_Any()); 1207 break; 1208 case TCKind._tk_boolean: 1209 os.write_boolean(read_boolean()); 1210 break; 1211 case TCKind._tk_char: 1212 os.write_char(read_char()); 1213 break; 1214 case TCKind._tk_wchar: 1215 os.write_wchar(read_wchar()); 1216 break; 1217 case TCKind._tk_octet: 1218 os.write_octet(read_octet()); 1219 break; 1220 case TCKind._tk_short: 1221 os.write_short(read_short()); 1222 break; 1223 case TCKind._tk_ushort: 1224 os.write_ushort(read_ushort()); 1225 break; 1226 case TCKind._tk_long: 1227 os.write_long(read_long()); 1228 break; 1229 case TCKind._tk_ulong: 1230 case TCKind._tk_enum: 1231 os.write_ulong(read_ulong()); 1232 break; 1233 case TCKind._tk_longlong: 1234 os.write_longlong(read_longlong()); 1235 break; 1236 case TCKind._tk_ulonglong: 1237 os.write_ulonglong(read_ulonglong()); 1238 break; 1239 case TCKind._tk_float: 1240 os.write_float(read_float()); 1241 break; 1242 case TCKind._tk_double: 1243 os.write_double(read_double()); 1244 break; 1245 case TCKind._tk_string: 1246 os.write_string(read_string()); 1247 break; 1248 case TCKind._tk_wstring: 1249 os.write_wstring(read_wstring()); 1250 break; 1251 case TCKind._tk_objref: 1252 os.write_Object(read_Object()); 1253 break; 1254 case TCKind._tk_alias: 1255 read_Any(os, tc.content_type()); 1256 break; 1257 case TCKind._tk_array: 1258 { 1259 int n = tc.length(); 1260 org.omg.CORBA.TypeCode c = tc.content_type(); 1261 for (int i = 0; i < n; i++) 1262 { 1263 read_Any(os, c); 1264 } 1265 } 1266 break; 1267 case TCKind._tk_sequence: 1268 { 1269 int n = read_ulong(); 1270 os.write_ulong(n); 1271 org.omg.CORBA.TypeCode c = tc.content_type(); 1272 for (int i = 0; i < n; i++) 1273 { 1274 read_Any(os, c); 1275 } 1276 } 1277 break; 1278 case TCKind._tk_struct: 1279 case TCKind._tk_except: 1280 { 1281 int n = tc.member_count(); 1282 for (int i = 0; i < n; i++) 1283 { 1284 read_Any(os, tc.member_type(i)); 1285 } 1286 } 1287 break; 1288 case TCKind._tk_union: 1289 { 1290 org.omg.CORBA.TypeCode dt = tc.discriminator_type(); 1291 org.omg.CORBA.Any disc = new org.apache.geronimo.interop.rmi.iiop.Any(); 1292 read_Any(disc.create_output_stream(), dt); 1293 disc.read_value(null, dt); 1294 write_disc(disc, os, dt); 1295 int di = tc.default_index(); 1296 int i, n = tc.member_count(); 1297 for (i = 0; i < n; i++) 1298 { 1299 org.omg.CORBA.Any label = tc.member_label(i); 1300 if (label.equal(disc)) 1301 { 1302 read_Any(os, tc.member_type(i)); 1303 break; 1304 } 1305 } 1306 if (i == n && di >= 0) 1307 { 1308 read_Any(os, tc.member_type(di)); 1309 } 1310 } 1311 break; 1312 case TCKind._tk_fixed: case TCKind._tk_value: default: 1315 throw new org.omg.CORBA.MARSHAL ("read_Any: type = " + tc); 1316 } 1317 } 1318 catch (org.omg.CORBA.TypeCodePackage.BadKind ex) 1319 { 1320 throw new org.omg.CORBA.MARSHAL ("read_Any: " + ex.toString()); 1321 } 1322 catch (org.omg.CORBA.TypeCodePackage.Bounds ex) 1323 { 1324 throw new org.omg.CORBA.MARSHAL ("read_Any: " + ex.toString()); 1325 } 1326 } 1327 1328 public org.omg.CORBA.Any read_any() { 1329 throw new org.omg.CORBA.NO_IMPLEMENT ("read_any: NOT IMPLMENTED"); 1330 } 1331 1332 public org.omg.CORBA.Principal read_Principal() { 1333 throw new org.omg.CORBA.NO_IMPLEMENT ("read_Principal: NOT IMPLMENTED"); 1334 } 1335 1336 public int read() throws java.io.IOException { 1337 throw new org.omg.CORBA.NO_IMPLEMENT ("read: NOT IMPLMENTED"); 1338 } 1339 1340 public java.math.BigDecimal read_fixed() { 1341 throw new org.omg.CORBA.NO_IMPLEMENT ("read_fixed: NOT IMPLMENTED"); 1342 } 1343 1344 public org.omg.CORBA.Context read_Context() { 1345 throw new org.omg.CORBA.NO_IMPLEMENT ("read_Context: NOT IMPLMENTED"); 1346 } 1347 1348 public org.omg.CORBA.Object read_Object(Class _class) { 1349 throw new org.omg.CORBA.NO_IMPLEMENT ("read_Object: NOT IMPLMENTED"); 1350 } 1351 1352 public org.omg.CORBA.ORB orb() { 1353 throw new org.omg.CORBA.NO_IMPLEMENT ("orb: NOT IMPLMENTED"); 1354 } 1355 1356 1357 1361 public java.io.Serializable read_value() { 1362 throw new org.omg.CORBA.NO_IMPLEMENT ("read_value: NOT IMPLMENTED"); 1363 } 1364 1365 public java.io.Serializable read_value(Class _class) { 1366 throw new org.omg.CORBA.NO_IMPLEMENT ("read_value: NOT IMPLMENTED"); 1367 } 1368 1369 public java.io.Serializable read_value(org.omg.CORBA.portable.BoxedValueHelper helper) { 1370 throw new org.omg.CORBA.NO_IMPLEMENT ("read_value: NOT IMPLMENTED"); 1371 } 1372 1373 public java.io.Serializable read_value(java.lang.String id) { 1374 throw new org.omg.CORBA.NO_IMPLEMENT ("read_value: NOT IMPLMENTED"); 1375 } 1376 1377 public java.io.Serializable read_value(java.io.Serializable todo) { 1378 throw new org.omg.CORBA.NO_IMPLEMENT ("read_value: NOT IMPLMENTED"); 1379 } 1380 1381 public java.lang.Object read_abstract_interface() { 1382 throw new org.omg.CORBA.NO_IMPLEMENT ("read_abstract_interface: NOT IMPLMENTED"); 1383 } 1384 1385 public java.lang.Object read_abstract_interface(Class _class) { 1386 throw new org.omg.CORBA.NO_IMPLEMENT ("read_abstract_interface: NOT IMPLMENTED"); 1387 } 1388 1389 1390 1394 protected void pool(byte[] oldBuffer) 1395 { 1396 if (oldBuffer.length <= MAXIMUM_POOLED_BUFFER_LENGTH) 1397 { 1398 _pooledBuffer = oldBuffer; 1399 } 1400 } 1401 1402 protected int read_ushort_no_align_big_endian() 1403 { 1404 return UnsignedShort.intValue(BigEndian.getShort(_buffer, _offset)); 1405 } 1406 1407 protected int read_ushort_no_align_little_endian() 1408 { 1409 return UnsignedShort.intValue(LittleEndian.getShort(_buffer, _offset)); 1410 } 1411 1412 protected int read_wchar_size() 1413 { 1414 read_align(1, 1); 1415 int size = _buffer[_offset++]; 1416 if (size < 2) 1417 { 1418 throw new org.omg.CORBA.MARSHAL ("wchar size = " + size); 1419 } 1420 return size; 1421 } 1422 1423 protected void read(java.io.InputStream input, byte[] buffer, int offset, int length) 1424 { 1425 try 1426 { 1427 while (offset < length) 1428 { 1429 int needLength = length - offset; 1430 int readLength = input.read(buffer, offset, needLength); 1431 if (readLength == -1) 1432 { 1433 throw new org.omg.CORBA.MARSHAL ("read: EOF"); 1434 } 1435 offset += readLength; 1436 } 1437 } 1438 catch (java.io.IOException ex) 1439 { 1440 throw new org.omg.CORBA.COMM_FAILURE (ex.toString()); 1441 } 1442 } 1443 1444 protected void read_fragments(java.io.InputStream input, String url) 1445 { 1446 int messageType = _giopMessage.type; 1447 int length = _giopMessage.size + 12; 1448 byte[] fullBuffer = ArrayUtil.getBytes(_buffer, 0, length); 1449 do 1450 { 1451 _offset = 0; 1452 receive_message(input, url, false); 1453 if (_giopMessage.type != MsgType_1_1._Fragment) 1454 { 1455 throw new org.omg.CORBA.MARSHAL ("GIOP Fragment: bad fragment type = " + _giopMessage.type); 1456 } 1457 int addSize = _giopMessage.size - 4; int needLength = length + addSize; 1459 if (needLength > fullBuffer.length) 1460 { 1461 byte[] newBuffer = new byte[needLength * 2]; 1462 System.arraycopy(fullBuffer, 0, newBuffer, 0, length); 1463 fullBuffer = newBuffer; 1464 } 1465 System.arraycopy(_buffer, 16, fullBuffer, length, addSize); 1466 length += addSize; 1467 } 1468 while (_moreFragments); 1469 _giopMessage.type = messageType; 1470 _giopMessage.size = length - 12; 1471 _buffer = fullBuffer; 1472 _offset = 12; 1473 _length = length; 1474 } 1475 1476 public boolean begin() 1477 { 1478 int length = read_ulong(); int len2 = read_ulong(); if( len2 != length - 4) 1481 { 1482 _offset -= 4; 1483 } 1484 1485 boolean saveLittle = _little; 1486 _little = read_boolean(); 1487 return saveLittle; 1488 } 1489 1490 public void end(boolean saveLittle) 1491 { 1492 _little = saveLittle; 1493 } 1494 1495 private void write_disc(org.omg.CORBA.Any disc, org.omg.CORBA.portable.OutputStream os, org.omg.CORBA.TypeCode dt) 1496 { 1497 int tk = dt.kind().value(); 1498 if (tk == TCKind._tk_alias) 1499 { 1500 try 1501 { 1502 write_disc(disc, os, dt.content_type()); 1503 } 1504 catch (org.omg.CORBA.TypeCodePackage.BadKind ex) 1505 { 1506 throw new org.omg.CORBA.MARSHAL ("write_disc: " + ex.toString()); 1507 } 1508 } 1509 switch (tk) 1510 { 1511 case TCKind._tk_boolean: 1512 os.write_boolean(disc.extract_boolean()); 1513 break; 1514 case TCKind._tk_octet: 1515 os.write_octet(disc.extract_octet()); 1516 break; 1517 case TCKind._tk_short: 1518 os.write_short(disc.extract_short()); 1519 break; 1520 case TCKind._tk_ushort: 1521 os.write_ushort(disc.extract_ushort()); 1522 break; 1523 case TCKind._tk_long: 1524 os.write_long(disc.extract_long()); 1525 break; 1526 case TCKind._tk_ulong: 1527 case TCKind._tk_enum: 1528 os.write_ulong(disc.extract_ulong()); 1529 break; 1530 case TCKind._tk_longlong: 1531 os.write_longlong(disc.extract_longlong()); 1532 break; 1533 case TCKind._tk_ulonglong: 1534 os.write_ulonglong(disc.extract_ulonglong()); 1535 break; 1536 default: 1537 throw new org.omg.CORBA.MARSHAL ("write_disc: type = " + dt); 1538 } 1539 } 1540 1541 protected void unzip() 1542 { 1543 try 1544 { 1545 int n = _length - _offset; 1546 ByteArrayInputStream bi = new ByteArrayInputStream (_buffer, _offset, n); 1547 ByteArrayOutputStream bo = new ByteArrayOutputStream (n * 4); 1548 GZIPInputStream gi = new GZIPInputStream (bi); 1549 int b; 1550 while ((b = gi.read()) != -1) 1551 { 1552 bo.write(b); 1553 } 1554 byte[] bytes = bo.toByteArray(); 1555 int newLength = _offset + bytes.length; 1556 if (newLength > _buffer.length) 1557 { 1558 byte[] newBuffer = new byte[newLength]; 1559 System.arraycopy(_buffer, 0, newBuffer, 0, _offset); 1560 _buffer = newBuffer; 1561 } 1562 System.arraycopy(bytes, 0, _buffer, _offset, bytes.length); 1563 _length = newLength; 1564 } 1565 catch (Exception ex) 1566 { 1567 throw new org.omg.CORBA.MARSHAL (ExceptionUtil.getStackTrace(ex)); 1568 } 1569 } 1570} 1571 | Popular Tags |