corba/src/share/classes/com/sun/corba/se/impl/protocol/oldlocal/LocalServerRequestImpl.sjava
changeset 19400 129989c42507
parent 19399 e2e5122cd62e
parent 19257 30a1d677a20c
child 19402 77755a81b73f
equal deleted inserted replaced
19399:e2e5122cd62e 19400:129989c42507
     1 /*
       
     2  * Copyright (c) 1999, 2003, 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 package com.sun.corba.se.impl.iiop;
       
    27 
       
    28 import org.omg.CORBA.SystemException;
       
    29 
       
    30 import com.sun.corba.se.impl.core.ServerRequest;
       
    31 import com.sun.corba.se.impl.core.ServiceContext;
       
    32 import com.sun.corba.se.impl.core.DuplicateServiceContext;
       
    33 import com.sun.corba.se.impl.core.UEInfoServiceContext;
       
    34 import com.sun.corba.se.impl.core.ServiceContexts;
       
    35 import com.sun.corba.se.impl.core.ServerResponse;
       
    36 import com.sun.corba.se.impl.corba.IOR;
       
    37 import com.sun.corba.se.impl.core.ORB;
       
    38 import com.sun.corba.se.impl.orbutil.ORBUtility;  //d11638
       
    39 import org.omg.CORBA.portable.UnknownException;
       
    40 import org.omg.CORBA.UNKNOWN;
       
    41 import org.omg.CORBA.CompletionStatus;
       
    42 import com.sun.corba.se.impl.ior.ObjectKey;
       
    43 import com.sun.corba.se.impl.protocol.giopmsgheaders.MessageBase;
       
    44 import com.sun.corba.se.impl.protocol.giopmsgheaders.ReplyMessage;
       
    45 import com.sun.corba.se.impl.protocol.giopmsgheaders.RequestMessage;
       
    46 
       
    47 class LocalServerRequestImpl extends IIOPInputStream implements ServerRequest {
       
    48     org.omg.CORBA.portable.OutputStream replyStream;
       
    49     org.omg.CORBA.portable.OutputStream exceptionReplyStream;
       
    50 
       
    51     LocalServerRequestImpl(ORB orb, byte[] buf, RequestMessage header)
       
    52     {
       
    53         super(orb, buf, header.getSize(), header.isLittleEndian(), header, null );
       
    54 
       
    55         this.request = header;
       
    56     }
       
    57 
       
    58     public int getRequestId() {
       
    59     	return request.getRequestId();
       
    60     }
       
    61 
       
    62     public boolean isOneWay() {
       
    63     	return !request.isResponseExpected();
       
    64     }
       
    65 
       
    66     public ServiceContexts getServiceContexts() {
       
    67     	return request.getServiceContexts();
       
    68     }
       
    69 
       
    70     public String getOperationName() {
       
    71     	return request.getOperation();
       
    72     }
       
    73 
       
    74     public ObjectKey getObjectKey() {
       
    75     	return request.getObjectKey();
       
    76     }
       
    77 
       
    78     public ServerResponse createResponse(ServiceContexts svc)
       
    79     {
       
    80     	return new LocalServerResponseImpl(this, svc);
       
    81     }
       
    82 
       
    83     public org.omg.CORBA.portable.OutputStream createReply() {
       
    84         if (replyStream == null) {
       
    85             replyStream = (org.omg.CORBA.portable.OutputStream)
       
    86                                 createResponse(null);
       
    87         }
       
    88         return replyStream;
       
    89     }
       
    90 
       
    91     public org.omg.CORBA.portable.OutputStream createExceptionReply() {
       
    92         if (exceptionReplyStream == null) {
       
    93             exceptionReplyStream = (org.omg.CORBA.portable.OutputStream)
       
    94                                         createUserExceptionResponse(null);
       
    95         }
       
    96         return exceptionReplyStream;
       
    97     }
       
    98 
       
    99     public ServerResponse createUserExceptionResponse(
       
   100 	ServiceContexts svc)
       
   101     {
       
   102     	return new LocalServerResponseImpl(this, svc, true);
       
   103     }
       
   104 
       
   105     public ServerResponse createUnknownExceptionResponse(
       
   106 	        UnknownException ex) {
       
   107         ServiceContexts contexts = null;
       
   108         SystemException sys = new UNKNOWN( 0,
       
   109             CompletionStatus.COMPLETED_MAYBE);
       
   110 
       
   111             try {
       
   112                 contexts = new ServiceContexts( (ORB)orb() );
       
   113                 UEInfoServiceContext uei = new UEInfoServiceContext(sys);
       
   114                 contexts.put(uei) ;
       
   115             } catch (DuplicateServiceContext d) {
       
   116             // can't happen
       
   117             }
       
   118 
       
   119         return createSystemExceptionResponse(sys,contexts);
       
   120     }
       
   121 
       
   122     public ServerResponse createSystemExceptionResponse(
       
   123     	SystemException ex, ServiceContexts svc) {
       
   124 
       
   125 	// Only do this if interceptors have been initialized on this request
       
   126 	// and have not completed their lifecycle (otherwise the info stack
       
   127 	// may be empty or have a different request's entry on top).
       
   128 	if (executePIInResponseConstructor()) {
       
   129 	    // Inform Portable Interceptors of the SystemException.  This is
       
   130 	    // required to be done here because the ending interception point
       
   131 	    // is called in the ServerResponseImpl constructor called below
       
   132 	    // but we do not currently write the SystemException into the
       
   133 	    // response until after the ending point is called.
       
   134 	    ORB orb = (ORB)orb();
       
   135 	    orb.getPIHandler().setServerPIInfo( ex );
       
   136 	}
       
   137 
       
   138 	if (orb() != null && ((ORB)orb()).subcontractDebugFlag && ex != null)
       
   139             ORBUtility.dprint(this, "Sending SystemException:", ex);
       
   140 
       
   141         LocalServerResponseImpl response =
       
   142             new LocalServerResponseImpl(this, svc, false);
       
   143         ORBUtility.writeSystemException(ex, response);
       
   144         return response;
       
   145     }
       
   146 
       
   147     public ServerResponse createLocationForward(
       
   148 	        IOR ior, ServiceContexts svc) {
       
   149         ReplyMessage reply = MessageBase.createReply( (ORB)orb(),
       
   150 	    request.getGIOPVersion(), request.getRequestId(),
       
   151 	    ReplyMessage.LOCATION_FORWARD, svc, ior);
       
   152         LocalServerResponseImpl response =
       
   153             new LocalServerResponseImpl(this, reply, ior);
       
   154 
       
   155         return response;
       
   156     }
       
   157 
       
   158     private RequestMessage request;
       
   159 
       
   160     /**
       
   161      * Check to see if the request is local.
       
   162      */
       
   163     public boolean isLocal(){
       
   164         return true;
       
   165     }
       
   166 
       
   167     private boolean _executeReturnServantInResponseConstructor = false;
       
   168 
       
   169     public boolean executeReturnServantInResponseConstructor()
       
   170     {
       
   171 	return _executeReturnServantInResponseConstructor;
       
   172     }
       
   173 
       
   174     public void setExecuteReturnServantInResponseConstructor(boolean b)
       
   175     {
       
   176 	_executeReturnServantInResponseConstructor = b;
       
   177     }
       
   178 
       
   179     
       
   180     private boolean _executeRemoveThreadInfoInResponseConstructor = false;
       
   181 
       
   182     public boolean executeRemoveThreadInfoInResponseConstructor()
       
   183     {
       
   184 	return _executeRemoveThreadInfoInResponseConstructor;
       
   185     }
       
   186 
       
   187     public void setExecuteRemoveThreadInfoInResponseConstructor(boolean b)
       
   188     {
       
   189 	_executeRemoveThreadInfoInResponseConstructor = b;
       
   190     }
       
   191 
       
   192     
       
   193     private boolean _executePIInResponseConstructor = false;
       
   194                                                             
       
   195     public boolean executePIInResponseConstructor() {
       
   196         return _executePIInResponseConstructor;
       
   197     }
       
   198 
       
   199     public void setExecutePIInResponseConstructor( boolean b ) {
       
   200         _executePIInResponseConstructor = b;
       
   201     }
       
   202 
       
   203     // We know that we're talking to the same ValueHandler, so
       
   204     // use the maximum version it supports.
       
   205     public byte getStreamFormatVersionForReply() {
       
   206         return ORBUtility.getMaxStreamFormatVersion();
       
   207     }
       
   208 }