Skip to content

Commit ae67478

Browse files
authored
Merge pull request resteasy#19 from jasondlee/highlight
Enable source code syntax highlighting
2 parents 9f06e18 + db1353c commit ae67478

9 files changed

Lines changed: 443 additions & 45 deletions

File tree

content/posts/2024-01-23-grpc-jakarta-rs-arrays.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ author: Ron Sigal
99
Release 1.0.0.Alpha5 of resteasy-grpc has a new feature for handling arbitrary arrays. Although protobuf comes
1010
with a representation of one dimension arrays, e.g.
1111

12-
```
12+
```protobuf
1313
message ints {
1414
repeated int64 is = 1;
1515
}
@@ -25,7 +25,7 @@ The mechanism has two parts:
2525

2626
arrays.proto looks like this:
2727

28-
```
28+
```protobuf
2929
message dev_resteasy_grpc_arrays___BooleanArray {
3030
repeated bool bool_field = 1;
3131
}
@@ -66,7 +66,7 @@ It starts with a definition of array message types for
6666
Then, `dev_resteasy_grpc_arrays___ArrayHolder` is defined with a oneof field that can
6767
hold any of these array message types. The self-referential field
6868

69-
```
69+
```protobuf
7070
dev_resteasy_grpc_arrays___ArrayHolderArray arrayHolderArray_field = 13;
7171
```
7272

@@ -77,7 +77,7 @@ Compiling arrays.proto generates `dev.resteasy.grpc.arrays.Array_proto`, which g
7777
gateway into the javabuf[^javabuf] world. Suppose we want to generate a representation of
7878
`int[] {3, 5}`. That would look like
7979

80-
```
80+
```java
8181
dev_resteasy_grpc_arrays___IntArray.Builder iab = dev_resteasy_grpc_arrays___IntArray.newBuilder();
8282
iab.addIntField(3);
8383
iab.addIntField(5);
@@ -105,34 +105,34 @@ of `int[][] {{3, 5}, {7, 11, 13}}`.
105105
To avoid the mess, grpc-bridge-runtime includes the class `dev.resteasy.grpc.arrays.ArrayUtility`. With `ArrayUtility`,
106106
building the javabuf representation of `int[][] {{3, 5}, {7, 11, 13}}` is as easy as
107107

108-
```
108+
```java
109109
dev_resteasy_grpc_arrays___ArrayHolder holder = ArrayUtility.getHolder(new int[][] {{3, 5}, {7, 11, 13}});
110110
```
111111

112112
Moreover, `ArrayUtility` can turn the `dev_resteasy_grpc_arrays___ArrayHolder` back to the original array:
113113

114-
```
114+
```java
115115
Object array = ArrayUtility.getArray(holder);
116116
Assert.assertArrayEquals(new int[][] {{3, 5}, {7, 11, 13}}, (int[][]) array);
117117
```
118118

119119
These two calls to `ArrayUtility` depend on the fact that the target array is built from a primitive Java type. If the
120120
array uses an application specific type, then there are two alternative calls that can be used:
121121

122-
```
122+
```java
123123
public static dev_resteasy_grpc_arrays___ArrayHolder getHolder(JavabufTranslator translator, Object o);
124124
```
125125

126126
and
127127

128-
```
128+
```java
129129
public static Object getArray(JavabufTranslator translator, Array_proto.dev_resteasy_grpc_arrays___ArrayHolder ah) throws Exception;
130130
```
131131

132132
Also, if an application uses arrays, the generated `JavabufTranslator` incorporates `ArrayUtility`, so that it can be
133133
used instead:
134134

135-
```
135+
```java
136136
dev_resteasy_grpc_arrays___ArrayHolder ah = (dev_resteasy_grpc_arrays___ArrayHolder) translator.translateToJavabuf(new int[][] {{3, 5}, {7, 11, 13}});
137137
Object array = translator.translateFromJavabuf(ah);
138138
Assert.assertArrayEquals(new int[][] {{3, 5}, {7, 11, 13}}, (int[][]) array);
@@ -141,7 +141,7 @@ used instead:
141141

142142
**Note.** The latter point can be usefully expanded, independent of the presence of arrays. Consider the class
143143

144-
```
144+
```java
145145
package dev.resteasy.grpc.example;
146146

147147
public class C {
@@ -160,15 +160,15 @@ used instead:
160160
Using the fluent methods created in, say, `C_proto` by the protobuf parser, an instance of
161161
`C_proto.dev_resteasy_grpc_example___C` can be created by
162162

163-
```
163+
```java
164164
C_proto.dev_resteasy_grpc_example___C.Builder cb = C_proto.dev_resteasy_grpc_example___C.newBuilder();
165165
C_proto.dev_resteasy_grpc_example___C c1 = cb.setI(3).setD(5.0).setS("seven").build();
166166
```
167167

168168
Note that each field must be set individually. On the other hand, given the `C(int, double, String)` constructor,
169169
an instance of `C_proto.dev_resteasy_grpc_example___C` can be created more directly:
170170

171-
```
171+
```java
172172
C_proto.dev_resteasy_grpc_example___C c2 = (C_proto.dev_resteasy_grpc_example___C) translator.translateToJavabuf(new C(3, 5.0, "seven"));
173173
```
174174

content/posts/2024-11-15-resteasy-spring-boot-with-springdoc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The [WildFly](https://github.com/wildfly/wildfly) and [Quarkus](https://github.c
2020

2121
- [Using MicroProfile OpenAPI With RESTEasy](https://resteasy.dev/2023/02/20/resteasy-microprofile-openapi/)
2222

23-
For Quarkus, here is a blog post that shows the usage of the built-in MicroProfile OpenAPI in Quarkus:
23+
For Quarkus, here is a blog post that shows the usage of the built-in MicroProfile OpenAPI in Quarkus:
2424

2525
- [MicroProfile OpenAPI for everyone](https://quarkus.io/blog/openapi-for-everyone/)
2626

content/posts/2025-02-14-resteasy-grpc-collections.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ and `java.util.Set`. In order to handle arbitrary implementations, idiosyncratic
1313
implementating classes are ignored and all implementations are assigned the least common nature of lists and sets. That is,
1414
an implementation of `java.util.List` is considered to be an ordered sequence and is translated to a protobuf
1515
message type of the form
16-
```
16+
```protobuf
1717
message java_util___ArrayList16 {
1818
string classname = 1;
1919
repeated int32 data = 2;
2020
}
2121
```
2222
and an implementation of `java.util.Set` is considered to be an unordered collection and is translated to a
2323
protobuf message type of the form
24-
```
24+
```protobuf
2525
message java_util___HashSet3 {
2626
string classname = 1;
2727
repeated string data = 2;
@@ -40,7 +40,7 @@ a workaround. The important thing is to define a protobuf message whose repeated
4040
`java_util___ArrayList16`. That would be a reasonable representation of `ArrayList<Integer>`. Similarly, `java_util___HashSet3`
4141
would be a reasonable representation of `HashSet<String>`. The `JavaToProtobufGenerator` class in the
4242
[grpc-bridge](https://github.com/resteasy/resteasy-grpc) module generates the protobuf messages and decorates them as follows:
43-
```
43+
```java
4444
// List: java.util.ArrayList<java.lang.Integer>
4545
message java_util___ArrayList16 {
4646
string classname = 1;
@@ -56,7 +56,7 @@ would be a reasonable representation of `HashSet<String>`. The `JavaToProtobufGe
5656
}
5757
```
5858
These are two simple examples. Consider something a little more complicated: `java.util.ArrayList<java.util.HashSet<java.lang.String>>`:
59-
```
59+
```java
6060
// List: java.util.ArrayList<java.util.HashSet<java.lang.String>>
6161
message java_util___ArrayList14 {
6262
string classname = 1;
@@ -70,7 +70,7 @@ field in `java_util___ArrayList14` is of type `java_util___HashSet3`.
7070
A complication arises in the form of type variables and wildcards. The solution adopted in resteasy-grpc is to map unassigned
7171
type variables and wildcards to `java.lang.Object`, which makes sense, since they can take any types at runtime. The protobuf
7272
analog to `java.lang.Object` is `google.protobuf.Any`, which is defined
73-
```
73+
```protobuf
7474
message Any {
7575
string type_url = 1;
7676
bytes value = 2;
@@ -81,7 +81,7 @@ package declared in the .proto file. The value field has built-in type bytes, w
8181
of bytes no longer than 2^32", according to https://developers.google.com/protocol-buffers/docs/proto3.
8282

8383
Suppose we have the Jakarta REST resource methods
84-
```
84+
```java
8585
package x.y;
8686

8787
@GET
@@ -110,13 +110,13 @@ Suppose we have the Jakarta REST resource methods
110110
}
111111
```
112112
where x.y.Grimble is
113-
```
113+
```java
114114
public class Grimble<T> {
115115
T t;
116116
}
117117
```
118118
`JavaToProtobufGenerator` would create the rpc and message definitions
119-
```
119+
```protobuf
120120
// p/grimble/raw x_y___Grimble google.protobuf.Empty GET sync
121121
rpc gr_raw (GeneralEntityMessage) returns (GeneralReturnMessage);
122122
@@ -155,7 +155,7 @@ where x.y.Grimble is
155155
```
156156
The details about the rpc comments are described elsewhere ([gRPC Bridge Project: User Guide](https://resteasy.dev/docs/grpc/)),
157157
but here it's enough to know that the rpc definition
158-
```
158+
```protobuf
159159
// p/grimble/variable x_y___Grimble18 google.protobuf.Empty GET sync
160160
rpc gr_variable (GeneralEntityMessage) returns (GeneralReturnMessage);
161161
```
@@ -175,15 +175,15 @@ type `google.protobuf.Any`, which, as discussed above, represents an arbitrary t
175175
`of java.lang.Object`.
176176

177177
The discussion about generic types and type variables applies to lists and sets. For example,
178-
```
178+
```java
179179
@Path("arraylist/hashset/wildcard")
180180
@POST
181181
public ArrayList<HashSet<?>> arraylistHashsetTest2(ArrayList<HashSet<?>> l) {
182182
return l;
183183
}
184184
```
185185
gives rise to
186-
```
186+
```java
187187
// List: java.util.ArrayList<java.util.HashSet<java.lang.Object>>
188188
message java_util___ArrayList13 {
189189
string classname = 1;
@@ -202,7 +202,7 @@ gives rise to
202202
Here we'll discuss a gRPC client intending to communicate with a Jakarta REST server. The subject is covered in detail in
203203
[gRPC Bridge Project: User Guide](https://resteasy.dev/docs/grpc/), but here we will look at sending and receiving
204204
`Collection`s. For example, consider the resource method
205-
```
205+
```java
206206
@GET
207207
@Path("arraylist/integer")
208208
public ArrayList<?> listArray0(ArrayList<Integer> list) {
@@ -212,15 +212,15 @@ Here we'll discuss a gRPC client intending to communicate with a Jakarta REST se
212212
We've seen that `java.util.ArrayList<java.lang.Integer>` translates to javabuf class `java_util___ArrayList16`. So the client
213213
has to create an instance of `java_util___ArrayList16` to send to the server. There are two possible strategies. One is to
214214
work in the javabuf world:
215-
```
215+
```java
216216
java_util___ArrayList16.Builder juaBuilder = java_util___ArrayList16.newBuilder();
217217
juaBuilder.setClassname("java.util.ArrayList");
218218
juaBuilder.addData(3);
219219
juaBuilder.addData(7);
220220
java_util___ArrayList16 jua = juaBuilder.build();
221221
```
222222
Alternatively, one could create an `ArrayList` and translate it to an `java_util___ArrayList16`:
223-
```
223+
```java
224224
ArrayList<Integer> list = new ArrayList<Integer>();
225225
list.add(3);
226226
list.add(7);
@@ -229,18 +229,18 @@ Alternatively, one could create an `ArrayList` and translate it to an `java_util
229229
```
230230
where `translator` is an instance of `dev.resteasy.grpc.bridge.runtime.protobuf.JavabufTranslator`.
231231
The next step is to build a `GeneralEntityMessage`:
232-
```
232+
```java
233233
GeneralEntityMessage.Builder gemBuilder = GeneralEntityMessage.newBuilder();
234234
gemBuilder.setJavaUtilArrayList16Field(gemBuilder.build());
235235
```
236236
Then the remote method can be invoked:
237-
```
237+
```java
238238
GeneralReturnMessage response = stub.listArray0(gem);
239239
```
240240
where `stub` is the client side representative of the server methods.
241241
Finally, the result can be extracted from the `GeneralReturnMessage`. Note that `listArray0` returns
242242
an instance of `ArrayList<?>`, which translates to javabuf class
243-
```
243+
```java
244244
// List: java.util.ArrayList<java.lang.Object>
245245
message java_util___ArrayList17 {
246246
string classname = 1;
@@ -249,11 +249,11 @@ an instance of `ArrayList<?>`, which translates to javabuf class
249249
}
250250
```
251251
This complicates things a bit since we have to extract the returned list from an `Any`.
252-
```
252+
```java
253253
java_util___ArrayList17 result = response.getJavaUtilArrayList17Field();
254254
Any any = response.getAnyField();
255255
Message result = any.unpack((Class) Utility.extractClassFromAny(any, translator));
256256
list = (ArrayList<Object>) translator.translateFromJavabuf(result);
257257
```
258258
### Maps
259-
Stay tuned for the next release, which which implementations of `java.util.Map` will be treated in a similar way.
259+
Stay tuned for the next release, in which implementations of `java.util.Map` will be treated similarly.

pom.xml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
</dependencyManagement>
3434

3535
<dependencies>
36+
<dependency>
37+
<groupId>io.quarkus</groupId>
38+
<artifactId>quarkus-arc</artifactId>
39+
</dependency>
3640
<dependency>
3741
<groupId>io.quarkiverse.roq</groupId>
3842
<artifactId>quarkus-roq</artifactId>
@@ -58,11 +62,12 @@
5862
<artifactId>quarkus-roq-plugin-tagging</artifactId>
5963
<version>${version.quarkus-roq}</version>
6064
</dependency>
61-
6265
<dependency>
63-
<groupId>io.quarkus</groupId>
64-
<artifactId>quarkus-arc</artifactId>
66+
<groupId>io.quarkiverse.roq</groupId>
67+
<artifactId>quarkus-roq-plugin-sitemap</artifactId>
68+
<version>${version.quarkus-roq}</version>
6569
</dependency>
70+
6671
<dependency>
6772
<groupId>com.fasterxml.jackson.dataformat</groupId>
6873
<artifactId>jackson-dataformat-yaml</artifactId>
@@ -71,12 +76,13 @@
7176
<groupId>com.fasterxml.jackson.datatype</groupId>
7277
<artifactId>jackson-datatype-jsr310</artifactId>
7378
</dependency>
74-
7579
<dependency>
76-
<groupId>io.quarkiverse.roq</groupId>
77-
<artifactId>quarkus-roq-plugin-sitemap</artifactId>
78-
<version>${version.quarkus-roq}</version>
80+
<groupId>org.mvnpm</groupId>
81+
<artifactId>highlight.js</artifactId>
82+
<version>11.11.1</version>
83+
<scope>provided</scope>
7984
</dependency>
85+
8086
<dependency>
8187
<groupId>io.quarkus</groupId>
8288
<artifactId>quarkus-junit5</artifactId>

public/css/org_common.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ These are the common css styles for the JBoss.org site.
9494

9595
/* = Common tags and elements */
9696

97+
pre:has(code) {
98+
margin: 0px;
99+
max-height: max-content;
100+
width: auto;
101+
padding: 0px;
102+
border: none;
103+
}
104+
97105
pre {
98106
margin: 0px;
99107
padding: 10px;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
site.escaped-pages=posts/*.md,docs/**.adoc
22

33
quarkus.log.category."io.quarkiverse.roq.frontmatter.deployment".level=DEBUG
4+
5+
quarkus.web-bundler.dependencies.auto-import=all
6+
quarkus.asciidoc.attributes.icons=font
7+
quarkus.asciidoc.attributes.source-highlighter=highlight.js

0 commit comments

Comments
 (0)