Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial implementation for the package #3

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 100 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,100 @@
# module-ballerinax-ibm.ctg
The Ballerina Connector for IBM CICS Transaction Gateway
# Ballerina IBM CICS Transaction Gateway connector

[![Build](https://github.com/ballerina-platform/module-ballerinax-ibm.ctg/actions/workflows/ci.yml/badge.svg)](https://github.com/ballerina-platform/module-ballerinax-ibm.ctg/actions/workflows/ci.yml)
[![Trivy](https://github.com/ballerina-platform/module-ballerinax-ibm.ctg/actions/workflows/trivy-scan.yml/badge.svg)](https://github.com/ballerina-platform/module-ballerinax-ibm.ctg/actions/workflows/trivy-scan.yml)
[![GraalVM Check](https://github.com/ballerina-platform/module-ballerinax-ibm.ctg/actions/workflows/build-with-bal-test-graalvm.yml/badge.svg)](https://github.com/ballerina-platform/module-ballerinax-ibm.ctg/actions/workflows/build-with-bal-test-graalvm.yml)
[![GitHub Last Commit](https://img.shields.io/github/last-commit/ballerina-platform/module-ballerinax-ibm.ctg.svg)](https://github.com/ballerina-platform/module-ballerinax-ibm.ctg/commits/main)
[![GitHub Issues](https://img.shields.io/github/issues/ballerina-platform/ballerina-library/module/ibm.ctg.svg?label=Open%20Issues)](https://github.com/ballerina-platform/ballerina-library/labels/module%2Fibm.ctg)

## Build from the source
ayeshLK marked this conversation as resolved.
Show resolved Hide resolved

### Setting up the prerequisites

1. Download and install Java SE Development Kit (JDK) version 17. You can download it from either of the following sources:

* [Oracle JDK](https://www.oracle.com/java/technologies/downloads/)
* [OpenJDK](https://adoptium.net/)

> **Note:** After installation, remember to set the `JAVA_HOME` environment variable to the directory where JDK was installed.

2. Download and install [Ballerina Swan Lake](https://ballerina.io/).

3. Download and install [Docker](https://www.docker.com/get-started).

> **Note**: Ensure that the Docker daemon is running before executing any tests.

4. Export Github Personal access token with read package permissions as follows,

```bash
export packageUser=<Username>
export packagePAT=<Personal access token>
```

### Build options

Execute the commands below to build from the source.

1. To build the package:

```bash
./gradlew clean build
```

2. To run the tests:

```bash
./gradlew clean test
```

3. To build the without the tests:

```bash
./gradlew clean build -x test
```

4. To run tests against different environments:

```bash
./gradlew clean test -Pgroups=<Comma separated groups/test cases>
```

5. To debug the package with a remote debugger:

```bash
./gradlew clean build -Pdebug=<port>
```

6. To debug with the Ballerina language:

```bash
./gradlew clean build -PbalJavaDebug=<port>
```

7. Publish the generated artifacts to the local Ballerina Central repository:

```bash
./gradlew clean build -PpublishToLocalCentral=true
```

8. Publish the generated artifacts to the Ballerina Central repository:

```bash
./gradlew clean build -PpublishToCentral=true
```

## Contribute to Ballerina

As an open-source project, Ballerina welcomes contributions from the community.

For more information, go to the [contribution guidelines](https://github.com/ballerina-platform/ballerina-lang/blob/master/CONTRIBUTING.md).

## Code of conduct

All the contributors are encouraged to read the [Ballerina Code of Conduct](https://ballerina.io/code-of-conduct).

## Useful links

* For more information go to the [`ibm.ctg` package](https://central.ballerina.io/ballerinax/ibm.ctg/latest).
* For example demonstrations of the usage, go to [Ballerina By Examples](https://ballerina.io/learn/by-example/).
* Chat live with us via our [Discord server](https://discord.gg/ballerinalang).
* Post all technical questions on Stack Overflow with the [#ballerina](https://stackoverflow.com/questions/tagged/ballerina) tag.
69 changes: 69 additions & 0 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,72 @@ groupId = "io.ballerina.lib"
artifactId = "ibm.ctg-native"
version = "0.1.0-SNAPSHOT"
path = "../native/build/libs/ibm.ctg-native-0.1.0-SNAPSHOT.jar"

[[platform.java17.dependency]]
groupId = "wso2"
artifactId = "ctgclient"
version = "9.3"
path = "./lib/ctgclient-9.3.jar"
scope = "provided"

[[platform.java17.dependency]]
groupId = "wso2"
artifactId = "ccf2"
version = "9.3"
path = "./lib/ccf2-9.3.jar"
scope = "provided"

[[platform.java17.dependency]]
groupId = "wso2"
artifactId = "cicsjee"
version = "9.3"
path = "./lib/cicsjee-9.3.jar"
scope = "provided"

[[platform.java17.dependency]]
groupId = "com.fasterxml.jackson.core"
artifactId = "jackson-databind"
version = "2.18.0"
path = "./lib/jackson-databind-2.18.0.jar"

[[platform.java17.dependency]]
groupId = "com.fasterxml.jackson.core"
artifactId = "jackson-core"
version = "2.18.0"
path = "./lib/jackson-core-2.18.0.jar"

[[platform.java17.dependency]]
groupId = "com.fasterxml.jackson.core"
artifactId = "jackson-annotations"
version = "2.18.0"
path = "./lib/jackson-annotations-2.18.0.jar"

[[platform.java17.dependency]]
groupId = "commons-io"
artifactId = "commons-io"
version = "2.17.0"
path = "./lib/commons-io-2.17.0.jar"

[[platform.java17.dependency]]
groupId = "org.apache.httpcomponents.core5"
artifactId = "httpcore5"
version = "5.3"
path = "./lib/httpcore5-5.3.jar"

[[platform.java17.dependency]]
groupId = "org.apache.httpcomponents.core5"
artifactId = "httpcore5-h2"
version = "5.3"
path = "./lib/httpcore5-h2-5.3.jar"

[[platform.java17.dependency]]
groupId = "org.apache.httpcomponents.client5"
artifactId = "httpclient5"
version = "5.4"
path = "./lib/httpclient5-5.4.jar"

[[platform.java17.dependency]]
groupId = "org.apache.geronimo.specs"
artifactId = "geronimo-j2ee-connector_1.6_spec"
version = "1.0"
path = "./lib/geronimo-j2ee-connector_1.6_spec-1.0.jar"
55 changes: 55 additions & 0 deletions ballerina/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,65 @@ ballerina {
platform = "java17"
}

configurations {
externalJars
}

dependencies {
// IBM CTG client dependencies
externalJars(group: 'wso2', name: 'ctgclient', version: "${ibmCtgSdkVersion}") {
transitive = false
}
externalJars(group: 'wso2', name: 'ccf2', version: "${ibmCtgSdkVersion}") {
transitive = false
}
externalJars(group: 'wso2', name: 'cicsjee', version: "${ibmCtgSdkVersion}") {
transitive = false
}

// Jackson dependencies
externalJars(group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: "${jacksonVersion}") {
transitive = false
}
externalJars(group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: "${jacksonVersion}") {
transitive = false
}
externalJars(group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: "${jacksonVersion}") {
transitive = false
}

// Apache commons-io dependencies
externalJars(group: 'commons-io', name: 'commons-io', version: "${commonsIoVersion}") {
transitive = false
}

// Apache http components dependencies
externalJars(group: 'org.apache.httpcomponents.core5', name: 'httpcore5', version: "${apacheHttpComponentsVersion}") {
transitive = false
}
externalJars(group: 'org.apache.httpcomponents.core5', name: 'httpcore5-h2', version: "${apacheHttpComponentsVersion}") {
transitive = false
}
externalJars(group: 'org.apache.httpcomponents.client5', name: 'httpclient5', version: "${apacheHttpClientVersion}") {
transitive = false
}

// Gerenimo j2ee spec dependency
externalJars(group: 'org.apache.geronimo.specs', name: 'geronimo-j2ee-connector_1.6_spec', version: "${geronimoJ2eeSpecVersion}") {
transitive = false
}
}

task updateTomlFiles {
doLast {
def newBallerinaToml = ballerinaTomlFilePlaceHolder.text.replace("@project.version@", project.version)
newBallerinaToml = newBallerinaToml.replace("@toml.version@", tomlVersion)
newBallerinaToml = newBallerinaToml.replace("@ctg.version@", ibmCtgSdkVersion)
newBallerinaToml = newBallerinaToml.replace("@jackson.version@", jacksonVersion)
newBallerinaToml = newBallerinaToml.replace("@commons.io.version@", commonsIoVersion)
newBallerinaToml = newBallerinaToml.replace("@http.core.version@", apacheHttpComponentsVersion)
newBallerinaToml = newBallerinaToml.replace("@http.client.version@", apacheHttpClientVersion)
newBallerinaToml = newBallerinaToml.replace("@geronimo.j2ee.version@", geronimoJ2eeSpecVersion)
ballerinaTomlFile.text = newBallerinaToml
}
}
Expand Down
64 changes: 64 additions & 0 deletions ballerina/client.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.com).
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

import ballerina/jballerina.java;

# IBM CTG client.
public isolated client class Client {

# Initialize the Ballerina IBM CTG client.
# ```ballerina
# ctg:ConnectionConfig congig = ...;
# ctg:Client ctg = check new(config);
# ```
#
# + configs - The IBM CTG client configurations
# + return - The `ctg:Client` or an `ctg:Error` if the initialization failed
public isolated function init(*ConnectionConfig configs) returns Error? {
return self.externInit(configs);
}

isolated function externInit(ConnectionConfig configs) returns Error? =
@java:Method {
name: "init",
'class: "io.ballerina.lib.ibm.ctg.NativeClientAdaptor"
} external;

# Executes the specified CICS transaction gateway request and retrieves the results.
# ```ballerina
# EciRequest request = ...;
# byte[]? response = check ctg->execute(request);
# ```
#
# + request - The `ctg:EciRequest` request with relevant details
# + return - A `byte[]`, nil, or else a `ctg:Error` if the operation failed.
remote function execute(*EciRequest request) returns byte[]|Error? =
@java:Method {
'class: "io.ballerina.lib.ibm.ctg.NativeClientAdaptor"
} external;


# Closes the IBM CTG client resources.
# ```ballerina
# check ctg->close();
# ```
#
# + return - A `ctg:Error` if there is an error while closing the client resources or else nil.
remote function close() returns Error? =
@java:Method {
'class: "io.ballerina.lib.ibm.ctg.NativeClientAdaptor"
} external;
}
18 changes: 18 additions & 0 deletions ballerina/errors.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.com).
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

# Represents a IBM CTG distinct error.
public type Error distinct error;
60 changes: 60 additions & 0 deletions ballerina/types.bal
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.com).
//
// WSO2 LLC. licenses this file to you under the Apache License,
// Version 2.0 (the "License"); you may not use this file except
// in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.


# Represents the Client configurations for IBM CTG client.
public type ConnectionConfig record {|
# CICS transaction gateway host
string host;
# CICS transaction gateway port
int port;
# CICS server name
string cicsServer;
# The authentication configurations for the CICS server
Auth auth;
# The SSL configurations for the CICS transaction gateway
SecureSocket secureSocket?;
|};

# Represents the client authentication configurations for CICS server.
ayeshLK marked this conversation as resolved.
Show resolved Hide resolved
public type Auth record {|
# The CICS userId
string userId;
# The CICS password
string password;
|};

# Represents the SSL configurations for CICS transaction gateway.
ayeshLK marked this conversation as resolved.
Show resolved Hide resolved
public type SecureSocket record {|
# The SSL keystore or the certificate
string sslKeyring;
# The `sslKeyring` password
string sslkeyringPassword?;
# The cipherSuites parameter can be used when establishing an SSL connection
string[] sslCipherSuites?;
|};

# Represents the ECI request details for CICS transaction gateway.
public type EciRequest record {|
# The program to invoke in the CICS server
string programName;
# The COMMAREA to be passed to the CICS program
byte[] commArea?;
# The size of the COMMAREA
int commAreaSize?;
# ECI request timeout in seconds
int timeout = 10;
|};
Loading
Loading