Skip to content

Add base java samples #316

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

stutiuneyal
Copy link
Contributor

No description provided.

@chughts chughts self-requested a review July 4, 2025 10:40
Copy link
Collaborator

@chughts chughts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

800 lines of code, mostly repeated that can be condensed down to no more than 200 lines of code.

The feedback for BasicGet equally applies to the rest of the modules.

@@ -0,0 +1,142 @@
# IBM MQ Base Java Samples
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like base-java as a name. Lead with Java eg. Java-MQ

@@ -0,0 +1,55 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file is missing copyright

@@ -0,0 +1,133 @@
package com.ibm.mq.samples.java;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing copyright


public class BasicGet {

private static class MQDetails {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class is repeated in all these samples, best to have a separate .java file for it.

Or to create a base class that BasicGet etc inherit from.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private static JSONArray endpoints;

public static void main(String[] args) {
loadEnv("env.json");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loadEnv, everything to do with env.json is common to all these files - needs to be in a separate file - used by the base class.

This main should

BasicGet bg = new BasicGet()

which in turn would new BasicBase()
which should load the endpoints as a class instance, and provide getter methods to read and manipulate them.


try {
Hashtable<String, Object> props = new Hashtable<>();
String ccdtUrl = System.getenv("MQCCDTURL");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Common shared check - should be a public method in the base class which all subclasses can invoke.

System.setProperty("MQCCDTURL", ccdtPath);
System.out.println("Using CCDT at: " + ccdtPath);
} else {
props.put(MQConstants.HOST_NAME_PROPERTY, details.HOST);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shared code - pubic method in shared base class.

System.setProperty("com.ibm.mq.ssl.keyStorePassword", "");
}

qMgr = new MQQueueManager(details.QMGR, props);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shared code - paramatized pubic method in base class.

queue = qMgr.accessQueue(details.QUEUE_NAME, openOptions);

boolean keepReading = true;
while (keepReading) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally code that belongs in the BasicGet

}
}

} catch (Exception e) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

best to have a common method - in base class - to handle the displaying of exceptions, so can show nested exceptions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants