1 /* |
|
2 * Copyright (c) 1999, 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 |
|
26 package com.sun.corba.se.impl.iiop; |
|
27 |
|
28 import org.omg.CORBA.SystemException; |
|
29 |
|
30 import com.sun.corba.se.impl.core.ServerResponse; |
|
31 import com.sun.corba.se.impl.core.ORB; |
|
32 import com.sun.corba.se.impl.corba.IOR; |
|
33 import com.sun.corba.se.impl.core.ServiceContext; |
|
34 import com.sun.corba.se.impl.core.ServiceContexts; |
|
35 import com.sun.corba.se.impl.core.ClientResponse; |
|
36 import com.sun.corba.se.impl.protocol.giopmsgheaders.MessageBase; |
|
37 import com.sun.corba.se.impl.protocol.giopmsgheaders.ReplyMessage; |
|
38 |
|
39 class LocalServerResponseImpl |
|
40 extends IIOPOutputStream |
|
41 implements ServerResponse |
|
42 { |
|
43 LocalServerResponseImpl(LocalServerRequestImpl request, ServiceContexts svc) |
|
44 { |
|
45 this(request, |
|
46 MessageBase.createReply( |
|
47 (ORB)request.orb(), |
|
48 request.getGIOPVersion(), |
|
49 request.getRequestId(), ReplyMessage.NO_EXCEPTION, |
|
50 svc, null), |
|
51 null); |
|
52 } |
|
53 |
|
54 LocalServerResponseImpl(LocalServerRequestImpl request, ServiceContexts svc, |
|
55 boolean user) |
|
56 { |
|
57 this(request, |
|
58 MessageBase.createReply( |
|
59 (ORB)request.orb(), |
|
60 request.getGIOPVersion(), request.getRequestId(), |
|
61 user ? ReplyMessage.USER_EXCEPTION : |
|
62 ReplyMessage.SYSTEM_EXCEPTION, |
|
63 svc, null), |
|
64 null); |
|
65 } |
|
66 |
|
67 LocalServerResponseImpl( LocalServerRequestImpl request, ReplyMessage reply, |
|
68 IOR ior) |
|
69 { |
|
70 super(request.getGIOPVersion(), |
|
71 (ORB)request.orb(), |
|
72 null, |
|
73 BufferManagerFactory.newBufferManagerWrite(BufferManagerFactory.GROW), |
|
74 request.getStreamFormatVersionForReply()); |
|
75 |
|
76 setMessage(reply); |
|
77 |
|
78 ORB orb = (ORB)request.orb(); |
|
79 |
|
80 ServerResponseImpl.runServantPostInvoke(orb, request); |
|
81 |
|
82 if( request.executePIInResponseConstructor() ) { |
|
83 // Invoke server request ending interception points (send_*): |
|
84 // Note: this may end up with a SystemException or an internal |
|
85 // Runtime ForwardRequest. |
|
86 orb.getPIHandler().invokeServerPIEndingPoint( reply ); |
|
87 |
|
88 // Note this will be executed even if a ForwardRequest or |
|
89 // SystemException is thrown by a Portable Interceptors ending |
|
90 // point since we end up in this constructor again anyway. |
|
91 orb.getPIHandler().cleanupServerPIRequest(); |
|
92 |
|
93 // See (Local)ServerRequestImpl.createSystemExceptionResponse |
|
94 // for why this is necesary. |
|
95 request.setExecutePIInResponseConstructor(false); |
|
96 } |
|
97 |
|
98 // Once you get here then the final reply is available (i.e., |
|
99 // postinvoke and interceptors have completed. |
|
100 if (request.executeRemoveThreadInfoInResponseConstructor()) { |
|
101 ServerResponseImpl.removeThreadInfo(orb, request); |
|
102 } |
|
103 |
|
104 reply.write(this); |
|
105 if (reply.getIOR() != null) |
|
106 reply.getIOR().write(this); |
|
107 |
|
108 this.reply = reply; |
|
109 this.ior = reply.getIOR(); |
|
110 } |
|
111 |
|
112 public boolean isSystemException() { |
|
113 if (reply != null) |
|
114 return reply.getReplyStatus() == ReplyMessage.SYSTEM_EXCEPTION; |
|
115 return false; |
|
116 } |
|
117 |
|
118 public boolean isUserException() { |
|
119 if (reply != null) |
|
120 return reply.getReplyStatus() == ReplyMessage.USER_EXCEPTION; |
|
121 return false; |
|
122 } |
|
123 |
|
124 public boolean isLocationForward() { |
|
125 if (ior != null) |
|
126 return true; |
|
127 return false; |
|
128 } |
|
129 |
|
130 public IOR getForwardedIOR() { |
|
131 return ior; |
|
132 } |
|
133 |
|
134 public int getRequestId() { |
|
135 if (reply != null) |
|
136 return reply.getRequestId(); |
|
137 return -1; |
|
138 } |
|
139 |
|
140 public ServiceContexts getServiceContexts() { |
|
141 if (reply != null) |
|
142 return reply.getServiceContexts(); |
|
143 return null; |
|
144 } |
|
145 |
|
146 public SystemException getSystemException() { |
|
147 if (reply != null) |
|
148 return reply.getSystemException(); |
|
149 return null; |
|
150 } |
|
151 |
|
152 public ReplyMessage getReply() |
|
153 { |
|
154 return reply ; |
|
155 } |
|
156 |
|
157 public ClientResponse getClientResponse() |
|
158 { |
|
159 // set the size of the marshalled data in the message header |
|
160 getMessage().setSize(getByteBuffer(), getSize()); |
|
161 |
|
162 // Construct a new ClientResponse out of the buffer in this ClientRequest |
|
163 LocalClientResponseImpl result = |
|
164 new LocalClientResponseImpl( (ORB)orb(), toByteArray(), reply); |
|
165 |
|
166 // NOTE (Ram J) (06/02/2000) if we set result.setIndex(bodyBegin) here |
|
167 // then the LocalClientResponse does not need to read the headers anymore. |
|
168 // This will be an optimisation which is can be done to speed up the |
|
169 // local invocation by avoiding reading the headers in the local cases. |
|
170 |
|
171 // BUGFIX(Ram Jeyaraman) result.setOffset is now done in |
|
172 // LocalClientResponseImpl constructor. |
|
173 /* |
|
174 // Skip over all of the GIOP header information. This positions |
|
175 // the offset in the buffer so that the skeleton can correctly read |
|
176 // the marshalled arguments. |
|
177 result.setOffset( bodyBegin ) ; |
|
178 */ |
|
179 |
|
180 return result ; |
|
181 } |
|
182 |
|
183 /** |
|
184 * Check to see if the response is local. |
|
185 */ |
|
186 public boolean isLocal(){ |
|
187 return true; |
|
188 } |
|
189 |
|
190 private ReplyMessage reply; |
|
191 private IOR ior; // forwarded IOR |
|
192 } |
|