1 /* 2 * Copyright (c) 2003, 2013, 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 import java.nio.ByteBuffer; 39 import java.security.AccessController; 40 import java.security.PrivilegedAction; 41 import javax.rmi.CORBA.Util; 42 import javax.rmi.CORBA.Tie; 43 44 import org.omg.CORBA.COMM_FAILURE; 45 import org.omg.CORBA.INTERNAL; 46 import org.omg.CORBA.SystemException; 47 import org.omg.CORBA.CompletionStatus; 48 import org.omg.CORBA.WrongTransaction; 49 import org.omg.CORBA.Request; 50 import org.omg.CORBA.NamedValue; 51 import org.omg.CORBA.NVList; 52 import org.omg.CORBA.Context; 53 import org.omg.CORBA.ContextList; 54 import org.omg.CORBA.ExceptionList; 55 import org.omg.CORBA.TypeCode; 56 import org.omg.CORBA.DATA_CONVERSION; 57 import org.omg.CORBA.UNKNOWN; 58 import org.omg.CORBA.portable.RemarshalException; 59 import org.omg.CORBA_2_3.portable.InputStream; 60 import org.omg.CORBA_2_3.portable.OutputStream; 61 import org.omg.CORBA.portable.Delegate; 62 import org.omg.CORBA.portable.ServantObject; 63 import org.omg.CORBA.portable.ApplicationException; 64 import org.omg.CORBA.portable.UnknownException; 65 import org.omg.IOP.TAG_CODE_SETS; 66 67 import com.sun.org.omg.SendingContext.CodeBase; 68 69 import com.sun.corba.se.pept.broker.Broker; 70 import com.sun.corba.se.pept.encoding.InputObject; 71 import com.sun.corba.se.pept.encoding.OutputObject; 72 import com.sun.corba.se.pept.protocol.ClientRequestDispatcher; 73 import com.sun.corba.se.pept.protocol.MessageMediator; 74 import com.sun.corba.se.pept.transport.Connection; 75 import com.sun.corba.se.pept.transport.ConnectionCache; 76 import com.sun.corba.se.pept.transport.ContactInfo; 77 78 import com.sun.corba.se.spi.ior.IOR; 79 import com.sun.corba.se.spi.ior.iiop.GIOPVersion; 80 import com.sun.corba.se.spi.ior.iiop.IIOPProfileTemplate; 81 import com.sun.corba.se.spi.ior.iiop.CodeSetsComponent; 82 import com.sun.corba.se.spi.oa.OAInvocationInfo; 83 import com.sun.corba.se.spi.oa.ObjectAdapterFactory; 84 import com.sun.corba.se.spi.orb.ORB; 85 import com.sun.corba.se.spi.orb.ORBVersion; 86 import com.sun.corba.se.spi.orb.ORBVersionFactory; 87 import com.sun.corba.se.spi.protocol.CorbaMessageMediator; 88 import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry; 89 import com.sun.corba.se.spi.transport.CorbaContactInfo ; 90 import com.sun.corba.se.spi.transport.CorbaContactInfoList ; 91 import com.sun.corba.se.spi.transport.CorbaContactInfoListIterator ; 92 import com.sun.corba.se.spi.transport.CorbaConnection; 93 94 import com.sun.corba.se.spi.servicecontext.ServiceContext; 95 import com.sun.corba.se.spi.servicecontext.ServiceContexts; 96 import com.sun.corba.se.spi.servicecontext.UEInfoServiceContext; 97 import com.sun.corba.se.spi.servicecontext.CodeSetServiceContext; 98 import com.sun.corba.se.spi.servicecontext.MaxStreamFormatVersionServiceContext; 99 import com.sun.corba.se.spi.servicecontext.SendingContextServiceContext; 100 import com.sun.corba.se.impl.encoding.ByteBufferWithInfo; 101 import com.sun.corba.se.impl.encoding.CDRInputObject; 102 import com.sun.corba.se.impl.encoding.CDROutputObject; 103 import com.sun.corba.se.impl.encoding.CDROutputStream; 104 import com.sun.corba.se.impl.encoding.CodeSetComponentInfo; 105 import com.sun.corba.se.impl.encoding.CodeSetConversion; 106 import com.sun.corba.se.impl.encoding.MarshalOutputStream; 107 import com.sun.corba.se.impl.encoding.MarshalInputStream; 108 import com.sun.corba.se.impl.orbutil.ORBUtility; 109 import com.sun.corba.se.impl.orbutil.ORBConstants; 110 import com.sun.corba.se.impl.protocol.giopmsgheaders.ReplyMessage; 111 import com.sun.corba.se.impl.protocol.giopmsgheaders.KeyAddr; 112 import com.sun.corba.se.impl.protocol.giopmsgheaders.ProfileAddr; 113 import com.sun.corba.se.impl.protocol.giopmsgheaders.ReferenceAddr; 114 import com.sun.corba.se.impl.transport.CorbaContactInfoListIteratorImpl; 115 import com.sun.corba.se.impl.protocol.giopmsgheaders.Message; 116 import com.sun.corba.se.impl.util.JDKBridge; 117 118 /** 119 * ClientDelegate is the RMI client-side subcontract or representation 120 * It implements RMI delegate as well as our internal ClientRequestDispatcher 121 * interface. 122 */ 123 public class SharedCDRClientRequestDispatcherImpl 124 extends 125 CorbaClientRequestDispatcherImpl 126 { 127 // REVISIT: 128 // Rather than have separate CDR subcontract, 129 // use same CorbaClientRequestDispatcherImpl but have 130 // different MessageMediator finishSendingRequest and waitForResponse 131 // handle what is done below. 132 // Benefit: then in ContactInfo no need to do a direct new 133 // of subcontract - does not complicate subcontract registry. 134 135 public InputObject marshalingComplete(java.lang.Object self, 136 OutputObject outputObject) 137 throws 138 ApplicationException, 139 org.omg.CORBA.portable.RemarshalException 140 { 141 ORB orb = null; 142 CorbaMessageMediator messageMediator = null; 143 try { 144 messageMediator = (CorbaMessageMediator) 145 outputObject.getMessageMediator(); 146 147 orb = (ORB) messageMediator.getBroker(); 148 149 if (orb.subcontractDebugFlag) { 150 dprint(".marshalingComplete->: " + opAndId(messageMediator)); 151 } 152 153 CDROutputObject cdrOutputObject = (CDROutputObject) outputObject; 154 155 // 156 // Create server-side input object. 157 // 158 159 ByteBufferWithInfo bbwi = cdrOutputObject.getByteBufferWithInfo(); 160 cdrOutputObject.getMessageHeader().setSize(bbwi.byteBuffer, bbwi.getSize()); 161 final ORB inOrb = orb; 162 final ByteBuffer inBuffer = bbwi.byteBuffer; 163 final Message inMsg = cdrOutputObject.getMessageHeader(); 164 CDRInputObject cdrInputObject = AccessController 165 .doPrivileged(new PrivilegedAction<CDRInputObject>() { 166 @Override 167 public CDRInputObject run() { 168 return new CDRInputObject(inOrb, null, inBuffer, 169 inMsg); 170 } 171 }); 172 messageMediator.setInputObject(cdrInputObject); 173 cdrInputObject.setMessageMediator(messageMediator); 174 175 // 176 // Dispatch 177 // 178 179 // REVISIT: Impl cast. 180 ((CorbaMessageMediatorImpl)messageMediator).handleRequestRequest( 181 messageMediator); 182 183 // InputStream must be closed on the InputObject so that its 184 // ByteBuffer can be released to the ByteBufferPool. We must do 185 // this before we re-assign the cdrInputObject reference below. 186 try { cdrInputObject.close(); } 187 catch (IOException ex) { 188 // No need to do anything since we're done with the input stream 189 // and cdrInputObject will be re-assigned a new client-side input 190 // object, (i.e. won't result in a corba error). 191 192 if (orb.transportDebugFlag) { 193 dprint(".marshalingComplete: ignoring IOException - " + ex.toString()); 194 } 195 } 196 197 // 198 // Create client-side input object 199 // 200 201 cdrOutputObject = (CDROutputObject) messageMediator.getOutputObject(); 202 bbwi = cdrOutputObject.getByteBufferWithInfo(); 203 cdrOutputObject.getMessageHeader().setSize(bbwi.byteBuffer, bbwi.getSize()); 204 final ORB inOrb2 = orb; 205 final ByteBuffer inBuffer2 = bbwi.byteBuffer; 206 final Message inMsg2 = cdrOutputObject.getMessageHeader(); 207 cdrInputObject = AccessController 208 .doPrivileged(new PrivilegedAction<CDRInputObject>() { 209 @Override 210 public CDRInputObject run() { 211 return new CDRInputObject(inOrb2, null, inBuffer2, 212 inMsg2); 213 } 214 }); 215 messageMediator.setInputObject(cdrInputObject); 216 cdrInputObject.setMessageMediator(messageMediator); 217 218 cdrInputObject.unmarshalHeader(); 219 220 InputObject inputObject = cdrInputObject; 221 222 return processResponse(orb, messageMediator, inputObject); 223 224 } finally { 225 if (orb.subcontractDebugFlag) { 226 dprint(".marshalingComplete<-: " + opAndId(messageMediator)); 227 } 228 } 229 } 230 231 protected void dprint(String msg) 232 { 233 ORBUtility.dprint("SharedCDRClientRequestDispatcherImpl", msg); 234 } 235 } 236 237 // End of file.