1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
|
// **********************************************************************
//
// Copyright (c) 2001
// ZeroC, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************
#include <Ice/Incoming.h>
#include <Ice/ObjectAdapterI.h> // We need ObjectAdapterI, not ObjectAdapter, because of inc/decUsageCount().
#include <Ice/ServantLocator.h>
#include <Ice/Object.h>
#include <Ice/LocalException.h>
using namespace std;
using namespace Ice;
using namespace IceInternal;
IceInternal::Incoming::Incoming(const InstancePtr& instance, const ObjectAdapterPtr& adapter) :
_is(instance),
_os(instance)
{
_current.adapter = adapter;
if(_current.adapter)
{
dynamic_cast<ObjectAdapterI*>(_current.adapter.get())->incUsageCount();
}
}
IceInternal::Incoming::~Incoming()
{
if(_current.adapter)
{
dynamic_cast<ObjectAdapterI*>(_current.adapter.get())->decUsageCount();
}
}
void
IceInternal::Incoming::invoke(bool response)
{
//
// Read the current.
//
_current.id.__read(&_is);
_is.read(_current.facet);
_is.read(_current.operation);
Byte b;
_is.read(b);
_current.mode = static_cast<OperationMode>(b);
Int sz;
_is.readSize(sz);
while(sz--)
{
pair<string, string> pr;
_is.read(pr.first);
_is.read(pr.second);
_current.ctx.insert(_current.ctx.end(), pr);
}
_is.startReadEncaps();
BasicStream::Container::size_type statusPos;
if(response)
{
statusPos = _os.b.size();
_os.write(static_cast<Byte>(0));
_os.startWriteEncaps();
}
else
{
statusPos = 0; // Initialize, to keep the compiler happy.
}
ObjectPtr servant;
ServantLocatorPtr locator;
LocalObjectPtr cookie;
DispatchStatus status;
//
// Don't put the code above into the try block below. Exceptions
// in the code above are considered fatal, and must propagate to
// the caller of this operation.
//
try
{
if(_current.adapter)
{
servant = _current.adapter->identityToServant(_current.id);
if(!servant && !_current.id.category.empty())
{
locator = _current.adapter->findServantLocator(_current.id.category);
if(locator)
{
servant = locator->locate(_current, cookie);
}
}
if(!servant)
{
locator = _current.adapter->findServantLocator("");
if(locator)
{
servant = locator->locate(_current, cookie);
}
}
}
if(!servant)
{
status = DispatchObjectNotExist;
}
else
{
if(!_current.facet.empty())
{
ObjectPtr facetServant = servant->ice_findFacetPath(_current.facet, 0);
if(!facetServant)
{
status = DispatchFacetNotExist;
}
else
{
status = facetServant->__dispatch(*this, _current);
}
}
else
{
status = servant->__dispatch(*this, _current);
}
}
}
catch(const LocationForward& ex)
{
if(locator && servant)
{
locator->finished(_current, servant, cookie);
}
_is.endReadEncaps();
if(response)
{
_os.endWriteEncaps();
_os.b.resize(statusPos);
_os.write(static_cast<Byte>(DispatchLocationForward));
_os.write(ex._prx);
}
return;
}
catch(const RequestFailedException& ex)
{
if(locator && servant)
{
locator->finished(_current, servant, cookie);
}
_is.endReadEncaps();
if(response)
{
_os.endWriteEncaps();
_os.b.resize(statusPos);
if(dynamic_cast<const ObjectNotExistException*>(&ex))
{
_os.write(static_cast<Byte>(DispatchObjectNotExist));
}
else if(dynamic_cast<const FacetNotExistException*>(&ex))
{
_os.write(static_cast<Byte>(DispatchFacetNotExist));
}
else if(dynamic_cast<const OperationNotExistException*>(&ex))
{
_os.write(static_cast<Byte>(DispatchOperationNotExist));
}
else
{
assert(false);
}
// Write the data from the exception, not from _current,
// so that a RequestFailedException can override the
// information from _current.
ex.id.__write(&_os);
_os.write(ex.facet);
_os.write(ex.operation);
}
return;
}
catch(const LocalException& ex)
{
if(locator && servant)
{
locator->finished(_current, servant, cookie);
}
_is.endReadEncaps();
if(response)
{
_os.endWriteEncaps();
_os.b.resize(statusPos);
_os.write(static_cast<Byte>(DispatchUnknownLocalException));
ostringstream str;
str << ex;
_os.write(str.str());
}
return;
}
catch(const UserException& ex)
{
if(locator && servant)
{
locator->finished(_current, servant, cookie);
}
_is.endReadEncaps();
if(response)
{
_os.endWriteEncaps();
_os.b.resize(statusPos);
_os.write(static_cast<Byte>(DispatchUnknownUserException));
ostringstream str;
str << ex;
_os.write(str.str());
}
return;
}
catch(const Exception& ex)
{
if(locator && servant)
{
locator->finished(_current, servant, cookie);
}
_is.endReadEncaps();
if(response)
{
_os.endWriteEncaps();
_os.b.resize(statusPos);
_os.write(static_cast<Byte>(DispatchUnknownException));
ostringstream str;
str << ex;
_os.write(str.str());
}
return;
}
catch(const std::exception& ex)
{
if(locator && servant)
{
locator->finished(_current, servant, cookie);
}
_is.endReadEncaps();
if(response)
{
_os.endWriteEncaps();
_os.b.resize(statusPos);
_os.write(static_cast<Byte>(DispatchUnknownException));
ostringstream str;
str << "std::exception: " << ex.what();
_os.write(str.str());
}
return;
}
catch(...)
{
if(locator && servant)
{
locator->finished(_current, servant, cookie);
}
_is.endReadEncaps();
if(response)
{
_os.endWriteEncaps();
_os.b.resize(statusPos);
_os.write(static_cast<Byte>(DispatchUnknownException));
string reason = "unknown c++ exception";
_os.write(reason);
}
return;
}
//
// Don't put the code below into the try block above. Exceptions
// in the code below are considered fatal, and must propagate to
// the caller of this operation.
//
if(locator && servant)
{
locator->finished(_current, servant, cookie);
}
_is.endReadEncaps();
if(response)
{
_os.endWriteEncaps();
if(status != DispatchOK && status != DispatchUserException)
{
assert(status == DispatchObjectNotExist ||
status == DispatchFacetNotExist ||
status == DispatchOperationNotExist);
_os.b.resize(statusPos);
_os.write(static_cast<Byte>(status));
_current.id.__write(&_os);
_os.write(_current.facet);
_os.write(_current.operation);
}
else
{
*(_os.b.begin() + statusPos) = static_cast<Byte>(status);
}
}
}
BasicStream*
IceInternal::Incoming::is()
{
return &_is;
}
BasicStream*
IceInternal::Incoming::os()
{
return &_os;
}
|