Save This Page
Home » openjdk-7 » com.sun.corba.se.impl » protocol » [javadoc | source]
    1   /*
    2    * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
    3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    4    *
    5    * This code is free software; you can redistribute it and/or modify it
    6    * under the terms of the GNU General Public License version 2 only, as
    7    * published by the Free Software Foundation.  Oracle designates this
    8    * particular file as subject to the "Classpath" exception as provided
    9    * by Oracle in the LICENSE file that accompanied this code.
   10    *
   11    * This code is distributed in the hope that it will be useful, but WITHOUT
   12    * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13    * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   14    * version 2 for more details (a copy is included in the LICENSE file that
   15    * accompanied this code).
   16    *
   17    * You should have received a copy of the GNU General Public License version
   18    * 2 along with this work; if not, write to the Free Software Foundation,
   19    * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   20    *
   21    * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   22    * or visit www.oracle.com if you need additional information or have any
   23    * questions.
   24    */
   25   
   26   /*
   27    * Licensed Materials - Property of IBM
   28    * RMI-IIOP v1.0
   29    * Copyright IBM Corp. 1998 1999  All Rights Reserved
   30    *
   31    */
   32   
   33   package com.sun.corba.se.impl.protocol;
   34   
   35   import java.io.IOException;
   36   import java.util.Iterator;
   37   import java.rmi.RemoteException;
   38   
   39   import javax.rmi.CORBA.Util;
   40   import javax.rmi.CORBA.Tie;
   41   
   42   import org.omg.CORBA.COMM_FAILURE;
   43   import org.omg.CORBA.INTERNAL;
   44   import org.omg.CORBA.SystemException;
   45   import org.omg.CORBA.Request;
   46   import org.omg.CORBA.NamedValue;
   47   import org.omg.CORBA.NVList;
   48   import org.omg.CORBA.Context;
   49   import org.omg.CORBA.ContextList;
   50   import org.omg.CORBA.ExceptionList;
   51   import org.omg.CORBA.TypeCode;
   52   import org.omg.CORBA.portable.RemarshalException;
   53   import org.omg.CORBA_2_3.portable.InputStream;
   54   import org.omg.CORBA_2_3.portable.OutputStream;
   55   import org.omg.CORBA.portable.Delegate;
   56   import org.omg.CORBA.portable.ServantObject;
   57   import org.omg.CORBA.portable.ApplicationException;
   58   import org.omg.CORBA.portable.UnknownException;
   59   import org.omg.IOP.ExceptionDetailMessage;
   60   import org.omg.IOP.TAG_CODE_SETS;
   61   
   62   import com.sun.org.omg.SendingContext.CodeBase;
   63   
   64   import com.sun.corba.se.pept.broker.Broker;
   65   import com.sun.corba.se.pept.encoding.InputObject;
   66   import com.sun.corba.se.pept.encoding.OutputObject;
   67   import com.sun.corba.se.pept.protocol.ClientRequestDispatcher;
   68   import com.sun.corba.se.pept.protocol.MessageMediator;
   69   import com.sun.corba.se.pept.transport.Connection;
   70   import com.sun.corba.se.pept.transport.OutboundConnectionCache;
   71   import com.sun.corba.se.pept.transport.ContactInfo;
   72   
   73   import com.sun.corba.se.spi.ior.IOR;
   74   import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
   75   import com.sun.corba.se.spi.ior.iiop.IIOPProfileTemplate;
   76   import com.sun.corba.se.spi.ior.iiop.CodeSetsComponent;
   77   import com.sun.corba.se.spi.oa.OAInvocationInfo;
   78   import com.sun.corba.se.spi.oa.ObjectAdapterFactory;
   79   import com.sun.corba.se.spi.orb.ORB;
   80   import com.sun.corba.se.spi.orb.ORBVersion;
   81   import com.sun.corba.se.spi.orb.ORBVersionFactory;
   82   import com.sun.corba.se.spi.protocol.CorbaMessageMediator;
   83   import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry;
   84   import com.sun.corba.se.spi.transport.CorbaContactInfo;
   85   import com.sun.corba.se.spi.transport.CorbaContactInfoList;
   86   import com.sun.corba.se.spi.transport.CorbaContactInfoListIterator;
   87   import com.sun.corba.se.spi.transport.CorbaConnection;
   88   import com.sun.corba.se.spi.logging.CORBALogDomains;
   89   
   90   import com.sun.corba.se.spi.servicecontext.MaxStreamFormatVersionServiceContext;
   91   import com.sun.corba.se.spi.servicecontext.ServiceContext;
   92   import com.sun.corba.se.spi.servicecontext.ServiceContexts;
   93   import com.sun.corba.se.spi.servicecontext.UEInfoServiceContext;
   94   import com.sun.corba.se.spi.servicecontext.CodeSetServiceContext;
   95   import com.sun.corba.se.spi.servicecontext.SendingContextServiceContext;
   96   import com.sun.corba.se.spi.servicecontext.ORBVersionServiceContext;
   97   import com.sun.corba.se.spi.servicecontext.MaxStreamFormatVersionServiceContext;
   98   import com.sun.corba.se.spi.servicecontext.UnknownServiceContext;
   99   
  100   import com.sun.corba.se.impl.encoding.CDRInputObject;
  101   import com.sun.corba.se.impl.encoding.CodeSetComponentInfo;
  102   import com.sun.corba.se.impl.encoding.CodeSetConversion;
  103   import com.sun.corba.se.impl.encoding.EncapsInputStream;
  104   import com.sun.corba.se.impl.encoding.MarshalOutputStream;
  105   import com.sun.corba.se.impl.encoding.MarshalInputStream;
  106   import com.sun.corba.se.impl.logging.ORBUtilSystemException;
  107   import com.sun.corba.se.impl.orbutil.ORBUtility;
  108   import com.sun.corba.se.impl.orbutil.ORBConstants;
  109   import com.sun.corba.se.impl.protocol.giopmsgheaders.ReplyMessage;
  110   import com.sun.corba.se.impl.protocol.giopmsgheaders.KeyAddr;
  111   import com.sun.corba.se.impl.protocol.giopmsgheaders.ProfileAddr;
  112   import com.sun.corba.se.impl.protocol.giopmsgheaders.ReferenceAddr;
  113   import com.sun.corba.se.impl.transport.CorbaContactInfoListIteratorImpl;
  114   import com.sun.corba.se.impl.util.JDKBridge;
  115   
  116   /**
  117    * ClientDelegate is the RMI client-side subcontract or representation
  118    * It implements RMI delegate as well as our internal ClientRequestDispatcher
  119    * interface.
  120    */
  121   public class CorbaClientRequestDispatcherImpl
  122       implements
  123           ClientRequestDispatcher
  124   {
  125       public OutputObject beginRequest(Object self, String opName,
  126                                        boolean isOneWay, ContactInfo contactInfo)
  127       {
  128         ORB orb = null;
  129         try {
  130           CorbaContactInfo corbaContactInfo = (CorbaContactInfo) contactInfo;
  131           orb =  (ORB)contactInfo.getBroker();
  132   
  133           if (orb.subcontractDebugFlag) {
  134               dprint(".beginRequest->: op/" + opName);
  135           }
  136   
  137           //
  138           // Portable Interceptor initialization.
  139           //
  140   
  141           orb.getPIHandler().initiateClientPIRequest( false );
  142   
  143           //
  144           // Connection.
  145           //
  146   
  147           CorbaConnection connection = null;
  148   
  149           // This locking is done so that multiple connections are not created
  150           // for the same endpoint
  151           //6929137 - Synchronized on contactInfo to avoid blocking across multiple endpoints
  152           synchronized (contactInfo) {
  153               if (contactInfo.isConnectionBased()) {
  154                   if (contactInfo.shouldCacheConnection()) {
  155                       connection = (CorbaConnection)
  156                           orb.getTransportManager()
  157                           .getOutboundConnectionCache(contactInfo).get(contactInfo);
  158                   }
  159                   if (connection != null) {
  160                       if (orb.subcontractDebugFlag) {
  161                           dprint(".beginRequest: op/" + opName
  162                                  + ": Using cached connection: " + connection);
  163                       }
  164                   } else {
  165                       try {
  166                           connection = (CorbaConnection)
  167                               contactInfo.createConnection();
  168                           if (orb.subcontractDebugFlag) {
  169                               dprint(".beginRequest: op/" + opName
  170                                      + ": Using created connection: " + connection);
  171                           }
  172                       } catch (RuntimeException e) {
  173                           if (orb.subcontractDebugFlag) {
  174                               dprint(".beginRequest: op/" + opName
  175                                      + ": failed to create connection: " + e);
  176                           }
  177                           // REVISIT: this part similar to marshalingComplete below.
  178                           boolean retry = getContactInfoListIterator(orb)
  179                                              .reportException(contactInfo, e);
  180                           // REVISIT:
  181                           // this part similar to Remarshal in this method below
  182                           if (retry) {
  183                               if(getContactInfoListIterator(orb).hasNext()) {
  184                                   contactInfo = (ContactInfo)
  185                                      getContactInfoListIterator(orb).next();
  186                                   unregisterWaiter(orb);
  187                                   return beginRequest(self, opName,
  188                                                       isOneWay, contactInfo);
  189                               } else {
  190                                   throw e;
  191                               }
  192                           } else {
  193                               throw e;
  194                           }
  195                       }
  196                       if (connection.shouldRegisterReadEvent()) {
  197                           // REVISIT: cast
  198                           orb.getTransportManager().getSelector(0)
  199                               .registerForEvent(connection.getEventHandler());
  200                           connection.setState("ESTABLISHED");
  201                       }
  202                       // Do not do connection reclaim here since the connections
  203                       // are marked in use by registerWaiter() call and since this
  204                       // call happens later do it after that.
  205                       if (contactInfo.shouldCacheConnection()) {
  206                           OutboundConnectionCache connectionCache =
  207                            orb.getTransportManager()
  208                               .getOutboundConnectionCache(contactInfo);
  209                           connectionCache.stampTime(connection);
  210                           connectionCache.put(contactInfo, connection);
  211       //              connectionCache.reclaim();
  212                       }
  213                   }
  214               }
  215           }
  216   
  217           CorbaMessageMediator messageMediator = (CorbaMessageMediator)
  218               contactInfo.createMessageMediator(
  219                   orb, contactInfo, connection, opName, isOneWay);
  220           if (orb.subcontractDebugFlag) {
  221               dprint(".beginRequest: " + opAndId(messageMediator)
  222                      + ": created message mediator: " +  messageMediator);
  223           }
  224   
  225           // NOTE: Thread data so we can get the mediator in release reply
  226           // in order to remove the waiter in CorbaConnection.
  227           // We cannot depend on obtaining information in releaseReply
  228           // via its InputStream argument since, on certain errors
  229           // (e.g., client marshaling errors), the stream may be null.
  230           // Likewise for releaseReply "self".
  231           // NOTE: This must be done before initializing the message since
  232           // that may start sending fragments which may end up in "early"
  233           // replies or client marshaling exceptions.
  234   
  235           orb.getInvocationInfo().setMessageMediator(messageMediator);
  236   
  237           if (connection != null && connection.getCodeSetContext() == null) {
  238               performCodeSetNegotiation(messageMediator);
  239           }
  240   
  241           addServiceContexts(messageMediator);
  242   
  243           OutputObject outputObject =
  244               contactInfo.createOutputObject(messageMediator);
  245           if (orb.subcontractDebugFlag) {
  246               dprint(".beginRequest: " + opAndId(messageMediator)
  247                      + ": created output object: " + outputObject);
  248           }
  249   
  250   
  251           // NOTE: Not necessary for oneways, but useful for debugging.
  252           // This must be done BEFORE message initialization since fragments
  253           // may be sent at that time.
  254           registerWaiter(messageMediator);
  255   
  256           // Do connection reclaim now
  257           synchronized (contactInfo) {
  258               if (contactInfo.isConnectionBased()) {
  259                   if (contactInfo.shouldCacheConnection()) {
  260                       OutboundConnectionCache connectionCache =
  261                                orb.getTransportManager()
  262                                   .getOutboundConnectionCache(contactInfo);
  263                       connectionCache.reclaim();
  264                   }
  265               }
  266           }
  267   
  268           orb.getPIHandler().setClientPIInfo(messageMediator);
  269           try {
  270               // This MUST come before message is initialized so
  271               // service contexts may be added by PI because
  272               // initial fragments may be sent during message initialization.
  273               orb.getPIHandler().invokeClientPIStartingPoint();
  274           } catch( RemarshalException e ) {
  275               if (orb.subcontractDebugFlag) {
  276                   dprint(".beginRequest: " + opAndId(messageMediator)
  277                          + ": Remarshal");
  278               }
  279   
  280               // NOTE: We get here because an interceptor raised ForwardRequest
  281               // and updated the IOR/Iterator.  Since we have a fresh iterator
  282               // hasNext should succeed.
  283   
  284               // REVISIT: We should feed ALL interceptor exceptions to
  285               // iterator.reportException so it can determine if it wants
  286               // to retry.  Right now, SystemExceptions will flow to the
  287               // client code.
  288   
  289               // REVISIT:
  290               // This assumes that interceptors update
  291               // ContactInfoList outside of subcontract.
  292               // Want to move that update to here.
  293               if (getContactInfoListIterator(orb).hasNext()) {
  294                   contactInfo = (ContactInfo)getContactInfoListIterator(orb).next();
  295                   if (orb.subcontractDebugFlag) {
  296                       dprint( "RemarshalException: hasNext true\ncontact info " + contactInfo );
  297                   }
  298   
  299                   // Fix for 6763340: Complete the first attempt before starting another.
  300                   orb.getPIHandler().makeCompletedClientRequest(
  301                       ReplyMessage.LOCATION_FORWARD, null ) ;
  302                   unregisterWaiter(orb);
  303                   orb.getPIHandler().cleanupClientPIRequest() ;
  304   
  305                   return beginRequest(self, opName, isOneWay, contactInfo);
  306               } else {
  307                   if (orb.subcontractDebugFlag) {
  308                       dprint( "RemarshalException: hasNext false" );
  309                   }
  310                   ORBUtilSystemException wrapper =
  311                       ORBUtilSystemException.get(orb,
  312                                                  CORBALogDomains.RPC_PROTOCOL);
  313                   throw wrapper.remarshalWithNowhereToGo();
  314               }
  315           }
  316   
  317           messageMediator.initializeMessage();
  318           if (orb.subcontractDebugFlag) {
  319               dprint(".beginRequest: " + opAndId(messageMediator)
  320                      + ": initialized message");
  321           }
  322   
  323           return outputObject;
  324   
  325         } finally {
  326           if (orb.subcontractDebugFlag) {
  327               dprint(".beginRequest<-: op/" + opName);
  328           }
  329         }
  330       }
  331   
  332       public InputObject marshalingComplete(java.lang.Object self,
  333                                             OutputObject outputObject)
  334           throws
  335               ApplicationException,
  336               org.omg.CORBA.portable.RemarshalException
  337       {
  338           ORB orb = null;
  339           CorbaMessageMediator messageMediator = null;
  340           try {
  341               messageMediator = (CorbaMessageMediator)
  342                   outputObject.getMessageMediator();
  343   
  344               orb = (ORB) messageMediator.getBroker();
  345   
  346               if (orb.subcontractDebugFlag) {
  347                   dprint(".marshalingComplete->: " + opAndId(messageMediator));
  348               }
  349   
  350               InputObject inputObject =
  351                   marshalingComplete1(orb, messageMediator);
  352   
  353               return processResponse(orb, messageMediator, inputObject);
  354   
  355           } finally {
  356               if (orb.subcontractDebugFlag) {
  357                   dprint(".marshalingComplete<-: " + opAndId(messageMediator));
  358               }
  359           }
  360       }
  361   
  362       public InputObject marshalingComplete1(
  363               ORB orb, CorbaMessageMediator messageMediator)
  364           throws
  365               ApplicationException,
  366               org.omg.CORBA.portable.RemarshalException
  367       {
  368           try {
  369               messageMediator.finishSendingRequest();
  370   
  371               if (orb.subcontractDebugFlag) {
  372                   dprint(".marshalingComplete: " + opAndId(messageMediator)
  373                          + ": finished sending request");
  374               }
  375   
  376               return messageMediator.waitForResponse();
  377   
  378           } catch (RuntimeException e) {
  379   
  380               if (orb.subcontractDebugFlag) {
  381                   dprint(".marshalingComplete: " + opAndId(messageMediator)
  382                          + ": exception: " + e.toString());
  383               }
  384   
  385               boolean retry  =
  386                   getContactInfoListIterator(orb)
  387                       .reportException(messageMediator.getContactInfo(), e);
  388   
  389               //Bug 6382377: must not lose exception in PI
  390   
  391               // Must run interceptor end point before retrying.
  392               Exception newException =
  393                       orb.getPIHandler().invokeClientPIEndingPoint(
  394                       ReplyMessage.SYSTEM_EXCEPTION, e);
  395   
  396               if (retry) {
  397                   if (newException == e) {
  398                       continueOrThrowSystemOrRemarshal(messageMediator,
  399                                                        new RemarshalException());
  400                   } else {
  401                       continueOrThrowSystemOrRemarshal(messageMediator,
  402                                                        newException);
  403                   }
  404               } else {
  405                   if (newException instanceof RuntimeException){
  406                       throw (RuntimeException)newException;
  407                   }
  408                   else if (newException instanceof RemarshalException)
  409                   {
  410                       throw (RemarshalException)newException;
  411                   }
  412   
  413                   // NOTE: Interceptor ending point will run in releaseReply.
  414                   throw e;
  415               }
  416               return null; // for compiler
  417           }
  418       }
  419   
  420       protected InputObject processResponse(ORB orb,
  421                                             CorbaMessageMediator messageMediator,
  422                                             InputObject inputObject)
  423           throws
  424               ApplicationException,
  425               org.omg.CORBA.portable.RemarshalException
  426       {
  427           ORBUtilSystemException wrapper =
  428               ORBUtilSystemException.get( orb,
  429                   CORBALogDomains.RPC_PROTOCOL ) ;
  430   
  431           if (orb.subcontractDebugFlag) {
  432               dprint(".processResponse: " + opAndId(messageMediator)
  433                      + ": response received");
  434           }
  435   
  436           // We know for sure now that we've sent a message.
  437           // So OK to not send initial again.
  438           if (messageMediator.getConnection() != null) {
  439               ((CorbaConnection)messageMediator.getConnection())
  440                   .setPostInitialContexts();
  441           }
  442   
  443           // NOTE: not necessary to set MessageMediator for PI.
  444           // It already has it.
  445   
  446           // Process the response.
  447   
  448           Exception exception = null;
  449   
  450           if (messageMediator.isOneWay()) {
  451               getContactInfoListIterator(orb)
  452                   .reportSuccess(messageMediator.getContactInfo());
  453               // Invoke Portable Interceptors with receive_other
  454               exception = orb.getPIHandler().invokeClientPIEndingPoint(
  455                   ReplyMessage.NO_EXCEPTION, exception );
  456               continueOrThrowSystemOrRemarshal(messageMediator, exception);
  457               return null;
  458           }
  459   
  460           consumeServiceContexts(orb, messageMediator);
  461   
  462           // Now that we have the service contexts processed and the
  463           // correct ORBVersion set, we must finish initializing the stream.
  464           // REVISIT - need interface for this operation.
  465           ((CDRInputObject)inputObject).performORBVersionSpecificInit();
  466   
  467           if (messageMediator.isSystemExceptionReply()) {
  468   
  469               SystemException se = messageMediator.getSystemExceptionReply();
  470   
  471               if (orb.subcontractDebugFlag) {
  472                   dprint(".processResponse: " + opAndId(messageMediator)
  473                          + ": received system exception: " + se);
  474               }
  475   
  476               boolean doRemarshal =
  477                   getContactInfoListIterator(orb)
  478                       .reportException(messageMediator.getContactInfo(), se);
  479   
  480               if (doRemarshal) {
  481   
  482                   // Invoke Portable Interceptors with receive_exception:
  483                   exception = orb.getPIHandler().invokeClientPIEndingPoint(
  484                       ReplyMessage.SYSTEM_EXCEPTION, se );
  485   
  486                   // If PI did not change the exception, throw a
  487                   // Remarshal.
  488                   if( se == exception ) {
  489                       // exception = null is to maintain symmetry with
  490                       // GenericPOAClientSC.
  491                       exception = null;
  492                       continueOrThrowSystemOrRemarshal(messageMediator,
  493                                                        new RemarshalException());
  494                       throw wrapper.statementNotReachable1() ;
  495                   } else {
  496                       //  Otherwise, throw the exception PI wants thrown.
  497                       continueOrThrowSystemOrRemarshal(messageMediator,
  498                                                        exception);
  499                       throw wrapper.statementNotReachable2() ;
  500                   }
  501               }
  502   
  503               // No retry, so see if was unknown.
  504   
  505               ServiceContexts contexts =
  506                   messageMediator.getReplyServiceContexts();
  507               if (contexts != null) {
  508                   UEInfoServiceContext usc =
  509                       (UEInfoServiceContext)
  510                       contexts.get(UEInfoServiceContext.SERVICE_CONTEXT_ID);
  511   
  512                   if (usc != null) {
  513                       Throwable unknown = usc.getUE() ;
  514                       UnknownException ue = new UnknownException(unknown);
  515   
  516                       // Invoke Portable Interceptors with receive_exception:
  517                       exception = orb.getPIHandler().invokeClientPIEndingPoint(
  518                           ReplyMessage.SYSTEM_EXCEPTION, ue );
  519   
  520                       continueOrThrowSystemOrRemarshal(messageMediator, exception);
  521                       throw wrapper.statementNotReachable3() ;
  522                   }
  523               }
  524   
  525               // It was not a comm failure nor unknown.
  526               // This is the general case.
  527   
  528               // Invoke Portable Interceptors with receive_exception:
  529               exception = orb.getPIHandler().invokeClientPIEndingPoint(
  530                   ReplyMessage.SYSTEM_EXCEPTION, se );
  531   
  532               continueOrThrowSystemOrRemarshal(messageMediator, exception);
  533   
  534               // Note: We should never need to execute this line, but
  535               // we should assert in case exception is null somehow.
  536               throw wrapper.statementNotReachable4() ;
  537           } else if (messageMediator.isUserExceptionReply()) {
  538   
  539               if (orb.subcontractDebugFlag) {
  540                   dprint(".processResponse: " + opAndId(messageMediator)
  541                          + ": received user exception");
  542               }
  543   
  544               getContactInfoListIterator(orb)
  545                   .reportSuccess(messageMediator.getContactInfo());
  546   
  547               String exceptionRepoId = peekUserExceptionId(inputObject);
  548               Exception newException = null;
  549   
  550               if (messageMediator.isDIIRequest()) {
  551                   exception = messageMediator.unmarshalDIIUserException(
  552                                   exceptionRepoId, (InputStream)inputObject);
  553                   newException = orb.getPIHandler().invokeClientPIEndingPoint(
  554                                      ReplyMessage.USER_EXCEPTION, exception );
  555                   messageMediator.setDIIException(newException);
  556   
  557               } else {
  558                   ApplicationException appException =
  559                       new ApplicationException(
  560                           exceptionRepoId,
  561                           (org.omg.CORBA.portable.InputStream)inputObject);
  562                   exception = appException;
  563                   newException = orb.getPIHandler().invokeClientPIEndingPoint(
  564                                      ReplyMessage.USER_EXCEPTION, appException );
  565               }
  566   
  567               if (newException != exception) {
  568                   continueOrThrowSystemOrRemarshal(messageMediator,newException);
  569               }
  570   
  571               if (newException instanceof ApplicationException) {
  572                   throw (ApplicationException)newException;
  573               }
  574               // For DII:
  575               // This return will be ignored - already unmarshaled above.
  576               return inputObject;
  577   
  578           } else if (messageMediator.isLocationForwardReply()) {
  579   
  580               if (orb.subcontractDebugFlag) {
  581                   dprint(".processResponse: " + opAndId(messageMediator)
  582                          + ": received location forward");
  583               }
  584   
  585               // NOTE: Expects iterator to update target IOR
  586               getContactInfoListIterator(orb).reportRedirect(
  587                   (CorbaContactInfo)messageMediator.getContactInfo(),
  588                   messageMediator.getForwardedIOR());
  589   
  590               // Invoke Portable Interceptors with receive_other:
  591               Exception newException = orb.getPIHandler().invokeClientPIEndingPoint(
  592                   ReplyMessage.LOCATION_FORWARD, null );
  593   
  594               if( !(newException instanceof RemarshalException) ) {
  595                   exception = newException;
  596               }
  597   
  598               // If PI did not change exception, throw Remarshal, else
  599               // throw the exception PI wants thrown.
  600               // KMC: GenericPOAClientSC did not check exception != null
  601               if( exception != null ) {
  602                   continueOrThrowSystemOrRemarshal(messageMediator, exception);
  603               }
  604               continueOrThrowSystemOrRemarshal(messageMediator,
  605                                                new RemarshalException());
  606               throw wrapper.statementNotReachable5() ;
  607   
  608           } else if (messageMediator.isDifferentAddrDispositionRequestedReply()){
  609   
  610               if (orb.subcontractDebugFlag) {
  611                   dprint(".processResponse: " + opAndId(messageMediator)
  612                          + ": received different addressing dispostion request");
  613               }
  614   
  615               // Set the desired target addressing disposition.
  616               getContactInfoListIterator(orb).reportAddrDispositionRetry(
  617                   (CorbaContactInfo)messageMediator.getContactInfo(),
  618                   messageMediator.getAddrDispositionReply());
  619   
  620               // Invoke Portable Interceptors with receive_other:
  621               Exception newException = orb.getPIHandler().invokeClientPIEndingPoint(
  622                   ReplyMessage.NEEDS_ADDRESSING_MODE, null);
  623   
  624               // For consistency with corresponding code in GenericPOAClientSC:
  625               if( !(newException instanceof RemarshalException) ) {
  626                   exception = newException;
  627               }
  628   
  629               // If PI did not change exception, throw Remarshal, else
  630               // throw the exception PI wants thrown.
  631               // KMC: GenericPOAClientSC did not include exception != null check
  632               if( exception != null ) {
  633                   continueOrThrowSystemOrRemarshal(messageMediator, exception);
  634               }
  635               continueOrThrowSystemOrRemarshal(messageMediator,
  636                                                new RemarshalException());
  637               throw wrapper.statementNotReachable6() ;
  638           } else /* normal response */ {
  639   
  640               if (orb.subcontractDebugFlag) {
  641                   dprint(".processResponse: " + opAndId(messageMediator)
  642                          + ": received normal response");
  643               }
  644   
  645               getContactInfoListIterator(orb)
  646                   .reportSuccess(messageMediator.getContactInfo());
  647   
  648               messageMediator.handleDIIReply((InputStream)inputObject);
  649   
  650               // Invoke Portable Interceptors with receive_reply:
  651               exception = orb.getPIHandler().invokeClientPIEndingPoint(
  652                   ReplyMessage.NO_EXCEPTION, null );
  653   
  654               // Remember: not thrown if exception is null.
  655               continueOrThrowSystemOrRemarshal(messageMediator, exception);
  656   
  657               return inputObject;
  658           }
  659       }
  660   
  661       // Filters the given exception into a SystemException or a
  662       // RemarshalException and throws it.  Assumes the given exception is
  663       // of one of these two types.  This is a utility method for
  664       // the above invoke code which must do this numerous times.
  665       // If the exception is null, no exception is thrown.
  666       //
  667       // Note that this code is duplicated in GenericPOAClientSC.java
  668       protected void continueOrThrowSystemOrRemarshal(
  669           CorbaMessageMediator messageMediator, Exception exception)
  670           throws
  671               SystemException, RemarshalException
  672       {
  673   
  674           ORB orb = (ORB) messageMediator.getBroker();
  675   
  676           if( exception == null ) {
  677   
  678               // do nothing.
  679   
  680           } else if( exception instanceof RemarshalException ) {
  681   
  682               // REVISIT - unify with PI handling
  683               orb.getInvocationInfo().setIsRetryInvocation(true);
  684   
  685               // NOTE - We must unregister the waiter NOW for this request
  686               // since the retry will result in a new request id.  Therefore
  687               // the old request id would be lost and we would have a memory
  688               // leak in the responseWaitingRoom.
  689               unregisterWaiter(orb);
  690   
  691               if (orb.subcontractDebugFlag) {
  692                   dprint(".continueOrThrowSystemOrRemarshal: "
  693                          + opAndId(messageMediator)
  694                          + ": throwing Remarshal");
  695               }
  696   
  697               throw (RemarshalException)exception;
  698   
  699           } else {
  700   
  701               if (orb.subcontractDebugFlag) {
  702                   dprint(".continueOrThrowSystemOrRemarshal: "
  703                          + opAndId(messageMediator)
  704                          + ": throwing sex:"
  705                          + exception);
  706               }
  707   
  708               throw (SystemException)exception;
  709           }
  710       }
  711   
  712       protected CorbaContactInfoListIterator  getContactInfoListIterator(ORB orb)
  713       {
  714           return (CorbaContactInfoListIterator)
  715               ((CorbaInvocationInfo)orb.getInvocationInfo())
  716                   .getContactInfoListIterator();
  717       }
  718   
  719       protected void registerWaiter(CorbaMessageMediator messageMediator)
  720       {
  721           if (messageMediator.getConnection() != null) {
  722               messageMediator.getConnection().registerWaiter(messageMediator);
  723           }
  724       }
  725   
  726       protected void unregisterWaiter(ORB orb)
  727       {
  728           MessageMediator messageMediator =
  729               orb.getInvocationInfo().getMessageMediator();
  730           if (messageMediator!=null && messageMediator.getConnection() != null) {
  731               // REVISIT:
  732               // The messageMediator may be null if COMM_FAILURE before
  733               // it is created.
  734               messageMediator.getConnection().unregisterWaiter(messageMediator);
  735           }
  736       }
  737   
  738       protected void addServiceContexts(CorbaMessageMediator messageMediator)
  739       {
  740           ORB orb = (ORB)messageMediator.getBroker();
  741           CorbaConnection c = (CorbaConnection) messageMediator.getConnection();
  742           GIOPVersion giopVersion = messageMediator.getGIOPVersion();
  743   
  744           ServiceContexts contexts = messageMediator.getRequestServiceContexts();
  745   
  746           addCodeSetServiceContext(c, contexts, giopVersion);
  747   
  748           // Add the RMI-IIOP max stream format version
  749           // service context to every request.  Once we have GIOP 1.3,
  750           // we could skip it since we now support version 2, but
  751           // probably safer to always send it.
  752           contexts.put(MaxStreamFormatVersionServiceContext.singleton);
  753   
  754           // ORBVersion servicecontext needs to be sent
  755           ORBVersionServiceContext ovsc = new ORBVersionServiceContext(
  756                           ORBVersionFactory.getORBVersion() ) ;
  757           contexts.put( ovsc ) ;
  758   
  759           // NOTE : We only want to send the runtime context the first time
  760           if ((c != null) && !c.isPostInitialContexts()) {
  761               // Do not do c.setPostInitialContexts() here.
  762               // If a client interceptor send_request does a ForwardRequest
  763               // which ends up using the same connection then the service
  764               // context would not be sent.
  765               SendingContextServiceContext scsc =
  766                   new SendingContextServiceContext( orb.getFVDCodeBaseIOR() ) ; //d11638
  767               contexts.put( scsc ) ;
  768           }
  769       }
  770   
  771       protected void consumeServiceContexts(ORB orb,
  772                                           CorbaMessageMediator messageMediator)
  773       {
  774           ServiceContexts ctxts = messageMediator.getReplyServiceContexts();
  775           ServiceContext sc ;
  776           ORBUtilSystemException wrapper = ORBUtilSystemException.get( orb,
  777                   CORBALogDomains.RPC_PROTOCOL ) ;
  778   
  779           if (ctxts == null) {
  780               return; // no service context available, return gracefully.
  781           }
  782   
  783           sc = ctxts.get( SendingContextServiceContext.SERVICE_CONTEXT_ID ) ;
  784   
  785           if (sc != null) {
  786               SendingContextServiceContext scsc =
  787                   (SendingContextServiceContext)sc ;
  788               IOR ior = scsc.getIOR() ;
  789   
  790               try {
  791                   // set the codebase returned by the server
  792                   if (messageMediator.getConnection() != null) {
  793                       ((CorbaConnection)messageMediator.getConnection()).setCodeBaseIOR(ior);
  794                   }
  795               } catch (ThreadDeath td) {
  796                   throw td ;
  797               } catch (Throwable t) {
  798                   throw wrapper.badStringifiedIor( t ) ;
  799               }
  800           }
  801   
  802           // see if the version subcontract is present, if yes, then set
  803           // the ORBversion
  804           sc = ctxts.get( ORBVersionServiceContext.SERVICE_CONTEXT_ID ) ;
  805   
  806           if (sc != null) {
  807               ORBVersionServiceContext ovsc =
  808                  (ORBVersionServiceContext) sc;
  809   
  810               ORBVersion version = ovsc.getVersion();
  811               orb.setORBVersion( version ) ;
  812           }
  813   
  814           getExceptionDetailMessage(messageMediator, wrapper);
  815       }
  816   
  817       protected void getExceptionDetailMessage(
  818           CorbaMessageMediator  messageMediator,
  819           ORBUtilSystemException wrapper)
  820       {
  821           ServiceContext sc = messageMediator.getReplyServiceContexts()
  822               .get(ExceptionDetailMessage.value);
  823           if (sc == null)
  824               return ;
  825   
  826           if (! (sc instanceof UnknownServiceContext)) {
  827               throw wrapper.badExceptionDetailMessageServiceContextType();
  828           }
  829           byte[] data = ((UnknownServiceContext)sc).getData();
  830           EncapsInputStream in =
  831               new EncapsInputStream((ORB)messageMediator.getBroker(),
  832                                     data, data.length);
  833           in.consumeEndian();
  834   
  835           String msg =
  836                 "----------BEGIN server-side stack trace----------\n"
  837               + in.read_wstring() + "\n"
  838               + "----------END server-side stack trace----------";
  839   
  840           messageMediator.setReplyExceptionDetailMessage(msg);
  841       }
  842   
  843       public void endRequest(Broker broker, Object self, InputObject inputObject)
  844       {
  845           ORB orb = (ORB)broker ;
  846   
  847           try {
  848               if (orb.subcontractDebugFlag) {
  849                   dprint(".endRequest->");
  850               }
  851   
  852               // Note: the inputObject may be null if an error occurs
  853               //       in request or before _invoke returns.
  854               // Note: self may be null also (e.g., compiler generates null in stub).
  855   
  856               MessageMediator messageMediator =
  857                   orb.getInvocationInfo().getMessageMediator();
  858               if (messageMediator != null)
  859               {
  860                   if (messageMediator.getConnection() != null)
  861                   {
  862                       ((CorbaMessageMediator)messageMediator)
  863                                 .sendCancelRequestIfFinalFragmentNotSent();
  864                   }
  865   
  866                   // Release any outstanding NIO ByteBuffers to the ByteBufferPool
  867   
  868                   InputObject inputObj = messageMediator.getInputObject();
  869                   if (inputObj != null) {
  870                       inputObj.close();
  871                   }
  872   
  873                   OutputObject outputObj = messageMediator.getOutputObject();
  874                   if (outputObj != null) {
  875                       outputObj.close();
  876                   }
  877   
  878               }
  879   
  880               // XREVISIT NOTE - Assumes unregistering the waiter for
  881               // location forwards has already happened somewhere else.
  882               // The code below is only going to unregister the final successful
  883               // request.
  884   
  885               // NOTE: In the case of a recursive stack of endRequests in a
  886               // finally block (because of Remarshal) only the first call to
  887               // unregisterWaiter will remove the waiter.  The rest will be
  888               // noops.
  889               unregisterWaiter(orb);
  890   
  891               // Invoke Portable Interceptors cleanup.  This is done to handle
  892               // exceptions during stream marshaling.  More generally, exceptions
  893               // that occur in the ORB after send_request (which includes
  894               // after returning from _request) before _invoke:
  895               orb.getPIHandler().cleanupClientPIRequest();
  896   
  897               // REVISIT: Early replies?
  898           } catch (IOException ex) {
  899               // See CDRInput/OutputObject.close() for more info.
  900               // This won't result in a Corba error if an IOException happens.
  901               if (orb.subcontractDebugFlag)
  902               {
  903                   dprint(".endRequest: ignoring IOException - " + ex.toString());
  904               }
  905           } finally {
  906               if (orb.subcontractDebugFlag) {
  907                   dprint(".endRequest<-");
  908               }
  909           }
  910       }
  911   
  912   
  913       protected void performCodeSetNegotiation(CorbaMessageMediator messageMediator)
  914       {
  915           CorbaConnection conn =
  916               (CorbaConnection) messageMediator.getConnection();
  917           IOR ior =
  918               ((CorbaContactInfo)messageMediator.getContactInfo())
  919               .getEffectiveTargetIOR();
  920           GIOPVersion giopVersion = messageMediator.getGIOPVersion();
  921   
  922           // XXX This seems to be a broken double checked locking idiom: FIX IT!
  923   
  924           // conn.getCodeSetContext() is null when no other requests have
  925           // been made on this connection to trigger code set negotation.
  926           if (conn != null &&
  927               conn.getCodeSetContext() == null &&
  928               !giopVersion.equals(GIOPVersion.V1_0)) {
  929   
  930               synchronized(conn) {
  931                   // Double checking.  Don't let any other
  932                   // threads use this connection until the
  933                   // code sets are straight.
  934                   if (conn.getCodeSetContext() != null)
  935                       return;
  936   
  937                   // This only looks at the first code set component.  If
  938                   // there can be multiple locations with multiple code sets,
  939                   // this requires more work.
  940                   IIOPProfileTemplate temp =
  941                       (IIOPProfileTemplate)ior.getProfile().
  942                       getTaggedProfileTemplate();
  943                   Iterator iter = temp.iteratorById(TAG_CODE_SETS.value);
  944                   if (!iter.hasNext()) {
  945                       // Didn't have a code set component.  The default will
  946                       // be to use ISO8859-1 for char data and throw an
  947                       // exception if wchar data is used.
  948                       return;
  949                   }
  950   
  951                   // Get the native and conversion code sets the
  952                   // server specified in its IOR
  953                   CodeSetComponentInfo serverCodeSets
  954                       = ((CodeSetsComponent)iter.next()).getCodeSetComponentInfo();
  955   
  956                   // Perform the negotiation between this ORB's code sets and
  957                   // the ones from the IOR
  958                   CodeSetComponentInfo.CodeSetContext result
  959                       = CodeSetConversion.impl().negotiate(
  960                             conn.getBroker().getORBData().getCodeSetComponentInfo(),
  961                             serverCodeSets);
  962   
  963                   conn.setCodeSetContext(result);
  964               }
  965           }
  966       }
  967   
  968       protected void addCodeSetServiceContext(CorbaConnection conn,
  969                                             ServiceContexts ctxs,
  970                                             GIOPVersion giopVersion) {
  971   
  972           // REVISIT.  OMG issue 3318 concerning sending the code set
  973           // service context more than once was deemed too much for the
  974           // RTF.  Here's our strategy for the moment:
  975           //
  976           // Send it on every request (necessary in cases of fragmentation
  977           // with multithreaded clients or when the first thing on a
  978           // connection is a LocateRequest).  Provide an ORB property
  979           // to disable multiple sends.
  980           //
  981           // Note that the connection is null in the local case and no
  982           // service context is included.  We use the ORB provided
  983           // encapsulation streams.
  984           //
  985           // Also, there will be no negotiation or service context
  986           // in GIOP 1.0.  ISO8859-1 is used for char/string, and
  987           // wchar/wstring are illegal.
  988           //
  989           if (giopVersion.equals(GIOPVersion.V1_0) || conn == null)
  990               return;
  991   
  992           CodeSetComponentInfo.CodeSetContext codeSetCtx = null;
  993   
  994           if (conn.getBroker().getORBData().alwaysSendCodeSetServiceContext() ||
  995               !conn.isPostInitialContexts()) {
  996   
  997               // Get the negotiated code sets (if any) out of the connection
  998               codeSetCtx = conn.getCodeSetContext();
  999           }
 1000   
 1001           // Either we shouldn't send the code set service context, or
 1002           // for some reason, the connection doesn't have its code sets.
 1003           // Perhaps the server didn't include them in the IOR.  Uses
 1004           // ISO8859-1 for char and makes wchar/wstring illegal.
 1005           if (codeSetCtx == null)
 1006               return;
 1007   
 1008           CodeSetServiceContext cssc = new CodeSetServiceContext(codeSetCtx);
 1009           ctxs.put(cssc);
 1010       }
 1011   
 1012       protected String peekUserExceptionId(InputObject inputObject)
 1013       {
 1014           CDRInputObject cdrInputObject = (CDRInputObject) inputObject;
 1015           // REVISIT - need interface for mark/reset
 1016           cdrInputObject.mark(Integer.MAX_VALUE);
 1017           String result = cdrInputObject.read_string();
 1018           cdrInputObject.reset();
 1019           return result;
 1020       }
 1021   
 1022       protected void dprint(String msg)
 1023       {
 1024           ORBUtility.dprint("CorbaClientRequestDispatcherImpl", msg);
 1025       }
 1026   
 1027       protected String opAndId(CorbaMessageMediator mediator)
 1028       {
 1029           return ORBUtility.operationNameAndRequestId(mediator);
 1030       }
 1031   }
 1032   
 1033   // End of file.

Save This Page
Home » openjdk-7 » com.sun.corba.se.impl » protocol » [javadoc | source]