-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathRPCInterfaceExampleImpl.java
More file actions
379 lines (321 loc) · 11.4 KB
/
RPCInterfaceExampleImpl.java
File metadata and controls
379 lines (321 loc) · 11.4 KB
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
package com.thrift.example.artificial;
import org.apache.thrift.TApplicationException;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TProtocolException;
import org.apache.thrift.transport.TTransportException;
import java.lang.reflect.UndeclaredThrowableException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;
/**
* created by manzhang on 2021/11/27
*/
public class RPCInterfaceExampleImpl implements RPCInterfaceExample{
private boolean authorized = false;
public void setAuthorized(boolean authorized) {
this.authorized = authorized;
}
@Override
public String simplePrimitive(int argInt, float argfloat, long arglong, double argdouble, char argchar, byte argbyte, boolean argboolean, short argshort) {
return "int:"+argInt+",float:"+argfloat+",long:"+arglong+",double:"+argdouble+",char:"+argchar+",byte:"+argbyte+",boolean:"+argboolean+",short:"+argshort;
}
@Override
public String simpleWrapPrimitive(Integer argInt, Float argfloat, Long arglong, Double argdouble, Character argchar, Byte argbyte, Boolean argboolean, Short argshort) {
return "int:"+argInt+",float:"+argfloat+",long:"+arglong+",double:"+argdouble+",char:"+argchar+",byte:"+argbyte+",boolean:"+argboolean+",short:"+argshort;
}
@Override
public GenericResponse array(List<String>[] args0) {
GenericResponse response = new GenericResponse();
response.info = Arrays.stream(args0).map(s-> String.join(",", s)).collect(Collectors.joining(";"));
return response;
}
@Override
public GenericResponse arrayboolean(boolean[] args0) {
GenericResponse response = new GenericResponse();
StringBuffer sb = new StringBuffer();
for (boolean b : args0){
sb.append(b+",");
}
sb.append("ARRAY_END");
response.info = sb.toString();
return response;
}
@Override
public GenericResponse list(List<String> args0) {
GenericResponse response = new GenericResponse();
response.info = String.join(",", args0);
return response;
}
@Override
public GenericResponse map(Map<String, String> args0) {
GenericResponse response = new GenericResponse();
response.info = args0.entrySet().stream().map(s-> s.getKey()+":"+s.getValue()).collect(Collectors.joining(","));
return response;
}
@Override
public GenericResponse listAndMap(List<Map<String, String>> args0) {
GenericResponse response = new GenericResponse();
response.info = args0.stream()
.map(l-> l.entrySet().stream().map(s-> s.getKey()+":"+s.getValue()).collect(Collectors.joining(",")))
.collect(Collectors.joining(";"));
return response;
}
@Override
public ObjectResponse objResponse() {
ObjectResponse response = new ObjectResponse();
response.f1 = "foo";
response.f2 = 42;
response.f3 = 0.42;
response.f4 = new double[]{0.0, 0.5, 1.0};
response.systemTime = System.nanoTime();
return response;
}
@Override
public CycleAObj objCycleA(CycleAObj objA) {
return objA;
}
@Override
public CycleBObj objCycleB() {
return null;
}
@Override
public String dateToString(Date date) {
return date.toString();
}
@Override
public String constraintInputs(ConstrainedRequest arg0, String arg1) {
return null;
}
@Override
public String handleCustomizedRequestA(CustomizedRequestA request) {
return null;
}
@Override
public String handleCustomizedRequestB(CustomizedRequestB request) {
return null;
}
@Override
public void login(AuthLoginDto dto) {
}
@Override
public PrivateFieldInResponseDto accessFieldDtoCheck(PrivateFieldInRequestDto dto) {
return null;
}
@Override
public ByteResponse byteResponse(byte arg1, Byte arg2) {
ByteResponse res = new ByteResponse();
res.byteValue = arg2;
res.pbyteValue = arg1;
return res;
}
@Override
public String authorizedEndpoint() {
if (authorized)
return "local";
return null;
}
@Override
public void throwRuntimeException() {
throw new RuntimeException("runtime exception");
}
@Override
public void throwUndeclaredThrowableException() {
throw new UndeclaredThrowableException(new IllegalStateException("undeclared"));
}
private final String child_mark = "child";
@Override
public StringChildDto handledInheritedGenericStringDto(StringChildDto dto) {
if (dto == null) return null;
dto.setCode(dto.getCode()!= null? child_mark+dto.getCode(): child_mark);
dto.setMessage(dto.getMessage()!=null? child_mark+ dto.getMessage(): child_mark);
return dto;
}
@Override
public IntChildDto handledInheritedGenericIntDto(IntChildDto dto) {
if (dto == null) return null;
dto.setCode(dto.getCode()!= null? 1+dto.getCode(): 0);
dto.setMessage(dto.getMessage()!=null? 1+ dto.getMessage(): 0);
return dto;
}
@Override
public ListChildDto handledInheritedGenericListDto(ListChildDto dto) {
if (dto == null) return null;
dto.setCode(dto.getCode()!= null? dto.getCode().stream().map(x-> x+1).collect(Collectors.toList()): Arrays.asList(0));
dto.setMessage(dto.getMessage()!=null? dto.getCode().stream().map(x-> x+1).collect(Collectors.toList()): Arrays.asList(0));
return dto;
}
@Override
public GenericDto<Integer, String> handleGenericIntString(GenericDto<Integer, String> dto) {
if (dto == null) return null;
dto.data1 = dto.data1 == null? 0 : dto.data1+1;
dto.data2 = dto.data2 == null? "generic" : "generic"+dto.data2;
return dto;
}
@Override
public GenericDto<StringChildDto, String> handleGenericObjectString(GenericDto<StringChildDto, String> dto) {
if (dto == null) return null;
if (dto.data1 == null)
dto.data1 = new StringChildDto(){{
setMessage(child_mark);
setCode(child_mark);
}};
else{
dto.data1 = handledInheritedGenericStringDto(dto.data1);
}
dto.data2 = dto.data2 == null? "generic" : "generic"+dto.data2;
return dto;
}
@Override
public NestedGenericDto<String> handleNestedGenericString(NestedGenericDto<String> dto) {
if (dto.intData == null){
dto.intData = new GenericDto<String, Integer>(){{
data1 = child_mark;
data2 = 0;
}};
}
if (dto.stringData == null){
dto.stringData = new GenericDto<String, String>(){{
data1 = child_mark;
data2 = child_mark;
}};
}
if (dto.list == null){
dto.list = Arrays.asList(child_mark, child_mark);
}
return dto;
}
@Override
public void handleException(String type) throws Exception {
if (type == null)
throw new NullPointerException("null");
if (type.equals("state"))
throw new IllegalStateException(type);
if (type.equals("argument"))
throw new IllegalArgumentException(type);
throw new RuntimeException(type);
}
@Override
public String handleEnumWithConstructor(ObjectEnum arg1) {
if (arg1 == null || arg1.enumWithConstructor == null) return null;
return arg1.enumWithConstructor.getDesc();
}
@Override
public String bigNumber(BigNumberObj arg1) {
if (arg1 == null) return null;
return arg1.toString();
}
@Override
public String immutableObj(ImmutableObj arg1) {
if (arg1 == null) return null;
return arg1.toString();
}
@Override
public String numericString(NumericStringObj arg1) {
if (arg1 == null) return null;
return arg1.toString();
}
@Override
public Map<String, NumericStringObj> mapResponse() {
return new HashMap<String, NumericStringObj>(){{
put("foo", new NumericStringObj(){{
setIntValue("42");
setLongValue("42L");
setBigDecimalValue("42.42");
setBigIntegerValue("4242");
}});
put("bar", new NumericStringObj(){{
setIntValue("2");
setLongValue("2L");
setBigDecimalValue("2.42");
setBigIntegerValue("242");
}});
}};
}
@Override
public List<BigNumberObj> listResponse() {
return Arrays.asList(
new BigNumberObj(){{
// bigdecimal
setBdPositiveFloat(new BigDecimal("10.12"));
setBdPositiveOrZeroFloat(new BigDecimal("0.00"));
setBdNegativeFloat(new BigDecimal("-10.12"));
setBdNegativeOrZeroFloat(new BigDecimal("-2.16"));
// biginteger
setBiPositive(BigInteger.TEN);
setBiPositiveOrZero(BigInteger.ZERO);
setBiNegative(BigInteger.valueOf(-10));
setBiNegativeOrZero(BigInteger.valueOf(-2));
}}
);
}
@Override
public boolean pBoolResponse() {
return false;
}
@Override
public byte pByteResponse() {
return 0;
}
@Override
public char pCharResponse() {
return 0;
}
@Override
public short pShortResponse() {
return 0;
}
@Override
public int pIntResponse() {
return 0;
}
@Override
public long pLongResponse() {
return 0;
}
@Override
public float pFloatResponse() {
return 0;
}
@Override
public double pDoubleResponse() {
return 0;
}
@Override
public String seedcheck(List<Long> longList, List<Integer> integerList, List<BigNumberObj> objList, Map<Integer, String> integerStringMap, BigNumberObj obj) {
StringBuilder sb = new StringBuilder();
if (longList != null){
longList.forEach(l-> sb.append(l).append(";"));
sb.append(System.lineSeparator());
}
if (integerList != null){
integerList.forEach(l-> sb.append(l).append(";"));
sb.append(System.lineSeparator());
}
if (objList != null){
objList.forEach(l-> sb.append(l.toString()).append(";"));
sb.append(System.lineSeparator());
}
if (integerStringMap != null){
integerStringMap.forEach((key, value) -> sb.append(key).append(":").append(value).append(";"));
sb.append(System.lineSeparator());
}
if (obj != null)
sb.append(obj).append(";");
return sb.toString();
}
@Override
public boolean throwTException(int type) throws Exception {
if (type == 0)
throw new TException("Base-TException");
if (type == 1)
throw new TApplicationException(TApplicationException.INTERNAL_ERROR, "TAPP-internal");
if (type == 2)
throw new TApplicationException(TApplicationException.PROTOCOL_ERROR, "TAPP-protocol");
if (type == 3)
throw new TProtocolException("TProtocol");
if (type == 4)
throw new TTransportException("TTransport");
throw new Exception("general");
}
}