Building custom Service Extensions in Java for the Meal Program Library
We will start by looking at the Java side of the picture. As an overview, here are some of the topics you will learn:
- Understanding the design of a custom Meal Order Service
- Using built-in platform services such as Record, Association, Setting
- Understanding Exception Handling
- Exposing custom Service Actions for Process Designer
- Exposing your own REST-based interfaces for Lunch Tutorial
With Java code, it's possible to create many different ways of the outside world accessing your service. The following diagram shows four important interface styles that are all represented in the Meal Program Library project.
As you can see, all of these are based on the concept of a Service that you implement that has registered Java interfaces. The Service can accessed from outside in any or all of four ways:
Interface Method | How to Create It | How it is Used | Tutorial Example |
---|---|---|---|
Service Action | Annotate the implementation with the @Action keyword, and register it with your MyLibrary class | It appears as what is called a Service Action in Process Designer and can be used just like any built-in Activity. | Get Meal Order |
Data Page Query | Extend the DataPageQuery class in the Standard Library, and register it with your MyLibrary class. | Any HTTP client can perform a GET on the special DataPageQuery resource, and provide the custom DataPageQuery class and required parameters. This returns a standard JSON structure with an array of any kind of data. | Meal Order Data Page Query |
Custom Resource | Extend the RestfulResource class in the Standard Library, and register it with your MyLibrary class. | Any HTTP client can perform any operations such as GET, PUT, POST, DELETE you implement on your resource. These are normally not needed for typical data operations on Records (sometimes called CRUD operations), because the Record Service already exposes resource such as RecordInstanceResource for that kind of interaction. | Meal Order Resource |
Custom Command | Extend the Command class in the Standard Library, and register it with your MyLibrary class. | Any HTTP client can perform a POST to the special Command resource, and provide the custom Command class and required parameters. This is intended to perform some kind of action that has side-effects on the system and would not follow standard resource-oriented semantics (GET, PUT, POST, DELETE). | Cancel Meal Order Command |
Take a look at the package structure to see how the code is laid out. Each package and Java class has a purpose as described below (remember you can click on the diagram to see it full-size).
Organizing it this way is a best practice, and this sample code follows the same package structure as the standard library in the SDK itself and is highly recommended. Note that when you create your own project, using a Maven archetype, the class that is generated for you is the Bundle class (in this case, MyLibrary.java). The rest of the structure is up to you to create.
We will go over the interesting aspects of this code, which should give you a good starting point for creating your own services.