The following steps introduce you to the features that enable you to deploy this project alongside the other two projects.
This opens the Java class in an editor.
This is the EJB class, as denoted by the @Stateless annotation. It imports the com.microfocus.cobol.runtimeservices API, which provides the Micro Focus RunUnit class. The following code shows a TemperatureConverter instance being wrapped in a RunUnit. Each instantiated RunUnit contains its own resources that enable it to run independent of other RunUnit instances, thus enabling the application to provide a multi-user environment.
import com.microfocus.cobol.runtimeservices.*; ... private TemperatureConverter createTemperatureConverter() { rununit = new RunUnit(); TemperatureConverter tempConverter = new TemperatureConverter(); rununit.Add(tempConverter); return tempConverter; }The RunUnit syntax includes a try...finally block containing a call to the StopRun method, ensuring that the resources used by the JVM COBOL are freed up when required, even in the event of an exception.
... TemperatureConverter temperatureConverter = createTemperatureConverter(); try { c = temperatureConverter.toCelsius(f); } finally { rununit.StopRun(); } ...
The interface implemented by the previous class appears.
The interface imports the JAX-WS-RS API to create a RESTful application. This can be seen by the annotations (@GET, @Path, @Produces) used throughout the TemperatureConverterBean class. For example, the following toCelsius method uses the annotations to configure how the request is handled:
The annotations help to build the URL that forms the request in the deployed application. The return phrase indicates that the response to the client will be returned in JSON format using a simple Temperature class.
The class is annotated with @XmlRootElement (name = "Temperature" ), which allows the build() API to use reflection on the class to build up the JSON output based on the fields and their values. The build() method then adds the appropriate header information to pass back to the client.
This is the wrapper class that enables the EJB to be deployed to the application server.
@ApplicationPath("/") public class TemperatureConverterApp extends javax.ws.rs.core.Application { @Override public Set<Class<?>> getClasses(){ Set<Class<?>> s = new HashSet<Class<?>>(); s.add(TemperatureConverterBean.class); return s; } }
By extending the JAX-WS-RS API this time, it uses the getClasses() method to register the TemperatureConverterBean EJB class with the application server, as a REST Web service.
As with the JVM COBOL project, this project contains a cobconfig.properties file configured in the same way. If one does not exist, use the options to add a new resource file.
The cobconfig.properties file is in the resource directory, and so is set to be included in the assembly when it is deployed.