/* * * Copyright (c) 1999 - 2011 my-Channels Ltd * Copyright (c) 2012 - 2017 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors. * * Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG. * */ package com.pcbsys.nirvana.nJMSApps; import com.pcbsys.foundation.utils.fEnvironment; import java.util.Enumeration; import javax.jms.JMSException; import javax.jms.MapMessage; import javax.jms.Message; public class MapMessageSubscriber extends Subscriber { public MapMessageSubscriber(String factoryName, String destinationName) { super(factoryName, destinationName); } public static void main(String[] args) { //Check to see if args were specified if ((args.length == 1) && args[0].equals("-?")) { UsageEnv(); } if (args.length < 2) { Usage(); System.exit(1); } //Process Environment Variables processEnvironmentVariable("RNAME"); processEnvironmentVariable("PRINCIPAL"); processEnvironmentVariable("PASSWORD"); processEnvironmentVariable("CONTEXT_FACTORY"); processEnvironmentVariable("PROVIDER_URL"); processEnvironmentVariable("LOGLEVEL"); processEnvironmentVariable("HPROXY"); processEnvironmentVariable("HAUTH"); processEnvironmentVariable("CKEYSTORE"); processEnvironmentVariable("CKEYSTOREPASSWD"); processEnvironmentVariable("CAKEYSTORE"); processEnvironmentVariable("CAKEYSTOREPASSWD"); // Install any proxy server settings fEnvironment.setProxyEnvironments(); // Install any ssl settings fEnvironment.setSSLEnvironments(); //Create an instance for this class MapMessageSubscriber subscriber = new MapMessageSubscriber(args[0], args[1]); boolean transacted = false; String selector = null; if (args.length > 2) { transacted = new Boolean(args[2]).booleanValue(); } if (args.length > 3) { selector = args[3]; } //Subscribe to the destination specified subscriber.doIt(args[0], args[1], transacted, selector); } /** * A callback is received by the API to this method each time a message is received from * the destination. * * @param msg A JMS Message object */ public void onMessage(Message msg) { try { if (msg instanceof MapMessage) { count++; MapMessage mm = (MapMessage) msg; System.out.println("JMS MSG ID : " + mm.getJMSMessageID()); System.out.println("JMS DELIVERY MODE : " + mm.getJMSDeliveryMode()); System.out.println("JMS TIME STAMP : " + mm.getJMSTimestamp()); Enumeration names = mm.getMapNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); Object val = mm.getObject(name); System.out.println(name + " : " + val); } } else { super.onMessage(msg); } if (transacted) { s.commit(); } } catch (JMSException e) { e.printStackTrace(); } } /** * Prints the usage message for this class */ protected static void Usage() { System.out.println("Usage ...\n\n"); System.out.println("jmsmapsub \n"); System.out.println(" \n"); JMSClient.printFactoryNameUsage(); JMSClient.printDestinationNameUsage(); System.out.println(" - Whether the session is transacted"); System.out.println(" - An optional message selector"); System.out.println("\n\nNote: -? provides help on environment variables \n"); } } // End of MapMessageSubscriber Class