Skip to content

Commit 11b0a77

Browse files
authored
Migration Guides: add section for Getters returning Optional. Fix code blocks. (helidon-io#2217)
1 parent f236587 commit 11b0a77

2 files changed

Lines changed: 67 additions & 25 deletions

File tree

docs/mp/guides/15_migration.adoc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,20 @@ in groupId `jakarta` (Jakarta EE modules).
103103
In case you declared a dependency on a javax module, you should change it to a jakarta one.
104104
105105
Example:
106-
```xml
106+
[source,xml]
107+
----
107108
<dependency>
108109
<groupId>javax.activation</groupId>
109110
<artifactId>javax.activation-api</artifactId>
110111
</dependency>
111-
```
112+
----
112113
113114
should be changed to
114-
```xml
115+
[source,xml]
116+
----
115117
<dependency>
116118
<groupId>jakarta.activation</groupId>
117119
<artifactId>jakarta.activation-api</artifactId>
118120
</dependency>
119-
```
120-
As the `javax` module is no longer in dependency management of Helidon parent pom files.
121+
----
122+
As the `javax` module is no longer in dependency management of Helidon parent pom files.

docs/se/guides/15_migration.adoc

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,36 @@ will help you migrate a Helidon SE 1.x application to 2.x.
2828
2929
include::../../common/guides/migration.adoc[]
3030
31+
== Getters
32+
33+
Some methods that act as getters of type `T` have been modified to return `Optional<T>`. You will
34+
need to change your code to handle the `Optional` return type. For example `ServerRequest.spanContext()`
35+
in 1.x had a return type of `SpanContext`. In 2.x it has a return type of `Optional<SpanContext>`.
36+
So if you had code like:
37+
38+
[source,java]
39+
.Helidon 1.x Code
40+
----
41+
Span myNewSpan = GlobalTracer.get()
42+
.buildSpan(“my-operation”)
43+
.asChildOf(serverRequest.spanContext())
44+
.start();
45+
----
46+
47+
you will need to change it to something like:
48+
49+
[source,java]
50+
.Helidon 2.x Code
51+
----
52+
Tracer.SpanBuilder spanBuilder = serverRequest.tracer()
53+
.buildSpan("my-operation");
54+
serverRequest.spanContext().ifPresent(spanBuilder::asChildOf);
55+
Span myNewSpan = spanBuilder.start();
56+
----
57+
58+
Note the use of `ifPresent()` on the returned `Optional<SpanContext>`.
59+
60+
3161
== Configuration
3262
3363
1. File watching is now done through a `ChangeWatcher` - use of `PollingStrategies.watch()` needs to be refactored to
@@ -51,7 +81,8 @@ include::../../common/guides/migration.adoc[]
5181
`Config` `Builder`
5282
5383
Example of advanced configuration of config:
54-
```java
84+
[source,java]
85+
----
5586
Config.builder()
5687
// system properties with a polling strategy of 10 seconds
5788
.addSource(ConfigSources.systemProperties()
@@ -67,7 +98,7 @@ Config.builder()
6798
// map config source (also supports polling strategy)
6899
.addSource(ConfigSources.create(Map.of("key", "value")))
69100
.build();
70-
```
101+
----
71102
72103
73104
== Resource class when loaded from Config
@@ -86,11 +117,12 @@ In Helidon 1.x support for JSON and other media types was configured when constr
86117
refactored so that it can be shared between the Helidon `WebServer` and `WebClient`.
87118
You now specify media support as part of the WebServer build:
88119
89-
```java
120+
[source,java]
121+
----
90122
WebServer.builder()
91123
.addMediaSupport(JsonpSupport.create()) //registers reader and writer for Json-P
92124
.build()
93-
```
125+
----
94126
95127
This replaces `Routing.builder().register(JsonSupport.create())...`
96128
@@ -128,33 +160,36 @@ Configuration has been updated to use the new `Resource` approach:
128160
The configuration has been updated to have a nicer tree structure:
129161
130162
Example of a public key from keystore:
131-
```yaml
163+
[source,yaml]
164+
----
132165
keystore:
133166
cert.alias: "service_cert"
134167
resource.path: "/conf/keystore.p12"
135168
type: "PKCS12"
136169
passphrase: "password"
137-
```
170+
----
138171
139172
Example of a private key from keystore:
140-
```yaml
173+
[source,yaml]
174+
----
141175
keystore:
142176
key:
143177
alias: "myPrivateKey"
144178
passphrase: "password"
145179
resource.resource-path: "keystore/keystore.p12"
146180
passphrase: "password"
147-
```
181+
----
148182
149183
Example of a pem resource with private key and certificate chain:
150-
```yaml
184+
[source,yaml]
185+
----
151186
pem:
152187
key:
153188
passphrase: "password"
154189
resource.resource-path: "keystore/id_rsa.p8"
155190
cert-chain:
156191
resource.resource-path: "keystore/public_key_cert.pem"
157-
```
192+
----
158193
159194
160195
== GrpcTlsDescriptor
@@ -174,29 +209,32 @@ Class `io.helidon.webserver.SSLContextBuilder` has been deprecated and will
174209
be removed.
175210
176211
The class uses a `Builder` pattern:
177-
```java
212+
[source,java]
213+
----
178214
TlsConfig.builder()
179215
.privateKey(KeyConfig.keystoreBuilder()
180216
.keystore(Resource.create("certificate.p12"))
181217
.keystorePassphrase("helidon")
182-
```
218+
----
183219
184220
The builder or built instance can be registered with a socket configuration builder
185221
including the `WebServer.Builder` itself:
186222
187-
```java
223+
[source,java]
224+
----
188225
WebServer.builder(routing())
189226
.tls(tlsConfig)
190227
.build();
191-
```
228+
----
192229
193230
=== Additional Sockets
194231
195232
Additional socket configuration has changed both in config
196233
and in API.
197234
198235
The configuration now accepts following structure:
199-
```yaml
236+
[source,yaml]
237+
----
200238
server:
201239
port: 8000
202240
sockets:
@@ -205,7 +243,7 @@ server:
205243
- name: "static"
206244
port: 8002
207245
enabled: false
208-
```
246+
----
209247
210248
Socket name is now a value of a property, allowing more freedom in naming.
211249
The default socket name is implicit (and set to `@default`).
@@ -214,12 +252,13 @@ We have added the `enabled` flag to support disabling sockets through configurat
214252
215253
To add socket using a builder, you can use:
216254
217-
```java
255+
[source,java]
256+
----
218257
WebServer.builder()
219258
.addSocket(SocketConfigurationBuidler.builder()
220259
.port(8001)
221260
.name("admin")));
222-
```
261+
----
223262
224263
There is also a specialized method to add a socket and routing
225264
together, to remove mapping through a name.
@@ -233,13 +272,14 @@ Most methods from this class have been moved to `WebServer.Builder` or deprecate
233272
234273
Example of a simple WebServer setup:
235274
236-
```java
275+
[source,java]
276+
----
237277
WebServer.builder()
238278
.port(8001)
239279
.host("localhost")
240280
.routing(createRouting())
241281
.build();
242-
```
282+
----
243283
244284
=== Other significant WebServer deprecations
245285

0 commit comments

Comments
 (0)