X

Geertjan's Blog

Application Container Cloud, Oracle JET, and NetBeans IDE (Part 2)

Geertjan Wielenga
Product Manager

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<List<Customer>> getAllCustomers() {
List<Customer> list = CustomerList.getInstance();
return new GenericEntity<List<Customer>>(list) {};
}

See the above code here.

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: 'birthday'}
);
}
return GeneratedContentViewModel;
});

Note: In the above, make sure that the value of 'idAttribute' is an existing column. For the sake of this example, where there's no unique ID, I'm using 'birthday' instead.

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.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.