1. /*
  2. * @(#)LocalServerResponseImpl.java 1.29 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.ServerResponse;
  10. import com.sun.corba.se.internal.core.IOR;
  11. import com.sun.corba.se.internal.core.ServiceContext;
  12. import com.sun.corba.se.internal.core.ServiceContexts;
  13. import com.sun.corba.se.internal.core.ClientResponse;
  14. import com.sun.corba.se.internal.iiop.messages.MessageBase;
  15. import com.sun.corba.se.internal.iiop.messages.ReplyMessage;
  16. class LocalServerResponseImpl
  17. extends IIOPOutputStream
  18. implements ServerResponse
  19. {
  20. LocalServerResponseImpl(LocalServerRequestImpl request, ServiceContexts svc)
  21. {
  22. this(request,
  23. MessageBase.createReply(
  24. (com.sun.corba.se.internal.iiop.ORB) request.orb(),
  25. request.getGIOPVersion(),
  26. request.getRequestId(), ReplyMessage.NO_EXCEPTION,
  27. svc, null),
  28. null);
  29. }
  30. LocalServerResponseImpl(LocalServerRequestImpl request, ServiceContexts svc,
  31. boolean user)
  32. {
  33. this(request,
  34. MessageBase.createReply(
  35. (com.sun.corba.se.internal.iiop.ORB) request.orb(),
  36. request.getGIOPVersion(), request.getRequestId(),
  37. user ? ReplyMessage.USER_EXCEPTION :
  38. ReplyMessage.SYSTEM_EXCEPTION,
  39. svc, null),
  40. null);
  41. }
  42. LocalServerResponseImpl( LocalServerRequestImpl request, ReplyMessage reply,
  43. IOR ior)
  44. {
  45. super(request.getGIOPVersion(),
  46. (com.sun.corba.se.internal.iiop.ORB)(request.orb()), null, false);
  47. setMessage(reply);
  48. ORB orb = (ORB)request.orb();
  49. ServerResponseImpl.runServantPostInvoke(orb, request);
  50. if( request.executePIInResponseConstructor() ) {
  51. // Invoke server request ending interception points (send_*):
  52. // Note: this may end up with a SystemException or an internal
  53. // Runtime ForwardRequest.
  54. orb.invokeServerPIEndingPoint( reply );
  55. // Note this will be executed even if a ForwardRequest or
  56. // SystemException is thrown by a Portable Interceptors ending
  57. // point since we end up in this constructor again anyway.
  58. orb.cleanupServerPIRequest();
  59. // See (Local)ServerRequestImpl.createSystemExceptionResponse
  60. // for why this is necesary.
  61. request.setExecutePIInResponseConstructor(false);
  62. }
  63. // Once you get here then the final reply is available (i.e.,
  64. // postinvoke and interceptors have completed.
  65. if (request.executeRemoveThreadInfoInResponseConstructor()) {
  66. ServerResponseImpl.removeThreadInfo(orb, request);
  67. }
  68. reply.write(this);
  69. if (reply.getIOR() != null)
  70. reply.getIOR().write(this);
  71. this.reply = reply;
  72. this.ior = reply.getIOR();
  73. }
  74. public boolean isSystemException() {
  75. if (reply != null)
  76. return reply.getReplyStatus() == ReplyMessage.SYSTEM_EXCEPTION;
  77. return false;
  78. }
  79. public boolean isUserException() {
  80. if (reply != null)
  81. return reply.getReplyStatus() == ReplyMessage.USER_EXCEPTION;
  82. return false;
  83. }
  84. public boolean isLocationForward() {
  85. if (ior != null)
  86. return true;
  87. return false;
  88. }
  89. public IOR getForwardedIOR() {
  90. return ior;
  91. }
  92. public int getRequestId() {
  93. if (reply != null)
  94. return reply.getRequestId();
  95. return -1;
  96. }
  97. public ServiceContexts getServiceContexts() {
  98. if (reply != null)
  99. return reply.getServiceContexts();
  100. return null;
  101. }
  102. public SystemException getSystemException() {
  103. if (reply != null)
  104. return reply.getSystemException();
  105. return null;
  106. }
  107. public ReplyMessage getReply()
  108. {
  109. return reply ;
  110. }
  111. public ClientResponse getClientResponse()
  112. {
  113. // set the size of the marshalled data in the message header
  114. getMessage().setSize(getByteBuffer(), getSize());
  115. // Construct a new ClientResponse out of the buffer in this ClientRequest
  116. LocalClientResponseImpl result =
  117. new LocalClientResponseImpl(
  118. (com.sun.corba.se.internal.iiop.ORB) orb(),
  119. toByteArray(), reply);
  120. // NOTE (Ram J) (06/02/2000) if we set result.setIndex(bodyBegin) here
  121. // then the LocalClientResponse does not need to read the headers anymore.
  122. // This will be an optimisation which is can be done to speed up the
  123. // local invocation by avoiding reading the headers in the local cases.
  124. // BUGFIX(Ram Jeyaraman) result.setOffset is now done in
  125. // LocalClientResponseImpl constructor.
  126. /*
  127. // Skip over all of the GIOP header information. This positions
  128. // the offset in the buffer so that the skeleton can correctly read
  129. // the marshalled arguments.
  130. result.setOffset( bodyBegin ) ;
  131. */
  132. return result ;
  133. }
  134. /**
  135. * Check to see if the response is local.
  136. */
  137. public boolean isLocal(){
  138. return true;
  139. }
  140. private ReplyMessage reply;
  141. private IOR ior; // forwarded IOR
  142. }