|
| 1 | +# Cloudevents Restful WS Microprofile Example |
| 2 | + |
| 3 | +This project uses Microprofile 5.0 with OpenLiberty |
| 4 | + |
| 5 | +If you would like to know more about Microprofile go to https://microprofile.io |
| 6 | + |
| 7 | +This Example uses Jakarta EE9 features as such the top level namespace of the `ws-api` packages has changed from `javax` to `jakarta` and uses the `cloudevents-http-restful-ws-jakarta` artifact. |
| 8 | + |
| 9 | +## Build and Execution |
| 10 | + |
| 11 | +### Running the application in dev mode |
| 12 | + |
| 13 | +You can run your application in dev mode that enables live coding using: |
| 14 | +``` |
| 15 | +mvn liberty:dev |
| 16 | +``` |
| 17 | + |
| 18 | +### Packaging and running the application |
| 19 | + |
| 20 | +To Package and run as a minimum jar without a full OpenLiberty server |
| 21 | +``` |
| 22 | +mvn liberty:package -Drunnable=mvn liberty:package -Dinclude=runnable |
| 23 | +``` |
| 24 | + |
| 25 | +### Making requests against the server |
| 26 | + |
| 27 | +This sample application has a `/events` RESTful endpoint on the application `cloudevents-restful-ws-microprofile-example |
| 28 | +the base application is available at `http://localhost:9080/cloudevents-restful-ws-microprofile-example/` |
| 29 | + |
| 30 | +There are three operations that can be performed: |
| 31 | +#### GET /events |
| 32 | +Returns a Cloud event with a payload containing a message |
| 33 | + |
| 34 | +```shell |
| 35 | +curl -v http://localhost:9080/cloudevents-restful-ws-microprofile-example/events |
| 36 | + |
| 37 | +* Trying 127.0.0.1:9080... |
| 38 | +* Connected to localhost (127.0.0.1) port 9080 (#0) |
| 39 | +> GET /cloudevents-restful-ws-microprofile-example/events HTTP/1.1 |
| 40 | +> Host: localhost:9080 |
| 41 | +> User-Agent: curl/7.83.1 |
| 42 | +> Accept: */* |
| 43 | +> |
| 44 | +* Mark bundle as not supporting multiuse |
| 45 | +< HTTP/1.1 201 no-content |
| 46 | +< Ce-Id: hello |
| 47 | +< Ce-Source: http://localhost |
| 48 | +< Ce-Specversion: 1.0 |
| 49 | +< Ce-Type: example.http |
| 50 | +< Content-Type: application/json |
| 51 | +< Content-Language: en-GB |
| 52 | +< Content-Length: 64 |
| 53 | +< Date: Wed, 17 Aug 2022 14:01:50 GMT |
| 54 | +< |
| 55 | +{"message":"Welcome to this Cloudevents + Microprofile example"} |
| 56 | +``` |
| 57 | +
|
| 58 | +#### POST /events |
| 59 | +POST a Cloudevent with a payload that is printed out in the server logs |
| 60 | +
|
| 61 | +```shell |
| 62 | +curl -v http://localhost:9080/cloudevents-restful-ws-microprofile-example/events \ |
| 63 | +-H "Ce-Specversion: 1.0" \ |
| 64 | +-H "Ce-Type: User" \ |
| 65 | +-H "Ce-Source: io.cloudevents.examples/user" \ |
| 66 | +-H "Ce-Id: 536808d3-88be-4077-9d7a-a3f162705f78" \ |
| 67 | +-H "Content-Type: application/json" \ |
| 68 | +-H "Ce-Subject: SUBJ-0001" \ |
| 69 | +-d "hello" |
| 70 | + |
| 71 | +* Trying 127.0.0.1:9080... |
| 72 | +* Connected to localhost (127.0.0.1) port 9080 (#0) |
| 73 | +> POST /cloudevents-restful-ws-microprofile-example/events HTTP/1.1 |
| 74 | +> Host: localhost:9080 |
| 75 | +> User-Agent: curl/7.83.1 |
| 76 | +> Accept: */* |
| 77 | +> Ce-Specversion: 1.0 |
| 78 | +> Ce-Type: User |
| 79 | +> Ce-Source: io.cloudevents.examples/user |
| 80 | +> Ce-Id: 536808d3-88be-4077-9d7a-a3f162705f78 |
| 81 | +> Content-Type: application/json |
| 82 | +> Ce-Subject: SUBJ-0001 |
| 83 | +> Content-Length: 5 |
| 84 | +> |
| 85 | +* Mark bundle as not supporting multiuse |
| 86 | +< HTTP/1.1 204 No Content |
| 87 | +< Content-Language: en-GB |
| 88 | +< Content-Length: 0 |
| 89 | +< Date: Thu, 18 Aug 2022 13:33:03 GMT |
| 90 | +< |
| 91 | +* Connection #0 to host localhost left intact |
| 92 | +``` |
| 93 | +Server log statement |
| 94 | +``` |
| 95 | +[INFO] Received request providing a event with body hello |
| 96 | +[INFO] CloudEvent{id='536808d3-88be-4077-9d7a-a3f162705f78', source=io.cloudevents.examples/user, type='User', datacontenttype='application/json', subject='SUBJ-0001', data=BytesCloudEventData{value=[104, 101, 108, 108, 111]}, extensions={}} |
| 97 | +``` |
| 98 | +
|
| 99 | +#### POST /events/echo |
| 100 | +POST a Cloudevent with a payload and have it echoed back as a Cloudevent |
| 101 | +
|
| 102 | +```shell |
| 103 | +curl -v http://localhost:9080/cloudevents-restful-ws-microprofile-example/events/echo \ |
| 104 | +-H "Ce-Specversion: 1.0" \ |
| 105 | +-H "Ce-Type: User" \ |
| 106 | +-H "Ce-Source: io.cloudevents.examples/user" \ |
| 107 | +-H "Ce-Id: 536808d3-88be-4077-9d7a-a3f162705f78" \ |
| 108 | +-H "Content-Type: application/json" \ |
| 109 | +-H "Ce-Subject: SUBJ-0001" \ |
| 110 | +-d "hello" |
| 111 | + |
| 112 | +* Trying 127.0.0.1:9080... |
| 113 | +* Connected to localhost (127.0.0.1) port 9080 (#0) |
| 114 | +> POST /cloudevents-restful-ws-microprofile-example/rest/events/echo HTTP/1.1 |
| 115 | +> Host: localhost:9080 |
| 116 | +> User-Agent: curl/7.83.1 |
| 117 | +> Accept: */* |
| 118 | +> Ce-Specversion: 1.0 |
| 119 | +> Ce-Type: User |
| 120 | +> Ce-Source: io.cloudevents.examples/user |
| 121 | +> Ce-Id: 536808d3-88be-4077-9d7a-a3f162705f78 |
| 122 | +> Content-Type: application/json |
| 123 | +> Ce-Subject: SUBJ-0001 |
| 124 | +> Content-Length: 5 |
| 125 | +> |
| 126 | +* Mark bundle as not supporting multiuse |
| 127 | +< HTTP/1.1 200 OK |
| 128 | +< Ce-Id: echo |
| 129 | +< Ce-Source: http://localhost |
| 130 | +< Ce-Specversion: 1.0 |
| 131 | +< Ce-Type: echo.http |
| 132 | +< Content-Type: application/json |
| 133 | +< Content-Language: en-GB |
| 134 | +< Content-Length: 17 |
| 135 | +< Date: Wed, 17 Aug 2022 12:57:59 GMT |
| 136 | +< |
| 137 | +{"echo": "hello"}* Connection #0 to host localhost left intact |
| 138 | +``` |
| 139 | +
|
| 140 | +
|
0 commit comments