Preparing a Spring Boot application to be called by a CICS program

With CICS® TS APAR PH14856, you can use annotations to enable a Java™ method to be invoked by a CICS application - CICS creates the PROGRAM resource for you. The Spring Boot application runs in a Liberty JVM server, and can be deployed within a JAR or WAR.

First, identify which Java class and method you want to call. Then, adhering to site standards and CICS naming rules, determine a suitable CICS program name.

Make sure that the Liberty JVM server is configured to enable linking to Spring Boot applications. For more information, see Linking to a Java EE application from a CICS program.

Note: To avoid concurrency issues, JCICS fields should be defined within the link-target method, or a subsequent prototype-scoped Bean, and not on the linked-to component class.
  1. Create a class to contain the methods that CICS calls. Creating a class keeps the CICS-specific code separate from the rest of your application.
  2. Create a method for each CICS PROGRAM resource to be created.
  3. Annotate each method with the @CICSProgram annotation, giving it a parameter of the PROGRAM name, such as @CICSProgram("CUSTGET").
    CICS PROGRAM names:
    • Must be 1 - 8 characters;
    • Must match the pattern A-Z a-z 0-9 $ @ #.
    Example of a simple class with a single method, annotated with the @CICSProgram annotation:
    @Component
    public class CustomerLinkTarget
    {
        @CICSProgram("CUSTGET")
        public void getCustomer()
        {
            // do work here
        }
    }

    Add targetType = TargetType.SPRINGBEAN if your class does not contain @Service, @Repository, @Controller, or @Component annotations.

    public class CustomerLinkTarget
    {
        @CICSProgram(value ="CUSTGET", targetType = TargetType.SPRINGBEAN) 
        public void getCustomer()
        {
            // do work here
        }
    }
    
  4. Validate the annotation is correctly specified.
    The annotation:
    • Must be on a method.
    • Must have a value attribute of a PROGRAM name.
    The method:
    • Must be concrete (not abstract).
    • Must be public.
    • Must have no arguments.
    The class:
    • Must be top level (not nested or anonymous).
    • Must not have more than one method that is annotated with the same PROGRAM name.
  5. Write the content of the annotated method. The content is likely to involve the following stages:
    1. Obtain containers from the channel.
    2. Obtain input data from containers in a channel.
    3. Use data-mapping code to convert the input data to Java objects.
    4. Call the application business logic.
    5. Use data mapping code to convert the resulting Java objects to output data.
    6. Place the output data in containers in a channel.
    Example of a class with a single method, annotated with the @CICSProgram annotation, and code to take input data from a container and put output data to a container:
    @Component
    public class CustomerLinkTarget
    {
        @CICSProgram("CUSTGET")
        public void getCustomer()
        {
            Channel currentChannel = Task.getTask().getCurrentChannel();
            Container dataContainer = currentChannel.getContainer("DATA");
    
            // do work here
    
            Container resultContainer = currentChannel.createContainer("RESULT");
            byte[] results = null; // change this to be the result of the work
            resultContainer.put(results);
        }
    }
  6. Ensure that the generated CICS proxy class is scanned for annotations by Spring.
    The CICS annotation processor generates a proxy class (a Spring bean) which needs to be scanned for annotations by the Spring framework. If you use the @SpringBootApplication annotation within the same package or a parent package, this happens automatically.
    The annotation processor generates the proxy class in a sub-package within the same package as the class in which you annotate with @CICSProgram. CICS ExplorerYou can check these in the Navigator view in CICS Explorer.

    In this example, the class with the @CICSProgram annotation is in the package springboot.link.app.ui.cics, and the annotation processor generates the proxy class in springboot.link.app.ui.cics.cics.proxy

    If you are not already using annotations, you must explicitly configure Spring to scan for annotations:
    1. Add component scan to your Spring component class.
      @ComponentScan(basePackages = "org.example.cics.proxy")
      If you are using XML configuration, you can enable component scan with:
      <context:component-scan base-package="org.example.cics.proxy"/>
  7. Build the application.
    • CICS Explorer If you are in CICS Explorer, you can right-click the project and select Export -> WAR file , or right-click a containing CICS Bundle Project and select Export Bundle to z/OS® UNIX file system.
    • If you are using the CICS build toolkit, the annotation processor is invoked automatically.
    • GradleMaven If you are building the Java code by using other tools, ensure that the dependency on the CICS annotation and the annotation processor configuration are correctly specified by using the artifacts on Maven Central. If you've done that in Steps 1 and 5, they are resolved automatically during build. Otherwise, you must ensure the com.ibm.cics.server.invocation.annotations.jar JAR file (which defines the @CICSProgram annotation) is on the classpath of the Java compiler. Also, ensure that the com.ibm.cics.server.invocation.jar JAR file (containing the annotation processor) is on the classpath of the Java compiler, or is otherwise specified in the -processorpath option. You can find both JAR files in the usshome /lib directory on z/OS UNIX , where usshome is the value of the USSHOME system initialization parameter.
    • If the class is packaged in a library JAR inside the WEB-INF/lib directory of a WAR file, export the generated metadata when you are building the JAR. CICS ExplorerIn CICS Explorer , you can do this by adding the library project to the deployment assembly of the Dynamic Web Project. From the properties dialog for the Dynamic Web Project, choose the Deployment Assembly page, click the Add button, and select the library project.
  8. Deploy the application.
If the application is installed by a CICS bundle, PROGRAM resources are created as the CICS bundle becomes ENABLED. If the application is installed directly from server.xml or from a file by using an <application> element, PROGRAM resources are created as the application is installed.

You can now link to the Spring Boot application from another CICS program by using:

EXEC CICS LINK PROGRAM("CUSTGET") CHANNEL()