Commit a4595ae
authored
Motivation
`DelegatingHttpJsonTranscodingService` transcodes incoming HTTP/JSON
requests into gRPC requests and forwards them to a delegate gRPC
service. Previously, the transcoded gRPC request was always serialized
as JSON (`application/grpc+json`) before being sent to the delegate.
However, when the delegate only supports `application/grpc+proto` (e.g.,
a standard gRPC service that does not have JSON marshalling enabled, or
a remote proxy upstream that expects proto wire format), the transcoded
request would be rejected or fail to deserialize correctly.
Modifications
- Added a `transcodedGrpcSerializationFormat(SerializationFormat)`
option to `DelegatingHttpJsonTranscodingServiceBuilder` (and the
internal `HttpJsonTranscoderBuilder`) that allows users to choose
between `GrpcSerializationFormats.JSON` (default, preserving existing
behaviour) and `GrpcSerializationFormats.PROTO`.
- When `PROTO` is selected, `HttpJsonTranscoder` converts the JSON
request body to a protobuf binary payload before framing and forwarding
to the delegate, and converts the protobuf binary response body back to
JSON before returning it to the HTTP client.
- Introduced a `JsonProtoMarshaller` helper inside `HttpJsonTranscoder`
that owns a pair of `GrpcMessageMarshaller` instances (one JSON, one
proto) and provides `jsonToProto` / `protoToJson` conversion using them.
- Refactored `GrpcMessageMarshaller` to expose public
`deserializeRequest(InputStream)`, `deserializeRequest(ByteBuf,
boolean)`, `deserializeResponse(InputStream)`, and
`deserializeResponse(ByteBuf, boolean)` overloads, extracting the
previously inlined per-type dispatch logic into dedicated methods to
support the new call sites.
- Added `grpcMethodDescriptor` and `jsonMarshaller` fields to
`HttpJsonTranscoderBuilder.HttpJsonGrpcMethod` so that the marshaller
pair can be constructed when proto transcoding is configured.
- Added a test case `shouldProxyHttpJsonRequestWithProtoUpstream` in
`DelegatingHttpJsonTranscodingServiceTest` to verify end-to-end
HTTP/JSON → proto → upstream → proto → JSON round-trip.
- Updated `DelegatingHttpJsonTranscodingDocServiceTest` to exercise the
new option.
Result
Users can now configure `DelegatingHttpJsonTranscodingService` to
forward transcoded requests using protobuf binary encoding to the
delegate, enabling interoperability with upstream gRPC services that
only accept `application/grpc+proto`.
```java
DelegatingHttpJsonTranscodingService.builder(grpcService)
.serviceDescriptors(MyServiceGrpc.getServiceDescriptor())
.transcodedGrpcSerializationFormat(GrpcSerializationFormats.PROTO)
.build();
```
1 parent 9ddbeeb commit a4595ae
7 files changed
Lines changed: 221 additions & 57 deletions
File tree
- grpc/src
- main/java/com/linecorp/armeria
- internal/common/grpc
- server/grpc
- test/java/com/linecorp/armeria/it/grpc
Lines changed: 63 additions & 41 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | | - | |
| 115 | + | |
116 | 116 | | |
117 | 117 | | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
| 118 | + | |
136 | 119 | | |
137 | 120 | | |
138 | 121 | | |
139 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
140 | 128 | | |
141 | 129 | | |
142 | 130 | | |
| |||
146 | 134 | | |
147 | 135 | | |
148 | 136 | | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
149 | 160 | | |
150 | 161 | | |
151 | 162 | | |
| |||
170 | 181 | | |
171 | 182 | | |
172 | 183 | | |
173 | | - | |
| 184 | + | |
174 | 185 | | |
175 | 186 | | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
| 187 | + | |
195 | 188 | | |
196 | 189 | | |
197 | 190 | | |
198 | | - | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
199 | 197 | | |
200 | 198 | | |
201 | 199 | | |
| |||
205 | 203 | | |
206 | 204 | | |
207 | 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 | + | |
208 | 230 | | |
209 | 231 | | |
210 | 232 | | |
| |||
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
| |||
77 | 78 | | |
78 | 79 | | |
79 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
80 | 90 | | |
81 | 91 | | |
82 | 92 | | |
| |||
110 | 120 | | |
111 | 121 | | |
112 | 122 | | |
| 123 | + | |
113 | 124 | | |
114 | 125 | | |
115 | 126 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1099 | 1099 | | |
1100 | 1100 | | |
1101 | 1101 | | |
| 1102 | + | |
1102 | 1103 | | |
1103 | 1104 | | |
1104 | 1105 | | |
| |||
Lines changed: 98 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
| 73 | + | |
72 | 74 | | |
73 | 75 | | |
74 | 76 | | |
75 | 77 | | |
76 | 78 | | |
77 | 79 | | |
| 80 | + | |
78 | 81 | | |
79 | 82 | | |
80 | 83 | | |
| |||
90 | 93 | | |
91 | 94 | | |
92 | 95 | | |
| 96 | + | |
93 | 97 | | |
94 | 98 | | |
95 | 99 | | |
| |||
146 | 150 | | |
147 | 151 | | |
148 | 152 | | |
| 153 | + | |
149 | 154 | | |
150 | 155 | | |
151 | 156 | | |
152 | 157 | | |
153 | | - | |
| 158 | + | |
| 159 | + | |
154 | 160 | | |
| 161 | + | |
155 | 162 | | |
156 | 163 | | |
157 | 164 | | |
| |||
214 | 221 | | |
215 | 222 | | |
216 | 223 | | |
| 224 | + | |
217 | 225 | | |
218 | | - | |
| 226 | + | |
| 227 | + | |
219 | 228 | | |
220 | 229 | | |
221 | 230 | | |
| |||
244 | 253 | | |
245 | 254 | | |
246 | 255 | | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
247 | 264 | | |
248 | | - | |
| 265 | + | |
| 266 | + | |
249 | 267 | | |
250 | | - | |
| 268 | + | |
| 269 | + | |
251 | 270 | | |
252 | 271 | | |
253 | 272 | | |
| |||
261 | 280 | | |
262 | 281 | | |
263 | 282 | | |
264 | | - | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
265 | 294 | | |
266 | 295 | | |
267 | 296 | | |
| |||
304 | 333 | | |
305 | 334 | | |
306 | 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 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
307 | 390 | | |
308 | 391 | | |
309 | 392 | | |
| |||
464 | 547 | | |
465 | 548 | | |
466 | 549 | | |
467 | | - | |
| 550 | + | |
468 | 551 | | |
469 | 552 | | |
470 | 553 | | |
| |||
759 | 842 | | |
760 | 843 | | |
761 | 844 | | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
762 | 848 | | |
763 | 849 | | |
764 | 850 | | |
765 | | - | |
| 851 | + | |
| 852 | + | |
766 | 853 | | |
767 | 854 | | |
768 | 855 | | |
| 856 | + | |
| 857 | + | |
769 | 858 | | |
770 | 859 | | |
771 | 860 | | |
| |||
786 | 875 | | |
787 | 876 | | |
788 | 877 | | |
789 | | - | |
| 878 | + | |
| 879 | + | |
790 | 880 | | |
791 | 881 | | |
792 | 882 | | |
| |||
0 commit comments