SharedCDRClientRequestDispatcherImpl.java revision 608:7e06bf1dcb09
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
33package com.sun.corba.se.impl.protocol;
34
35import java.io.IOException;
36import java.util.Iterator;
37import java.rmi.RemoteException;
38import java.nio.ByteBuffer;
39import java.security.AccessController;
40import java.security.PrivilegedAction;
41import javax.rmi.CORBA.Util;
42import javax.rmi.CORBA.Tie;
43
44import org.omg.CORBA.COMM_FAILURE;
45import org.omg.CORBA.INTERNAL;
46import org.omg.CORBA.SystemException;
47import org.omg.CORBA.CompletionStatus;
48import org.omg.CORBA.WrongTransaction;
49import org.omg.CORBA.Request;
50import org.omg.CORBA.NamedValue;
51import org.omg.CORBA.NVList;
52import org.omg.CORBA.Context;
53import org.omg.CORBA.ContextList;
54import org.omg.CORBA.ExceptionList;
55import org.omg.CORBA.TypeCode;
56import org.omg.CORBA.DATA_CONVERSION;
57import org.omg.CORBA.UNKNOWN;
58import org.omg.CORBA.portable.RemarshalException;
59import org.omg.CORBA_2_3.portable.InputStream;
60import org.omg.CORBA_2_3.portable.OutputStream;
61import org.omg.CORBA.portable.Delegate;
62import org.omg.CORBA.portable.ServantObject;
63import org.omg.CORBA.portable.ApplicationException;
64import org.omg.CORBA.portable.UnknownException;
65import org.omg.IOP.TAG_CODE_SETS;
66
67import com.sun.org.omg.SendingContext.CodeBase;
68
69import com.sun.corba.se.pept.broker.Broker;
70import com.sun.corba.se.pept.encoding.InputObject;
71import com.sun.corba.se.pept.encoding.OutputObject;
72import com.sun.corba.se.pept.protocol.ClientRequestDispatcher;
73import com.sun.corba.se.pept.protocol.MessageMediator;
74import com.sun.corba.se.pept.transport.Connection;
75import com.sun.corba.se.pept.transport.ConnectionCache;
76import com.sun.corba.se.pept.transport.ContactInfo;
77
78import com.sun.corba.se.spi.ior.IOR;
79import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
80import com.sun.corba.se.spi.ior.iiop.IIOPProfileTemplate;
81import com.sun.corba.se.spi.ior.iiop.CodeSetsComponent;
82import com.sun.corba.se.spi.oa.OAInvocationInfo;
83import com.sun.corba.se.spi.oa.ObjectAdapterFactory;
84import com.sun.corba.se.spi.orb.ORB;
85import com.sun.corba.se.spi.orb.ORBVersion;
86import com.sun.corba.se.spi.orb.ORBVersionFactory;
87import com.sun.corba.se.spi.protocol.CorbaMessageMediator;
88import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry;
89import com.sun.corba.se.spi.transport.CorbaContactInfo ;
90import com.sun.corba.se.spi.transport.CorbaContactInfoList ;
91import com.sun.corba.se.spi.transport.CorbaContactInfoListIterator ;
92import com.sun.corba.se.spi.transport.CorbaConnection;
93
94import com.sun.corba.se.spi.servicecontext.ServiceContext;
95import com.sun.corba.se.spi.servicecontext.ServiceContexts;
96import com.sun.corba.se.spi.servicecontext.UEInfoServiceContext;
97import com.sun.corba.se.spi.servicecontext.CodeSetServiceContext;
98import com.sun.corba.se.spi.servicecontext.MaxStreamFormatVersionServiceContext;
99import com.sun.corba.se.spi.servicecontext.SendingContextServiceContext;
100import com.sun.corba.se.impl.encoding.ByteBufferWithInfo;
101import com.sun.corba.se.impl.encoding.CDRInputObject;
102import com.sun.corba.se.impl.encoding.CDROutputObject;
103import com.sun.corba.se.impl.encoding.CDROutputStream;
104import com.sun.corba.se.impl.encoding.CodeSetComponentInfo;
105import com.sun.corba.se.impl.encoding.CodeSetConversion;
106import com.sun.corba.se.impl.encoding.MarshalOutputStream;
107import com.sun.corba.se.impl.encoding.MarshalInputStream;
108import com.sun.corba.se.impl.orbutil.ORBUtility;
109import com.sun.corba.se.impl.orbutil.ORBConstants;
110import com.sun.corba.se.impl.protocol.giopmsgheaders.ReplyMessage;
111import com.sun.corba.se.impl.protocol.giopmsgheaders.KeyAddr;
112import com.sun.corba.se.impl.protocol.giopmsgheaders.ProfileAddr;
113import com.sun.corba.se.impl.protocol.giopmsgheaders.ReferenceAddr;
114import com.sun.corba.se.impl.transport.CorbaContactInfoListIteratorImpl;
115import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
116import 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 */
123public 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.
238