How to generate clean properties file from a Bar file?

The standard procedure to generate properties file from a Bar file is to use mqsireadbar command. The problem with this command is, it generates lot of stuffs which we really don’t need.

The ACE developer usually removes the clumsy stuffs from the generated properties to keeps only the required stuffs. Is it something simple to do? NO

If the bar file contains many messages flows/nodes, it is a tedious job to clean up and if any mandatory property is accidentally lost, the impact would be huge and also difficult to identify what is going on in Production.

To solve this problem, we’ve found an automated solution which takes care of

  • Removing unnecessary stuffs
  • Keeping only those that valid
  • Prettyprint the property values
  • Work with latest ACEv12 version
  • Simplifying the process

First, let us see how the properties file looks like when using mqsireadbar command

mqsireadbar -b "C:\Test\RESTRequest_Clientproject.generated.bar" -r > "C:\Test\RESTRequest_Clientproject.generated1.properties"

and the properties file generated is

BIP1052I: Reading Bar file using runtime mqsireadbar...
C:\Test\RESTRequest_Clientproject.generated.bar:
  RESTRequest_Client.appzip (10/11/20 1:05 AM):
    application.descriptor (10/11/20 1:05 AM):
    RESTRequest_Client_inputMessage.xml (10/11/20 1:05 AM):
    RESTRequest_Client.msgflow (10/11/20 1:05 AM):
    Deployment descriptor:
      startMode
      javaIsolation
      RESTRequest_Client#additionalInstances
      RESTRequest_Client#notificationThresholdMsgsPerSec
      RESTRequest_Client#maximumRateMsgsPerSec
      RESTRequest_Client#processingTimeoutSec
      RESTRequest_Client#processingTimeoutAction
      RESTRequest_Client#wlmPolicy
      RESTRequest_Client#commitCount
      RESTRequest_Client#commitInterval
      RESTRequest_Client#coordinatedTransaction
      RESTRequest_Client#consumerPolicySet
      RESTRequest_Client#providerPolicySet
      RESTRequest_Client#consumerPolicySetBindings
      RESTRequest_Client#providerPolicySetBindings
      RESTRequest_Client#securityProfileName
      RESTRequest_Client#monitoringProfile
      RESTRequest_Client#startMode
      RESTRequest_Client#startInstancesWhenFlowStarts
      RESTRequest_Client#HTTP Input.URLSpecifier = /REST/getUser
      RESTRequest_Client#HTTP Input.useHTTPS
      RESTRequest_Client#HTTP Input.decompressInputMessage
      RESTRequest_Client#HTTP Input.timeoutForClient
      RESTRequest_Client#HTTP Input.faultFormat
      RESTRequest_Client#HTTP Input.validateMaster
      RESTRequest_Client#HTTP Input.securityProfileName
      RESTRequest_Client#HTTP Reply.validateMaster
      RESTRequest_Client#getUser.securityIdentity
      RESTRequest_Client#getUser.timeoutForServer
      RESTRequest_Client#getUser.baseURL
      RESTRequest_Client#getUser.httpProxyLocation = http://localhost:7800
      RESTRequest_Client#getUser.enableKeepAlive
      RESTRequest_Client#getUser.requestCompressionType
      RESTRequest_Client#getUser.protocol
      RESTRequest_Client#getUser.allowedCiphers
      RESTRequest_Client#getUser.hostnameChecking
      RESTRequest_Client#getUser.keyAlias
      RESTRequest_Client#getUser.enableCRLCheck
      RESTRequest_Client#getUser.acceptCompressedResponses = true
      RESTRequest_Client#getUser.validateMaster
      RESTRequest_Client#getUser.securityProfileName

BIP8071I: Successful command completion.

Now After using the solution we’ve developed, the output looks like this

RESTRequest_Client#HTTP Input.URLSpecifier = /REST/getUser
RESTRequest_Client#getUser.httpProxyLocation = http://localhost:7800
RESTRequest_Client#getUser.acceptCompressedResponses = true

As you can see, those clutters are removed and provides you really what you want.

How this solution works? Here is the java code which does the magic

import com.ibm.integration.admin.proxy.BarFile;
import com.ibm.integration.admin.proxy.DeploymentDescriptor;

import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

public class GeneratePropertiesFile {

    public static String fileChooser(String ext) {

        String file = null;

        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        fileChooser.setAcceptAllFileFilterUsed(false);
        fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("*."
                + ext, ext));
        if (fileChooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION
                && fileChooser.getSelectedFile().getAbsolutePath()
                .endsWith(ext)) {
            file = fileChooser.getSelectedFile().getAbsolutePath();
        }

        return file;

    }

    public static void savePropFile(String propFileName, List<String> propLines) throws IOException {
        JFileChooser jfc = new JFileChooser();
        File file = new File(propFileName);
        jfc.setSelectedFile(file);

        jfc.setCurrentDirectory(file.getParentFile());

        jfc.setDialogTitle("Save As ");
        jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
        jfc.setAcceptAllFileFilterUsed(false);
        jfc.addChoosableFileFilter(new FileNameExtensionFilter("*.properties", "properties"));

        if (jfc.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
            file = jfc.getSelectedFile();
            if (file == null) {
                System.out.println("Not a valid file");
            } else {

                if (!file.getName().toLowerCase().endsWith(".properties")) {
                    file = new File(file.getParentFile(), file.getName()
                            + ".properties");
                }
                System.out.println(file);
                Files.write(Paths.get(file.getAbsolutePath()), propLines);
                JOptionPane.showMessageDialog(null,"Properties file successfully generated");
            }

        }
    }

        public static void main (String[]args){

            String outBar = fileChooser("bar");

            List<String> lines = new ArrayList<>();

            try {
                Collections.list(BarFile.loadBarFile(outBar).getBarEntries())
                        .stream()
                        .filter(barEntry -> barEntry.isApplication() || barEntry.isLibrary()
                                || barEntry.isSharedLibrary())
                        .forEach(barEntry -> {

                            try {
                              ..............................................
                            } catch (IOException e) {
                                e.printStackTrace();
                                JOptionPane.showMessageDialog(null,
                                        "Error occurred, check the stacktrace for more details");
                            }
                        });

                if (lines.isEmpty()) {
                    JOptionPane.showMessageDialog(null,
                            "No overridable properties found");
                } else {
                    savePropFile(outBar.substring(0,outBar.lastIndexOf(".")), lines);
                }

            } catch (IOException e) {
                e.printStackTrace();
                JOptionPane.showMessageDialog(null,
                        "Error occurred, check the stacktrace for more details");
            }
        }
    }

Once you run this java program, it will ask you the bar file location

Select the bar file

Next, it will ask you to choose the properties file location with pre-populated name

Once the properties file is generated, it shows an acknowledgement message

The properties file generated was

RESTRequest_Client#HTTP Input.URLSpecifier = /REST/getUser
RESTRequest_Client#getUser.httpProxyLocation = http://localhost:7800
RESTRequest_Client#getUser.acceptCompressedResponses = true

To buy this solution, please contact us at support@vaithu.com.

We’ve more than 15+ years of experience in ACE(formerly WMB/IIB). If you’re looking for consultation or any assistance, please contact us at support@vaithu.com.