1 7 8 package com.sun.corba.se.impl.protocol; 9 10 import java.io.ByteArrayOutputStream ; 11 import java.io.IOException ; 12 import java.io.PrintWriter ; 13 import java.nio.ByteBuffer ; 14 import java.nio.channels.SelectionKey ; 15 import java.util.EmptyStackException ; 16 import java.util.Iterator ; 17 18 import org.omg.CORBA.Any ; 19 import org.omg.CORBA.CompletionStatus ; 20 import org.omg.CORBA.ExceptionList ; 21 import org.omg.CORBA.INTERNAL ; 22 import org.omg.CORBA.Principal ; 23 import org.omg.CORBA.SystemException ; 24 import org.omg.CORBA.TypeCode ; 25 import org.omg.CORBA.UnknownUserException ; 26 import org.omg.CORBA.UNKNOWN ; 27 import org.omg.CORBA.portable.ResponseHandler ; 28 import org.omg.CORBA.portable.UnknownException ; 29 import org.omg.CORBA_2_3.portable.InputStream ; 30 import org.omg.CORBA_2_3.portable.OutputStream ; 31 import org.omg.IOP.ExceptionDetailMessage ; 32 import org.omg.IOP.TAG_RMI_CUSTOM_MAX_STREAM_FORMAT ; 33 34 import com.sun.corba.se.pept.broker.Broker; 35 import com.sun.corba.se.pept.encoding.InputObject; 36 import com.sun.corba.se.pept.encoding.OutputObject; 37 import com.sun.corba.se.pept.protocol.MessageMediator; 38 import com.sun.corba.se.pept.protocol.ProtocolHandler; 39 import com.sun.corba.se.pept.transport.ByteBufferPool; 40 import com.sun.corba.se.pept.transport.Connection; 41 import com.sun.corba.se.pept.transport.ContactInfo; 42 import com.sun.corba.se.pept.transport.EventHandler; 43 44 import com.sun.corba.se.spi.ior.IOR; 45 import com.sun.corba.se.spi.ior.ObjectKey; 46 import com.sun.corba.se.spi.ior.ObjectKeyTemplate; 47 import com.sun.corba.se.spi.ior.iiop.GIOPVersion; 48 import com.sun.corba.se.spi.ior.iiop.IIOPProfileTemplate; 49 import com.sun.corba.se.spi.ior.iiop.IIOPProfile; 50 import com.sun.corba.se.spi.ior.iiop.MaxStreamFormatVersionComponent; 51 import com.sun.corba.se.spi.oa.OAInvocationInfo; 52 import com.sun.corba.se.spi.oa.ObjectAdapter; 53 import com.sun.corba.se.spi.orb.ORB; 54 import com.sun.corba.se.spi.orb.ORBVersionFactory; 55 import com.sun.corba.se.spi.protocol.CorbaMessageMediator; 56 import com.sun.corba.se.spi.protocol.CorbaProtocolHandler; 57 import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher; 58 import com.sun.corba.se.spi.protocol.ForwardException; 59 import com.sun.corba.se.spi.transport.CorbaConnection; 60 import com.sun.corba.se.spi.transport.CorbaContactInfo; 61 import com.sun.corba.se.spi.transport.CorbaResponseWaitingRoom; 62 import com.sun.corba.se.spi.logging.CORBALogDomains; 63 64 import com.sun.corba.se.spi.servicecontext.ORBVersionServiceContext; 65 import com.sun.corba.se.spi.servicecontext.ServiceContexts; 66 import com.sun.corba.se.spi.servicecontext.UEInfoServiceContext; 67 import com.sun.corba.se.spi.servicecontext.MaxStreamFormatVersionServiceContext; 68 import com.sun.corba.se.spi.servicecontext.SendingContextServiceContext; 69 import com.sun.corba.se.spi.servicecontext.UnknownServiceContext; 70 71 import com.sun.corba.se.impl.corba.RequestImpl; 72 import com.sun.corba.se.impl.encoding.BufferManagerFactory; 73 import com.sun.corba.se.impl.encoding.BufferManagerReadStream; 74 import com.sun.corba.se.impl.encoding.CDRInputObject; 75 import com.sun.corba.se.impl.encoding.CDROutputObject; 76 import com.sun.corba.se.impl.encoding.EncapsOutputStream; 77 import com.sun.corba.se.impl.logging.ORBUtilSystemException; 78 import com.sun.corba.se.impl.logging.InterceptorsSystemException; 79 import com.sun.corba.se.impl.orbutil.ORBConstants; 80 import com.sun.corba.se.impl.orbutil.ORBUtility; 81 import com.sun.corba.se.impl.ior.iiop.JavaSerializationComponent; 82 import com.sun.corba.se.impl.protocol.AddressingDispositionException; 83 import com.sun.corba.se.impl.protocol.RequestCanceledException; 84 import com.sun.corba.se.impl.protocol.giopmsgheaders.AddressingDispositionHelper; 85 import com.sun.corba.se.impl.protocol.giopmsgheaders.CancelRequestMessage; 86 import com.sun.corba.se.impl.protocol.giopmsgheaders.FragmentMessage_1_1; 87 import com.sun.corba.se.impl.protocol.giopmsgheaders.FragmentMessage_1_2; 88 import com.sun.corba.se.impl.protocol.giopmsgheaders.LocateRequestMessage; 89 import com.sun.corba.se.impl.protocol.giopmsgheaders.LocateRequestMessage_1_0; 90 import com.sun.corba.se.impl.protocol.giopmsgheaders.LocateRequestMessage_1_1; 91 import com.sun.corba.se.impl.protocol.giopmsgheaders.LocateRequestMessage_1_2; 92 import com.sun.corba.se.impl.protocol.giopmsgheaders.LocateReplyOrReplyMessage; 93 import com.sun.corba.se.impl.protocol.giopmsgheaders.LocateReplyMessage; 94 import com.sun.corba.se.impl.protocol.giopmsgheaders.LocateReplyMessage_1_0; 95 import com.sun.corba.se.impl.protocol.giopmsgheaders.LocateReplyMessage_1_1; 96 import com.sun.corba.se.impl.protocol.giopmsgheaders.LocateReplyMessage_1_2; 97 import com.sun.corba.se.impl.protocol.giopmsgheaders.Message; 98 import com.sun.corba.se.impl.protocol.giopmsgheaders.MessageBase; 99 import com.sun.corba.se.impl.protocol.giopmsgheaders.MessageHandler; 100 import com.sun.corba.se.impl.protocol.giopmsgheaders.ReplyMessage; 101 import com.sun.corba.se.impl.protocol.giopmsgheaders.ReplyMessage_1_0; 102 import com.sun.corba.se.impl.protocol.giopmsgheaders.ReplyMessage_1_1; 103 import com.sun.corba.se.impl.protocol.giopmsgheaders.ReplyMessage_1_2; 104 import com.sun.corba.se.impl.protocol.giopmsgheaders.RequestMessage; 105 import com.sun.corba.se.impl.protocol.giopmsgheaders.RequestMessage_1_0 ; 106 import com.sun.corba.se.impl.protocol.giopmsgheaders.RequestMessage_1_1 ; 107 import com.sun.corba.se.impl.protocol.giopmsgheaders.RequestMessage_1_2 ; 108 109 112 115 public class CorbaMessageMediatorImpl 116 implements 117 CorbaMessageMediator, 118 CorbaProtocolHandler, 119 MessageHandler 120 { 121 protected ORB orb; 122 protected ORBUtilSystemException wrapper ; 123 protected InterceptorsSystemException interceptorWrapper ; 124 protected CorbaContactInfo contactInfo; 125 protected CorbaConnection connection; 126 protected short addrDisposition; 127 protected CDROutputObject outputObject; 128 protected CDRInputObject inputObject; 129 protected Message messageHeader; 130 protected RequestMessage requestHeader; 131 protected LocateReplyOrReplyMessage replyHeader; 132 protected String replyExceptionDetailMessage; 133 protected IOR replyIOR; 134 protected Integer requestIdInteger; 135 protected Message dispatchHeader; 136 protected ByteBuffer dispatchByteBuffer; 137 protected byte streamFormatVersion; 138 protected boolean streamFormatVersionSet = false; 139 140 protected org.omg.CORBA.Request diiRequest; 141 142 protected boolean cancelRequestAlreadySent = false; 143 144 protected ProtocolHandler protocolHandler; 145 protected boolean _executeReturnServantInResponseConstructor = false; 146 protected boolean _executeRemoveThreadInfoInResponseConstructor = false; 147 protected boolean _executePIInResponseConstructor = false; 148 149 153 public CorbaMessageMediatorImpl(ORB orb, 154 ContactInfo contactInfo, 155 Connection connection, 156 GIOPVersion giopVersion, 157 IOR ior, 158 int requestId, 159 short addrDisposition, 160 String operationName, 161 boolean isOneWay) 162 { 163 this( orb, connection ) ; 164 165 this.contactInfo = (CorbaContactInfo) contactInfo; 166 this.addrDisposition = addrDisposition; 167 168 streamFormatVersion = 169 getStreamFormatVersionForThisRequest( 170 ((CorbaContactInfo)this.contactInfo).getEffectiveTargetIOR(), 171 giopVersion); 172 streamFormatVersionSet = true; 173 174 requestHeader = (RequestMessage) MessageBase.createRequest( 175 this.orb, 176 giopVersion, 177 ORBUtility.getEncodingVersion(orb, ior), 178 requestId, 179 !isOneWay, 180 ((CorbaContactInfo)this.contactInfo).getEffectiveTargetIOR(), 181 this.addrDisposition, 182 operationName, 183 new ServiceContexts(orb), 184 null); 185 } 186 187 191 public CorbaMessageMediatorImpl(ORB orb, 192 Connection connection) 193 { 194 this.orb = orb; 195 this.connection = (CorbaConnection)connection; 196 this.wrapper = ORBUtilSystemException.get( orb, 197 CORBALogDomains.RPC_PROTOCOL ) ; 198 this.interceptorWrapper = InterceptorsSystemException.get( orb, 199 CORBALogDomains.RPC_PROTOCOL ) ; 200 } 201 202 206 public CorbaMessageMediatorImpl(ORB orb, 210 CorbaConnection connection, 211 Message dispatchHeader, 212 ByteBuffer byteBuffer) 213 { 214 this( orb, connection ) ; 215 this.dispatchHeader = dispatchHeader; 216 this.dispatchByteBuffer = byteBuffer; 217 } 218 219 224 public Broker getBroker() 225 { 226 return orb; 227 } 228 229 public ContactInfo getContactInfo() 230 { 231 return contactInfo; 232 } 233 234 public Connection getConnection() 235 { 236 return connection; 237 } 238 239 public void initializeMessage() 240 { 241 getRequestHeader().write(outputObject); 242 } 243 244 public void finishSendingRequest() 245 { 246 outputObject.finishSendingMessage(); 248 } 249 250 public InputObject waitForResponse() 251 { 252 if (getRequestHeader().isResponseExpected()) { 253 return connection.waitForResponse(this); 254 } 255 return null; 256 } 257 258 public void setOutputObject(OutputObject outputObject) 259 { 260 this.outputObject = (CDROutputObject) outputObject; 261 } 262 263 public OutputObject getOutputObject() 264 { 265 return outputObject; 266 } 267 268 public void setInputObject(InputObject inputObject) 269 { 270 this.inputObject = (CDRInputObject) inputObject; 271 } 272 273 public InputObject getInputObject() 274 { 275 return inputObject; 276 } 277 278 283 public void setReplyHeader(LocateReplyOrReplyMessage header) 284 { 285 this.replyHeader = header; 286 this.replyIOR = header.getIOR(); } 288 289 public LocateReplyMessage getLocateReplyHeader() 290 { 291 return (LocateReplyMessage) replyHeader; 292 } 293 294 public ReplyMessage getReplyHeader() 295 { 296 return (ReplyMessage) replyHeader; 297 } 298 299 public void setReplyExceptionDetailMessage(String message) 300 { 301 replyExceptionDetailMessage = message; 302 } 303 304 public RequestMessage getRequestHeader() 305 { 306 return requestHeader; 307 } 308 309 public GIOPVersion getGIOPVersion() 310 { 311 if (messageHeader != null) { 312 return messageHeader.getGIOPVersion(); 313 } 314 return getRequestHeader().getGIOPVersion(); 315 } 316 317 public byte getEncodingVersion() { 318 if (messageHeader != null) { 319 return messageHeader.getEncodingVersion(); 320 } 321 return getRequestHeader().getEncodingVersion(); 322 } 323 324 public int getRequestId() 325 { 326 return getRequestHeader().getRequestId(); 327 } 328 329 public Integer getRequestIdInteger() 330 { 331 if (requestIdInteger == null) { 332 requestIdInteger = new Integer (getRequestHeader().getRequestId()); 333 } 334 return requestIdInteger; 335 } 336 337 public boolean isOneWay() 338 { 339 return ! getRequestHeader().isResponseExpected(); 340 } 341 342 public short getAddrDisposition() 343 { 344 return addrDisposition; 345 } 346 347 public String getOperationName() 348 { 349 return getRequestHeader().getOperation(); 350 } 351 352 public ServiceContexts getRequestServiceContexts() 353 { 354 return getRequestHeader().getServiceContexts(); 355 } 356 357 public ServiceContexts getReplyServiceContexts() 358 { 359 return getReplyHeader().getServiceContexts(); 360 } 361 362 public void sendCancelRequestIfFinalFragmentNotSent() 363 { 364 if ((!sentFullMessage()) && sentFragment() && 365 (!cancelRequestAlreadySent)) 366 { 367 try { 368 if (orb.subcontractDebugFlag) { 369 dprint(".sendCancelRequestIfFinalFragmentNotSent->: " 370 + opAndId(this)); 371 } 372 connection.sendCancelRequestWithLock(getGIOPVersion(), 373 getRequestId()); 374 cancelRequestAlreadySent = true; 378 } catch (IOException e) { 379 if (orb.subcontractDebugFlag) { 380 dprint(".sendCancelRequestIfFinalFragmentNotSent: !ERROR : " + opAndId(this), 381 e); 382 } 383 384 throw interceptorWrapper.ioexceptionDuringCancelRequest( 387 CompletionStatus.COMPLETED_MAYBE, e ); 388 } finally { 389 if (orb.subcontractDebugFlag) { 390 dprint(".sendCancelRequestIfFinalFragmentNotSent<-: " 391 + opAndId(this)); 392 } 393 } 394 } 395 } 396 397 public boolean sentFullMessage() 398 { 399 return outputObject.getBufferManager().sentFullMessage(); 400 } 401 402 public boolean sentFragment() 403 { 404 return outputObject.getBufferManager().sentFragment(); 405 } 406 407 public void setDIIInfo(org.omg.CORBA.Request diiRequest) 408 { 409 this.diiRequest = diiRequest; 410 } 411 412 public boolean isDIIRequest() 413 { 414 return diiRequest != null; 415 } 416 417 public Exception unmarshalDIIUserException(String repoId, InputStream is) 418 { 419 if (! isDIIRequest()) { 420 return null; 421 } 422 423 ExceptionList _exceptions = diiRequest.exceptions(); 424 425 try { 426 for (int i=0; i<_exceptions.count() ; i++) { 428 TypeCode tc = _exceptions.item(i); 429 if ( tc.id().equals(repoId) ) { 430 Any eany = orb.create_any(); 435 eany.read_value(is, (TypeCode )tc); 436 437 return new UnknownUserException (eany); 438 } 439 } 440 } catch (Exception b) { 441 throw wrapper.unexpectedDiiException(b); 442 } 443 444 return wrapper.unknownCorbaExc( CompletionStatus.COMPLETED_MAYBE); 446 } 447 448 public void setDIIException(Exception exception) 449 { 450 diiRequest.env().exception(exception); 451 } 452 453 public void handleDIIReply(InputStream inputStream) 454 { 455 if (! isDIIRequest()) { 456 return; 457 } 458 ((RequestImpl)diiRequest).unmarshalReply(inputStream); 459 } 460 461 public Message getDispatchHeader() 462 { 463 return dispatchHeader; 464 } 465 466 public void setDispatchHeader(Message msg) 467 { 468 dispatchHeader = msg; 469 } 470 471 public ByteBuffer getDispatchBuffer() 472 { 473 return dispatchByteBuffer; 474 } 475 476 public void setDispatchBuffer(ByteBuffer byteBuffer) 477 { 478 dispatchByteBuffer = byteBuffer; 479 } 480 481 public int getThreadPoolToUse() { 482 int poolToUse = 0; 483 Message msg = getDispatchHeader(); 484 if (msg != null) { 487 poolToUse = msg.getThreadPoolToUse(); 488 } 489 return poolToUse; 490 } 491 492 public byte getStreamFormatVersion() 493 { 494 if (streamFormatVersionSet) { 500 return streamFormatVersion; 501 } 502 return getStreamFormatVersionForReply(); 503 } 504 505 514 public byte getStreamFormatVersionForReply() { 515 516 ServiceContexts svc = getRequestServiceContexts(); 518 519 MaxStreamFormatVersionServiceContext msfvsc 520 = (MaxStreamFormatVersionServiceContext)svc.get( 521 MaxStreamFormatVersionServiceContext.SERVICE_CONTEXT_ID); 522 523 if (msfvsc != null) { 524 byte localMaxVersion = ORBUtility.getMaxStreamFormatVersion(); 525 byte remoteMaxVersion = msfvsc.getMaximumStreamFormatVersion(); 526 527 return (byte)Math.min(localMaxVersion, remoteMaxVersion); 528 } else { 529 if (getGIOPVersion().lessThan(GIOPVersion.V1_3)) 532 return ORBConstants.STREAM_FORMAT_VERSION_1; 533 else 534 return ORBConstants.STREAM_FORMAT_VERSION_2; 535 } 536 } 537 538 public boolean isSystemExceptionReply() 539 { 540 return replyHeader.getReplyStatus() == ReplyMessage.SYSTEM_EXCEPTION; 541 } 542 543 public boolean isUserExceptionReply() 544 { 545 return replyHeader.getReplyStatus() == ReplyMessage.USER_EXCEPTION; 546 } 547 548 public boolean isLocationForwardReply() 549 { 550 return ( (replyHeader.getReplyStatus() == ReplyMessage.LOCATION_FORWARD) || 551 (replyHeader.getReplyStatus() == ReplyMessage.LOCATION_FORWARD_PERM) ); 552 } 554 555 public boolean isDifferentAddrDispositionRequestedReply() 556 { 557 return replyHeader.getReplyStatus() == ReplyMessage.NEEDS_ADDRESSING_MODE; 558 } 559 560 public short getAddrDispositionReply() 561 { 562 return replyHeader.getAddrDisposition(); 563 } 564 565 public IOR getForwardedIOR() 566 { 567 return replyHeader.getIOR(); 568 } 569 570 public SystemException getSystemExceptionReply() 571 { 572 return replyHeader.getSystemException(replyExceptionDetailMessage); 573 } 574 575 580 public ObjectKey getObjectKey() 581 { 582 return getRequestHeader().getObjectKey(); 583 } 584 585 public void setProtocolHandler(CorbaProtocolHandler protocolHandler) 586 { 587 throw wrapper.methodShouldNotBeCalled() ; 588 } 589 590 public CorbaProtocolHandler getProtocolHandler() 591 { 592 return this; 594 } 595 596 601 public org.omg.CORBA.portable.OutputStream createReply() 602 { 603 getProtocolHandler().createResponse(this, (ServiceContexts) null); 606 return (OutputStream ) getOutputObject(); 607 } 608 609 public org.omg.CORBA.portable.OutputStream createExceptionReply() 610 { 611 getProtocolHandler().createUserExceptionResponse(this, (ServiceContexts) null); 614 return (OutputStream ) getOutputObject(); 615 } 616 617 public boolean executeReturnServantInResponseConstructor() 618 { 619 return _executeReturnServantInResponseConstructor; 620 621 } 622 623 public void setExecuteReturnServantInResponseConstructor(boolean b) 624 { 625 _executeReturnServantInResponseConstructor = b; 626 } 627 628 public boolean executeRemoveThreadInfoInResponseConstructor() 629 { 630 return _executeRemoveThreadInfoInResponseConstructor; 631 } 632 633 public void setExecuteRemoveThreadInfoInResponseConstructor(boolean b) 634 { 635 _executeRemoveThreadInfoInResponseConstructor = b; 636 } 637 638 public boolean executePIInResponseConstructor() 639 { 640 return _executePIInResponseConstructor; 641 } 642 643 public void setExecutePIInResponseConstructor( boolean b ) 644 { 645 _executePIInResponseConstructor = b; 646 } 647 648 private byte getStreamFormatVersionForThisRequest(IOR ior, 649 GIOPVersion giopVersion) 650 { 651 652 byte localMaxVersion 653 = ORBUtility.getMaxStreamFormatVersion(); 654 655 IOR effectiveTargetIOR = 656 ((CorbaContactInfo)this.contactInfo).getEffectiveTargetIOR(); 657 IIOPProfileTemplate temp = 658 (IIOPProfileTemplate)effectiveTargetIOR.getProfile().getTaggedProfileTemplate(); 659 Iterator iter = temp.iteratorById(TAG_RMI_CUSTOM_MAX_STREAM_FORMAT.value); 660 if (!iter.hasNext()) { 661 if (giopVersion.lessThan(GIOPVersion.V1_3)) 664 return ORBConstants.STREAM_FORMAT_VERSION_1; 665 else 666 return ORBConstants.STREAM_FORMAT_VERSION_2; 667 } 668 669 byte remoteMaxVersion 670 = ((MaxStreamFormatVersionComponent)iter.next()).getMaxStreamFormatVersion(); 671 672 return (byte)Math.min(localMaxVersion, remoteMaxVersion); 673 } 674 675 679 683 684 protected boolean isThreadDone = false; 685 686 691 public boolean handleRequest(MessageMediator messageMediator) 692 { 693 try { 694 dispatchHeader.callback(this); 695 } catch (IOException e) { 696 ; 698 } 699 return isThreadDone; 700 } 701 702 707 private void setWorkThenPoolOrResumeSelect(Message header) 708 { 709 if (getConnection().getEventHandler().shouldUseSelectThreadToWait()) { 710 resumeSelect(header); 711 } else { 712 715 isThreadDone = true; 716 717 orb.getTransportManager().getSelector(0) 719 .unregisterForEvent(getConnection().getEventHandler()); 720 orb.getTransportManager().getSelector(0) 722 .registerForEvent(getConnection().getEventHandler()); 723 } 724 } 725 726 private void setWorkThenReadOrResumeSelect(Message header) 727 { 728 if (getConnection().getEventHandler().shouldUseSelectThreadToWait()) { 729 resumeSelect(header); 730 } else { 731 isThreadDone = false; 734 } 735 } 736 737 private void resumeSelect(Message header) 738 { 739 743 if (transportDebug()) { 744 dprint(".resumeSelect:->"); 745 String requestId = "?"; 747 if (header instanceof RequestMessage) { 748 requestId = 749 new Integer (((RequestMessage)header) 750 .getRequestId()).toString(); 751 } else if (header instanceof ReplyMessage) { 752 requestId = 753 new Integer (((ReplyMessage)header) 754 .getRequestId()).toString(); 755 } else if (header instanceof FragmentMessage_1_2) { 756 requestId = 757 new Integer (((FragmentMessage_1_2)header) 758 .getRequestId()).toString(); 759 } 760 dprint(".resumeSelect: id/" 761 + requestId 762 + " " + getConnection() 763 ); 764 765 } 766 767 EventHandler eventHandler = getConnection().getEventHandler(); 772 orb.getTransportManager().getSelector(0).registerInterestOps(eventHandler); 773 774 if (transportDebug()) { 775 dprint(".resumeSelect:<-"); 776 } 777 } 778 779 private void setInputObject() 780 { 781 if (getConnection().getContactInfo() != null) { 785 inputObject = (CDRInputObject) 786 getConnection().getContactInfo() 787 .createInputObject(orb, this); 788 } else if (getConnection().getAcceptor() != null) { 789 inputObject = (CDRInputObject) 790 getConnection().getAcceptor() 791 .createInputObject(orb, this); 792 } else { 793 throw new RuntimeException ("CorbaMessageMediatorImpl.setInputObject"); 794 } 795 inputObject.setMessageMediator(this); 796 setInputObject(inputObject); 797 } 798 799 private void signalResponseReceived() 800 { 801 connection.getResponseWaitingRoom() 805 .responseReceived((InputObject)inputObject); 806 } 807 808 public void handleInput(Message header) throws IOException 810 { 811 try { 812 messageHeader = header; 813 814 if (transportDebug()) 815 dprint(".handleInput->: " 816 + MessageBase.typeToString(header.getType())); 817 818 setWorkThenReadOrResumeSelect(header); 819 820 switch(header.getType()) 821 { 822 case Message.GIOPCloseConnection: 823 if (transportDebug()) { 824 dprint(".handleInput: CloseConnection: purging"); 825 } 826 connection.purgeCalls(wrapper.connectionRebind(), true, false); 827 break; 828 case Message.GIOPMessageError: 829 if (transportDebug()) { 830 dprint(".handleInput: MessageError: purging"); 831 } 832 connection.purgeCalls(wrapper.recvMsgError(), true, false); 833 break; 834 default: 835 if (transportDebug()) { 836 dprint(".handleInput: ERROR: " 837 + MessageBase.typeToString(header.getType())); 838 } 839 throw wrapper.badGiopRequestType() ; 840 } 841 releaseByteBufferToPool(); 842 } finally { 843 if (transportDebug()) { 844 dprint(".handleInput<-: " 845 + MessageBase.typeToString(header.getType())); 846 } 847 } 848 } 849 850 public void handleInput(RequestMessage_1_0 header) throws IOException 851 { 852 try { 853 if (transportDebug()) dprint(".REQUEST 1.0->: " + header); 854 try { 855 messageHeader = requestHeader = (RequestMessage) header; 856 setInputObject(); 857 } finally { 858 setWorkThenPoolOrResumeSelect(header); 859 } 860 getProtocolHandler().handleRequest(header, this); 861 } catch (Throwable t) { 862 if (transportDebug()) 863 dprint(".REQUEST 1.0: !!ERROR!!: " + header, t); 864 } finally { 866 if (transportDebug()) dprint(".REQUEST 1.0<-: " + header); 867 } 868 } 869 870 public void handleInput(RequestMessage_1_1 header) throws IOException 871 { 872 try { 873 if (transportDebug()) dprint(".REQUEST 1.1->: " + header); 874 try { 875 messageHeader = requestHeader = (RequestMessage) header; 876 setInputObject(); 877 connection.serverRequest_1_1_Put(this); 878 } finally { 879 setWorkThenPoolOrResumeSelect(header); 880 } 881 getProtocolHandler().handleRequest(header, this); 882 } catch (Throwable t) { 883 if (transportDebug()) 884 dprint(".REQUEST 1.1: !!ERROR!!: " + header, t); 885 } finally { 887 if (transportDebug()) dprint(".REQUEST 1.1<-: " + header); 888 } 889 } 890 891 public void handleInput(RequestMessage_1_2 header) throws IOException 893 { 894 try { 895 try { 896 897 messageHeader = requestHeader = (RequestMessage) header; 898 899 header.unmarshalRequestID(dispatchByteBuffer); 900 setInputObject(); 901 902 if (transportDebug()) dprint(".REQUEST 1.2->: id/" 903 + header.getRequestId() 904 + ": " 905 + header); 906 907 connection.serverRequestMapPut(header.getRequestId(), this); 914 } finally { 915 setWorkThenPoolOrResumeSelect(header); 920 } 921 getProtocolHandler().handleRequest(header, this); 923 } catch (Throwable t) { 924 if (transportDebug()) dprint(".REQUEST 1.2: id/" 925 + header.getRequestId() 926 + ": !!ERROR!!: " 927 + header, 928 t); 929 } finally { 931 connection.serverRequestMapRemove(header.getRequestId()); 932 933 if (transportDebug()) dprint(".REQUEST 1.2<-: id/" 934 + header.getRequestId() 935 + ": " 936 + header); 937 } 938 } 939 940 public void handleInput(ReplyMessage_1_0 header) throws IOException 941 { 942 try { 943 try { 944 if (transportDebug()) dprint(".REPLY 1.0->: " + header); 945 messageHeader = replyHeader = (ReplyMessage) header; 946 setInputObject(); 947 948 inputObject.unmarshalHeader(); 950 951 signalResponseReceived(); 952 } finally{ 953 setWorkThenReadOrResumeSelect(header); 954 } 955 } catch (Throwable t) { 956 if (transportDebug())dprint(".REPLY 1.0: !!ERROR!!: " + header, t); 957 } finally { 959 if (transportDebug()) dprint(".REPLY 1.0<-: " + header); 960 } 961 } 962 963 public void handleInput(ReplyMessage_1_1 header) throws IOException 964 { 965 try { 966 if (transportDebug()) dprint(".REPLY 1.1->: " + header); 967 messageHeader = replyHeader = (ReplyMessage) header; 968 setInputObject(); 969 970 if (header.moreFragmentsToFollow()) { 971 972 connection.clientReply_1_1_Put(this); 975 976 setWorkThenPoolOrResumeSelect(header); 981 982 inputObject.unmarshalHeader(); 985 986 signalResponseReceived(); 987 988 } else { 989 990 995 inputObject.unmarshalHeader(); 998 999 signalResponseReceived(); 1000 1001 setWorkThenReadOrResumeSelect(header); 1002 } 1003 } catch (Throwable t) { 1004 if (transportDebug()) dprint(".REPLY 1.1: !!ERROR!!: " + header); 1005 } finally { 1007 if (transportDebug()) dprint(".REPLY 1.1<-: " + header); 1008 } 1009 } 1010 1011 public void handleInput(ReplyMessage_1_2 header) throws IOException 1012 { 1013 try { 1014 try { 1015 messageHeader = replyHeader = (ReplyMessage) header; 1016 1017 header.unmarshalRequestID(dispatchByteBuffer); 1019 1020 if (transportDebug()) { 1021 dprint(".REPLY 1.2->: id/" 1022 + + header.getRequestId() 1023 + ": more?: " + header.moreFragmentsToFollow() 1024 + ": " + header); 1025 } 1026 1027 setInputObject(); 1028 1029 signalResponseReceived(); 1030 } finally { 1031 setWorkThenReadOrResumeSelect(header); 1032 } 1033 } catch (Throwable t) { 1034 if (transportDebug()) dprint(".REPLY 1.2: id/" 1035 + header.getRequestId() 1036 + ": !!ERROR!!: " 1037 + header, t); 1038 } finally { 1040 if (transportDebug()) dprint(".REPLY 1.2<-: id/" 1041 + header.getRequestId() 1042 + ": " 1043 + header); 1044 } 1045 } 1046 1047 public void handleInput(LocateRequestMessage_1_0 header) throws IOException 1048 { 1049 try { 1050 if (transportDebug()) 1051 dprint(".LOCATE_REQUEST 1.0->: " + header); 1052 try { 1053 messageHeader = header; 1054 setInputObject(); 1055 } finally { 1056 setWorkThenPoolOrResumeSelect(header); 1057 } 1058 getProtocolHandler().handleRequest(header, this); 1059 } catch (Throwable t) { 1060 if (transportDebug()) 1061 dprint(".LOCATE_REQUEST 1.0: !!ERROR!!: " + header, t); 1062 } finally { 1064 if (transportDebug()) 1065 dprint(".LOCATE_REQUEST 1.0<-: " + header); 1066 } 1067 1068 } 1069 1070 public void handleInput(LocateRequestMessage_1_1 header) throws IOException 1071 { 1072 try { 1073 if (transportDebug()) 1074 dprint(".LOCATE_REQUEST 1.1->: " + header); 1075 try { 1076 messageHeader = header; 1077 setInputObject(); 1078 } finally { 1079 setWorkThenPoolOrResumeSelect(header); 1080 } 1081 getProtocolHandler().handleRequest(header, this); 1082 } catch (Throwable t) { 1083 if (transportDebug()) 1084 dprint(".LOCATE_REQUEST 1.1: !!ERROR!!: " + header, t); 1085 } finally { 1087 if (transportDebug()) 1088 dprint(".LOCATE_REQUEST 1.1<-:" + header); 1089 } 1090 } 1091 1092 public void handleInput(LocateRequestMessage_1_2 header) throws IOException 1093 { 1094 try { 1095 try { 1096 messageHeader = header; 1097 1098 header.unmarshalRequestID(dispatchByteBuffer); 1099 setInputObject(); 1100 1101 if (transportDebug()) 1102 dprint(".LOCATE_REQUEST 1.2->: id/" 1103 + header.getRequestId() 1104 + ": " 1105 + header); 1106 1107 if (header.moreFragmentsToFollow()) { 1108 connection.serverRequestMapPut(header.getRequestId(),this); 1109 } 1110 } finally { 1111 setWorkThenPoolOrResumeSelect(header); 1112 } 1113 getProtocolHandler().handleRequest(header, this); 1114 } catch (Throwable t) { 1115 if (transportDebug()) 1116 dprint(".LOCATE_REQUEST 1.2: id/" 1117 + header.getRequestId() 1118 + ": !!ERROR!!: " 1119 + header, t); 1120 } finally { 1122 if (transportDebug()) 1123 dprint(".LOCATE_REQUEST 1.2<-: id/" 1124 + header.getRequestId() 1125 + ": " 1126 + header); 1127 } 1128 } 1129 1130 public void handleInput(LocateReplyMessage_1_0 header) throws IOException 1131 { 1132 try { 1133 if (transportDebug()) 1134 dprint(".LOCATE_REPLY 1.0->:" + header); 1135 try { 1136 messageHeader = header; 1137 setInputObject(); 1138 inputObject.unmarshalHeader(); signalResponseReceived(); 1140 } finally { 1141 setWorkThenReadOrResumeSelect(header); 1142 } 1143 } catch (Throwable t) { 1144 if (transportDebug()) 1145 dprint(".LOCATE_REPLY 1.0: !!ERROR!!: " + header, t); 1146 } finally { 1148 if (transportDebug()) 1149 dprint(".LOCATE_REPLY 1.0<-: " + header); 1150 } 1151 } 1152 1153 public void handleInput(LocateReplyMessage_1_1 header) throws IOException 1154 { 1155 try { 1156 if (transportDebug()) dprint(".LOCATE_REPLY 1.1->: " + header); 1157 try { 1158 messageHeader = header; 1159 setInputObject(); 1160 inputObject.unmarshalHeader(); 1162 signalResponseReceived(); 1163 } finally { 1164 setWorkThenReadOrResumeSelect(header); 1165 } 1166 } catch (Throwable t) { 1167 if (transportDebug()) 1168 dprint(".LOCATE_REPLY 1.1: !!ERROR!!: " + header, t); 1169 } finally { 1171 if (transportDebug()) dprint(".LOCATE_REPLY 1.1<-: " + header); 1172 } 1173 } 1174 1175 public void handleInput(LocateReplyMessage_1_2 header) throws IOException 1176 { 1177 try { 1178 try { 1179 messageHeader = header; 1180 1181 header.unmarshalRequestID(dispatchByteBuffer); 1183 1184 setInputObject(); 1185 1186 if (transportDebug()) dprint(".LOCATE_REPLY 1.2->: id/" 1187 + header.getRequestId() 1188 + ": " 1189 + header); 1190 1191 signalResponseReceived(); 1192 } finally { 1193 setWorkThenPoolOrResumeSelect(header); } 1195 } catch (Throwable t) { 1196 if (transportDebug()) 1197 dprint(".LOCATE_REPLY 1.2: id/" 1198 + header.getRequestId() 1199 + ": !!ERROR!!: " 1200 + header, t); 1201 } finally { 1203 if (transportDebug()) dprint(".LOCATE_REPLY 1.2<-: id/" 1204 + header.getRequestId() 1205 + ": " 1206 + header); 1207 } 1208 } 1209 1210 public void handleInput(FragmentMessage_1_1 header) throws IOException 1211 { 1212 try { 1213 if (transportDebug()) { 1214 dprint(".FRAGMENT 1.1->: " 1215 + "more?: " + header.moreFragmentsToFollow() 1216 + ": " + header); 1217 } 1218 try { 1219 messageHeader = header; 1220 MessageMediator mediator = null; 1221 CDRInputObject inputObject = null; 1222 1223 if (connection.isServer()) { 1224 mediator = connection.serverRequest_1_1_Get(); 1225 } else { 1226 mediator = connection.clientReply_1_1_Get(); 1227 } 1228 if (mediator != null) { 1229 inputObject = (CDRInputObject) mediator.getInputObject(); 1230 } 1231 1232 if (inputObject == null) { 1242 if (transportDebug()) 1243 dprint(".FRAGMENT 1.1: ++++DISCARDING++++: " + header); 1244 releaseByteBufferToPool(); 1247 return; 1248 } 1249 1250 inputObject.getBufferManager() 1251 .processFragment(dispatchByteBuffer, header); 1252 1253 if (! header.moreFragmentsToFollow()) { 1254 if (connection.isServer()) { 1255 connection.serverRequest_1_1_Remove(); 1256 } else { 1257 connection.clientReply_1_1_Remove(); 1258 } 1259 } 1260 } finally { 1261 setWorkThenReadOrResumeSelect(header); 1264 } 1265 } catch (Throwable t) { 1266 if (transportDebug()) 1267 dprint(".FRAGMENT 1.1: !!ERROR!!: " + header, t); 1268 } finally { 1270 if (transportDebug()) dprint(".FRAGMENT 1.1<-: " + header); 1271 } 1272 } 1273 1274 public void handleInput(FragmentMessage_1_2 header) throws IOException 1275 { 1276 try { 1277 try { 1278 messageHeader = header; 1279 1280 1285 header.unmarshalRequestID(dispatchByteBuffer); 1286 1287 if (transportDebug()) { 1288 dprint(".FRAGMENT 1.2->: id/" 1289 + header.getRequestId() 1290 + ": more?: " + header.moreFragmentsToFollow() 1291 + ": " + header); 1292 } 1293 1294 MessageMediator mediator = null; 1295 InputObject inputObject = null; 1296 1297 if (connection.isServer()) { 1298 mediator = 1299 connection.serverRequestMapGet(header.getRequestId()); 1300 } else { 1301 mediator = 1302 connection.clientRequestMapGet(header.getRequestId()); 1303 } 1304 if (mediator != null) { 1305 inputObject = mediator.getInputObject(); 1306 } 1307 if (inputObject == null) { 1309 if (transportDebug()) { 1310 dprint(".FRAGMENT 1.2: id/" 1311 + header.getRequestId() 1312 + ": ++++DISCARDING++++: " 1313 + header); 1314 } 1315 releaseByteBufferToPool(); 1318 return; 1319 } 1320 ((CDRInputObject)inputObject) 1321 .getBufferManager().processFragment( 1322 dispatchByteBuffer, header); 1323 1324 if (! connection.isServer()) { 1327 1334 } 1335 } finally { 1336 setWorkThenReadOrResumeSelect(header); 1339 } 1340 } catch (Throwable t) { 1341 if (transportDebug()) 1342 dprint(".FRAGMENT 1.2: id/" 1343 + header.getRequestId() 1344 + ": !!ERROR!!: " 1345 + header, t); 1346 } finally { 1348 if (transportDebug()) dprint(".FRAGMENT 1.2<-: id/" 1349 + header.getRequestId() 1350 + ": " 1351 + header); 1352 } 1353 } 1354 1355 public void handleInput(CancelRequestMessage header) throws IOException 1356 { 1357 try { 1358 try { 1359 messageHeader = header; 1360 setInputObject(); 1361 1362 inputObject.unmarshalHeader(); 1364 1365 if (transportDebug()) dprint(".CANCEL->: id/" 1366 + header.getRequestId() + ": " 1367 + header.getGIOPVersion() + ": " 1368 + header); 1369 1370 processCancelRequest(header.getRequestId()); 1371 releaseByteBufferToPool(); 1372 } finally { 1373 setWorkThenReadOrResumeSelect(header); 1374 } 1375 } catch (Throwable t) { 1376 if (transportDebug()) dprint(".CANCEL: id/" 1377 + header.getRequestId() 1378 + ": !!ERROR!!: " 1379 + header, t); 1380 } finally { 1382 if (transportDebug()) dprint(".CANCEL<-: id/" 1383 + header.getRequestId() + ": " 1384 + header.getGIOPVersion() + ": " 1385 + header); 1386 } 1387 } 1388 1389 private void throwNotImplemented() 1390 { 1391 isThreadDone = false; 1392 throwNotImplemented(""); 1393 } 1394 1395 private void throwNotImplemented(String msg) 1396 { 1397 throw new RuntimeException ("CorbaMessageMediatorImpl: not implemented " + msg); 1398 } 1399 1400 private void dprint(String msg, Throwable t) 1401 { 1402 dprint(msg); 1403 t.printStackTrace(System.out); 1404 } 1405 1406 private void dprint(String msg) 1407 { 1408 ORBUtility.dprint("CorbaMessageMediatorImpl", msg); 1409 } 1410 1411 protected String opAndId(CorbaMessageMediator mediator) 1412 { 1413 return ORBUtility.operationNameAndRequestId(mediator); 1414 } 1415 1416 private boolean transportDebug() 1417 { 1418 return orb.transportDebugFlag; 1419 } 1420 1421 private final void processCancelRequest(int cancelReqId) { 1423 1424 1428 1455 1456 if (!connection.isServer()) { 1457 return; } 1459 1460 1464 MessageMediator mediator = connection.serverRequestMapGet(cancelReqId); 1466 int requestId ; 1467 if (mediator == null) { 1468 mediator = connection.serverRequest_1_1_Get(); 1470 if (mediator == null) { 1471 return; } 1478 1479 requestId = ((CorbaMessageMediator) mediator).getRequestId(); 1480 1481 if (requestId != cancelReqId) { 1482 return; } 1486 1487 if (requestId == 0) { return; } 1500 } else { 1501 requestId = ((CorbaMessageMediator) mediator).getRequestId(); 1502 } 1503 1504 Message msg = ((CorbaMessageMediator)mediator).getRequestHeader(); 1505 if (msg.getType() != Message.GIOPRequest) { 1506 wrapper.badMessageTypeForCancel() ; 1509 } 1510 1511 1514 1524 BufferManagerReadStream bufferManager = (BufferManagerReadStream) 1525 ((CDRInputObject)mediator.getInputObject()).getBufferManager(); 1526 bufferManager.cancelProcessing(cancelReqId); 1527 } 1528 1529 1534 public void handleRequest(RequestMessage msg, 1535 CorbaMessageMediator messageMediator) 1536 { 1537 try { 1538 beginRequest(messageMediator); 1539 try { 1540 handleRequestRequest(messageMediator); 1541 if (messageMediator.isOneWay()) { 1542 return; 1543 } 1544 } catch (Throwable t) { 1545 if (messageMediator.isOneWay()) { 1546 return; 1547 } 1548 handleThrowableDuringServerDispatch( 1549 messageMediator, t, CompletionStatus.COMPLETED_MAYBE); 1550 } 1551 sendResponse(messageMediator); 1552 } catch (Throwable t) { 1553 dispatchError(messageMediator, "RequestMessage", t); 1554 } finally { 1555 endRequest(messageMediator); 1556 } 1557 } 1558 1559 public void handleRequest(LocateRequestMessage msg, 1560 CorbaMessageMediator messageMediator) 1561 { 1562 try { 1563 beginRequest(messageMediator); 1564 try { 1565 handleLocateRequest(messageMediator); 1566 } catch (Throwable t) { 1567 handleThrowableDuringServerDispatch( 1568 messageMediator, t, CompletionStatus.COMPLETED_MAYBE); 1569 } 1570 sendResponse(messageMediator); 1571 } catch (Throwable t) { 1572 dispatchError(messageMediator, "LocateRequestMessage", t); 1573 } finally { 1574 endRequest(messageMediator); 1575 } 1576 } 1577 1578 private void beginRequest(CorbaMessageMediator messageMediator) 1579 { 1580 ORB orb = (ORB) messageMediator.getBroker(); 1581 if (orb.subcontractDebugFlag) { 1582 dprint(".handleRequest->:"); 1583 } 1584 connection.serverRequestProcessingBegins(); 1585 } 1586 1587 private void dispatchError(CorbaMessageMediator messageMediator, 1588 String msg, Throwable t) 1589 { 1590 if (orb.subcontractDebugFlag) { 1591 dprint(".handleRequest: " + opAndId(messageMediator) 1592 + ": !!ERROR!!: " 1593 + msg, 1594 t); 1595 } 1596 } 1599 1600 private void sendResponse(CorbaMessageMediator messageMediator) 1601 { 1602 if (orb.subcontractDebugFlag) { 1603 dprint(".handleRequest: " + opAndId(messageMediator) 1604 + ": sending response"); 1605 } 1606 CDROutputObject outputObject = (CDROutputObject) 1608 messageMediator.getOutputObject(); 1609 if (outputObject != null) { 1610 outputObject.finishSendingMessage(); 1612 } 1613 } 1614 1615 private void endRequest(CorbaMessageMediator messageMediator) 1616 { 1617 ORB orb = (ORB) messageMediator.getBroker(); 1618 if (orb.subcontractDebugFlag) { 1619 dprint(".handleRequest<-: " + opAndId(messageMediator)); 1620 } 1621 1622 1624 try { 1625 OutputObject outputObj = messageMediator.getOutputObject(); 1626 if (outputObj != null) { 1627 outputObj.close(); 1628 } 1629 InputObject inputObj = messageMediator.getInputObject(); 1630 if (inputObj != null) { 1631 inputObj.close(); 1632 } 1633 } catch (IOException ex) { 1634 if (orb.subcontractDebugFlag) { 1638 dprint(".endRequest: IOException:" + ex.getMessage(), ex); 1639 } 1640 } finally { 1641 ((CorbaConnection)messageMediator.getConnection()).serverRequestProcessingEnds(); 1642 } 1643 } 1644 1645 protected void handleRequestRequest(CorbaMessageMediator messageMediator) 1646 { 1647 ((CDRInputObject)messageMediator.getInputObject()).unmarshalHeader(); 1649 1650 ORB orb = (ORB)messageMediator.getBroker(); 1651 orb.checkShutdownState(); 1652 1653 ObjectKey okey = messageMediator.getObjectKey(); 1654 if (orb.subcontractDebugFlag) { 1655 ObjectKeyTemplate oktemp = okey.getTemplate() ; 1656 dprint( ".handleRequest: " + opAndId(messageMediator) 1657 + ": dispatching to scid: " + oktemp.getSubcontractId()); 1658 } 1659 1660 CorbaServerRequestDispatcher sc = okey.getServerRequestDispatcher(orb); 1661 1662 if (orb.subcontractDebugFlag) { 1663 dprint(".handleRequest: " + opAndId(messageMediator) 1664 + ": dispatching to sc: " + sc); 1665 } 1666 1667 if (sc == null) { 1668 throw wrapper.noServerScInDispatch() ; 1669 } 1670 1671 1678 try { 1679 orb.startingDispatch(); 1680 sc.dispatch(messageMediator); 1681 } finally { 1682 orb.finishedDispatch(); 1683 } 1684 } 1685 1686 protected void handleLocateRequest(CorbaMessageMediator messageMediator) 1687 { 1688 ORB orb = (ORB)messageMediator.getBroker(); 1689 LocateRequestMessage msg = (LocateRequestMessage) 1690 messageMediator.getDispatchHeader(); 1691 IOR ior = null; 1692 LocateReplyMessage reply = null; 1693 short addrDisp = -1; 1694 1695 try { 1696 ((CDRInputObject)messageMediator.getInputObject()).unmarshalHeader(); 1697 CorbaServerRequestDispatcher sc = 1698 msg.getObjectKey().getServerRequestDispatcher( orb ) ; 1699 if (sc == null) { 1700 return; 1701 } 1702 1703 ior = sc.locate(msg.getObjectKey()); 1704 1705 if ( ior == null ) { 1706 reply = MessageBase.createLocateReply( 1707 orb, msg.getGIOPVersion(), 1708 msg.getEncodingVersion(), 1709 msg.getRequestId(), 1710 LocateReplyMessage.OBJECT_HERE, null); 1711 1712 } else { 1713 reply = MessageBase.createLocateReply( 1714 orb, msg.getGIOPVersion(), 1715 msg.getEncodingVersion(), 1716 msg.getRequestId(), 1717 LocateReplyMessage.OBJECT_FORWARD, ior); 1718 } 1719 1721 } catch (AddressingDispositionException ex) { 1722 1723 1726 reply = MessageBase.createLocateReply( 1727 orb, msg.getGIOPVersion(), 1728 msg.getEncodingVersion(), 1729 msg.getRequestId(), 1730 LocateReplyMessage.LOC_NEEDS_ADDRESSING_MODE, null); 1731 1732 addrDisp = ex.expectedAddrDisp(); 1733 1734 } catch (RequestCanceledException ex) { 1735 1736 return; 1738 } catch ( Exception ex ) { 1739 1740 1743 1746 reply = MessageBase.createLocateReply( 1747 orb, msg.getGIOPVersion(), 1748 msg.getEncodingVersion(), 1749 msg.getRequestId(), 1750 LocateReplyMessage.UNKNOWN_OBJECT, null); 1751 } 1752 1753 CDROutputObject outputObject = 1754 createAppropriateOutputObject(messageMediator, 1755 msg, reply); 1756 messageMediator.setOutputObject(outputObject); 1757 outputObject.setMessageMediator(messageMediator); 1758 1759 reply.write(outputObject); 1760 if (ior != null) { 1762 ior.write(outputObject); 1763 } 1764 if (addrDisp != -1) { 1765 AddressingDispositionHelper.write(outputObject, addrDisp); 1766 } 1767 } 1768 1769 private CDROutputObject createAppropriateOutputObject( 1770 CorbaMessageMediator messageMediator, 1771 Message msg, LocateReplyMessage reply) 1772 { 1773 CDROutputObject outputObject; 1774 1775 if (msg.getGIOPVersion().lessThan(GIOPVersion.V1_2)) { 1776 outputObject = new CDROutputObject( 1779 (ORB) messageMediator.getBroker(), 1780 this, 1781 GIOPVersion.V1_0, 1782 (CorbaConnection) messageMediator.getConnection(), 1783 reply, 1784 ORBConstants.STREAM_FORMAT_VERSION_1); 1785 } else { 1786 outputObject = new CDROutputObject( 1789 (ORB) messageMediator.getBroker(), 1790 messageMediator, 1791 reply, 1792 ORBConstants.STREAM_FORMAT_VERSION_1); 1793 } 1794 return outputObject; 1795 } 1796 1797 public void handleThrowableDuringServerDispatch( 1798 CorbaMessageMediator messageMediator, 1799 Throwable throwable, 1800 CompletionStatus completionStatus) 1801 { 1802 if (((ORB)messageMediator.getBroker()).subcontractDebugFlag) { 1803 dprint(".handleThrowableDuringServerDispatch: " 1804 + opAndId(messageMediator) + ": " 1805 + throwable); 1806 } 1807 1808 1811 1821 handleThrowableDuringServerDispatch(messageMediator, 1822 throwable, 1823 completionStatus, 1824 1); 1825 } 1826 1827 1828 1830 protected void handleThrowableDuringServerDispatch( 1831 CorbaMessageMediator messageMediator, 1832 Throwable throwable, 1833 CompletionStatus completionStatus, 1834 int iteration) 1835 { 1836 if (iteration > 10) { 1837 if (((ORB)messageMediator.getBroker()).subcontractDebugFlag) { 1838 dprint(".handleThrowableDuringServerDispatch: " 1839 + opAndId(messageMediator) 1840 + ": cannot handle: " 1841 + throwable); 1842 } 1843 1844 RuntimeException rte = 1846 new RuntimeException ("handleThrowableDuringServerDispatch: " + 1847 "cannot create response."); 1848 rte.initCause(throwable); 1849 throw rte; 1850 } 1851 1852 try { 1853 if (throwable instanceof ForwardException) { 1854 ForwardException fex = (ForwardException)throwable ; 1855 createLocationForward( messageMediator, fex.getIOR(), null ) ; 1856 return; 1857 } 1858 1859 if (throwable instanceof AddressingDispositionException) { 1860 handleAddressingDisposition( 1861 messageMediator, 1862 (AddressingDispositionException)throwable); 1863 return; 1864 } 1865 1866 1868 SystemException sex = 1869 convertThrowableToSystemException(throwable, completionStatus); 1870 1871 createSystemExceptionResponse(messageMediator, sex, null); 1872 return; 1873 1874 } catch (Throwable throwable2) { 1875 1876 1880 handleThrowableDuringServerDispatch(messageMediator, 1881 throwable2, 1882 completionStatus, 1883 iteration + 1); 1884 return; 1885 } 1886 } 1887 1888 protected SystemException convertThrowableToSystemException( 1889 Throwable throwable, 1890 CompletionStatus completionStatus) 1891 { 1892 if (throwable instanceof SystemException ) { 1893 return (SystemException )throwable; 1894 } 1895 1896 if (throwable instanceof RequestCanceledException) { 1897 1902 return wrapper.requestCanceled( throwable ) ; 1903 } 1904 1905 1913 1918 return wrapper.runtimeexception( CompletionStatus.COMPLETED_MAYBE, throwable ) ; 1919 } 1920 1921 protected void handleAddressingDisposition( 1922 CorbaMessageMediator messageMediator, 1923 AddressingDispositionException ex) 1924 { 1925 1926 short addrDisp = -1; 1927 1928 1930 1932 switch (messageMediator.getRequestHeader().getType()) { 1933 case Message.GIOPRequest : 1934 ReplyMessage replyHeader = MessageBase.createReply( 1935 (ORB)messageMediator.getBroker(), 1936 messageMediator.getGIOPVersion(), 1937 messageMediator.getEncodingVersion(), 1938 messageMediator.getRequestId(), 1939 ReplyMessage.NEEDS_ADDRESSING_MODE, 1940 null, null); 1941 CDROutputObject outputObject = new CDROutputObject( 1943 (ORB)messageMediator.getBroker(), 1944 this, 1945 messageMediator.getGIOPVersion(), 1946 (CorbaConnection)messageMediator.getConnection(), 1947 replyHeader, 1948 ORBConstants.STREAM_FORMAT_VERSION_1); 1949 messageMediator.setOutputObject(outputObject); 1950 outputObject.setMessageMediator(messageMediator); 1951 replyHeader.write(outputObject); 1952 AddressingDispositionHelper.write(outputObject, 1953 ex.expectedAddrDisp()); 1954 return; 1955 1956 case Message.GIOPLocateRequest : 1957 LocateReplyMessage locateReplyHeader = MessageBase.createLocateReply( 1958 (ORB)messageMediator.getBroker(), 1959 messageMediator.getGIOPVersion(), 1960 messageMediator.getEncodingVersion(), 1961 messageMediator.getRequestId(), 1962 LocateReplyMessage.LOC_NEEDS_ADDRESSING_MODE, 1963 null); 1964 1965 addrDisp = ex.expectedAddrDisp(); 1966 1967 outputObject = 1969 createAppropriateOutputObject(messageMediator, 1970 messageMediator.getRequestHeader(), 1971 locateReplyHeader); 1972 messageMediator.setOutputObject(outputObject); 1973 outputObject.setMessageMediator(messageMediator); 1974 locateReplyHeader.write(outputObject); 1975 IOR ior = null; 1976 if (ior != null) { 1977 ior.write(outputObject); 1978 } 1979 if (addrDisp != -1) { 1980 AddressingDispositionHelper.write(outputObject, addrDisp); 1981 } 1982 return; 1983 } 1984 } 1985 1986 public CorbaMessageMediator createResponse( 1987 CorbaMessageMediator messageMediator, 1988 ServiceContexts svc) 1989 { 1990 return createResponseHelper( 1995 messageMediator, 1996 getServiceContextsForReply(messageMediator, null)); 1997 } 1998 1999 public CorbaMessageMediator createUserExceptionResponse( 2000 CorbaMessageMediator messageMediator, ServiceContexts svc) 2001 { 2002 return createResponseHelper( 2004 messageMediator, 2005 getServiceContextsForReply(messageMediator, null), 2006 true); 2007 } 2008 2009 public CorbaMessageMediator createUnknownExceptionResponse( 2010 CorbaMessageMediator messageMediator, UnknownException ex) 2011 { 2012 ServiceContexts contexts = null; 2015 SystemException sys = new UNKNOWN ( 0, 2016 CompletionStatus.COMPLETED_MAYBE); 2017 contexts = new ServiceContexts( (ORB)messageMediator.getBroker() ); 2018 UEInfoServiceContext uei = new UEInfoServiceContext(sys); 2019 contexts.put( uei ) ; 2020 return createSystemExceptionResponse(messageMediator, sys, contexts); 2021 } 2022 2023 public CorbaMessageMediator createSystemExceptionResponse( 2024 CorbaMessageMediator messageMediator, 2025 SystemException ex, 2026 ServiceContexts svc) 2027 { 2028 if (messageMediator.getConnection() != null) { 2029 2037 CorbaMessageMediatorImpl mediator = (CorbaMessageMediatorImpl) 2039 ((CorbaConnection)messageMediator.getConnection()) 2040 .serverRequestMapGet(messageMediator.getRequestId()); 2041 2042 OutputObject existingOutputObject = null; 2043 if (mediator != null) { 2044 existingOutputObject = mediator.getOutputObject(); 2045 } 2046 2047 if (existingOutputObject != null && 2050 mediator.sentFragment() && 2051 ! mediator.sentFullMessage()) 2052 { 2053 return mediator; 2054 } 2055 } 2056 2057 if (messageMediator.executePIInResponseConstructor()) { 2061 ((ORB)messageMediator.getBroker()).getPIHandler().setServerPIInfo( ex ); 2068 } 2069 2070 if (((ORB)messageMediator.getBroker()).subcontractDebugFlag && 2071 ex != null) 2072 { 2073 dprint(".createSystemExceptionResponse: " 2074 + opAndId(messageMediator), 2075 ex); 2076 } 2077 2078 ServiceContexts serviceContexts = 2079 getServiceContextsForReply(messageMediator, svc); 2080 2081 2085 addExceptionDetailMessage(messageMediator, ex, serviceContexts); 2086 2087 CorbaMessageMediator response = 2088 createResponseHelper(messageMediator, serviceContexts, false); 2089 2090 2094 ORBUtility.writeSystemException( 2095 ex, (OutputStream )response.getOutputObject()); 2096 2097 return response; 2098 } 2099 2100 private void addExceptionDetailMessage(CorbaMessageMediator mediator, 2101 SystemException ex, 2102 ServiceContexts serviceContexts) 2103 { 2104 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 2105 PrintWriter pw = new PrintWriter (baos); 2106 ex.printStackTrace(pw); 2107 pw.flush(); EncapsOutputStream encapsOutputStream = 2109 new EncapsOutputStream((ORB)mediator.getBroker()); 2110 encapsOutputStream.putEndian(); 2111 encapsOutputStream.write_wstring(baos.toString()); 2112 UnknownServiceContext serviceContext = 2113 new UnknownServiceContext(ExceptionDetailMessage.value, 2114 encapsOutputStream.toByteArray()); 2115 serviceContexts.put(serviceContext); 2116 } 2117 2118 public CorbaMessageMediator createLocationForward( 2119 CorbaMessageMediator messageMediator, IOR ior, ServiceContexts svc) 2120 { 2121 ReplyMessage reply 2122 = MessageBase.createReply( 2123 (ORB)messageMediator.getBroker(), 2124 messageMediator.getGIOPVersion(), 2125 messageMediator.getEncodingVersion(), 2126 messageMediator.getRequestId(), 2127 ReplyMessage.LOCATION_FORWARD, 2128 getServiceContextsForReply(messageMediator, svc), 2129 ior); 2130 2131 return createResponseHelper(messageMediator, reply, ior); 2132 } 2133 2134 protected CorbaMessageMediator createResponseHelper( 2135 CorbaMessageMediator messageMediator, ServiceContexts svc) 2136 { 2137 ReplyMessage message = 2138 MessageBase.createReply( 2139 (ORB)messageMediator.getBroker(), 2140 messageMediator.getGIOPVersion(), 2141 messageMediator.getEncodingVersion(), 2142 messageMediator.getRequestId(), 2143 ReplyMessage.NO_EXCEPTION, 2144 svc, 2145 null); 2146 return createResponseHelper(messageMediator, message, null); 2147 } 2148 2149 protected CorbaMessageMediator createResponseHelper( 2150 CorbaMessageMediator messageMediator, ServiceContexts svc,boolean user) 2151 { 2152 ReplyMessage message = 2153 MessageBase.createReply( 2154 (ORB)messageMediator.getBroker(), 2155 messageMediator.getGIOPVersion(), 2156 messageMediator.getEncodingVersion(), 2157 messageMediator.getRequestId(), 2158 user ? ReplyMessage.USER_EXCEPTION : 2159 ReplyMessage.SYSTEM_EXCEPTION, 2160 svc, 2161 null); 2162 return createResponseHelper(messageMediator, message, null); 2163 } 2164 2165 protected CorbaMessageMediator createResponseHelper( 2167 CorbaMessageMediator messageMediator, ReplyMessage reply, IOR ior) 2168 { 2169 runServantPostInvoke(messageMediator); 2171 runInterceptors(messageMediator, reply); 2172 runRemoveThreadInfo(messageMediator); 2173 2174 if (((ORB)messageMediator.getBroker()).subcontractDebugFlag) { 2175 dprint(".createResponseHelper: " 2176 + opAndId(messageMediator) + ": " 2177 + reply); 2178 } 2179 2180 messageMediator.setReplyHeader(reply); 2181 2182 OutputObject replyOutputObject; 2183 if (messageMediator.getConnection() == null) { 2186 replyOutputObject = 2188 new CDROutputObject(orb, messageMediator, 2189 messageMediator.getReplyHeader(), 2190 messageMediator.getStreamFormatVersion(), 2191 BufferManagerFactory.GROW); 2192 } else { 2193 replyOutputObject = messageMediator.getConnection().getAcceptor() 2194 .createOutputObject(messageMediator.getBroker(), messageMediator); 2195 } 2196 messageMediator.setOutputObject(replyOutputObject); 2197 messageMediator.getOutputObject().setMessageMediator(messageMediator); 2198 2199 reply.write((OutputStream ) messageMediator.getOutputObject()); 2200 if (reply.getIOR() != null) { 2201 reply.getIOR().write((OutputStream ) messageMediator.getOutputObject()); 2202 } 2203 2206 return messageMediator; 2209 } 2210 2211 protected void runServantPostInvoke(CorbaMessageMediator messageMediator) 2212 { 2213 ORB orb = null; 2219 if (messageMediator.executeReturnServantInResponseConstructor()) { 2222 messageMediator.setExecuteReturnServantInResponseConstructor(false); 2228 messageMediator.setExecuteRemoveThreadInfoInResponseConstructor(true); 2229 2230 try { 2231 orb = (ORB)messageMediator.getBroker(); 2232 OAInvocationInfo info = orb.peekInvocationInfo() ; 2233 ObjectAdapter oa = info.oa(); 2234 try { 2235 oa.returnServant() ; 2236 } catch (Throwable thr) { 2237 wrapper.unexpectedException( thr ) ; 2238 2239 if (thr instanceof Error ) 2240 throw (Error )thr ; 2241 else if (thr instanceof RuntimeException ) 2242 throw (RuntimeException )thr ; 2243 } finally { 2244 oa.exit(); 2245 } 2246 } catch (EmptyStackException ese) { 2247 throw wrapper.emptyStackRunServantPostInvoke( ese ) ; 2248 } 2249 } 2250 } 2251 2252 protected void runInterceptors(CorbaMessageMediator messageMediator, 2253 ReplyMessage reply) 2254 { 2255 if( messageMediator.executePIInResponseConstructor() ) { 2256 ((ORB)messageMediator.getBroker()).getPIHandler(). 2260 invokeServerPIEndingPoint( reply ); 2261 2262 ((ORB)messageMediator.getBroker()).getPIHandler(). 2266 cleanupServerPIRequest(); 2267 2268 messageMediator.setExecutePIInResponseConstructor(false); 2270 } 2271 } 2272 2273 protected void runRemoveThreadInfo(CorbaMessageMediator messageMediator) 2274 { 2275 if (messageMediator.executeRemoveThreadInfoInResponseConstructor()) { 2278 messageMediator.setExecuteRemoveThreadInfoInResponseConstructor(false); 2279 ((ORB)messageMediator.getBroker()).popInvocationInfo() ; 2280 } 2281 } 2282 2283 protected ServiceContexts getServiceContextsForReply( 2284 CorbaMessageMediator messageMediator, ServiceContexts contexts) 2285 { 2286 CorbaConnection c = (CorbaConnection) messageMediator.getConnection(); 2287 2288 if (((ORB)messageMediator.getBroker()).subcontractDebugFlag) { 2289 dprint(".getServiceContextsForReply: " 2290 + opAndId(messageMediator) 2291 + ": " + c); 2292 } 2293 2294 if (contexts == null) { 2295 contexts = new ServiceContexts(((ORB)messageMediator.getBroker())); 2296 } 2297 2298 2300 if (c != null && !c.isPostInitialContexts()) { 2301 c.setPostInitialContexts(); 2302 SendingContextServiceContext scsc = 2303 new SendingContextServiceContext( 2304 ((ORB)messageMediator.getBroker()).getFVDCodeBaseIOR()) ; 2305 2306 if (contexts.get( scsc.getId() ) != null) 2307 throw wrapper.duplicateSendingContextServiceContext() ; 2308 2309 contexts.put( scsc ) ; 2310 2311 if ( ((ORB)messageMediator.getBroker()).subcontractDebugFlag) 2312 dprint(".getServiceContextsForReply: " 2313 + opAndId(messageMediator) 2314 + ": added SendingContextServiceContext" ) ; 2315 } 2316 2317 2319 ORBVersionServiceContext ovsc 2320 = new ORBVersionServiceContext(ORBVersionFactory.getORBVersion()); 2321 2322 if (contexts.get( ovsc.getId() ) != null) 2323 throw wrapper.duplicateOrbVersionServiceContext() ; 2324 2325 contexts.put( ovsc ) ; 2326 2327 if ( ((ORB)messageMediator.getBroker()).subcontractDebugFlag) 2328 dprint(".getServiceContextsForReply: " 2329 + opAndId(messageMediator) 2330 + ": added ORB version service context"); 2331 2332 return contexts; 2333 } 2334 2335 private void releaseByteBufferToPool() { 2339 if (dispatchByteBuffer != null) { 2340 orb.getByteBufferPool().releaseByteBuffer(dispatchByteBuffer); 2341 if (transportDebug()) { 2342 int bbId = System.identityHashCode(dispatchByteBuffer); 2343 StringBuffer sb = new StringBuffer (); 2344 sb.append(".handleInput: releasing ByteBuffer (" + bbId + 2345 ") to ByteBufferPool"); 2346 dprint(sb.toString()); 2347 } 2348 } 2349 } 2350} 2351 2352 2354 2355 | Popular Tags |