Java Server Pages

To embedding a Corda® image in a Java* Server Page (JSP), use either the Java Corda Embedder or the Corda Embedder Java Tag Library. This section uses the Java Corda Embedder.

Embedding a Corda image into a JSP can be broken down into the following steps:

The example code at the end of this section shows how to embed a Corda image in JSP.

Note: This documentation assumes that you are familiar with JSP.

Importing the Library

Before importing the Corda Embedder library into a Java Server Page, make sure that <product_root>\Server\dev_tools\embedder\java\CordaEmbedder.jar is in the classpath for the Web application. For more information, see Java Application Servers in the Corda 7 Install and Administration manual.

To import the Corda Embedder library, include code similar to the following at the beginning of the Java Server Page.

<%@ page import="com.corda.CordaEmbedder" %>

This instructs the Web application to load the CordaEmbedder class.

Delimiting the Code For a Corda Image

Delimit Java code for a Corda image as you would any other code or script in an JSP—with <% and %> (open angle bracket, percent sign and percent sign, close angle bracket), as in the following code segment:

<%

myImage.imageTemplate = "image_templates\examples\line.itxml";

myImage.loadITXML("http://<server_address>/?graph1");

%>

Instantiating a Corda Embedder Object

To instantiate a Corda Embedder object, use code similar to the following:

CordaEmbedder myImage = new CordaEmbedder();

Setting the Server Information

Corda Embedder needs to know two Corda Server™ addresses: the address that the Web client uses to access Corda Server (externalServerAddress), and the address that Corda Embedder uses to access Corda Server (internalCommPortAddress). For more information about determining these addresses, see Identifying Server Addresses.

For example, if the Corda Embedder communicates with Corda Server at 10.0.1.1:2002, and Web clients request images from http://<server_address>:2001, include the following in the code that generates the Corda image:

myImage.externalServerAddress = "http://<server_address>:2001"

myImage.internalCommPortAddress = "10.0.1.1:2002"

Specifying Image Information

After specifying server address information, give Corda Embedder some information about the Corda image you want to embed.

There are numerous Corda Embedder commands to specify image information, which are consistent in all Web application environments. Thus, it is unnecessary to discuss each of these commands individually at this time.

The table below provides links to more information about Corda image features and components:

Topic

Where To Go

Annotations

Data Annotations in the Corda Builder™ User Guide

Content Delivery / Presentation Control

Image Deployment Issues and Descriptive Text Settings

Data

Connecting to Data Files and Connecting to Databases

Drilldown

Building Drilldown

Graph or Map Customization

Dynamically Customizing Graphs and Maps

Image Size & Format

Changing the Image Format and Changing Image Size

Writing the Image to a Web Page

To write the embedding HTML to a Web page, place code similar to the following at the location in the Java Server Page where you want the Corda image to appear.

<%= myImage.getEmbeddingHTML() %>

Note that it is opened with a <%= instead of just <%. The equals sign instructs the application server to write a string to the Web page, which in this case is myImage.getEmbeddingHTML(). There should be nothing else between the opening and closing angle brackets, as the Web application server expects only a string, not a code segment.

Note: WebObjects Users: bind this return value to a WOString. In the .wod file you must make sure that you include the following line in the WOString declaration: escapeHTML = NO. Otherwise, the HTML codes are converted to escape characters.

Complete Example Code

The code sample below demonstrates embedding a Corda image in a Java Server Page.

Note: To produce an example map instead of a graph, replace examples/bar.itxml with examples/map/australia_combo.itxml in the code designating the Image Template file.

Embedding a Corda Image in a Java Server Page

<%@ page language="java" contentType="text/html" %>

<%@ page import="com.corda.CordaEmbedder" %>

<html>

<head>

<title>My First Embedded Image</title>

</head>

<body>

<h1>This is your image</h1>

<hr />

<!-- insert embedder code here -->

<%

CordaEmbedder myImage = new CordaEmbedder();

myImage.externalServerAddress="<server_address>:2001";

myImage.internalCommPortAddress = "localhost:2002";

myImage.imageTemplate = "image_templates\examples\bar.itxml";

myImage.width = 600;

myImage.height = 400;

myImage.pcScript = "title.setText(Hello World)";

%>

<%= myImage.getEmbeddingHTML() %>

<hr />

<p>If you see an image above, congratulations.  You have successfully embedded your first image.</p>

</body>

</html>