1 7 package com.sun.corba.se.impl.interceptors; 8 9 import org.omg.CORBA.Any ; 10 import org.omg.CORBA.BAD_INV_ORDER ; 11 import org.omg.CORBA.CompletionStatus ; 12 import org.omg.CORBA.INTERNAL ; 13 import org.omg.CORBA.LocalObject ; 14 import org.omg.CORBA.NO_IMPLEMENT ; 15 import org.omg.CORBA.NO_RESOURCES ; 16 import org.omg.CORBA.NVList ; 17 import org.omg.CORBA.Object ; 18 import org.omg.CORBA.Policy ; 19 import org.omg.CORBA.TypeCode ; 20 21 import org.omg.PortableServer.Servant ; 22 23 import org.omg.IOP.TaggedProfile ; 24 import org.omg.IOP.ServiceContext ; 25 26 import org.omg.Dynamic.Parameter ; 27 28 import org.omg.PortableInterceptor.InvalidSlot ; 29 import org.omg.PortableInterceptor.ServerRequestInfo ; 30 import org.omg.PortableInterceptor.LOCATION_FORWARD ; 31 import org.omg.PortableInterceptor.SUCCESSFUL ; 32 import org.omg.PortableInterceptor.SYSTEM_EXCEPTION ; 33 import org.omg.PortableInterceptor.TRANSPORT_RETRY ; 34 import org.omg.PortableInterceptor.USER_EXCEPTION ; 35 36 import com.sun.corba.se.spi.oa.ObjectAdapter; 37 import com.sun.corba.se.spi.presentation.rmi.StubAdapter; 38 39 import com.sun.corba.se.impl.protocol.giopmsgheaders.ReplyMessage; 40 41 import com.sun.corba.se.spi.servicecontext.ServiceContexts; 42 import com.sun.corba.se.spi.orb.ORB; 43 44 import com.sun.corba.se.spi.ior.ObjectKeyTemplate; 45 import com.sun.corba.se.spi.ior.ObjectAdapterId ; 46 47 import com.sun.corba.se.spi.protocol.CorbaMessageMediator; 48 49 import java.util.*; 50 51 55 public final class ServerRequestInfoImpl 56 extends RequestInfoImpl 57 implements ServerRequestInfo 58 { 59 static final int CALL_RECEIVE_REQUEST_SERVICE_CONTEXT = 0; 61 62 static final int CALL_RECEIVE_REQUEST = 0; 65 static final int CALL_INTERMEDIATE_NONE = 1; 66 67 static final int CALL_SEND_REPLY = 0; 69 static final int CALL_SEND_EXCEPTION = 1; 70 static final int CALL_SEND_OTHER = 2; 71 72 78 private boolean forwardRequestRaisedInEnding; 81 82 private CorbaMessageMediator request; 84 private java.lang.Object servant; 85 private byte[] objectId; 86 private ObjectKeyTemplate oktemp ; 87 88 private byte[] adapterId; 90 private String [] adapterName; 91 92 private ArrayList addReplyServiceContextQueue; 93 private ReplyMessage replyMessage; 94 private String targetMostDerivedInterface; 95 private NVList dsiArguments; 96 private Any dsiResult; 97 private Any dsiException; 98 private boolean isDynamic; 99 private ObjectAdapter objectAdapter; 100 private int serverRequestId; 101 102 private Parameter [] cachedArguments; 104 private Any cachedSendingException; 105 private HashMap cachedRequestServiceContexts; 107 private HashMap cachedReplyServiceContexts; 109 110 116 117 121 void reset() { 122 super.reset(); 123 124 126 forwardRequestRaisedInEnding = false; 127 128 request = null; 129 servant = null; 130 objectId = null; 131 oktemp = null; 132 133 adapterId = null; 134 adapterName = null; 135 136 addReplyServiceContextQueue = null; 137 replyMessage = null; 138 targetMostDerivedInterface = null; 139 dsiArguments = null; 140 dsiResult = null; 141 dsiException = null; 142 isDynamic = false; 143 objectAdapter = null; 144 serverRequestId = myORB.getPIHandler().allocateServerRequestId(); 145 146 cachedArguments = null; 148 cachedSendingException = null; 149 cachedRequestServiceContexts = null; 150 cachedReplyServiceContexts = null; 151 152 startingPointCall = CALL_RECEIVE_REQUEST_SERVICE_CONTEXT; 153 intermediatePointCall = CALL_RECEIVE_REQUEST; 154 endingPointCall = CALL_SEND_REPLY; 155 } 156 157 161 162 protected static final int MID_SENDING_EXCEPTION = MID_RI_LAST + 1; 165 protected static final int MID_OBJECT_ID = MID_RI_LAST + 2; 166 protected static final int MID_ADAPTER_ID = MID_RI_LAST + 3; 167 protected static final int MID_TARGET_MOST_DERIVED_INTERFACE 168 = MID_RI_LAST + 4; 169 protected static final int MID_GET_SERVER_POLICY = MID_RI_LAST + 5; 170 protected static final int MID_SET_SLOT = MID_RI_LAST + 6; 171 protected static final int MID_TARGET_IS_A = MID_RI_LAST + 7; 172 protected static final int MID_ADD_REPLY_SERVICE_CONTEXT 173 = MID_RI_LAST + 8; 174 protected static final int MID_SERVER_ID = MID_RI_LAST + 9; 175 protected static final int MID_ORB_ID = MID_RI_LAST + 10; 176 protected static final int MID_ADAPTER_NAME = MID_RI_LAST + 11; 177 178 protected static final boolean validCall[][] = { 181 { true , true , true , true , true }, 197 { true , true , true , true , true }, 198 { false, true , true , false, false }, 199 { false, true , true , true , true }, 200 { false, true , true , true , true }, 201 { false, true , true , false, false }, 202 { false, false, true , false, false }, 203 { true , true , true , true , true }, 204 { true , true , true , true , true }, 205 { false, false, true , true , true }, 206 { false, false, false, false, true }, 207 { true , true , true , true , true }, 208 { true , true , true , true , true }, 209 { false, false, true , true , true }, 210 { false, false, false, true , false }, 213 { false, true , true , true , true }, 214 { false, true , true , true , true }, 215 { false, true , false, false, false }, 216 { true , true , true , true , true }, 217 { true , true , true , true , true }, 218 { false, true , false, false, false }, 219 { true , true , true , true , true }, 220 { false, true , true , true , true }, 221 { false, true , true , true , true }, 222 { false, true , true , true , true } 223 }; 224 225 229 230 235 ServerRequestInfoImpl( ORB myORB ) { 236 super( myORB ); 237 startingPointCall = CALL_RECEIVE_REQUEST_SERVICE_CONTEXT; 238 intermediatePointCall = CALL_RECEIVE_REQUEST; 239 endingPointCall = CALL_SEND_REPLY; 240 serverRequestId = myORB.getPIHandler().allocateServerRequestId(); 241 } 242 243 246 public Any sending_exception () { 247 checkAccess( MID_SENDING_EXCEPTION ); 248 249 if( cachedSendingException == null ) { 250 Any result = null ; 251 252 if( dsiException != null ) { 253 result = dsiException; 254 } else if( exception != null ) { 255 result = exceptionToAny( exception ); 256 } else { 257 throw wrapper.exceptionUnavailable() ; 260 } 261 262 cachedSendingException = result; 263 } 264 265 return cachedSendingException; 266 } 267 268 271 public byte[] object_id () { 272 checkAccess( MID_OBJECT_ID ); 273 274 if( objectId == null ) { 275 throw stdWrapper.piOperationNotSupported6() ; 280 } 281 282 286 return objectId; 287 } 288 289 private void checkForNullTemplate() 290 { 291 if (oktemp == null) { 292 throw stdWrapper.piOperationNotSupported7() ; 297 } 298 } 299 300 public String server_id() 301 { 302 checkAccess( MID_SERVER_ID ) ; 303 checkForNullTemplate() ; 304 305 309 return Integer.toString( oktemp.getServerId() ) ; 310 } 311 312 public String orb_id() 313 { 314 checkAccess( MID_ORB_ID ) ; 315 316 return myORB.getORBData().getORBId() ; 317 } 318 319 synchronized public String [] adapter_name() 320 { 321 checkAccess( MID_ADAPTER_NAME ) ; 322 323 if (adapterName == null) { 324 checkForNullTemplate() ; 325 326 ObjectAdapterId oaid = oktemp.getObjectAdapterId() ; 327 adapterName = oaid.getAdapterName() ; 328 } 329 330 return adapterName ; 331 } 332 333 336 synchronized public byte[] adapter_id () 337 { 338 checkAccess( MID_ADAPTER_ID ); 339 340 if( adapterId == null ) { 341 checkForNullTemplate() ; 342 adapterId = oktemp.getAdapterId() ; 343 } 344 345 return adapterId; 346 } 347 348 351 public String target_most_derived_interface () { 352 checkAccess( MID_TARGET_MOST_DERIVED_INTERFACE ); 353 return targetMostDerivedInterface; 354 } 355 356 360 public Policy get_server_policy (int type) { 361 364 Policy result = null; 365 366 if( objectAdapter != null ) { 367 result = objectAdapter.getEffectivePolicy( type ); 368 } 369 370 373 return result; 374 } 375 376 382 public void set_slot (int id, Any data) throws InvalidSlot { 383 386 slotTable.set_slot( id, data ); 387 } 388 389 393 public boolean target_is_a (String id) { 394 checkAccess( MID_TARGET_IS_A ); 395 396 boolean result = false ; 397 if( servant instanceof Servant ) { 398 result = ((Servant )servant)._is_a( id ); 399 } else if (StubAdapter.isStub( servant )) { 400 result = ((org.omg.CORBA.Object )servant)._is_a( id ); 401 } else { 402 throw wrapper.servantInvalid() ; 403 } 404 405 return result; 406 } 407 408 411 public void add_reply_service_context ( ServiceContext service_context, 412 boolean replace ) 413 { 414 417 if( currentExecutionPoint == EXECUTION_POINT_ENDING ) { 418 ServiceContexts scs = replyMessage.getServiceContexts(); 419 420 if( scs == null ) { 422 scs = new ServiceContexts( myORB ); 423 replyMessage.setServiceContexts( scs ); 424 } 425 426 if( cachedReplyServiceContexts == null ) { 427 cachedReplyServiceContexts = new HashMap(); 428 } 429 430 addServiceContext( cachedReplyServiceContexts, scs, 433 service_context, replace ); 434 } 435 436 452 AddReplyServiceContextCommand addReply = 453 new AddReplyServiceContextCommand(); 454 addReply.service_context = service_context; 455 addReply.replace = replace; 456 457 if( addReplyServiceContextQueue == null ) { 458 addReplyServiceContextQueue = new ArrayList(); 459 } 460 461 enqueue( addReply ); 463 } 464 465 470 478 479 482 public int request_id (){ 483 491 return serverRequestId; 492 } 493 494 497 public String operation (){ 498 return request.getOperationName(); 501 } 502 503 506 public Parameter [] arguments (){ 507 checkAccess( MID_ARGUMENTS ); 508 509 if( cachedArguments == null ) { 510 if( !isDynamic ) { 511 throw stdWrapper.piOperationNotSupported1() ; 512 } 513 514 if( dsiArguments == null ) { 515 throw stdWrapper.piOperationNotSupported8() ; 516 } 517 518 cachedArguments = nvListToParameterArray( dsiArguments ); 521 } 522 523 528 return cachedArguments; 529 } 530 531 534 public TypeCode [] exceptions (){ 535 checkAccess( MID_EXCEPTIONS ); 536 537 539 throw stdWrapper.piOperationNotSupported2() ; 540 } 541 542 545 public String [] contexts (){ 546 checkAccess( MID_CONTEXTS ); 547 548 550 throw stdWrapper.piOperationNotSupported3() ; 551 } 552 553 556 public String [] operation_context (){ 557 checkAccess( MID_OPERATION_CONTEXT ); 558 559 562 throw stdWrapper.piOperationNotSupported4() ; 563 } 564 565 568 public Any result (){ 569 checkAccess( MID_RESULT ); 570 571 if( !isDynamic ) { 572 throw stdWrapper.piOperationNotSupported5() ; 573 } 574 575 if( dsiResult == null ) { 576 throw wrapper.piDsiResultIsNull() ; 577 } 578 579 583 return dsiResult; 584 } 585 586 589 public boolean response_expected (){ 590 return !request.isOneWay(); 593 } 594 595 598 public Object forward_reference (){ 599 checkAccess( MID_FORWARD_REFERENCE ); 600 if( replyStatus != LOCATION_FORWARD.value ) { 604 throw stdWrapper.invalidPiCall1() ; 605 } 606 607 return getForwardRequestException().forward; 608 } 609 610 613 public org.omg.IOP.ServiceContext get_request_service_context( int id ) { 614 checkAccess( MID_GET_REQUEST_SERVICE_CONTEXT ); 615 616 if( cachedRequestServiceContexts == null ) { 617 cachedRequestServiceContexts = new HashMap(); 618 } 619 620 return getServiceContext( cachedRequestServiceContexts, 621 request.getRequestServiceContexts(), id ); 622 } 623 624 627 public org.omg.IOP.ServiceContext get_reply_service_context( int id ) { 628 checkAccess( MID_GET_REPLY_SERVICE_CONTEXT ); 629 630 if( cachedReplyServiceContexts == null ) { 631 cachedReplyServiceContexts = new HashMap(); 632 } 633 634 return getServiceContext( cachedReplyServiceContexts, 635 replyMessage.getServiceContexts(), id ); 636 } 637 638 642 643 private class AddReplyServiceContextCommand { 647 ServiceContext service_context; 648 boolean replace; 649 } 650 651 private void enqueue( AddReplyServiceContextCommand addReply ) { 657 int size = addReplyServiceContextQueue.size(); 658 boolean found = false; 659 660 for( int i = 0; i < size; i++ ) { 661 AddReplyServiceContextCommand cmd = 662 (AddReplyServiceContextCommand) 663 addReplyServiceContextQueue.get( i ); 664 665 if( cmd.service_context.context_id == 666 addReply.service_context.context_id ) 667 { 668 found = true; 669 if( addReply.replace ) { 670 addReplyServiceContextQueue.set( i, addReply ); 671 } else { 672 throw stdWrapper.serviceContextAddFailed( 673 new Integer ( cmd.service_context.context_id ) ) ; 674 } 675 break; 676 } 677 } 678 679 if( !found ) { 680 addReplyServiceContextQueue.add( addReply ); 681 } 682 } 683 684 688 689 694 protected void setCurrentExecutionPoint( int executionPoint ) { 695 super.setCurrentExecutionPoint( executionPoint ); 696 697 if( (executionPoint == EXECUTION_POINT_ENDING) && 701 (addReplyServiceContextQueue != null) ) 702 { 703 int size = addReplyServiceContextQueue.size(); 704 for( int i = 0; i < size; i++ ) { 705 AddReplyServiceContextCommand addReply = 706 (AddReplyServiceContextCommand) 707 addReplyServiceContextQueue.get( i ); 708 try { 709 add_reply_service_context( addReply.service_context, 710 addReply.replace ); 711 } 712 catch( BAD_INV_ORDER e ) { 713 } 720 } 721 722 } 726 } 727 728 731 protected void setInfo( CorbaMessageMediator request, ObjectAdapter oa, 732 byte[] objectId, ObjectKeyTemplate oktemp ) 733 { 734 this.request = request; 735 this.objectId = objectId; 736 this.oktemp = oktemp; 737 this.objectAdapter = oa ; 738 this.connection = (com.sun.corba.se.spi.legacy.connection.Connection) 739 request.getConnection(); 740 } 741 742 745 protected void setDSIArguments( NVList arguments ) { 746 this.dsiArguments = arguments; 747 } 748 749 752 protected void setDSIException( Any exception ) { 753 this.dsiException = exception; 754 755 cachedSendingException = null; 757 } 758 759 762 protected void setDSIResult( Any result ) { 763 this.dsiResult = result; 764 } 765 766 770 protected void setException( Exception exception ) { 771 super.setException( exception ); 772 773 this.dsiException = null; 775 776 cachedSendingException = null; 778 } 779 780 783 protected void setInfo( java.lang.Object servant, 784 String targetMostDerivedInterface ) 785 { 786 this.servant = servant; 787 this.targetMostDerivedInterface = targetMostDerivedInterface; 788 this.isDynamic = 789 (servant instanceof 790 org.omg.PortableServer.DynamicImplementation ) || 791 (servant instanceof org.omg.CORBA.DynamicImplementation ); 792 } 793 794 797 void setReplyMessage( ReplyMessage replyMessage ) { 798 this.replyMessage = replyMessage; 799 } 800 801 805 protected void setReplyStatus( short replyStatus ) { 806 super.setReplyStatus( replyStatus ); 807 switch( replyStatus ) { 808 case SUCCESSFUL.value: 809 endingPointCall = CALL_SEND_REPLY; 810 break; 811 case SYSTEM_EXCEPTION.value: 812 case USER_EXCEPTION.value: 813 endingPointCall = CALL_SEND_EXCEPTION; 814 break; 815 case LOCATION_FORWARD.value: 816 case TRANSPORT_RETRY.value: 817 endingPointCall = CALL_SEND_OTHER; 818 break; 819 } 820 } 821 822 826 void releaseServant() { 827 this.servant = null; 828 } 829 830 834 void setForwardRequestRaisedInEnding() { 835 this.forwardRequestRaisedInEnding = true; 836 } 837 838 842 boolean isForwardRequestRaisedInEnding() { 843 return this.forwardRequestRaisedInEnding; 844 } 845 846 849 boolean isDynamic() { 850 return this.isDynamic; 851 } 852 853 856 protected void checkAccess( int methodID ) 857 { 858 int validCallIndex = 0; 861 switch( currentExecutionPoint ) { 862 case EXECUTION_POINT_STARTING: 863 validCallIndex = 0; 864 break; 865 case EXECUTION_POINT_INTERMEDIATE: 866 validCallIndex = 1; 867 break; 868 case EXECUTION_POINT_ENDING: 869 switch( endingPointCall ) { 870 case CALL_SEND_REPLY: 871 validCallIndex = 2; 872 break; 873 case CALL_SEND_EXCEPTION: 874 validCallIndex = 3; 875 break; 876 case CALL_SEND_OTHER: 877 validCallIndex = 4; 878 break; 879 } 880 break; 881 } 882 883 if( !validCall[methodID][validCallIndex] ) { 885 throw stdWrapper.invalidPiCall2() ; 886 } 887 } 888 889 } 890 | Popular Tags |