In part 1, yesterday, we deployed a Node.js application, with static resources architected on Orace JET, to the Application Container Cloud Service (ACCS). However, ACCS is also applicable to Java SE applications.
There are several use cases for running Java SE applications on ACCS:
http://docs.oracle.com/cloud/latest/apaas_gs/apaas_tutorials_create_sample_java_se_applications.htm
I followed this scenario:
http://www.oracle.com/webfolder/technetwork/tutorials/obe/cloud/apaas/griz-jersey-intro/Grizzly-Jersey-Intro.html
However, I wanted to serve up JSON, rather than Strings, so I rewrote "getAllCustomers" in "CustomerService" to the following:
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/all")
public GenericEntity> getAllCustomers() {
List list = CustomerList.getInstance();
return new GenericEntity>(list) {};
}
More info in this example for JSON-related scenarios:
http://www.oracle.com/webfolder/technetwork/tutorials/obe/cloud/apaas/basic_grizzly_jersey/jersey-grizzly-json-service.html
Also, I needed a ContainerResponseFilter, to handle CORS:
import java.io.IOException;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.ext.Provider;
@Provider
public class CORSFilter implements ContainerResponseFilter {
@Override
public void filter(ContainerRequestContext request,
ContainerResponseContext response) throws IOException {
response.getHeaders().add("Access-Control-Allow-Origin", "*");
response.getHeaders().add("Access-Control-Allow-Headers",
"origin, content-type, accept, authorization");
response.getHeaders().add("Access-Control-Allow-Credentials", "true");
response.getHeaders().add("Access-Control-Allow-Methods",
"GET, POST, PUT, DELETE, OPTIONS, HEAD");
}
}
My application now looks like this:
I created a cloud-ready package with an uber JAR (in my case named "CustomerAwesomizer.jar"), as described in the documentation, and then uploaded it to ACCS:
Here's the upload form that follows from the above:
After a bit, the application is available in my dashboard, as can be seen below, with a Java SE icon:
Next, now that the application is contained and deployed by ACCS, when I go to the REST endpoint in the browser I can see the JSON payload:
The final step is to create a user interface in JET:
Here's the JavaScript side of my JET module:
define(['ojs/ojcore', 'knockout', 'ojs/ojtable', 'ojs/ojdatacollection-common'
], function (oj, ko) {
function GeneratedContentViewModel() {
var self = this;
self.data = ko.observableArray();
$.getJSON("https://foo.oraclecloud.com/myapp/customers/all").
then(function (json) {
$.each(json, function () {
self.data.push({
birthday: this.birthday,
city: this.city,
firstName: this.firstName,
lastName: this.lastName
});
});
});
self.datasource = new oj.ArrayTableDataSource(
self.data,
{idAttribute: 'id'}
);
}
return GeneratedContentViewModel;
});
And here's the HTML:
<h1>Customer View</h1>
<table id="table"
data-bind="ojComponent: {
component: 'ojTable',
data: datasource,
columns: [
{headerText: 'Name', field: 'firstName'},
{headerText: 'Surname', field: 'lastName'},
{headerText: 'Birthday', field: 'birthday'},
{headerText: 'City', field: 'city'},
]}">
</table>
The above is a simple end-to-end scenario of ACCS providing the backend and Oracle JET the frontend of an enterprise application.