Skip to content

Commit 0f4f83d

Browse files
committed
Fix WebAPI client example for Java
Signed-off-by: Yasumasa Suenaga <[email protected]>
1 parent b9b261c commit 0f4f83d

File tree

129 files changed

+39
-23337
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+39
-23337
lines changed

samples/java-client/README.md

+12-41
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,19 @@
11
# Java Client Example
22

3-
This folder contains an example for WebAPI client in Java. Client library would
4-
be generated dynamically via
5-
[openapi-generator-maven-plugin](https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator-maven-plugin),
6-
and call WebAPI endpoints without HTTP code.
3+
This folder contains an example for WebAPI client in Java. Client library would be pulled from [GitHub Packages](https://github.com/orgs/Green-Software-Foundation/packages?repo_name=carbon-aware-sdk).
74

8-
Javadoc is [here](apidocs).
9-
10-
openapi-generator-maven-plugin generates Maven/Gradle project when it kicks,
11-
however this example uses generated codes directly. So you don't need to
12-
run/modify project files in it.
5+
Javadoc is [here](https://carbon-aware-sdk.greensoftware.foundation/client-apidocs/1.0.0/java).
136

147
## Requirements
158

16-
- OpenAPI spec file
17-
- Both online and offline file are available.
18-
- See [WebAPI document](../../docs/carbon-aware-webapi.md#autogenerate-webapi)
19-
for details.
209
- WebAPI instance
21-
- See the [Overview](../../docs/overview.md#publish-webapi-with-container)
22-
if you'd like to start it on container.
10+
- See the [Overview](../../docs/overview.md#publish-webapi-with-container) if you'd like to start it on container.
2311
- Java 8 or later
2412
- Maven
2513

2614
## Client code
2715

28-
[WebApiClient.java](src/main/java/foundation/greensoftware/carbonawaresdk/samples/java/WebApiClient.java)
29-
is an example program to call WebAPI endpoint. It calls all of endpoints, and
30-
shows the result.
16+
[WebApiClient.java](src/main/java/example/foundation/greensoftware/carbonawaresdk/WebApiClient.java) is an example program to call WebAPI endpoint. It calls all of endpoints, and shows the result.
3117

3218
Following methods are available:
3319

@@ -53,19 +39,14 @@ Following methods are available:
5339
- Call /emissions/average-carbon-intensity/batch
5440
- Shows average data for westus yesterday.
5541

56-
[OffsetDateTime](https://docs.oracle.com/javase/8/docs/api/java/time/OffsetDateTime.html)
57-
is used for parameters in each APIs. However the error occurs if nano sec is set
58-
to it in case of WattTime. So it is highly recommended that clears nanosec field
59-
like `withNano(0)`.
42+
[OffsetDateTime](https://docs.oracle.com/javase/8/docs/api/java/time/OffsetDateTime.html) is used for parameters in each APIs. However the error occurs if nano sec is set to it in case of WattTime. So it is highly recommended that clears nanosec field like `withNano(0)`.
6043

6144
## How it works
6245

6346
### 1. Set up for [POM](pom.xml)
6447

6548
You need to change following properties:
6649

67-
- `openapi.spec`
68-
- OpenAPI spec file
6950
- `webapi.endpoint`
7051
- WebAPI base URL
7152

@@ -83,27 +64,23 @@ $ mvn exec:java
8364

8465
### Running in container
8566

86-
This example also can run in container. You can use
87-
[Maven official image](https://hub.docker.com/_/maven).
67+
This example also can run in container. You can use [Maven official image](https://hub.docker.com/_/maven).
8868

89-
If you want to run both WebAPI and build process in container, you need to join
90-
2 containers to same network.
69+
If you want to run both WebAPI and build process in container, you need to join 2 containers to same network.
9170

9271
Following instructions are for Podman.
9372

9473
#### 1. Create pod
9574

96-
This pod publishes port 80 in the pod to 8080 on the host, then you can access
97-
WebAPI in the pod. The pod is named to `carbon-aware-sdk`.
75+
This pod publishes port 80 in the pod to 8080 on the host, then you can access WebAPI in the pod. The pod is named to `carbon-aware-sdk`.
9876

9977
```sh
10078
podman pod create -p 8080:80 --name carbon-aware-sdk
10179
```
10280

10381
#### 2. Start WebAPI container
10482

105-
Start WebAPI container in `carbon-aware-sdk` pod. It is specified at `--pod`
106-
option.
83+
Start WebAPI container in `carbon-aware-sdk` pod. It is specified at `--pod` option.
10784

10885
See [Overview](../../docs/overview.md) document to build container image.
10986

@@ -117,13 +94,9 @@ $ podman run -it --rm --pod carbon-aware-sdk \
11794

11895
#### 3. Run Maven in the container
11996

120-
Run `mvn` command in Maven container in `catbon-aware-sdk` pod. You need to
121-
mount Carbon Aware SDK source directory to the container. It mounts to `/src` in
122-
the container in following case.
97+
Run `mvn` command in Maven container in `catbon-aware-sdk` pod. You need to mount Carbon Aware SDK source directory to the container. It mounts to `/src` in the container in following case.
12398

124-
In following command, you can rebuild java-client, and can run the artifact. You
125-
can get artifacts from `samples/java-client/target` on the container host of
126-
course.
99+
In following command, you can rebuild java-client, and can run the artifact. You can get artifacts from `samples/java-client/target` on the container host of course.
127100

128101
```sh
129102
$ podman run -it --rm --pod carbon-aware-sdk \
@@ -132,6 +105,4 @@ $ podman run -it --rm --pod carbon-aware-sdk \
132105
mvn -f /src/samples/java-client/pom.xml clean package exec:java
133106
```
134107

135-
Maven will download many dependencies in each `mvn` call. You can avoid it when
136-
you mount `.m2` like `-v $HOME/.m2:/root/.m2` because it shares Maven cache
137-
between the host and the container.
108+
Maven will download many dependencies in each `mvn` call. You can avoid it when you mount `.m2` like `-v $HOME/.m2:/root/.m2` because it shares Maven cache between the host and the container.

0 commit comments

Comments
 (0)