src/share/classes/com/sun/corba/se/impl/protocol/BootstrapServerRequestDispatcher.java

Thu, 31 Aug 2017 18:10:36 +0800

author
aoqi
date
Thu, 31 Aug 2017 18:10:36 +0800
changeset 748
6845b95cba6b
parent 158
91006f157c46
parent 0
7ef37b2cdcad
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.corba.se.impl.protocol ;
aoqi@0 27
aoqi@0 28 import java.util.Iterator ;
aoqi@0 29
aoqi@0 30 import org.omg.CORBA.SystemException ;
aoqi@0 31
aoqi@0 32 import com.sun.corba.se.pept.protocol.MessageMediator;
aoqi@0 33
aoqi@0 34 import com.sun.corba.se.spi.ior.IOR ;
aoqi@0 35 import com.sun.corba.se.spi.ior.ObjectKey ;
aoqi@0 36 import com.sun.corba.se.spi.orb.ORB ;
aoqi@0 37 import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher ;
aoqi@0 38 import com.sun.corba.se.spi.protocol.CorbaMessageMediator;
aoqi@0 39
aoqi@0 40 import com.sun.corba.se.impl.encoding.MarshalInputStream ;
aoqi@0 41 import com.sun.corba.se.impl.encoding.MarshalOutputStream ;
aoqi@0 42
aoqi@0 43 import com.sun.corba.se.spi.logging.CORBALogDomains ;
aoqi@0 44
aoqi@0 45 import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
aoqi@0 46
aoqi@0 47 /**
aoqi@0 48 * Class BootstrapServerRequestDispatcher handles the requests coming to the
aoqi@0 49 * BootstrapServer. It implements Server so that it can be registered
aoqi@0 50 * as a subcontract. It is passed a BootstrapServiceProperties object
aoqi@0 51 * which contains
aoqi@0 52 * the supported ids and their values for the bootstrap service. This
aoqi@0 53 * Properties object is only read from, never written to, and is shared
aoqi@0 54 * among all threads.
aoqi@0 55 * <p>
aoqi@0 56 * The BootstrapServerRequestDispatcher responds primarily to GIOP requests,
aoqi@0 57 * but LocateRequests are also handled for graceful interoperability.
aoqi@0 58 * The BootstrapServerRequestDispatcher handles one request at a time.
aoqi@0 59 */
aoqi@0 60 public class BootstrapServerRequestDispatcher
aoqi@0 61 implements CorbaServerRequestDispatcher
aoqi@0 62 {
aoqi@0 63 private ORB orb;
aoqi@0 64
aoqi@0 65 ORBUtilSystemException wrapper ;
aoqi@0 66
aoqi@0 67 private static final boolean debug = false;
aoqi@0 68
aoqi@0 69 public BootstrapServerRequestDispatcher(ORB orb )
aoqi@0 70 {
aoqi@0 71 this.orb = orb;
aoqi@0 72 this.wrapper = ORBUtilSystemException.get( orb,
aoqi@0 73 CORBALogDomains.RPC_PROTOCOL ) ;
aoqi@0 74 }
aoqi@0 75
aoqi@0 76 /**
aoqi@0 77 * Dispatch is called by the ORB and will serve get(key) and list()
aoqi@0 78 * invocations on the initial object key.
aoqi@0 79 */
aoqi@0 80 public void dispatch(MessageMediator messageMediator)
aoqi@0 81 {
aoqi@0 82 CorbaMessageMediator request = (CorbaMessageMediator) messageMediator;
aoqi@0 83 CorbaMessageMediator response = null;
aoqi@0 84
aoqi@0 85 try {
aoqi@0 86 MarshalInputStream is = (MarshalInputStream)
aoqi@0 87 request.getInputObject();
aoqi@0 88 String method = request.getOperationName();
aoqi@0 89 response = request.getProtocolHandler().createResponse(request, null);
aoqi@0 90 MarshalOutputStream os = (MarshalOutputStream)
aoqi@0 91 response.getOutputObject();
aoqi@0 92
aoqi@0 93 if (method.equals("get")) {
aoqi@0 94 // Get the name of the requested service
aoqi@0 95 String serviceKey = is.read_string();
aoqi@0 96
aoqi@0 97 // Look it up
aoqi@0 98 org.omg.CORBA.Object serviceObject =
aoqi@0 99 orb.getLocalResolver().resolve( serviceKey ) ;
aoqi@0 100
aoqi@0 101 // Write reply value
aoqi@0 102 os.write_Object(serviceObject);
aoqi@0 103 } else if (method.equals("list")) {
aoqi@0 104 java.util.Set keys = orb.getLocalResolver().list() ;
aoqi@0 105 os.write_long( keys.size() ) ;
aoqi@0 106 Iterator iter = keys.iterator() ;
aoqi@0 107 while (iter.hasNext()) {
aoqi@0 108 String obj = (String)iter.next() ;
aoqi@0 109 os.write_string( obj ) ;
aoqi@0 110 }
aoqi@0 111 } else {
aoqi@0 112 throw wrapper.illegalBootstrapOperation( method ) ;
aoqi@0 113 }
aoqi@0 114
aoqi@0 115 } catch (org.omg.CORBA.SystemException ex) {
aoqi@0 116 // Marshal the exception thrown
aoqi@0 117 response = request.getProtocolHandler().createSystemExceptionResponse(
aoqi@0 118 request, ex, null);
aoqi@0 119 } catch (java.lang.RuntimeException ex) {
aoqi@0 120 // Unknown exception
aoqi@0 121 SystemException sysex = wrapper.bootstrapRuntimeException( ex ) ;
aoqi@0 122 response = request.getProtocolHandler().createSystemExceptionResponse(
aoqi@0 123 request, sysex, null ) ;
aoqi@0 124 } catch (java.lang.Exception ex) {
aoqi@0 125 // Unknown exception
aoqi@0 126 SystemException sysex = wrapper.bootstrapException( ex ) ;
aoqi@0 127 response = request.getProtocolHandler().createSystemExceptionResponse(
aoqi@0 128 request, sysex, null ) ;
aoqi@0 129 }
aoqi@0 130
aoqi@0 131 return;
aoqi@0 132 }
aoqi@0 133
aoqi@0 134 /**
aoqi@0 135 * Locates the object mentioned in the locate requests, and returns
aoqi@0 136 * object here iff the object is the initial object key. A SystemException
aoqi@0 137 * thrown if the object key is not the initial object key.
aoqi@0 138 */
aoqi@0 139 public IOR locate( ObjectKey objectKey) {
aoqi@0 140 return null;
aoqi@0 141 }
aoqi@0 142
aoqi@0 143 /**
aoqi@0 144 * Not implemented
aoqi@0 145 */
aoqi@0 146 public int getId() {
aoqi@0 147 throw wrapper.genericNoImpl() ;
aoqi@0 148 }
aoqi@0 149 }

mercurial