JSP

To embed a Highwire™ link 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 Highwire link into a JSP can be broken down into the following steps:

The example code at the end of this section shows how a Java Server Page can use the Corda Embedder to create a Highwire link.

Note: This documentation assumes that you have set up a Java-extensible Web application server and that you are familiar with JSP.

Importing the Library

Before importing the Corda Embedder library into a Java Server Page, make sure that Server\dev_tools\embedder\java\CordaEmbedder.jar is in the classpath for the Web application. If you do not know how to add a .jar file to the Web application's classpath, see Java Application Servers in the Corda 7 Install and Administration manual.

To import the Corda Embedder library, include the following line 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 Highwire Link

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

<%

myImage.loadDoc("examples/html/asset.html");

%>

Instantiating a Corda Embedder Object

To instantiate a Corda Embedder object, use the following line of code (this assumes that you want to name the object myImage).

CordaEmbedder myImage = new CordaEmbedder();

Setting the Server Information

In order to use the Corda Embedder you must first tell it the location of Corda Server™ .

You need to set two values: the address that the Web client uses to access Corda Server (externalServerAddress), and the address that Corda Embedder use to access Corda Server (internalCommPortAddress).

For example, if the Corda Embedder communicates with Corda Server at 10.0.1.1:2002, and Web clients request Corda images from http://myserver.mycompany.com:2001, you need to include the following lines in the code that generates the Highwire link:

myImage.externalServerAddress = "http://myserver.mycompany.com:2001"

myImage.internalCommPortAddress = "10.0.1.1:2002"

A Corda Server administrator can tell you what values you need to use for these settings. If you are having trouble finding these values, see Identifying Server Addresses in the Corda 7 Developer Reference.

Note: If you are serving documents from the Corda Server Servlet instead of the Corda Server, you must also set the isPostRequest attribute to true.

Setting Document Information

After you have specified the server address information, give the Corda Embedder some information about the Corda image you want to create.

The most important piece of information you need to provide is the location of the Web document you want to convert. Do this using the Corda Embedder loadDoc method.

myImage.loadDoc("http://localhost/highwire.jsp");

This allows us to specify the URL directly, but it unfortunately decreases the portability of the JSP—you'll have to change the code if you ever change the location of the Web application.

Alternatively, use the request object to dynamically compute the current URL of the JSP. The code below shows one way of doing this.

String pagename = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getRequestURI();

myImage.loadDoc(pagename);

For more information about the request object, see the JSP documentation.

There are a number of other Corda Embedder commands for specifying document information. Fortunately, these commands are consistent in all Web application environments. Thus, it is unnecessary to discuss each of these commands individually at this time. For more information, see Other Topics in this manual, and Corda Embedder API in the Corda 7 Developer Reference.

Writing the Link to a Web Page

When you are ready to actually write the embedding HTML to the Web page, place the following code segment at the location in the Java Server Page where you want the link to 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, 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 following Java Server Page produces a Web page that contains a link to a Highwire document. When you click this link, Corda Server translates the Web page to PDF.

Simple JSP Application

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

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

 

<html>

<head>

<title>My First Highwire Document</title>

</head>

<body>

<h1>This is a very simple Web page</h1>

<hr />

<p>Click below to convert this page to PDF using Corda Server's Highwire.</p>

 

<!-- insert Embedder code here -->

<%

CordaEmbedder myImage = new CordaEmbedder();

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

myImage.internalCommPortAddress = "localhost:2002";

String pagename = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getRequestURI();

myImage.loadDoc(pagename);

%>

<%= myImage.getEmbeddingHTML() %>

 

</body>

</html>