1 7 15 16 17 package com.sun.corba.se.impl.protocol; 18 19 import org.omg.PortableServer.Servant ; 20 21 import org.omg.CORBA.SystemException ; 22 import org.omg.CORBA.INTERNAL ; 23 import org.omg.CORBA.UNKNOWN ; 24 import org.omg.CORBA.CompletionStatus ; 25 import org.omg.CORBA.Any ; 26 27 import org.omg.CORBA.portable.InvokeHandler ; 28 import org.omg.CORBA.portable.InputStream ; 29 import org.omg.CORBA.portable.OutputStream ; 30 import org.omg.CORBA.portable.UnknownException ; 31 import org.omg.CORBA.portable.ResponseHandler ; 32 33 import com.sun.org.omg.SendingContext.CodeBase; 34 35 import com.sun.corba.se.pept.encoding.OutputObject; 36 import com.sun.corba.se.pept.protocol.MessageMediator; 37 38 import com.sun.corba.se.spi.orb.ORB; 39 import com.sun.corba.se.spi.orb.ORBVersion; 40 import com.sun.corba.se.spi.orb.ORBVersionFactory; 41 import com.sun.corba.se.spi.ior.IOR ; 42 import com.sun.corba.se.spi.ior.ObjectKey; 43 import com.sun.corba.se.spi.ior.ObjectKeyTemplate; 44 import com.sun.corba.se.spi.ior.ObjectAdapterId; 45 import com.sun.corba.se.spi.oa.ObjectAdapterFactory; 46 import com.sun.corba.se.spi.oa.ObjectAdapter; 47 import com.sun.corba.se.spi.oa.OAInvocationInfo; 48 import com.sun.corba.se.spi.oa.OADestroyed; 49 import com.sun.corba.se.spi.oa.NullServant; 50 import com.sun.corba.se.spi.protocol.CorbaMessageMediator; 51 import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher; 52 import com.sun.corba.se.spi.protocol.ForwardException ; 53 import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry; 54 import com.sun.corba.se.spi.transport.CorbaConnection; 55 import com.sun.corba.se.spi.logging.CORBALogDomains; 56 import com.sun.corba.se.spi.ior.iiop.GIOPVersion; 57 58 import com.sun.corba.se.impl.protocol.SpecialMethod ; 59 import com.sun.corba.se.spi.servicecontext.ServiceContext; 60 import com.sun.corba.se.spi.servicecontext.ServiceContexts; 61 import com.sun.corba.se.spi.servicecontext.UEInfoServiceContext; 62 import com.sun.corba.se.spi.servicecontext.CodeSetServiceContext; 63 import com.sun.corba.se.spi.servicecontext.SendingContextServiceContext; 64 import com.sun.corba.se.spi.servicecontext.ORBVersionServiceContext; 65 66 import com.sun.corba.se.impl.corba.ServerRequestImpl ; 67 import com.sun.corba.se.impl.encoding.MarshalInputStream; 68 import com.sun.corba.se.impl.encoding.MarshalOutputStream; 69 import com.sun.corba.se.impl.encoding.CodeSetComponentInfo; 70 import com.sun.corba.se.impl.encoding.OSFCodeSetRegistry; 71 import com.sun.corba.se.impl.orbutil.ORBConstants; 72 import com.sun.corba.se.impl.orbutil.ORBUtility; 73 import com.sun.corba.se.impl.protocol.RequestCanceledException; 74 import com.sun.corba.se.impl.logging.ORBUtilSystemException; 75 import com.sun.corba.se.impl.logging.POASystemException; 76 77 public class CorbaServerRequestDispatcherImpl 78 implements CorbaServerRequestDispatcher 79 { 80 protected ORB orb; private ORBUtilSystemException wrapper ; 82 private POASystemException poaWrapper ; 83 84 88 public CorbaServerRequestDispatcherImpl(ORB orb) 89 { 90 this.orb = orb; 91 wrapper = ORBUtilSystemException.get( orb, 92 CORBALogDomains.RPC_PROTOCOL ) ; 93 poaWrapper = POASystemException.get( orb, 94 CORBALogDomains.RPC_PROTOCOL ) ; 95 } 96 97 120 public IOR locate(ObjectKey okey) 121 { 122 try { 123 if (orb.subcontractDebugFlag) 124 dprint(".locate->"); 125 126 ObjectKeyTemplate oktemp = okey.getTemplate() ; 127 128 try { 129 checkServerId(okey); 130 } catch (ForwardException fex) { 131 return fex.getIOR() ; 132 } 133 134 findObjectAdapter(oktemp); 136 137 return null ; 138 } finally { 139 if (orb.subcontractDebugFlag) 140 dprint(".locate<-"); 141 } 142 } 143 144 public void dispatch(MessageMediator messageMediator) 145 { 146 CorbaMessageMediator request = (CorbaMessageMediator) messageMediator; 147 try { 148 if (orb.subcontractDebugFlag) { 149 dprint(".dispatch->: " + opAndId(request)); 150 } 151 152 consumeServiceContexts(request); 155 156 ((MarshalInputStream)request.getInputObject()) 160 .performORBVersionSpecificInit(); 161 162 ObjectKey okey = request.getObjectKey(); 163 164 try { 166 checkServerId(okey); 167 } catch (ForwardException fex) { 168 if (orb.subcontractDebugFlag) { 169 dprint(".dispatch: " + opAndId(request) 170 + ": bad server id"); 171 } 172 173 request.getProtocolHandler() 174 .createLocationForward(request, fex.getIOR(), null); 175 return; 176 } 177 178 String operation = request.getOperationName(); 179 ObjectAdapter objectAdapter = null ; 180 181 try { 182 byte[] objectId = okey.getId().getId() ; 183 ObjectKeyTemplate oktemp = okey.getTemplate() ; 184 objectAdapter = findObjectAdapter(oktemp); 185 186 java.lang.Object servant = getServantWithPI(request, objectAdapter, 187 objectId, oktemp, operation); 188 189 dispatchToServant(servant, request, objectId, objectAdapter); 190 } catch (ForwardException ex) { 191 if (orb.subcontractDebugFlag) { 192 dprint(".dispatch: " + opAndId(request) 193 + ": ForwardException caught"); 194 } 195 196 request.getProtocolHandler() 199 .createLocationForward(request, ex.getIOR(), null); 200 } catch (OADestroyed ex) { 201 if (orb.subcontractDebugFlag) { 202 dprint(".dispatch: " + opAndId(request) 203 + ": OADestroyed exception caught"); 204 } 205 206 212 dispatch(request); 215 } catch (RequestCanceledException ex) { 216 if (orb.subcontractDebugFlag) { 217 dprint(".dispatch: " + opAndId(request) 218 + ": RequestCanceledException caught"); 219 } 220 221 throw ex; 226 } catch (UnknownException ex) { 227 if (orb.subcontractDebugFlag) { 228 dprint(".dispatch: " + opAndId(request) 229 + ": UnknownException caught " + ex); 230 } 231 232 if (ex.originalEx instanceof RequestCanceledException) { 239 throw (RequestCanceledException) ex.originalEx; 240 } 241 242 ServiceContexts contexts = new ServiceContexts(orb); 243 UEInfoServiceContext usc = new UEInfoServiceContext( 244 ex.originalEx); 245 246 contexts.put( usc ) ; 247 248 SystemException sysex = wrapper.unknownExceptionInDispatch( 249 CompletionStatus.COMPLETED_MAYBE, ex ) ; 250 request.getProtocolHandler() 251 .createSystemExceptionResponse(request, sysex, 252 contexts); 253 } catch (Throwable ex) { 254 if (orb.subcontractDebugFlag) { 255 dprint(".dispatch: " + opAndId(request) 256 + ": other exception " + ex); 257 } 258 request.getProtocolHandler() 259 .handleThrowableDuringServerDispatch( 260 request, ex, CompletionStatus.COMPLETED_MAYBE); 261 } 262 return; 263 } finally { 264 if (orb.subcontractDebugFlag) { 265 dprint(".dispatch<-: " + opAndId(request)); 266 } 267 } 268 } 269 270 private void releaseServant(ObjectAdapter objectAdapter) 271 { 272 try { 273 if (orb.subcontractDebugFlag) { 274 dprint(".releaseServant->"); 275 } 276 277 if (objectAdapter == null) { 278 if (orb.subcontractDebugFlag) { 279 dprint(".releaseServant: null object adapter"); 280 } 281 return ; 282 } 283 284 try { 285 objectAdapter.returnServant(); 286 } finally { 287 objectAdapter.exit(); 288 orb.popInvocationInfo() ; 289 } 290 } finally { 291 if (orb.subcontractDebugFlag) { 292 dprint(".releaseServant<-"); 293 } 294 } 295 } 296 297 private java.lang.Object getServant(ObjectAdapter objectAdapter, byte[] objectId, 299 String operation) 300 throws OADestroyed 301 { 302 try { 303 if (orb.subcontractDebugFlag) { 304 dprint(".getServant->"); 305 } 306 307 OAInvocationInfo info = objectAdapter.makeInvocationInfo(objectId); 308 info.setOperation(operation); 309 orb.pushInvocationInfo(info); 310 objectAdapter.getInvocationServant(info); 311 return info.getServantContainer() ; 312 } finally { 313 if (orb.subcontractDebugFlag) { 314 dprint(".getServant<-"); 315 } 316 } 317 } 318 319 protected java.lang.Object getServantWithPI(CorbaMessageMediator request, 320 ObjectAdapter objectAdapter, 321 byte[] objectId, ObjectKeyTemplate oktemp, String operation) 322 throws OADestroyed 323 { 324 try { 325 if (orb.subcontractDebugFlag) { 326 dprint(".getServantWithPI->"); 327 } 328 329 orb.getPIHandler().initializeServerPIInfo(request, objectAdapter, 333 objectId, oktemp); 334 orb.getPIHandler().invokeServerPIStartingPoint(); 335 336 objectAdapter.enter() ; 337 338 if (request != null) 342 request.setExecuteReturnServantInResponseConstructor(true); 343 344 java.lang.Object servant = getServant(objectAdapter, objectId, 345 operation); 346 347 String mdi = "unknown" ; 352 353 if (servant instanceof NullServant) 354 handleNullServant(operation, (NullServant)servant); 355 else 356 mdi = objectAdapter.getInterfaces(servant, objectId)[0] ; 357 358 orb.getPIHandler().setServerPIInfo(servant, mdi); 359 360 if (((servant != null) && 361 !(servant instanceof org.omg.CORBA.DynamicImplementation ) && 362 !(servant instanceof org.omg.PortableServer.DynamicImplementation )) || 363 (SpecialMethod.getSpecialMethod(operation) != null)) { 364 orb.getPIHandler().invokeServerPIIntermediatePoint(); 365 } 366 367 return servant ; 368 } finally { 369 if (orb.subcontractDebugFlag) { 370 dprint(".getServantWithPI<-"); 371 } 372 } 373 } 374 375 protected void checkServerId(ObjectKey okey) 376 { 377 try { 378 if (orb.subcontractDebugFlag) { 379 dprint(".checkServerId->"); 380 } 381 382 ObjectKeyTemplate oktemp = okey.getTemplate() ; 383 int sId = oktemp.getServerId() ; 384 int scid = oktemp.getSubcontractId() ; 385 386 if (!orb.isLocalServerId(scid, sId)) { 387 if (orb.subcontractDebugFlag) { 388 dprint(".checkServerId: bad server id"); 389 } 390 391 orb.handleBadServerId(okey); 392 } 393 } finally { 394 if (orb.subcontractDebugFlag) { 395 dprint(".checkServerId<-"); 396 } 397 } 398 } 399 400 private ObjectAdapter findObjectAdapter(ObjectKeyTemplate oktemp) 401 { 402 try { 403 if (orb.subcontractDebugFlag) { 404 dprint(".findObjectAdapter->"); 405 } 406 407 RequestDispatcherRegistry scr = orb.getRequestDispatcherRegistry() ; 408 int scid = oktemp.getSubcontractId() ; 409 ObjectAdapterFactory oaf = scr.getObjectAdapterFactory(scid); 410 if (oaf == null) { 411 if (orb.subcontractDebugFlag) { 412 dprint(".findObjectAdapter: failed to find ObjectAdapterFactory"); 413 } 414 415 throw wrapper.noObjectAdapterFactory() ; 416 } 417 418 ObjectAdapterId oaid = oktemp.getObjectAdapterId() ; 419 ObjectAdapter oa = oaf.find(oaid); 420 421 if (oa == null) { 422 if (orb.subcontractDebugFlag) { 423 dprint(".findObjectAdapter: failed to find ObjectAdaptor"); 424 } 425 426 throw wrapper.badAdapterId() ; 427 } 428 429 return oa ; 430 } finally { 431 if (orb.subcontractDebugFlag) { 432 dprint(".findObjectAdapter<-"); 433 } 434 } 435 } 436 437 443 protected void handleNullServant(String operation, NullServant nserv ) 444 { 445 try { 446 if (orb.subcontractDebugFlag) { 447 dprint(".handleNullServant->: " + operation); 448 } 449 450 SpecialMethod specialMethod = 451 SpecialMethod.getSpecialMethod(operation); 452 453 if ((specialMethod == null) || 454 !specialMethod.isNonExistentMethod()) { 455 if (orb.subcontractDebugFlag) { 456 dprint(".handleNullServant: " + operation 457 + ": throwing OBJECT_NOT_EXIST"); 458 } 459 460 throw nserv.getException() ; 461 } 462 } finally { 463 if (orb.subcontractDebugFlag) { 464 dprint(".handleNullServant<-: " + operation); 465 } 466 } 467 } 468 469 protected void consumeServiceContexts(CorbaMessageMediator request) 470 { 471 try { 472 if (orb.subcontractDebugFlag) { 473 dprint(".consumeServiceContexts->: " 474 + opAndId(request)); 475 } 476 477 ServiceContexts ctxts = request.getRequestServiceContexts(); 478 ServiceContext sc ; 479 480 GIOPVersion giopVersion = request.getGIOPVersion(); 481 482 486 boolean hasCodeSetContext = processCodeSetContext(request, ctxts); 487 488 if (orb.subcontractDebugFlag) { 489 dprint(".consumeServiceContexts: " + opAndId(request) 490 + ": GIOP version: " + giopVersion); 491 dprint(".consumeServiceContexts: " + opAndId(request) 492 + ": as code set context? " + hasCodeSetContext); 493 } 494 495 sc = ctxts.get( 496 SendingContextServiceContext.SERVICE_CONTEXT_ID ) ; 497 498 if (sc != null) { 499 SendingContextServiceContext scsc = 500 (SendingContextServiceContext)sc ; 501 IOR ior = scsc.getIOR() ; 502 503 try { 504 ((CorbaConnection)request.getConnection()) 505 .setCodeBaseIOR(ior); 506 } catch (ThreadDeath td) { 507 throw td ; 508 } catch (Throwable t) { 509 throw wrapper.badStringifiedIor( t ) ; 510 } 511 } 512 513 519 524 boolean isForeignORB = false; 530 531 if (giopVersion.equals(GIOPVersion.V1_0) && hasCodeSetContext) { 532 if (orb.subcontractDebugFlag) { 533 dprint(".consumeServiceCOntexts: " + opAndId(request) 534 + ": Determined to be an old Sun ORB"); 535 } 536 537 orb.setORBVersion(ORBVersionFactory.getOLD()) ; 538 } else { 540 isForeignORB = true; 543 } 544 545 sc = ctxts.get( ORBVersionServiceContext.SERVICE_CONTEXT_ID ) ; 548 if (sc != null) { 549 ORBVersionServiceContext ovsc = 550 (ORBVersionServiceContext) sc; 551 552 ORBVersion version = ovsc.getVersion(); 553 orb.setORBVersion(version); 554 555 isForeignORB = false; 556 } 557 558 if (isForeignORB) { 559 if (orb.subcontractDebugFlag) { 560 dprint(".consumeServiceContexts: " + opAndId(request) 561 + ": Determined to be a foreign ORB"); 562 } 563 564 orb.setORBVersion(ORBVersionFactory.getFOREIGN()); 565 } 566 } finally { 567 if (orb.subcontractDebugFlag) { 568 dprint(".consumeServiceContexts<-: " + opAndId(request)); 569 } 570 } 571 } 572 573 protected CorbaMessageMediator dispatchToServant( 574 java.lang.Object servant, 575 CorbaMessageMediator req, 576 byte[] objectId, ObjectAdapter objectAdapter) 577 { 578 try { 579 if (orb.subcontractDebugFlag) { 580 dprint(".dispatchToServant->: " + opAndId(req)); 581 } 582 583 CorbaMessageMediator response = null ; 584 585 String operation = req.getOperationName() ; 586 587 SpecialMethod method = SpecialMethod.getSpecialMethod(operation) ; 588 if (method != null) { 589 if (orb.subcontractDebugFlag) { 590 dprint(".dispatchToServant: " + opAndId(req) 591 + ": Handling special method"); 592 } 593 594 response = method.invoke(servant, req, objectId, objectAdapter); 595 return response ; 596 } 597 598 if (servant instanceof org.omg.CORBA.DynamicImplementation ) { 600 if (orb.subcontractDebugFlag) { 601 dprint(".dispatchToServant: " + opAndId(req) 602 + ": Handling old style DSI type servant"); 603 } 604 605 org.omg.CORBA.DynamicImplementation dynimpl = 606 (org.omg.CORBA.DynamicImplementation )servant; 607 ServerRequestImpl sreq = new ServerRequestImpl(req, orb); 608 609 dynimpl.invoke(sreq); 612 613 response = handleDynamicResult(sreq, req); 614 } else if (servant instanceof org.omg.PortableServer.DynamicImplementation ) { 615 if (orb.subcontractDebugFlag) { 616 dprint(".dispatchToServant: " + opAndId(req) 617 + ": Handling POA DSI type servant"); 618 } 619 620 org.omg.PortableServer.DynamicImplementation dynimpl = 621 (org.omg.PortableServer.DynamicImplementation )servant; 622 ServerRequestImpl sreq = new ServerRequestImpl(req, orb); 623 624 dynimpl.invoke(sreq); 627 628 response = handleDynamicResult(sreq, req); 629 } else { 630 if (orb.subcontractDebugFlag) { 631 dprint(".dispatchToServant: " + opAndId(req) 632 + ": Handling invoke handler type servant"); 633 } 634 635 InvokeHandler invhandle = (InvokeHandler )servant ; 636 637 OutputStream stream = 638 (OutputStream )invhandle._invoke( 639 operation, 640 (org.omg.CORBA.portable.InputStream )req.getInputObject(), 641 req); 642 response = (CorbaMessageMediator) 643 ((OutputObject)stream).getMessageMediator(); 644 } 645 646 return response ; 647 } finally { 648 if (orb.subcontractDebugFlag) { 649 dprint(".dispatchToServant<-: " + opAndId(req)); 650 } 651 } 652 } 653 654 protected CorbaMessageMediator handleDynamicResult( 655 ServerRequestImpl sreq, 656 CorbaMessageMediator req) 657 { 658 try { 659 if (orb.subcontractDebugFlag) { 660 dprint(".handleDynamicResult->: " + opAndId(req)); 661 } 662 663 CorbaMessageMediator response = null ; 664 665 Any excany = sreq.checkResultCalled(); 667 668 if (excany == null) { if (orb.subcontractDebugFlag) { 670 dprint(".handleDynamicResult: " + opAndId(req) 671 + ": handling normal result"); 672 } 673 674 response = sendingReply(req); 676 OutputStream os = (OutputStream ) response.getOutputObject(); 677 sreq.marshalReplyParams(os); 678 } else { 679 if (orb.subcontractDebugFlag) { 680 dprint(".handleDynamicResult: " + opAndId(req) 681 + ": handling error"); 682 } 683 684 response = sendingReply(req, excany); 685 } 686 687 return response ; 688 } finally { 689 if (orb.subcontractDebugFlag) { 690 dprint(".handleDynamicResult<-: " + opAndId(req)); 691 } 692 } 693 } 694 695 protected CorbaMessageMediator sendingReply(CorbaMessageMediator req) 696 { 697 try { 698 if (orb.subcontractDebugFlag) { 699 dprint(".sendingReply->: " + opAndId(req)); 700 } 701 702 ServiceContexts scs = new ServiceContexts(orb); 703 return req.getProtocolHandler().createResponse(req, scs); 704 } finally { 705 if (orb.subcontractDebugFlag) { 706 dprint(".sendingReply<-: " + opAndId(req)); 707 } 708 } 709 } 710 711 715 protected CorbaMessageMediator sendingReply(CorbaMessageMediator req, Any excany) 716 { 717 try { 718 if (orb.subcontractDebugFlag) { 719 dprint(".sendingReply/Any->: " + opAndId(req)); 720 } 721 722 ServiceContexts scs = new ServiceContexts(orb); 723 724 CorbaMessageMediator resp; 727 String repId=null; 728 try { 729 repId = excany.type().id(); 730 } catch (org.omg.CORBA.TypeCodePackage.BadKind e) { 731 throw wrapper.problemWithExceptionTypecode( e ) ; 732 } 733 734 if (ORBUtility.isSystemException(repId)) { 735 if (orb.subcontractDebugFlag) { 736 dprint(".sendingReply/Any: " + opAndId(req) 737 + ": handling system exception"); 738 } 739 740 InputStream in = excany.create_input_stream(); 742 SystemException ex = ORBUtility.readSystemException(in); 743 resp = req.getProtocolHandler() 745 .createSystemExceptionResponse(req, ex, scs); 746 } else { 747 if (orb.subcontractDebugFlag) { 748 dprint(".sendingReply/Any: " + opAndId(req) 749 + ": handling user exception"); 750 } 751 752 resp = req.getProtocolHandler() 753 .createUserExceptionResponse(req, scs); 754 OutputStream os = (OutputStream )resp.getOutputObject(); 755 excany.write_value(os); 756 } 757 758 return resp; 759 } finally { 760 if (orb.subcontractDebugFlag) { 761 dprint(".sendingReply/Any<-: " + opAndId(req)); 762 } 763 } 764 } 765 766 771 protected boolean processCodeSetContext( 772 CorbaMessageMediator request, ServiceContexts contexts) 773 { 774 try { 775 if (orb.subcontractDebugFlag) { 776 dprint(".processCodeSetContext->: " + opAndId(request)); 777 } 778 779 ServiceContext sc = contexts.get( 780 CodeSetServiceContext.SERVICE_CONTEXT_ID); 781 if (sc != null) { 782 if (request.getConnection() == null) { 784 return true; 785 } 786 787 if (request.getGIOPVersion().equals(GIOPVersion.V1_0)) { 791 return true; 792 } 793 794 CodeSetServiceContext cssc = (CodeSetServiceContext)sc ; 795 CodeSetComponentInfo.CodeSetContext csctx = cssc.getCodeSetContext(); 796 797 808 if (((CorbaConnection)request.getConnection()) 811 .getCodeSetContext() == null) 812 { 813 814 if (orb.subcontractDebugFlag) { 816 dprint(".processCodeSetContext: " + opAndId(request) 817 + ": Setting code sets to: " + csctx); 818 } 819 820 ((CorbaConnection)request.getConnection()) 821 .setCodeSetContext(csctx); 822 823 if (csctx.getCharCodeSet() != 836 OSFCodeSetRegistry.ISO_8859_1.getNumber()) { 837 ((MarshalInputStream)request.getInputObject()) 838 .resetCodeSetConverters(); 839 } 840 } 841 } 842 843 return sc != null ; 851 } finally { 852 if (orb.subcontractDebugFlag) { 853 dprint(".processCodeSetContext<-: " + opAndId(request)); 854 } 855 } 856 } 857 858 protected void dprint(String msg) 859 { 860 ORBUtility.dprint("CorbaServerRequestDispatcherImpl", msg); 861 } 862 863 protected String opAndId(CorbaMessageMediator mediator) 864 { 865 return ORBUtility.operationNameAndRequestId(mediator); 866 } 867 } 868 869 871 | Popular Tags |