Skip to content

Commit

Permalink
align README.md vs functionality
Browse files Browse the repository at this point in the history
Signed-off-by: Maxim Nesen <maxim.nesen@oracle.com>
  • Loading branch information
senivam committed Feb 20, 2024
1 parent 63f97fd commit 92f29b6
Show file tree
Hide file tree
Showing 110 changed files with 714 additions and 453 deletions.
2 changes: 1 addition & 1 deletion examples/config/basics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ containing config in HOCON (Human-Optimized Config Object Notation) format

## Build and run

```bash
```shell
mvn package
java -jar target/helidon-examples-config-basics.jar
```
2 changes: 1 addition & 1 deletion examples/config/changes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ the most up-to-date value. Sometimes that is all you need.

## Build and run

```bash
```shell
mvn package
java -jar target/helidon-examples-config-changes.jar
```
2 changes: 1 addition & 1 deletion examples/config/git/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ checks to make sure the value is the expected `hello`.

## Build and run

```bash
```shell
mvn package
export ENVIRONMENT_NAME=test
java -jar target/helidon-examples-config-git.jar
Expand Down
2 changes: 1 addition & 1 deletion examples/config/mapping/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ system how to construct a POJO instance.

## Build and run

```bash
```shell
mvn package
java -jar target/helidon-examples-config-mapping.jar
```
2 changes: 1 addition & 1 deletion examples/config/metadata/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Example:

## Build and run

```bash
```shell
mvn package
java -jar target/helidon-examples-config-metadata.jar > application.yaml
```
2 changes: 1 addition & 1 deletion examples/config/overrides/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ take precedence over the settings in the original config sources.

## Build and run

```bash
```shell
mvn package
java -jar target/helidon-examples-config-overrides.jar
```
2 changes: 1 addition & 1 deletion examples/config/sources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ filter.

## Build and run

```bash
```shell
mvn package
java -jar target/helidon-examples-config-sources.jar
```
72 changes: 46 additions & 26 deletions examples/cors/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ uncomment that line and then package and run the application.

## Build and run

```bash
```shell
mvn package
java -jar helidon-examples-cors.jar
java -jar target/helidon-examples-cors.jar
```

## Using the app endpoints as with the "classic" greeting app

These normal greeting app endpoints work just as in the original greeting app:

```bash
```shell
curl -X GET http://localhost:8080/greet
{"message":"Hello World!"}

Expand All @@ -45,7 +45,7 @@ The following requests illustrate the CORS protocol with the example app.
By setting `Origin` and `Host` headers that do not indicate the same system we trigger CORS processing in the
server:

```bash
```shell
# Follow the CORS protocol for GET
curl -i -X GET -H "Origin: http://foo.com" -H "Host: here.com" http://localhost:8080/greet

Expand All @@ -63,8 +63,17 @@ Note the new headers `Access-Control-Allow-Origin` and `Vary` in the response.

The same happens for a `GET` requesting a personalized greeting (by passing the name of the
person to be greeted):
```bash
```shell
curl -i -X GET -H "Origin: http://foo.com" -H "Host: here.com" http://localhost:8080/greet/Joe

HTTP/1.1 200 OK
Date: Wed, 31 Jan 2024 11:58:06 +0100
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 24
Content-Type: application/json
Vary: ORIGIN

{"greeting":"Hola Joe!"}
```
These two `GET` requests work because the `Main#corsSupportForGreeting` method adds a default `CrossOriginConfig` to the
Expand All @@ -83,24 +92,25 @@ The CORS protocol requires the client to send a _pre-flight_ request before send

This command sends a pre-flight `OPTIONS` request to see if the server will accept a subsequent `PUT` request from the
specified origin to change the greeting:
```bash
```shell
curl -i -X OPTIONS \
-H "Access-Control-Request-Method: PUT" \
-H "Origin: http://foo.com" \
-H "Host: here.com" \
http://localhost:8080/greet/greeting

HTTP/1.1 200 OK
Date: Wed, 31 Jan 2024 12:00:15 +0100
Access-Control-Allow-Methods: PUT
Access-Control-Allow-Origin: http://foo.com
Date: Thu, 30 Apr 2020 17:30:59 -0500
transfer-encoding: chunked
connection: keep-alive
Access-Control-Max-Age: 3600
Connection: keep-alive
Content-Length: 0
```
The successful status and the returned `Access-Control-Allow-xxx` headers indicate that the
server accepted the pre-flight request. That means it is OK for us to send `PUT` request to perform the actual change
of greeting. (See below for how the server rejects a pre-flight request.)
```bash
```shell
curl -i -X PUT \
-H "Origin: http://foo.com" \
-H "Host: here.com" \
Expand All @@ -111,14 +121,24 @@ curl -i -X PUT \
http://localhost:8080/greet/greeting

HTTP/1.1 204 No Content
Date: Wed, 31 Jan 2024 12:01:45 +0100
Access-Control-Allow-Origin: http://foo.com
Date: Thu, 30 Apr 2020 17:32:55 -0500
Vary: Origin
connection: keep-alive
Connection: keep-alive
Content-Length: 0
Vary: ORIGIN
```
And we run one more `GET` to observe the change in the greeting:
```bash
```shell
curl -i -X GET -H "Origin: http://foo.com" -H "Host: here.com" http://localhost:8080/greet/Joe

HTTP/1.1 200 OK
Date: Wed, 31 Jan 2024 12:02:13 +0100
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 26
Content-Type: application/json
Vary: ORIGIN

{"greeting":"Cheers Joe!"}
```
Note that the tests in the example `MainTest` class follow these same steps.
Expand All @@ -131,38 +151,38 @@ need this feature, but the example shows how easy it is to add.

With the same server running, repeat the `OPTIONS` request from above, but change the `Origin` header to refer to
`other.com`:
```bash
```shell
curl -i -X OPTIONS \
-H "Access-Control-Request-Method: PUT" \
-H "Origin: http://other.com" \
-H "Host: here.com" \
http://localhost:8080/greet/greeting
HTTP/1.1 403 Forbidden
Date: Mon, 4 May 2020 10:49:41 -0500
transfer-encoding: chunked
connection: keep-alive
HTTP/1.1 403 CORS origin is not in allowed list
Date: Wed, 31 Jan 2024 12:02:51 +0100
Connection: keep-alive
Content-Length: 0
```
This fails because the app set up CORS using the "restrictive-cors" configuration in `application.yaml` which allows
sharing only with `foo.com` and `there.com`, not with `other.com`.

Stop the running app, uncomment the commented section at the end of `application.yaml`, and build and run the app again.
```bash
```shell
mvn package
java -jar helidon-examples-cors.jar
java -jar target/helidon-examples-cors.jar
```
Send the previous `OPTIONS` request again and note the successful result:
```bash
```shell
HTTP/1.1 200 OK
Date: Wed, 31 Jan 2024 12:05:36 +0100
Access-Control-Allow-Methods: PUT
Access-Control-Allow-Origin: http://other.com
Access-Control-Max-Age: 3600
Date: Mon, 4 May 2020 18:52:54 -0500
transfer-encoding: chunked
connection: keep-alive
Connection: keep-alive
Content-Length: 0
```
The application uses the now-uncommented portion of the config file to override the rest of the CORS set-up. You can
choose whatever key name you want for the override. Just make sure you tell your end users whatever the key is your app
uses for overrides.

A real application might read the normal configuration (`restrictive-cors`) from one config source and any overrides
from another. This example combines them in one config source just for simplicity.
from another. This example combines them in one config source just for simplicity.
6 changes: 6 additions & 0 deletions examples/dbclient/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
Each subdirectory contains example code that highlights specific aspects of
Helidon DB Client.

build examples in all folders (including the common folder) by
```shell
mvn package
```
in the current folder.

---

Pokémon, and Pokémon character names are trademarks of Nintendo.
22 changes: 22 additions & 0 deletions examples/dbclient/common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Common library for the DB Client examples

shall be built using

```shell

mvn install

```

to be accessible for the DB Client examples

or make the whole pack of DB Client examples at the level above by

```shell

cd ../
mvn package

```

and get all DB Client examples compiled at once.
2 changes: 1 addition & 1 deletion examples/dbclient/mongodb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ java -jar target/helidon-examples-dbclient-mongodb.jar
```


## Exercise
## Exercise

The application has the following endpoints:

Expand Down
6 changes: 3 additions & 3 deletions examples/dbclient/pokemons/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Helidon DB Client Pokemon Example with JDBC
# Helidon DB Client Pokémon Example with JDBC

This example shows how to run Helidon DB Client over JDBC.

Application provides REST service endpoint with CRUD operations on Pokemons
Application provides REST service endpoint with CRUD operations on Pokémons
database.

## Database
Expand All @@ -24,7 +24,7 @@ Database model contains two tables:
| name | varchar | &nbsp; |
| id_type | integer | Type(id) |

with 1:N relationship between *Types* and *Pokemons*
with 1:N relationship between *Types* and *Pokémons*

Examples are given for H2, Oracle, or MySQL databases (note that MySQL is currently not supported for GraalVM native image)

Expand Down
6 changes: 3 additions & 3 deletions examples/employee-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ The service uses Helidon DB Client to access the database.

## Build and run

```bash
```shell
mvn package
java -jar target/employee-app.jar
java -jar target/helidon-examples-employee-app.jar
```

## Create script
Expand Down Expand Up @@ -290,4 +290,4 @@ INSERT INTO EMPLOYEE (ID, FIRSTNAME, LASTNAME, EMAIL, PHONE, BIRTHDATE, TITLE, D
INSERT INTO EMPLOYEE (ID, FIRSTNAME, LASTNAME, EMAIL, PHONE, BIRTHDATE, TITLE, DEPARTMENT) VALUES (EMPLOYEE_SEQ.nextVal, 'Zora', 'Sawayn', 'Zora.Sawayn@example.com', '923-555-0161', '1978-03-18', 'Dynamic Marketing Designer', 'Security');

INSERT INTO EMPLOYEE (ID, FIRSTNAME, LASTNAME, EMAIL, PHONE, BIRTHDATE, TITLE, DEPARTMENT) VALUES (EMPLOYEE_SEQ.nextVal, 'Cordia', 'Willms', 'Cordia.Willms@example.com', '778-555-0187', '1989-03-31', 'Human Division Representative', 'Optimization');
```
```
6 changes: 3 additions & 3 deletions examples/graphql/basics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ manually creates a GraphQL Schema using the [GraphQL Java](https://github.com/gr

Start the application:

```bash
```shell
mvn package
java -jar target/helidon-examples-graphql-basics.jar
```
Expand All @@ -18,15 +18,15 @@ Probe the GraphQL endpoints:

1. Hello word endpoint:

```bash
```shell
curl -X POST http://127.0.0.1:PORT/graphql -d '{"query":"query { hello }"}'

"data":{"hello":"world"}}
```

1. Hello in different languages

```bash
```shell
curl -X POST http://127.0.0.1:PORT/graphql -d '{"query":"query { helloInDifferentLanguages }"}'
{"data":{"helloInDifferentLanguages":["Bonjour","Hola","Zdravstvuyte","Nǐn hǎo","Salve","Gudday","Konnichiwa","Guten Tag"]}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2023 Oracle and/or its affiliates.
* Copyright (c) 2020, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -48,7 +48,7 @@ public static void main(String[] args) {
.routing(routing -> routing
.register(GraphQlService.create(buildSchema())))
.build();

server.start();
String endpoint = "http://localhost:" + server.port();
System.out.printf("""
GraphQL started on %1$s/graphql
Expand Down
8 changes: 4 additions & 4 deletions examples/health/basics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ custom health check.

Start the application:

```bash
```shell
mvn package
java -jar target/helidon-examples-health-basics.jar
```
Expand All @@ -17,7 +17,7 @@ Note the port number reported by the application.

Probe the health endpoints:

```bash
curl -X GET http://localhost:PORT/health/
curl -X GET http://localhost:PORT/health/ready
```shell
curl -i -X GET http://localhost:8080/observe/health/ready
curl -i -X GET http://localhost:8080/observe/health/
```
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2023 Oracle and/or its affiliates.
* Copyright (c) 2018, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -49,6 +49,7 @@ public static void main(String[] args) {
ObserveFeature observe = ObserveFeature.builder()
.observersDiscoverServices(true)
.addObserver(HealthObserver.builder()
.details(true)
.useSystemServices(true)
.addCheck(() -> HealthCheckResponse.builder()
.status(HealthCheckResponse.Status.UP)
Expand All @@ -65,6 +66,7 @@ public static void main(String[] args) {
.featuresDiscoverServices(false)
.addFeature(observe)
.routing(Main::routing)
.port(8080)
.build()
.start();

Expand Down
Loading

0 comments on commit 92f29b6

Please sign in to comment.