Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated java readme files #51

Merged
merged 3 commits into from
Feb 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions client-samples/java/rest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ This project is a starting template for integrating with REST APIs on the API Pl
## Using this template
The first step is to create the DER encoded file and configure the properties file, as described below.

This template provides two methods for making API calls: using a simple OkHttp request or a Retrofit request. The okHttp method is shown in a singular function with sequential instructions, whereas the retrofit code has been wrapped in the `MsRetrofitWrapper` class.
Using retrofit requires more code changes, so it is recommended to initially call the API with the OkHttp request.
This template provides two methods for making API calls: an OkHttp request and a Retrofit2 request. The OkHttp method is shown in a singular function with sequential instructions, whereas the Retrofit code has been wrapped in the `MsRetrofitWrapper` class.
Using Retrofit2 requires more code changes, so it is recommended to check your authentication is working and initially call the API with the OkHttp request.

To configure this application for a different API, the following changes need to be made (there are more details on retrofit below):
To configure this application for a different API, the following changes need to be made (there are further details on Retrofit2 below):

| Method | Class | What needs to be changed? |
|----------------|------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
Expand All @@ -31,18 +31,23 @@ _If you are using the OkHttp template_
_If you are using the Retrofit template_
- [`ExampleApplication.java`](./src/main/java/com/ms/infra/example/application/ExampleApplication.java)

## Java Versions
This template works with the following Java LTS versions:
- 11
- 17
- 21

## Create DER Encoded File
For this example the RSA Private key that was generated, `private_key.pem`, is not in a format that Java will understand and needs to be converted to a binary encoding.
For this template, the RSA Private key that was generated, `private_key.pem`, is not in a format that Java will understand and needs to be converted to a binary encoding.
The [PKCS8](https://en.wikipedia.org/wiki/PKCS_8) format is a standardized way to store a private key information.
To convert the `private_key.pem` to PKCS8 use the following command

```shell
openssl pkcs8 -topk8 -inform PEM -outform DER -in private_key.pem -out private_key.der -nocrypt
```
The `der` output format is a just an encoding format, to find out more check <https://en.wikipedia.org/wiki/X.690#DER_encoding>
The `der` output format is just an encoding format, to find out more check <https://en.wikipedia.org/wiki/X.690#DER_encoding>

Now that we have the file private key in a usable format we can use the Java Client to test the connection to Morgan Stanley's API offering.
Now that we have the private key file in a usable format, we can use the Java Client to test the connection to Morgan Stanley's API offering.

## Configuring the Java Client

Expand All @@ -61,7 +66,7 @@ Make these changes to the `META-INF/microprofile-config.properties` resource fil
| `proxy-port` | Optional proxy port | False |

## Retrofit
This example app uses plain Java, with no larger frameworks such as Spring Boot. It uses the retrofit library, which configures API calls as an interface. Please see the [HelloWorldRestService interface](./src/main/java/com/ms/infra/example/application/servies/HelloWorldRestService.java) for an example. You can find the Retrofit docs [here](https://square.github.io/retrofit/).
This template uses plain Java, with no larger frameworks such as Spring Boot. It uses the retrofit library, which configures API calls as an interface. Please see the [HelloWorldRestService interface](./src/main/java/com/ms/infra/example/application/servies/HelloWorldRestService.java) for an example. You can find the Retrofit docs [here](https://square.github.io/retrofit/).

Below are the example services we have configured (using the hello world endpoint):

Expand All @@ -73,6 +78,12 @@ Below are the example services we have configured (using the hello world endpoin
The `ExampleApplication.java` file shows how to use the MsRetrofitWrapper and makes a GET request to the `services` endpoint.

## Running the Java Client application
This template is designed and tested on the following Java LTS versions:
- 11
- 17
- 21


It is important to ensure that the Java SDK is installed and the `JAVA_HOME` environment variable has been set.
This can be checked by performing the following:

Expand Down
10 changes: 8 additions & 2 deletions client-samples/java/websockets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ To convert the `private_key.pem` to PKCS8 use the following command
```shell
openssl pkcs8 -topk8 -inform PEM -outform DER -in private_key.pem -out private_key.der -nocrypt
```
The `der` output format is a just an encoding format, to find out more check <https://en.wikipedia.org/wiki/X.690#DER_encoding>
The `der` output format is just an encoding format, to find out more check <https://en.wikipedia.org/wiki/X.690#DER_encoding>

Now that we have the file private key in a usable format we can use the Java Client to test the connection to Morgan Stanley's API offering.
Now that we have the private key file in a usable format we can use the Java Client to test the connection to Morgan Stanley's API offering.

### Properties
Make these changes to the `META-INF/microprofile-config.properties` resource file
Expand All @@ -33,6 +33,12 @@ Make these changes to the `META-INF/microprofile-config.properties` resource fil
| `proxy-port` | Optional proxy port | False |

## Running the Java Client application
This template is designed and tested on the following Java LTS versions:
- 11
- 17
- 21


It is important to ensure that the Java SDK is installed and the `JAVA_HOME` environment variable has been set.
This can be checked by performing the following:

Expand Down