// --------------------------------------------------------- // (c) Copyright IBM Corp. 2000 All rights reserved. // // This sample program is owned by International Business Machines // Corporation or one of its subsidiaries ("IBM") and is copyrighted // and licensed, not sold. // // You may copy, modify, and distribute this sample program in any // form without payment to IBM, for any purpose including developing, // using, marketing or distributing programs that include or are // derivative works of the sample program. // // The sample program is provided to you on an "AS IS" basis, without // warranty of any kind. IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, // EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // Some jurisdictions do not allow for the exclusion or limitation of // implied warranties, so the above limitations or exclusions may not // apply to you. IBM shall not be liable for any damages you suffer as // a result of using, modifying or distributing the sample program or // its derivatives. // // Each copy of any portion of this sample program or any derivative // work, must include the above copyright notice and disclaimer of // warranty. // --------------------------------------------------------- // --------------------------------------------------------------------- // This example is used to start the sample CreditRequest process using XML // // Also, this process is started as a particular user that is not the WinNT logged on user // // The user identifier is set to ADMIN // (This user must be defined in the MQSeries Workflow runtime database) // XML messages for MQSeries Workflow are put into the queue EXEXMLINPUTQ // The queue manager is set to FMCQM in this code. // // Process name = CreditRequest // InputContainer = PersonInfo // container members = FirstName and LastName both are string types // // You will need to compile this using the command: // javac StartCreditRequest.java // // To run it, make sure the MQSeries Workflow server is started. // Make sure you have imported and translated fmccred.fdl // Type: java StartCreditRequest // // A window/dialog is displayed that prompts you for the First Name and Last Name. // Press the pushbutton to start the process. // You will get no response back. Must login to client to verify process start. // // This sample code was tested using MQSeries Workflow 3.2.1 service pack 2 // and JDK 1.1.7b // // dsb - 5/08/2000 // // --------------------------------------------------------------------- import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.text.*; import javax.swing.event.*; import com.ibm.mq.*; //MQSeries java classes public class StartCreditRequest extends JFrame implements ActionListener, DocumentListener { // variables used private JLabel fnameLabel = null; private JTextField fnameText = null;; private JLabel lnameLabel = null; private JTextField lnameText = null; private JButton startButton = null; private JButton cancelButton = null; private Document myDocTextField = null; private String firstName = null; private String lastName = null; private MQQueueManager wfqmgr = null; private MQQueue xmlinputq = null; private String procTempName = null; private String procInstName = null; private String contName = null; private String xmlRequestMessage = null; public StartCreditRequest() { // put title on window super( "Credit Request Application" ); //setSize(500,450); setLocation(300,300); // center of display addWindowListener( new WindowAdapter( ) { public void windowClosing( WindowEvent e ) { System.exit( 0 ); } } ); JPanel rootPanel = new JPanel(); rootPanel.setLayout(new BorderLayout()); JPanel fnamePanel = new JPanel(); fnamePanel.setLayout(new FlowLayout()); fnameLabel = new JLabel("First Name: "); fnameText = new JTextField(25); fnamePanel.add(fnameLabel); fnamePanel.add(fnameText); JPanel lnamePanel = new JPanel(); lnamePanel.setLayout(new FlowLayout()); lnameLabel= new JLabel("Last Name: "); lnameText = new JTextField(25); lnamePanel.add(lnameLabel); lnamePanel.add(lnameText); myDocTextField = lnameText.getDocument(); myDocTextField.addDocumentListener(this); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new FlowLayout()); startButton = new JButton("Start Request Process"); cancelButton = new JButton("Cancel"); buttonPanel.add(startButton); startButton.addActionListener(this); startButton.setEnabled(false); buttonPanel.add(cancelButton); cancelButton.addActionListener(this); rootPanel.add("North",fnamePanel); rootPanel.add("Center",lnamePanel); rootPanel.add("South", buttonPanel); getContentPane( ).setLayout(new BorderLayout( )); getContentPane( ).add("Center", rootPanel); pack(); setVisible(true); } public void insertUpdate(DocumentEvent evtDoc) { if (myDocTextField.getLength() > 0) startButton.setEnabled(true); } public void removeUpdate(DocumentEvent evtDoc) { if (myDocTextField.getLength() > 0) startButton.setEnabled(true); else startButton.setEnabled(false); } public void changedUpdate(DocumentEvent evtDoc) { // nothing here } public void actionPerformed( ActionEvent e ) { // ------------------------------------ // See if the start button was pressed // ------------------------------------ if ( e.getActionCommand( ) == "Start Request Process" ) { // get the data from the input fields firstName=fnameText.getText(); lastName=lnameText.getText(); System.out.println("Firstname = '" + firstName + "'"); System.out.println("Lastname = '" + lastName + "'"); // ------------------------------------------- // Connect to queue manager and open the queue // ------------------------------------------- try { wfqmgr = new MQQueueManager( "FMCQM" ); // SET_IDENTITY_CONTEXT is used to change the useridentifier int openOptions = MQC.MQOO_OUTPUT | MQC.MQOO_SET_IDENTITY_CONTEXT; xmlinputq = wfqmgr.accessQueue("EXEXMLINPUTQ", openOptions, null, null, null); } catch (MQException mqException) { System.out.println("MQException has been thrown on connect or open"); System.exit(99); } // ------------------------------------------------- // Build the XML message that will start the process // ------------------------------------------------- procTempName="CreditRequest"; procInstName = lastName; contName = "PersonInfo"; xmlRequestMessage= "" + "\n " + "\n " + "\n No" + "\n " + "\n " + "\n " + procTempName + "" + "\n " + procInstName + "" + "\n " + "\n <" + contName + ">" + "\n " + firstName + "" + "" + lastName + "" + ""+ "\n " + "\n " + "\n \n\n\n"; try { // ------------------------------------------------------- // Set user identifier and write the message to the buffer // ------------------------------------------------------- MQMessage msg = new MQMessage(); msg.userId = "ADMIN"; // use an userid other than WinNT userid msg.writeString(xmlRequestMessage); // ---------------------------------------------------- // Specify put options and put the message on the queue // ---------------------------------------------------- MQPutMessageOptions pmo = new MQPutMessageOptions(); pmo.options = MQC.MQPMO_SET_IDENTITY_CONTEXT; // to use non-WinNT userid xmlinputq.put(msg, pmo); System.out.println("Have put xml message on queue."); } // end try catch(MQException mqexception) { System.out.println("MQException thrown on put of message."); } catch (java.io.IOException exception) { System.out.println("An error occurred writing string into the message buffer. Exception = " + exception); this.cleanup(); this.endApp(); } // close queue and disconnect this.cleanup(); // End application this.endApp(); } // endif Start button pressed // ------------------------------------ // See if the cancel button was pressed // ------------------------------------ if ( e.getActionCommand( ) == "Cancel" ) { this.endApp(); } } //end actionPerformed // ---------------------------------------- // Close the queue and disconnect from qmgr // ---------------------------------------- public void cleanup() { System.out.println("Closing queue and disconnect from qmgr."); try { xmlinputq.close(); } catch(MQException mqexecption) { System.out.println("MQException has been thrown on close of queue."); } try { wfqmgr.disconnect(); } catch(MQException mqexception) { System.out.println("MQException has been thrown on disconnect from qmgr."); } } // end ActionPerformed // ------------------- // End the application // ------------------- public void endApp() { System.out.println("Leaving this application."); System.exit(0); } // -------------------------------- // Main // -------------------------------- public static void main( String[] args ) { StartCreditRequest startCreditRequest = new StartCreditRequest( ); } } // end of StartCreditRequest class