BootstrapServerRequestDispatcher.java revision 608:7e06bf1dcb09
1/*
2 * Copyright (c) 2002, 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
26package com.sun.corba.se.impl.protocol ;
27
28import java.util.Iterator ;
29
30import org.omg.CORBA.SystemException ;
31
32import com.sun.corba.se.pept.protocol.MessageMediator;
33
34import com.sun.corba.se.spi.ior.IOR ;
35import com.sun.corba.se.spi.ior.ObjectKey ;
36import com.sun.corba.se.spi.orb.ORB ;
37import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher ;
38import com.sun.corba.se.spi.protocol.CorbaMessageMediator;
39
40import com.sun.corba.se.impl.encoding.MarshalInputStream ;
41import com.sun.corba.se.impl.encoding.MarshalOutputStream ;
42
43import com.sun.corba.se.spi.logging.CORBALogDomains ;
44
45import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
46
47/**
48 * Class BootstrapServerRequestDispatcher handles the requests coming to the
49 * BootstrapServer. It implements Server so that it can be registered
50 * as a subcontract. It is passed a BootstrapServiceProperties object
51 * which contains
52 * the supported ids and their values for the bootstrap service. This
53 * Properties object is only read from, never written to, and is shared
54 * among all threads.
55 * <p>
56 * The BootstrapServerRequestDispatcher responds primarily to GIOP requests,
57 * but LocateRequests are also handled for graceful interoperability.
58 * The BootstrapServerRequestDispatcher handles one request at a time.
59 */
60public class BootstrapServerRequestDispatcher
61    implements CorbaServerRequestDispatcher
62{
63    private ORB orb;
64
65    ORBUtilSystemException wrapper ;
66
67    private static final boolean debug = false;
68
69    public BootstrapServerRequestDispatcher(ORB orb )
70    {
71        this.orb = orb;
72        this.wrapper = ORBUtilSystemException.get( orb,
73            CORBALogDomains.RPC_PROTOCOL ) ;
74    }
75
76    /**
77     * Dispatch is called by the ORB and will serve get(key) and list()
78     * invocations on the initial object key.
79     */
80    public void dispatch(MessageMediator messageMediator)
81    {
82        CorbaMessageMediator request = (CorbaMessageMediator) messageMediator;
83        CorbaMessageMediator response = null;
84
85        try {
86            MarshalInputStream is = (MarshalInputStream)
87                request.getInputObject();
88            String method = request.getOperationName();
89            response = request.getProtocolHandler().createResponse(request, null);
90            MarshalOutputStream os = (MarshalOutputStream)
91                response.getOutputObject();
92
93            if (method.equals("get")) {
94                // Get the name of the requested service
95                String serviceKey = is.read_string();
96
97                // Look it up
98                org.omg.CORBA.Object serviceObject =
99                    orb.getLocalResolver().resolve( serviceKey ) ;
100
101                // Write reply value
102                os.write_Object(serviceObject);
103            } else if (method.equals("list")) {
104                java.util.Set keys = orb.getLocalResolver().list() ;
105                os.write_long( keys.size() ) ;
106                Iterator iter = keys.iterator() ;
107                while (iter.hasNext()) {
108                    String obj = (String)iter.next() ;
109                    os.write_string( obj ) ;
110                }
111            } else {
112                throw wrapper.illegalBootstrapOperation( method ) ;
113            }
114
115        } catch (org.omg.CORBA.SystemException ex) {
116            // Marshal the exception thrown
117            response = request.getProtocolHandler().createSystemExceptionResponse(
118                request, ex, null);
119        } catch (java.lang.RuntimeException ex) {
120            // Unknown exception
121            SystemException sysex = wrapper.bootstrapRuntimeException( ex ) ;
122            response = request.getProtocolHandler().createSystemExceptionResponse(
123                 request, sysex, null ) ;
124        } catch (java.lang.Exception ex) {
125            // Unknown exception
126            SystemException sysex = wrapper.bootstrapException( ex ) ;
127            response = request.getProtocolHandler().createSystemExceptionResponse(
128                 request, sysex, null ) ;
129        }
130
131        return;
132    }
133
134    /**
135     * Locates the object mentioned in the locate requests, and returns
136     * object here iff the object is the initial object key. A SystemException
137     * thrown if the object key is not the initial object key.
138     */
139    public IOR locate( ObjectKey objectKey) {
140        return null;
141    }
142
143    /**
144     * Not implemented
145     */
146    public int getId() {
147        throw wrapper.genericNoImpl() ;
148    }
149}
150