1 // Copyright (C) 2005 Audrius Meskauskas (AudriusA@Bioinformatics.org) |
|
2 |
|
3 // Mauve is free software; you can redistribute it and/or modify |
|
4 // it under the terms of the GNU General Public License as published by |
|
5 // the Free Software Foundation; either version 2, or (at your option) |
|
6 // any later version. |
|
7 |
|
8 // Mauve is distributed in the hope that it will be useful, |
|
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 // GNU General Public License for more details. |
|
12 |
|
13 // You should have received a copy of the GNU General Public License |
|
14 // along with Mauve; see the file COPYING. If not, write to |
|
15 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
16 // Boston, MA 02110-1301 USA. |
|
17 |
|
18 package gnu.testlet.org.omg.PortableInterceptor.Interceptor; |
|
19 |
|
20 import org.omg.CORBA.Any; |
|
21 import org.omg.CORBA.BAD_PARAM; |
|
22 import org.omg.CORBA.LocalObject; |
|
23 import org.omg.CORBA.ORB; |
|
24 import org.omg.IOP.ServiceContext; |
|
25 import org.omg.PortableInterceptor.ClientRequestInfo; |
|
26 import org.omg.PortableInterceptor.ForwardRequest; |
|
27 |
|
28 /** |
|
29 * A sample client request interceptor. |
|
30 */ |
|
31 public class ucClientRequestInterceptor extends LocalObject |
|
32 implements org.omg.PortableInterceptor.ClientRequestInterceptor |
|
33 { |
|
34 StringBuffer callPattern = new StringBuffer(); |
|
35 public static boolean destroyed; |
|
36 |
|
37 /** |
|
38 * Get class name as name of this test interceptor. |
|
39 */ |
|
40 public String name() |
|
41 { |
|
42 return getClass().getName(); |
|
43 } |
|
44 |
|
45 public void destroy() |
|
46 { |
|
47 destroyed = true; |
|
48 } |
|
49 |
|
50 public void receive_exception(ClientRequestInfo info) |
|
51 throws ForwardRequest |
|
52 { |
|
53 callPattern.append("Ex"); |
|
54 |
|
55 // _get_theField is handled in the forwarded target without interceptors. |
|
56 if (!info.operation().equals("_get_theField")) |
|
57 { |
|
58 ServiceContext s = info.get_reply_service_context(6000); |
|
59 String ps = new String(s.context_data); |
|
60 if (s.context_id != 6000) |
|
61 { |
|
62 throw new RuntimeException( |
|
63 "C ERROR Returned context 6000 id mismatch" |
|
64 ); |
|
65 } |
|
66 |
|
67 String p = callPattern.toString(); |
|
68 |
|
69 if (!( |
|
70 "SRq[throwException]Ex".equals(p) || |
|
71 "SRq[passCharacters]Ex".equals(p) |
|
72 ) |
|
73 ) |
|
74 { |
|
75 throw new RuntimeException("Invalid client pattern " + p); |
|
76 } |
|
77 |
|
78 if (!( |
|
79 "InRq[throwException]Ex".equals(ps) || |
|
80 "InRq[passCharacters]Ex".equals(ps) |
|
81 ) |
|
82 ) |
|
83 { |
|
84 throw new RuntimeException("Invalid server pattern " + ps); |
|
85 } |
|
86 } |
|
87 } |
|
88 |
|
89 public void receive_other(ClientRequestInfo info) throws ForwardRequest |
|
90 { |
|
91 callPattern.append("Fx"); |
|
92 } |
|
93 |
|
94 public void receive_reply(ClientRequestInfo info) |
|
95 { |
|
96 callPattern.append("Rr"); |
|
97 checkServerCtx(info); |
|
98 |
|
99 // Check if the two server side service contexts are present. |
|
100 // _get_theField is handled in the forwarded target without interceptors. |
|
101 if (!info.operation().equals("_get_theField")) |
|
102 { |
|
103 ServiceContext s = info.get_reply_service_context(6000); |
|
104 String ps = new String(s.context_data); |
|
105 if (s.context_id != 6000) |
|
106 { |
|
107 throw new RuntimeException( |
|
108 "C ERROR Returned context 6000 id mismatch" |
|
109 ); |
|
110 } |
|
111 |
|
112 if (!"SRq[sayHello]Rr".equals(callPattern.toString())) |
|
113 { |
|
114 throw new RuntimeException("Invalid client pattern " + |
|
115 callPattern |
|
116 ); |
|
117 } |
|
118 |
|
119 if (!"InRq[sayHello]Rp".equals(ps)) |
|
120 { |
|
121 throw new RuntimeException("Invalid server pattern " + ps); |
|
122 } |
|
123 } |
|
124 } |
|
125 |
|
126 private void checkServerCtx(ClientRequestInfo info) |
|
127 { |
|
128 // _get_theField is handled in the forwarded target without interceptors. |
|
129 if (!info.operation().equals("_get_theField")) |
|
130 { |
|
131 ServiceContext se = info.get_reply_service_context(6001); |
|
132 if (se.context_data.length != 0) |
|
133 { |
|
134 throw new RuntimeException( |
|
135 "C ERROR Server side context 6001 is not present in reply." |
|
136 ); |
|
137 } |
|
138 |
|
139 ServiceContext sx = info.get_reply_service_context(6002); |
|
140 if (sx.context_data.length != 0) |
|
141 { |
|
142 throw new RuntimeException( |
|
143 "C ERROR Server side context 6001 is not present in reply." |
|
144 ); |
|
145 } |
|
146 |
|
147 if (se.context_id != 6001) |
|
148 { |
|
149 throw new RuntimeException( |
|
150 "C ERROR Returned context 6001 id mismatch" |
|
151 ); |
|
152 } |
|
153 } |
|
154 else |
|
155 { |
|
156 // Handled by the forwarded target without interceptors. No context |
|
157 // should |
|
158 // be added. |
|
159 try |
|
160 { |
|
161 info.get_reply_service_context(6000); |
|
162 throw new RuntimeException( |
|
163 "C ERROR context 6000 present where it should not be" |
|
164 ); |
|
165 } |
|
166 catch (BAD_PARAM e) |
|
167 { |
|
168 // Excepected. |
|
169 } |
|
170 } |
|
171 } |
|
172 |
|
173 public void send_poll(ClientRequestInfo info) |
|
174 { |
|
175 callPattern.append("Sp"); |
|
176 } |
|
177 |
|
178 /** |
|
179 * Add a sample service context. |
|
180 */ |
|
181 public void send_request(ClientRequestInfo info) throws ForwardRequest |
|
182 { |
|
183 try |
|
184 { |
|
185 Any is0 = info.get_slot(ucInitialiser.slot_0); |
|
186 |
|
187 if (!is0.extract_string().equals("Initial value for slot 0")) |
|
188 { |
|
189 throw new RuntimeException("Wrong initial slot 0 value"); |
|
190 } |
|
191 |
|
192 Any is1 = info.get_slot(ucInitialiser.slot_1); |
|
193 if (!is1.extract_string().equals("Initial value for slot 1")) |
|
194 { |
|
195 throw new RuntimeException("Wrong initial slot 1 value"); |
|
196 } |
|
197 |
|
198 Any s0 = ORB.init().create_any(); |
|
199 Any s1 = ORB.init().create_any(); |
|
200 |
|
201 s0.insert_string("Client slot zero"); |
|
202 s1.insert_string("Client slot one"); |
|
203 } |
|
204 catch (Exception e) |
|
205 { |
|
206 throw new RuntimeException("Client Slot problem", e); |
|
207 } |
|
208 |
|
209 callPattern.setLength(0); |
|
210 callPattern.append("SRq[" + info.operation() + "]"); |
|
211 |
|
212 // One with content. |
|
213 ServiceContext c = new ServiceContext(); |
|
214 c.context_id = 5000; |
|
215 c.context_data = "my_request_context_1".getBytes(); |
|
216 |
|
217 info.add_request_service_context(c, false); |
|
218 |
|
219 // Another empty. |
|
220 ServiceContext ce = new ServiceContext(); |
|
221 ce.context_id = 5001; |
|
222 ce.context_data = new byte[ 0 ]; |
|
223 |
|
224 info.add_request_service_context(ce, false); |
|
225 } |
|
226 } |
|