6 Integrating XA Global Transactions Between WebLogic Server and Helidon Using MicroTx

Oracle Transaction Manager for Microservices (MicroTx) Free ensures consistency of XA transactions across Oracle WebLogic Server (WebLogic Server) applications, Helidon microservices, and the JDBC resources deployed in both Helidon and WebLogic Server. At this time, the integration with MicroTx Free is offered for evaluation purposes only.

This chapter explains how MicroTx ensures consistency of XA transactions using the following distributed applications as an example. In this example, the applications are deployed in a Kubernetes cluster. However, the integration of XA transactions described in this example does not depend on Kubernetes, and can be implemented on any supported platform.

  • Helidon Teller Application (transaction initiator)
  • Helidon Application (participant application)
  • WebLogic Server (participant application)
  • MicroTx Transaction Coordinator

The following graphic shows the flow of XA transactions between the various applications and the role of MicroTx as the coordinator of the transactions. Here, the XA transaction is initiated by the Helidon Teller Application, and then distributed to other Helidon and WebLogic Server Applications (the participant applications in the transaction):

Figure 6-1 WebLogic Server, Helidon, and MicroTx Integration



This chapter includes the following topics:

Prerequisites

In this example, it is assumed that the applications are running in Kubernetes and you have already deployed WebLogic Server, the WebLogic Kubernetes Operator (Operator), Helidon, and MicroTx in the same Kubernetes cluster.
See Preparing the Kubernetes Cluster for WebLogic Server and Helidon Integration.

Note:

Transaction integration with MicroTx is supported only with WebLogic Server 14c (14.1.1.0) and Helidon 2.x because these releases of the products support JDK 11.

To deploy MicroTx in the Kubernetes cluster, obtain the MicroTx image from Oracle Container Registry. To obtain samples, client libraries, and deployment scripts, download the MicroTx binaries from Transaction Manager for Microservices Free.

Downloading MicroTx Binaries from Transaction Manager for Microservices Free

  1. Go to https://www.oracle.com/database/transaction-manager-for-microservices/, click Download MicroTx Free, and then download the installation bundle (.zip file) for Oracle Transaction Manager for Microservices Free. You will be directed to Oracle Software Delivery Cloud.
  2. You can download the ZIP file using the Oracle Download Manager or simply by clicking the file to download.
  3. Extract the contents of the ZIP file, preferably in to a new directory. The otmm-22.3.2 folder contains the following folders:
    • lib: This folder contains the MicroTx library files. You must use these library files in your application code to use MicroTx to manage transactions amongst your application microservices.
    • otmm: This folder contains the MicroTx image and YAML files which you can use to install and configure MicroTx. The image in this folder is the same image that is available in the Oracle Container Registry. Oracle recommends that you use the MicroTx image from the Oracle Container Registry. For steps to download, see Downloading the MicroTx image from Oracle Container Registry.
    • samples: This folder contains the source code for sample applications for different transaction protocols. The source code of the sample applications also includes the MicroTx libraries.

      Note:

      Oracle recommends that you review the sample documentation to become familiar with the build and integration procedures.

Downloading the MicroTx image from Oracle Container Registry

  1. Go to Oracle Container Registry.
  2. In the search box, specify Oracle Transaction Manager and click otmm in the Search Results page.
  3. In the Tags section of the page, you can view the available versions of MicroTx. To download the latest version, run the following command:
    docker pull container-registry.oracle.com/database/otmm:latest
    To download a specific version, for example version 22.3.2, run the following command:
    docker pull container-registry.oracle.com/database/otmm:22.3.2

In addition, complete the following tasks as part of the prerequisites:

  • Configure a WebLogic Server XA data source or emulate two-phase commit data source and target it to the WebLogic cluster. This data source will be used by the WebLogic JAX-RS based web application (which contains the MicroTx library) to connect to the database.
  • Configure the JTA Transaction Log as a JDBC store. See Using a JDBC TLog Store in Administering the WebLogic Persistent Store.
  • To enable communication between WebLogic Server and Helidon applications, ensure that:
    • The MicroTx Transaction Coordinator Service (TCS) is up and running.
    • The Helidon Teller Application is up and running.
    • WebLogic Server is able to communicate with MicroTx TCS and the Teller services.
  • By default, all resources configured as part of the same Kubernetes cluster communicate with each other using a short name or a fully qualified domain name (FQDN). In case of any restrictions, you should add network rules to enable working with MicroTx TCS.
To configure the data sources, you can use one of the following options:
  • WebLogic Deploy Tooling (WDT) Model: The Model in Image domain home pattern enables you to configure the data source using the WDT model files. See Model in Image.
  • WebLogic Scripting Tool (WLST): The Domain in Persistent Volume (PV) domain home pattern enables you to configure the data source using WLST. See Domain Home on a PV.
  • WebLogic Server Administration Console: The Domain in Persistent Volume (PV) domain home pattern enables you to configure the data source using the Administration Console. See Domain Home on a PV.

In addition, you should have completed the following:

Preparing WebLogic Server to Work with MicroTx

To enable transaction coordination between WebLogic Server and Helidon applications involving data sources, you should first create and deploy the data sources used by the application to connect to the database. You should also configure the JTA TLog JDBC Store for the WebLogic cluster.

Creating the JDBC Data Sources Using WebLogic Deploy Tooling

You will use WDT to create the XA and non-XA data sources. For more information about WDT, see WebLogic Deploy Tooling.

Creating the XA Data Source Using WebLogic Deploy Tooling

An example of creating the XA data source, oraxads, using WDT:

resources:
    JDBCSystemResource:
        oraxads:
            Target: cluster-1
            JdbcResource:
                DatasourceType: GENERIC
                JDBCConnectionPoolParams:
                    TestFrequencySeconds: 600
                    InitialCapacity: 2
                    ConnectionReserveTimeoutSeconds: 10
                    TestConnectionsOnReserve: true
                    MaxCapacity: 30
                    TestTableName: SQL SELECT 1 FROM DUAL
                    MinCapacity: 3
                JDBCDataSourceParams:
                    JNDIName: oraxads
                    GlobalTransactionsProtocol: TwoPhaseCommit
                JDBCDriverParams:
                    DriverName: oracle.jdbc.xa.client.OracleXADataSource
                    PasswordEncrypted: '@@PROP:oraxads.password@@'
                    URL: jdbc:oracle:thin:@//@@PROP:oraxads.url@@
                    Properties:
                        user:
                            Value: '@@PROP:oraxads.user@@'
                        databaseName: {}
Creating the Non-XA Data Source Using WebLogic Deploy Tooling

An example of creating the non-XA data source, jtads, using WDT:

resources:
    JDBCSystemResource:
        jtads:
            Target: cluster-1
            JdbcResource:
                DatasourceType: GENERIC
                JDBCConnectionPoolParams:
                    TestFrequencySeconds: 600
                    InitialCapacity: 2
                    ConnectionReserveTimeoutSeconds: 10
                    TestConnectionsOnReserve: true
                    MaxCapacity: 30
                    TestTableName: SQL SELECT 1 FROM DUAL
                    MinCapacity: 3
                JDBCDataSourceParams:
                    JNDIName: jtads
                    GlobalTransactionsProtocol: None
                JDBCDriverParams:
                    DriverName: oracle.jdbc.OracleDriver
                    PasswordEncrypted: '@@PROP:jtads.password@@'
                    URL: jdbc:oracle:thin:@//@@PROP:jtads.url@@
                    Properties:
                        user:
                            Value: '@@PROP:jtads.user@@'
                        databaseName: {}
Configuring the JTA Transaction Log as a JDBC Store

Before you configure the JTA Transaction Log as a JDBC store, ensure that you have created the data source used by the transaction log store to log transactions. See Creating the JDBC Data Sources Using WebLogic Deploy Tooling.

You can configure the JTA Transaction Log as a JDBC store using one of the following methods:

Configuring the JTA Transaction Log as a JDBC Store Using WebLogic Deploy Tooling

The following example of the WDT script uses the non-XA data source, jtads, to configure the JTA Transaction Log as a JDBC store:

topology:
    ServerTemplate:
        server-template_1:
            TransactionLogJDBCStore:
                Enabled: true
                DataSource: jtads
                PrefixName: TLOG_${serverName}_
Configuring the JTA Transaction Log as a JDBC Store Using the WebLogic Scripting Tool

The following example of the WLST script uses the non-XA data source, jtads, to configure the JTA Transaction Log as a JDBC store:

import sys,os,socket, traceback
 
adminUsername=sys.argv[1]
adminPassword=sys.argv[2]
adminT3URL=sys.argv[3]
 
connect(adminUsername,adminPassword,adminT3URL)
edit()
startEdit()
##Here SERVER_TEMPLATE_NAME refers to WebLogic dynamic-cluster Server Template Name
cd('/ServerTemplates/SERVER_TEMPLATE_NAME')
cd('/ServerTemplates/SERVER_TEMPLATE_NAME/TransactionLogJDBCStore/SERVER_TEMPLATE_NAME')
##Here jtads refers to datasource name used for Transaction Log JDBC Store
cmo.setDataSource(getMBean('/JDBCSystemResources/jtads'))
cmo.setEnabled(true)
cmo.setPrefixName('TLOG_${serverName}_')
save()
activate()
disconnect()
Configuring the JTA Transaction Log as a JDBC Store Using the Administration Console
To configure the JTA Transaction Log as a JDBC store:
  1. Log in to the WebLogic Server Administration Console.
  2. If you have not already done so, in the Change Center of the Administration Console, click Lock & Edit.
  3. In the left pane of the Console, expand Environment, expand Clusters, and then click Server Templates.
  4. On the right pane of the Console, select a template from the list of templates.
  5. In the Server Template Settings screen, select the Configurations tab and click the Services tab.
  6. In the Transaction Log Store section of the screen, specify the following:
    • In the Type field, select JDBC.
    • In the Data Source field, select jtads.

      Note:

      Here the non-XA data source, jtads, is used. You have already created this data source using the WDT script. See Creating the Non-XA Data Source Using WebLogic Deploy Tooling.
    • In the Prefix Name field, select TLOG_${serverName}_.
  7. Save the changes.

Modifying the MicroTx Configurations

When running in Kubernetes, transaction integration between WebLogic Server and Helidon coordinated by MicroTx requires that you deploy WebLogic Server, Helidon, and MicroTx in the same Kubernetes cluster and that you configure all the Kubernetes resources and services. See Preparing the Kubernetes Cluster for WebLogic Server and Helidon Integration.

The Kubernetes resources can be part of different namespaces. To work with all the namespaces within the Kubernetes cluster, you should enable MicroTx TCS to communicate with services across all the namespaces by modifying the MicroTx TCS PeerAuthentication policy.

Allowing Communication Between Peers Across Namespaces

Peer authentication provides service-to-service authentication in a Kubernetes cluster with Istio service mesh. For more information, see PeerAuthentication.

Change the Oracle Transaction Manager for Microservices (OTMM) PeerAuthentication policy's spec.mtls.mode value from STRICT to PERMISSIVE in the <otmm>/helmcharts/tmm/templates/auth.yaml file. The PERMISSIVE value facilitates communication across all the namespaces in the Kubernetes cluster.

The spec.mtls.mode value before the change:

apiVersion: "security.istio.io/v1beta1"
kind: "PeerAuthentication"
metadata:
  name: "peer-auth"
  namespace: {{ .Values.applicationNameSpace }}
spec:
  mtls:
    mode: STRICT

The spec.mtls.mode value after the change:

apiVersion: "security.istio.io/v1beta1"
kind: "PeerAuthentication"
metadata:
  name: "peer-auth"
  namespace: {{ .Values.applicationNameSpace }}
spec:
  mtls:
    mode: PERMISSIVE

For more information about peer authentication, see PeerAuthentication.

Creating Routing Rules

Routing rules are created to access the WebLogic Servers, the WebLogic Server Administration Console, applications, and Helidon.

Create an Istio VirtualService to define a set of traffic routing rules that apply to all the applications of the WebLogic cluster, Helidon, and the teller service. You may use the following example of the script as reference:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: wls-domain-virtualservice
  namespace: wls-domain-ns
spec:
  gateways:
    - otmm/otmm-gateway
  hosts:
    - '*'
  http:
    - match:
        - uri:
            prefix: /console
        - uri:
            prefix: /management
        - port: 7001
      route:
        - destination:
            host: wls-domain-admin-server
            port:
              number: 7001
 
    - match:
        - uri:
            prefix: /mtxwls
        - port: 8001
      route:
        - destination:
            host: wls-domain-cluster-cluster-1
            port:
              number: 8001
 
    - match:
        - uri:
            prefix: /mtxhelidon
        - port: 8084
      route:
        - destination:
            host: microtx-helidon.helidon-ns.svc.cluster.local
            port:
              number: 8084
 
    - match:
        - uri:
            prefix: /mtxteller
        - port: 8087
      route:
        - destination:
            host: microtx-teller.helidon-ns.svc.cluster.local
            port:
              number: 8087

For more information about the Istio virtual service specifications, see Istio Gateway.

WebLogic Server and MicroTx have their own Administration Consoles. By default, the MicroTx Console is not supported. You will experience path collision if you access the WebLogic Server Administration Console using http(s)://LoadBalancer/console. In this case, you need to change the notpaths value in the Oracle Transaction Manager for Microservices (OTMM) Authorization Policy rules in <otmm>/helmcharts/tmm/templates/auth.yaml file, as shown below. However, you can also use different URLs by rewriting the paths.

apiVersion: "security.istio.io/v1beta1"
kind: "AuthorizationPolicy"
metadata:
  name: "frontend-ingress"
  namespace: {{ .Values.istioSystemNameSpace }}
spec:
  selector:
    matchLabels:
      istio: {{ .Values.istioIngressGateway.name }}
  action: {{ .Values.authentication.requestsWithNoJWT }}
  rules:
    - from:
        - source:
            notRequestPrincipals: ["*"]
      to:
        - operation:
            ###########notPaths Value before change ["/console*"]######################
            notPaths: ["/mtxconsole*"]

Setting Up the Integration of WebLogic Server with Helidon and MicroTx Applications and Services

With MicroTx, you can ensure a spectrum of data consistency across microservices and cloud native applications without writing any complex code. With a choice of transaction protocols and use of APIs and annotations included in the client libraries, MicroTx makes it easy to use distributed transactions in applications deployed in Kubernetes. In this integration, MicroTx coordinates the distributed XA transactions that span Helidon and WebLogic Server applications.

As part of the MicroTx and WebLogic Server integration, MicroTx uses WebLogic Server Interposed Transaction Manager (ITM) to coordinate the transactions with WebLogic Server.

To enable the JDBC resources deployed in the WebLogic Server domain (as javax.transaction.xa.XAResource) to participate in the transaction, MicroTx must interface with WebLogic Server using ITM. The WebLogic Server ITM exposes a javax.transaction.xa.XAResource implementation using the weblogic.transaction.InterposedTransactionManager interface. The MicroTx transaction manager accesses the InterposedTransactionManager interface to coordinate with the WebLogic Server transaction manager XAResource during its commit processing. See Participating in Transactions Managed by a Third-Party Transaction Manager in Developing JTA Applications for Oracle WebLogic Server.

Download the MicroTx binaries from the MicroTx Downloads page (see Prerequisites) and complete the following tasks to enable the integration between WebLogic Server, Helidon, and MicroTx applications and services:

Building and Deploying the Helidon Teller Application

To build and deploy the teller application:
  1. Obtain the OTMM library from the <OTMM_BINARIES_EXTRACTED_PATH>/lib/java/ location and install it to the local Maven repository using the following command:
    mvn install:install-file -Dfile=<OTMM_BINARIES_EXTRACTED_PATH>/lib/java/TmmLib-22.3.2.jar -DpomFile=<OTMM_BINARIES_EXTRACTED_PATH>/lib/java/TmmLib-22.3.2.pom

    Note:

    The following Maven dependency is used to refer to the installed OTMM library:
    <dependency>
         <groupId>com.oracle.tmm.jta</groupId>
         <artifactId>TmmLib</artifactId>
         <version>22.3.2</version>
    </dependency>
  2. Create the Docker image for the Helidon Teller Application and deploy it in the Kubernetes cluster.

    In the MicroTx binaries, the Helidon Teller Application samples are available in the <OTMM_BINARIES_EXTRACTED_PATH>/samples/xa/java/weblogic/teller location.

    1. Update the application.yaml file available in the <OTMM_BINARIES_EXTRACTED_PATH>/samples/xa/java/weblogic/teller/src/main/resources location. In this file, specify the endpoint URLs of the Helidon Teller Application along with the authentication details, if any.
      helidonServiceEndpoint: http://<HELIDON_APP_K8S_SERVICE_NAME>:<HELIDON_APP_K8S_SERVICE_PORT>/<HELIDON_APP_CONTEXT_PATH>
      weblogicServiceEndpoint: http://<WEBLOGIC_APP_K8S_SERVICE_NAME>:<WEBLOGIC_APP_K8S_SERVICE_PORT>/<WEBLOGIC_APP_CONTEXT_PATH>
      Weblogic:
        BasicAuth:
          UserName: <wls_username>
          Password: <wls_password>

      For example:

      helidonServiceEndpoint: http://microtx-helidon.helidon-ns.svc.cluster.local:8084/mtxhelidon
      weblogicServiceEndpoint: http://wls-domain-cluster-cluster-1.wls-domain-ns.svc.cluster.local:8001/mtxwls
      Weblogic:
        BasicAuth:
          UserName: <wls_username>
          Password: <wls_password>
    2. Update the tmm.properties file available in the <OTMM_BINARIES_EXTRACTED_PATH>/samples/xa/java/weblogic/teller/src/main/resources location.
      ### oracle.tmm.TcsUrl value refers to the MicroTx coordinator URL
      oracle.tmm.TcsUrl = http(s)://<OTMM_K8S_SERVICE_NAME>:<OTMM_SERVICE_PORT>/api/v1
      oracle.tmm.TcsConnPoolSize = 15
      ### oracle.tmm.CallbackUrl refers to the Helidon Teller Application call-back URL along with the context path
      oracle.tmm.CallbackUrl = http://<HELIDON_TELLER_APP_K8s_SERVICE_NAME>:<HELIDON_TELLER_APP_K8s_SERVICE_NAME>/<HELIDON_TELLER_APP_CONTEXTPATH>
       
      ## Transaction Timeout Out value in milli seconds
      oracle.tmm.TransactionTimeout = 60000
       
      oracle.tmm.PropagateTraceHeaders = false

      For example:

      oracle.tmm.TcsUrl = http://otmm-tcs.otmm.svc.cluster.local:9000/api/v1
      oracle.tmm.TcsConnPoolSize = 15
      oracle.tmm.CallbackUrl = http://microtx-teller.heidon-ns.svc.cluster.local:8087/mtxteller
      oracle.tmm.TransactionTimeout = 60000
      oracle.tmm.PropagateTraceHeaders = false
    3. Go to the teller directory and create the Docker image:
      cd <OTMM_BINARIES_EXTRACTED_PATH>/samples/xa/java/weblogic/teller
      docker build -t <IMAGE_NAME>
    4. Tag and upload the image to the container registry, and then refer the image in the Kubernetes pods. Use the following commands to tag and upload the image:
      docker tag <IMAGE_NAME> <CONTAINER_REGISTRY>:<IMAGE_NAME>
      docker push <CONTAINER_REGISTRY>:<IMAGE_NAME>

Building and Deploying the Helidon Participant Application

To build and deploy the participant application:
  1. Obtain the OTMM library from the <OTMM_BINARIES_EXTRACTED_PATH>/lib/java/ location and install it to the local Maven repository using the following command:
    mvn install:install-file -Dfile=<OTMM_BINARIES_EXTRACTED_PATH>/lib/java/TmmLib-22.3.2.jar -DpomFile=<OTMM_BINARIES_EXTRACTED_PATH>/lib/java/TmmLib-22.3.2.pom

    Note:

    The following MVN dependency is used to refer to the installed OTMM library:
    <dependency>
         <groupId>com.oracle.tmm.jta</groupId>
         <artifactId>TmmLib</artifactId>
         <version>22.3.2</version>
    </dependency>
  2. Create the Docker image for the Helidon Participant Application and deploy it in the Kubernetes cluster.

    In the MicroTx binaries, the Helidon Participant Application samples are available in the <OTMM_BINARIES_EXTRACTED_PATH>/samples/xa/java/weblogic/helidon-app location.

    1. Update the application.yaml file available in the <OTMM_BINARIES_EXTRACTED_PATH>/samples/xa/java/weblogic/helidon-app/src/main/resources location. In this file, specify the database XA connection details of the Helidon Participant Application.

      Note:

      In this application.yaml file, the local data source, orcl, is referred in the application code. If you want to use a different data source, you should also change the name in the application code.
      oracle:
        ucp:
          jdbc:
            PoolXADataSource:
              localOrcl:
                URL: jdbc:oracle:thin:@127.0.0.1:1521/orcl
                connectionFactoryClassName: oracle.jdbc.xa.client.OracleXADataSource
                user: <db-username>
                password: <db-password>
    2. Update the tmm.properties file available in the <OTMM_BINARIES_EXTRACTED_PATH>/samples/xa/java/weblogic/helidon-app/src/main/resources location.
      ### oracle.tmm.TcsUrl value the MicroTx coordinator URL
      oracle.tmm.TcsUrl = http(s)://<OTMM_K8S_SERVICE_NAME>:<OTMM_SERVICE_PORT>/api/v1
      oracle.tmm.TcsConnPoolSize = 15
      ### oracle.tmm.CallbackUrl refers to the Helidon Teller Application call-back URL along with context path
      oracle.tmm.CallbackUrl = http://<HELIDON_PARTICIPANT_APP_K8s_SERVICE_NAME>:<HELIDON_PARTICIPANT_APP_K8s_SERVICE_PORT>/<HELIDON_PARTICIPANT_APP_CONTEXTPATH>
      ##RM Id
      oracle.tmm.xa.<rmid> = HELIDON-TX-RM-ID-FOR-MICROTX-TESTS

      For example:

      oracle.tmm.TcsUrl = http://otmm-tcs.otmm.svc.cluster.local:9000/api/v1
      oracle.tmm.TcsConnPoolSize = 15
      oracle.tmm.CallbackUrl = http://microtx-helidon.helidon-ns.svc.cluster.local:8084/mtxhelidon
      # Resource Manager(RM) Unique Id. Make sure to replace the id value with the RM used in the application
      oracle.tmm.xa.rmid = HELIDON-TX-RM-ID-FOR-MICROTX-TESTS
    3. Go to the Dockerfile location and create the Docker image:
      cd <OTMM_BINARIES_EXTRACTED_PATH>/samples/xa/java/weblogic/helidon-app
      docker build -t <IMAGE_NAME>
    4. Tag and upload the image to the container registry, and then refer the image in the Kubernetes pods. Use the following commands to tag and upload the image:
      docker tag <IMAGE_NAME> <CONTAINER_REGISTRY>:<IMAGE_NAME>
      docker push <CONTAINER_REGISTRY>:<IMAGE_NAME>

Building and Deploying the MicroTx Application WAR File in the WebLogic Server Domain

To build an application WAR (Web Application Resource or Web Application ARchive) file for WebLogic Server and target the file to the WebLogic cluster or the Managed Server resources:

  1. Create the database resources (such as a database user, tables, views, and so on) required for the application.
  2. In WebLogic Server, create the required XA and non-XA JDBC data sources used by the current application.
  3. Create and deploy the data source for the JDBC TLog store (non-XA data source). See Using a JDBC Store in Administering the WebLogic Persistent Store. You will set the JTA Transaction Log Store attribute for this data source. Target the data source to the WebLogic cluster.
  4. Add the TmmLib library to the local Maven repository. This library is available in the <OTMM_BINARIES_EXTRACTED_PATH>/lib/java/ location.
  5. Install the OTMM library to the local Maven repository using the following command:
    mvn install:install-file -Dfile=<OTMM_BINARIES_EXTRACTED_PATH>/lib/java/TmmLib-22.3.2.jar -DpomFile=<OTMM_BINARIES_EXTRACTED_PATH>/lib/java/weblogic/TmmLib-weblogic-22.3.2.pom

    Note:

    The following MVN dependency is used to refer to the installed OTMM library:
    <dependency>
         <groupId>com.oracle.tmm.jta</groupId>
         <artifactId>TmmLib</artifactId>
         <version>22.3.2</version>
    </dependency>
  6. Build the application for WebLogic Server.

    The sample WebLogic Server application is a JAX-RS based web application. This service participates in the transactions. Therefore, it is also called as an XA participant service. It provides the required business logic and uses Oracle database (RDBMS) as the resource manager.

    The sample application is available in the <OTMM_BINARIES_EXTRACTED_PATH>/samples/xa/java/weblogic/weblogic-jaxrs-app location. You may use this sample as a reference when building your own applications.

    1. Update the MicroTx TCS configuration file (tmm.properties available in the <OTMM_BINARIES_EXTRACTED_PATH>/samples/xa/java/weblogic/weblogic-jaxrs-app/src/main/resources location.
      ### oracle.tmm.TcsUrl value refer to OTMM Service URL
      oracle.tmm.TcsUrl = http(s)://<OTMM_K8S_SERVICE_NAME>:<OTMM_K8S_SERVICE_PORT>/api/v1
      oracle.tmm.TcsConnPoolSize = 15
      ### oracle.tmm.CallbackUrl refers to weblogic application callback URL along with context path
      oracle.tmm.CallbackUrl = http://<WEBLOGIC_APP_K8S_SERVICE_NAME>:<WEBLOGIC_APP_K8S_SERVICE_PORT>/<WEBLOGIC_APP_CONTEXT_PATH> 
      ### WebLogic Name Space. This is mandatory for WebLogic Apps. We are using this to derive the WLS Managed Server Name to maintain Tx affinity
      oracle.tmm.WeblogicNamespace = <WLS_DOMAIN_NAME_SPACE>
       
      ### Resource Manager(RM) Unique Id. Make sure to replace the id value with the RM used in the application
      oracle.tmm.xa.<rmid> = DEPT-JPA-0DE1-453C-B872-291FDBF49CFF
      oracle.tmm.UseApacheConnectorProvider=false
      ### oracle.tmm.WeblogicTxnSupport should be set to true for WebLogic MicroTx Applications
      oracle.tmm.WeblogicTxnSupport = true

      For example, the following sample of the tmm.properties file is used to work with the WebLogic cluster deployed in Kubernetes. Here, the MicroTx application is deployed in the WebLogic cluster and is accessed using the cluster URL 'http://wls-domain-cluster-cluster-1.wls-domain-ns.svc.cluster.local:8001/mtxwls/'. The WebLogic Server domain namespace used in this sample is wls-domain-ns.

      oracle.tmm.TcsUrl = http://otmm-tcs.otmm.svc.cluster.local:9000/api/v1
      oracle.tmm.TcsConnPoolSize = 15
      oracle.tmm.CallbackUrl = http://wls-domain-cluster-cluster-1.wls-domain-ns.svc.cluster.local:8001/mtxwls
      oracle.tmm.WeblogicNamespace = wls-domain-ns
      # Resource Manager(RM) Unique Id. Make sure to replace the id value with the RM used in the application
      oracle.tmm.xa.Rmid = WLS-TX-RM-ID-FOR-MICROTX-TESTS
      oracle.tmm.UseApacheConnectorProvider=false
      oracle.tmm.WeblogicTxnSupport = true
    2. Build the project using the following command:
      mvn clean package -DskipTests=true
    3. Deploy the generated WebLogic Server JAX-RS web application WAR file (which includes the MicroTx library) in the WebLogic cluster. If you are using the 'Model in Image' pattern, you will deploy the application using WDT. If you are using the 'Domain home on PV' pattern, you can use WLST or the WebLogic Server Administration Console to deploy the application.

Note:

If you want to work with your own JAX-RS application, ensure that you add the following pom dependency and the javax.ws.rs.core.Application subclass to your JAX-RS application. However, you need to use the WebLogic data source connection in your application.

This following dependency is referred from the local Maven repository. Therefore, you should add this artifactory to the local Maven repository before packaging the project.

<dependency>
   <groupId>com.oracle.tmm.jta</groupId>
   <artifactId>TmmLib</artifactId>
   <version>22.3.2</version>
</dependency>

Also, add the javax.ws.rs.core.Application subclass to scan all the resource classes annotated with @Provider and @Path. This subclass is required to register the MicroTx filter classes, callback resources, and connection factory classes.

The javax.ws.rs.core.Application subclass method 'getClasses()' or 'getSingletons()' return the relevant JAX-RS resources and providers. If empty sets are returned in both the getClasses() and getSingletons() methods, all the JAX-RS resource and provider classes that are found in the application are added to the JAX-RS application subclass.

package com.oracle.mtm.sample;
 
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
 
@ApplicationPath("/")
public class WebLogicWebApp extends Application {
}

Deploying the Web Application in the WebLogic Cluster Using WebLogic Deploy Tooling

The following example script is used to deploy the WebLogic Server JAX-RS web application WAR file in the WebLogic cluster using WDT:

appDeployments:
    Application:
        mtxwwls :
            SourcePath: wlsdeploy/applications/mtxwls.war
            Target: cluster-1
            ModuleType: war

Deploying the MicroTx Coordinator Service

Before you deploy the MicroTx Coordinator Service, ensure that you have deployed the Istio service mesh in the Kubernetes cluster.

To deploy the MicroTx Coordinator Service:

  1. Navigate to the OTMM helmcharts directory:
    cd <OTMM_BINARIES_EXTRACTED_PATH>/otmm/helmcharts/tmm
  2. Change the following properties in the values.yaml file.
    • tmmReplicaCount: By default, this value is set to 1. Change this count based on your requirement.
    • tmmImage: By default, this value is set to tmm:22.3.x. You should use the URL of the OTMM image.
    • tmmExternalURL (in the tmmConfiguration section): Update the host and port details. The host value should be the public IP of Istio or the name of the host. The port value should be set to the SSL or non-SSL port associated with Istio.
    • xaCoordinator.enabled (in the tmmConfiguration section): Set this property to true for XA transactions.
    • storage.type (in the tmmConfiguration section): By default, the storage type is set to memory. Oracle recommends you to use db for HA.
    • Database connection details (in the tmmConfiguration section): Update these details if the storage type is set to db.
  3. Create the OTMM namespace and install the OTMM Helmchart using the following commands:
    cd <OTMM_BINARIES_EXTRACTED_PATH>/helmcharts
    kubectl create ns otmm
    kubectl label namespace otmm istio-injection=enabled
    helm install otmm --namespace otmm tmm --values ./tmm/values.yaml

A few samples of the values.yaml file:

  • A sample of the configuration values in the tmmImage section of the file (you can refer the tmmImage image from Oracle Container Registry instead of storing and referring the image from the local container registry):

    tmmImage:
      image: <Image_Registry>/tmm:22.3.x
      imagePullPolicy: Always
      imagePullSecret: regcred
  • A sample of the configuration values for the tmmExternalURL, xaCoordinator, and storage.type properties in the tmmConfiguration section of file:

    tmmConfiguration:
      tmmId: "TCS01"
      tmmAppName: otmm-tcs
      port: 9000
      tmmExternalURL:
        protocol: http
        host: x.x.x.x
        port: 80
     
      xaCoordinator:
        enabled: "true"
        txMaxTimeout: 600000
      lraCoordinator:
        enabled: "false"
      tccCoordinator:
        enabled: "false"
     
      storage:
        type: db
        db:
          connectionString: "tcps://<ORACLE_DB_HOST>:<ORACLE_DB_PORT>/<ORACLE_DB_SERVICE>?retry_count=20&retry_delay=3"
          credentialSecretName: "walletsecret"
          connectionParams: ""
          walletConfigMap:
            configMapName: "db-wallet-cmap"
        completedTransactionTTL: 60
     
      # Sample configuration values for Retry settings
      #The maximum number of times the TMM (Transaction Coordinator) will retry an operation in case of certain failures
      maxRetryCount: 10
      #The minimum retry interval in milliseconds
      minRetryInterval: 1000
      #The maximum retry interval in milliseconds
      maxRetryInterval: 10000
      # Coordinator HTTP client timeout value in seconds. A Timeout of zero means no timeout. Max allowed value is 900 seconds
      httpClientTimeoutInSecs: 180

Note:

By default, the OTMM Coordinator Service's httpClientTimeoutInSecs value is set to 180 seconds. This timeout is considered when OTMM coordinator service communicates with the transaction participants to complete the transaction. This value is used along with the other retry settings parameters in values.yaml.

Troubleshooting Common Issues

Learn about the common issues you may encounter when setting up the integration between WebLogic Server and Helidon with MicroTx.

Issue 1

In the Helidon applications, the XA connections fail and report an error when the Application Context Path is defined by extending the javax.ws.rs.core.Application class provided by the JAX-RS implementation. Here is a sample of the error message:

2023.03.17 11:39:16 WARNING io.helidon.microprofile.server.JaxRsCdiExtension
!thread!: Internal server error java.lang.NullPointerException
        at oracle.tmm.jta.common.TrmConnectionFactory.getXAConn(TrmConnectionFactory.java:47)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcc essorImpl.java:62)
. . . .

The following sample code shows the exception that is reported (after you create the Helidon Application/Context path by extending javax.ws.rs.core.Application):

package com.oracle.mtm.sample.resource;
 
import java.util.Set;
 
import javax.enterprise.context.ApplicationScoped;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
 
//Adding Application Context path by extending javax.ws.rs.core.Application
@ApplicationScoped
@ApplicationPath("/helidonapp")
public class HelidonApplication extends Application {
    @Override
    public Set<Class<?>> getClasses() {
        return Set.of(AccountsResource.class);
    }
}

Solution:

Create the Application/Context path by extending org.glassfish.jersey.server.ResourceConfig, as shown below:

package com.oracle.mtm.sample.resource;
 
import java.util.Set;
 
import javax.enterprise.context.ApplicationScoped;
import org.glassfish.jersey.server.ResourceConfig;
import javax.ws.rs.ApplicationPath;  
 
//Adding Application Context path by extending org.glassfish.jersey.server.ResourceConfig
@ApplicationPath("/helidonapp")
public class HelidonApplication extends ResourceConfig {
}

Issue 2

The Helidon Teller Application reports the transaction limit error. Here is a sample of the error message:

2023.04.10 06:03:05 INFO TMMLibDefaultLogger !thread!: begin response from TCS: transaction limit error. Reached total allowed transactions count of 4800. Please try after one hour
---429
2023.04.10 06:03:05 WARNING io.helidon.microprofile.server.JaxRsCdiExtension !thread!: Internal server error
javax.transaction.SystemException: transaction limit error. Reached total allowed transactions count of 4800. Please try after one hour
 
        at oracle.tmm.jta.TrmUserTransaction.begin(TrmUserTransaction.java:183)
        at oracle.tmm.jta.TrmUserTransaction.begin(TrmUserTransaction.java:124)
        at oracle.tmm.jta.transactional.TrmTransactionalRequired.intercept(TrmTransactionalRequired.java:51)
. . . .
. . . .

Solution:

The MicroTx Free release 22.3.1 and earlier have restrictions on the number of transactions allowed per hour. Use MicroTx Free 22.3.2 and later to remove this restriction.

Issue 3

When the correct privileges are not granted in the database, Helidon and WebLogic Server report an error (XAER_RMERR error) when trying to recover transactions. Here is a sample of the error message:

2023.05.02 11:47:09 SEVERE TMMLibDefaultLogger !thread!: RMID : <RMID> XA Exception:  XAErr: -3 XAErrString: XAER_RMERR
javax.transaction.xa.XAException
        at oracle.jdbc.xa.OracleXAResource.recover(OracleXAResource.java:754)
        at oracle.tmm.jta.common.TrmXAResource.xaop(TrmXAResource.java:225)
. . . .

Solution:

Provide the following database privileges to the Helidon and WebLogic database users:

GRANT SELECT ON sys.dba_pending_transactions TO <DB_USERNAME>;
GRANT SELECT ON sys.dba_2pc_pending TO <DB_USERNAME>;
GRANT EXECUTE ON sys.dbms_xa TO <DB_USERNAME>;
GRANT FORCE ANY TRANSACTION TO <DB_USERNAME>;