Create a Java Client Application
This sample Java application has been created to demonstrate communication with the Morgan Stanley API offering. It requires some simple security configuration based on setup with Morgan Stanley.
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. The PKCS8 format is a standardized way to store a private key information. To convert the
private_key.pem to PKCS8 use the following command.
openssl pkcs8 -topk8 -inform PEM -outform DER -in private_key.pem -out private_key.der -nocrypt
der output format is a 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.
Configuring the Java Client
Open the sample application below in an IDE or text editor and make the following changes to the Client application.yaml
The client id that will be sent to you from your Morgan Stanley contact
The scope/s that will be sent to from your Morgan Stanley contact
The path to the private_key.der that has been created
The path to the public_key.cer that was created and sent to your Morgan Stanley contact
The application is pre-configured to call the "Hello" endpoint (https://api.morganstanley.com/hello/services). This is visible in the java file
Main.java and you can optionally change this to another API endpoint.
The sample code below can be copied into your IDE of choice or alternatively you can download the code here.
Running the Java Client Application
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:
If the result is empty, you will need to download and configure Java on your machine.
Once the Java SDK is installed and the
JAVA_HOME environment variable has been set it is possible to run the application. This can be done using the terminal/command prompt and navigating to the java folder. From here type in the appropriate command to launch the application
The Application will launch and connect to the Morgan Stanley API offering and output the result.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.