The following steps show the features required in order to deploy it alongside the other two projects.
The Java class appears.
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 to allow it to run independently 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; }
... TemperatureConverter temperatureConverter = createTemperatureConverter(); try { c = temperatureConverter.toCelsius(f); } finally { rununit.StopRun(); } ...
The interface implemented by the previous class appears.
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); } }
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.