1. /*
  2. * @(#)LocalServerRequestImpl.java 1.28 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.internal.iiop;
  8. import org.omg.CORBA.SystemException;
  9. import com.sun.corba.se.internal.core.ServerRequest;
  10. import com.sun.corba.se.internal.core.ServiceContext;
  11. import com.sun.corba.se.internal.core.DuplicateServiceContext;
  12. import com.sun.corba.se.internal.core.UEInfoServiceContext;
  13. import com.sun.corba.se.internal.core.ServiceContexts;
  14. import com.sun.corba.se.internal.core.ServerResponse;
  15. import com.sun.corba.se.internal.core.IOR;
  16. import com.sun.corba.se.internal.orbutil.ORBUtility; //d11638
  17. import org.omg.CORBA.portable.UnknownException;
  18. import org.omg.CORBA.UNKNOWN;
  19. import org.omg.CORBA.CompletionStatus;
  20. import com.sun.corba.se.internal.ior.ObjectKey;
  21. import com.sun.corba.se.internal.iiop.messages.MessageBase;
  22. import com.sun.corba.se.internal.iiop.messages.ReplyMessage;
  23. import com.sun.corba.se.internal.iiop.messages.RequestMessage;
  24. class LocalServerRequestImpl extends IIOPInputStream implements ServerRequest {
  25. org.omg.CORBA.portable.OutputStream replyStream;
  26. org.omg.CORBA.portable.OutputStream exceptionReplyStream;
  27. LocalServerRequestImpl(ORB orb, byte[] buf, RequestMessage header)
  28. {
  29. super(orb, buf, header.getSize(), header.isLittleEndian(), header, null );
  30. this.request = header;
  31. }
  32. public int getRequestId() {
  33. return request.getRequestId();
  34. }
  35. public boolean isOneWay() {
  36. return !request.isResponseExpected();
  37. }
  38. public ServiceContexts getServiceContexts() {
  39. return request.getServiceContexts();
  40. }
  41. public String getOperationName() {
  42. return request.getOperation();
  43. }
  44. public ObjectKey getObjectKey() {
  45. return request.getObjectKey();
  46. }
  47. public ServerResponse createResponse(ServiceContexts svc)
  48. {
  49. return new LocalServerResponseImpl(this, svc);
  50. }
  51. public org.omg.CORBA.portable.OutputStream createReply() {
  52. if (replyStream == null) {
  53. replyStream = (org.omg.CORBA.portable.OutputStream)
  54. createResponse(null);
  55. }
  56. return replyStream;
  57. }
  58. public org.omg.CORBA.portable.OutputStream createExceptionReply() {
  59. if (exceptionReplyStream == null) {
  60. exceptionReplyStream = (org.omg.CORBA.portable.OutputStream)
  61. createUserExceptionResponse(null);
  62. }
  63. return exceptionReplyStream;
  64. }
  65. public ServerResponse createUserExceptionResponse(
  66. ServiceContexts svc)
  67. {
  68. return new LocalServerResponseImpl(this, svc, true);
  69. }
  70. public ServerResponse createUnknownExceptionResponse(
  71. UnknownException ex) {
  72. ServiceContexts contexts = null;
  73. SystemException sys = new UNKNOWN( 0,
  74. CompletionStatus.COMPLETED_MAYBE);
  75. try {
  76. contexts = new ServiceContexts(
  77. (com.sun.corba.se.internal.corba.ORB)orb());
  78. UEInfoServiceContext uei = new UEInfoServiceContext(sys);
  79. contexts.put(uei) ;
  80. } catch (DuplicateServiceContext d) {
  81. // can't happen
  82. }
  83. return createSystemExceptionResponse(sys,contexts);
  84. }
  85. public ServerResponse createSystemExceptionResponse(
  86. SystemException ex, ServiceContexts svc) {
  87. // Only do this if interceptors have been initialized on this request
  88. // and have not completed their lifecycle (otherwise the info stack
  89. // may be empty or have a different request's entry on top).
  90. if (executePIInResponseConstructor()) {
  91. // Inform Portable Interceptors of the SystemException. This is
  92. // required to be done here because the ending interception point
  93. // is called in the ServerResponseImpl constructor called below
  94. // but we do not currently write the SystemException into the
  95. // response until after the ending point is called.
  96. ORB orb = (ORB)orb();
  97. orb.setServerPIInfo( ex );
  98. }
  99. if (orb() != null && ((ORB)orb()).subcontractDebugFlag && ex != null)
  100. ORBUtility.dprint(this, "Sending SystemException:", ex);
  101. LocalServerResponseImpl response =
  102. new LocalServerResponseImpl(this, svc, false);
  103. ORBUtility.writeSystemException(ex, response);
  104. return response;
  105. }
  106. public ServerResponse createLocationForward(
  107. IOR ior, ServiceContexts svc) {
  108. ReplyMessage reply = MessageBase.createReply(
  109. (com.sun.corba.se.internal.iiop.ORB) orb(),
  110. request.getGIOPVersion(),
  111. request.getRequestId(),
  112. ReplyMessage.LOCATION_FORWARD,
  113. svc, ior);
  114. LocalServerResponseImpl response =
  115. new LocalServerResponseImpl(this, reply, ior);
  116. return response;
  117. }
  118. private RequestMessage request;
  119. /**
  120. * Check to see if the request is local.
  121. */
  122. public boolean isLocal(){
  123. return true;
  124. }
  125. private boolean _executeReturnServantInResponseConstructor = false;
  126. public boolean executeReturnServantInResponseConstructor()
  127. {
  128. return _executeReturnServantInResponseConstructor;
  129. }
  130. public void setExecuteReturnServantInResponseConstructor(boolean b)
  131. {
  132. _executeReturnServantInResponseConstructor = b;
  133. }
  134. private boolean _executeRemoveThreadInfoInResponseConstructor = false;
  135. public boolean executeRemoveThreadInfoInResponseConstructor()
  136. {
  137. return _executeRemoveThreadInfoInResponseConstructor;
  138. }
  139. public void setExecuteRemoveThreadInfoInResponseConstructor(boolean b)
  140. {
  141. _executeRemoveThreadInfoInResponseConstructor = b;
  142. }
  143. private boolean _executePIInResponseConstructor = false;
  144. public boolean executePIInResponseConstructor() {
  145. return _executePIInResponseConstructor;
  146. }
  147. public void setExecutePIInResponseConstructor( boolean b ) {
  148. _executePIInResponseConstructor = b;
  149. }
  150. }