This file provides you background information for setting up and running the sample implementation of the Wishlist service.
To get the most of this guide, you should be able to work with Java, Apache Maven, and git.
The list of required software and operating systems is listed on the Prerequisites page of the Getting Started guides on the Dev Portal.
You need credentials to access APIs on YaaS. The easiest way to get such credentials is to declare that the API calls are made by one of your applications.
-
Register and sign in to the Builder.
-
Create or join an organization.
If you don't have an organization yet, we suggest you create an organization with a non-commercial purpose. This will allow you to carry on with the subscription to beta packages.
-
Follow the instructions of the Create Projects guide to create a new project and subscribe to the following beta packages:
- Customer Accounts (Beta)
- Email (Beta)
- Media (Beta)
- Persistence (Beta)
Take note of the Identifier of your project.
-
Create an client for your project and select the required scopes:
- hybris.customer_read
- hybris.customer_create
- hybris.email_manage
- hybris.email_send
- hybris.media_manage
- hybris.document_view
- hybris.document_manage
Take note of the Identifier of your client, as well as of its Client ID and Client Secret.
From the point of view of this service, a wishlist belongs to one of your customers. This means that you need to create a test customer account to carry on.
-
Get a token to authenticate and authorize the API call:
- Open the API console for the OAuth2 API on the Dev Portal.
- Select the POST method for the endpoint
/token
, then click Try It. - Enter the client_id and client_secret of your client.
- Enter the grant_type :
client_credentials
. - Enter the scope:
hybris.customer_create
. - Send the request by clicking POST. Check that the OAuth2 service returns a response with the status
200 (OK)
and with a body containing the requested scope. - Locate the access_token in the body of the response and take note of its value.
-
Create the customer:
-
Open the API console for the Customer API on the Dev Portal.
-
Select the POST method for the endpoint
{tenant}/customers
, then click Try It. -
Enter the tenant URL parameter: Use the Identifier of your project.
-
Enter the Authorization header:
Bearer
, followed by the access token received above. -
Enter the Body:
{ "firstName": "<your first name>", "contactEmail": "<your e-mail address>" }
-
Send the request by clicking POST. Check that the Customer service returns a response with the status
201 (Created)
and with a body containing the customer information. -
Take note of the id of your new customer.
-
The source code contains automated tests that ensure that the service works as expected. These tests need information about your test project. Moreover, you need to provide your client credentials so that the service can authenticate against YaaS.
-
Clone the git repository:
git clone https://github.com/SAP/yaas_java_jersey_wishlist.git cd yaas_java_jersey_wishlist
-
Use your favorite editor to edit the file TestConstants.java under
src/test/java/com/sap/wishlist/api
:- Update the constant TENANT: Set it to the Identifier of your project.
- Update the constant CUSTOMER: Set it to the id of your customer.
-
Edit the file default.properties under
src/main/resources
:- Set the parameter YAAS_CLIENT_IS_APPLICATION to
true
, as you are using the credentials of your client and run in single tenant mode. - Set the parameter YAAS_CLIENT to the Identifier of your client
- Set the parameter YAAS_CLIENT_ID to the Client ID of your client.
- Set the parameter YAAS_CLIENT_SECRET to the Client Secret of your client.
- Set the parameter YAAS_CLIENT_IS_APPLICATION to
It is recommended that you provide these credentials using environment variables. When deploying the service to CloudFoundry, provide the credentials as environment entries within the manifest.yml used for the deployment.
However, in this example, we set them in the source code for the sake of simplicity.