1. /*
  2. * @(#)BootstrapServerRequestDispatcher.java 1.25 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.impl.protocol ;
  8. import java.util.Iterator ;
  9. import org.omg.CORBA.SystemException ;
  10. import com.sun.corba.se.pept.protocol.MessageMediator;
  11. import com.sun.corba.se.spi.ior.IOR ;
  12. import com.sun.corba.se.spi.ior.ObjectKey ;
  13. import com.sun.corba.se.spi.orb.ORB ;
  14. import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher ;
  15. import com.sun.corba.se.spi.protocol.CorbaMessageMediator;
  16. import com.sun.corba.se.impl.encoding.MarshalInputStream ;
  17. import com.sun.corba.se.impl.encoding.MarshalOutputStream ;
  18. import com.sun.corba.se.spi.logging.CORBALogDomains ;
  19. import com.sun.corba.se.impl.logging.ORBUtilSystemException ;
  20. /**
  21. * Class BootstrapServerRequestDispatcher handles the requests coming to the
  22. * BootstrapServer. It implements Server so that it can be registered
  23. * as a subcontract. It is passed a BootstrapServiceProperties object
  24. * which contains
  25. * the supported ids and their values for the bootstrap service. This
  26. * Properties object is only read from, never written to, and is shared
  27. * among all threads.
  28. * <p>
  29. * The BootstrapServerRequestDispatcher responds primarily to GIOP requests,
  30. * but LocateRequests are also handled for graceful interoperability.
  31. * The BootstrapServerRequestDispatcher handles one request at a time.
  32. */
  33. public class BootstrapServerRequestDispatcher
  34. implements CorbaServerRequestDispatcher
  35. {
  36. private ORB orb;
  37. ORBUtilSystemException wrapper ;
  38. private static final boolean debug = false;
  39. public BootstrapServerRequestDispatcher(ORB orb )
  40. {
  41. this.orb = orb;
  42. this.wrapper = ORBUtilSystemException.get( orb,
  43. CORBALogDomains.RPC_PROTOCOL ) ;
  44. }
  45. /**
  46. * Dispatch is called by the ORB and will serve get(key) and list()
  47. * invocations on the initial object key.
  48. */
  49. public void dispatch(MessageMediator messageMediator)
  50. {
  51. CorbaMessageMediator request = (CorbaMessageMediator) messageMediator;
  52. CorbaMessageMediator response = null;
  53. try {
  54. MarshalInputStream is = (MarshalInputStream)
  55. request.getInputObject();
  56. String method = request.getOperationName();
  57. response = request.getProtocolHandler().createResponse(request, null);
  58. MarshalOutputStream os = (MarshalOutputStream)
  59. response.getOutputObject();
  60. if (method.equals("get")) {
  61. // Get the name of the requested service
  62. String serviceKey = is.read_string();
  63. // Look it up
  64. org.omg.CORBA.Object serviceObject =
  65. orb.getLocalResolver().resolve( serviceKey ) ;
  66. // Write reply value
  67. os.write_Object(serviceObject);
  68. } else if (method.equals("list")) {
  69. java.util.Set keys = orb.getLocalResolver().list() ;
  70. os.write_long( keys.size() ) ;
  71. Iterator iter = keys.iterator() ;
  72. while (iter.hasNext()) {
  73. String obj = (String)iter.next() ;
  74. os.write_string( obj ) ;
  75. }
  76. } else {
  77. throw wrapper.illegalBootstrapOperation( method ) ;
  78. }
  79. } catch (org.omg.CORBA.SystemException ex) {
  80. // Marshal the exception thrown
  81. response = request.getProtocolHandler().createSystemExceptionResponse(
  82. request, ex, null);
  83. } catch (java.lang.RuntimeException ex) {
  84. // Unknown exception
  85. SystemException sysex = wrapper.bootstrapRuntimeException( ex ) ;
  86. response = request.getProtocolHandler().createSystemExceptionResponse(
  87. request, sysex, null ) ;
  88. } catch (java.lang.Exception ex) {
  89. // Unknown exception
  90. SystemException sysex = wrapper.bootstrapException( ex ) ;
  91. response = request.getProtocolHandler().createSystemExceptionResponse(
  92. request, sysex, null ) ;
  93. }
  94. return;
  95. }
  96. /**
  97. * Locates the object mentioned in the locate requests, and returns
  98. * object here iff the object is the initial object key. A SystemException
  99. * thrown if the object key is not the initial object key.
  100. */
  101. public IOR locate( ObjectKey objectKey) {
  102. return null;
  103. }
  104. /**
  105. * Not implemented
  106. */
  107. public int getId() {
  108. throw wrapper.genericNoImpl() ;
  109. }
  110. }