ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » Workflow Engines - IBM MQ Workflow & Business Process Choreographer » Starting a Workflow process from java

Post new topic  Reply to topic
 Starting a Workflow process from java « View previous topic :: View next topic » 
Author Message
hbrahi1
PostPosted: Tue Apr 08, 2003 11:30 am    Post subject: Starting a Workflow process from java Reply with quote

Newbie

Joined: 08 Apr 2003
Posts: 3
Location: Montreal

Hi,

I'm just trying to create a new process in MQWF by puttin' an XML message to EXEXMLINPUTQ, but i have some problems with the security manager which throws a security exception, even if I'm logged in and I'm a valid user.

Vennella, I've found a java class that you posted but I'm not able to untar it, can you just send me the source file unzipped.

thanks in advance.

bra.
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
vennela
PostPosted: Tue Apr 08, 2003 12:00 pm    Post subject: Reply with quote

Jedi Knight

Joined: 11 Aug 2002
Posts: 4055
Location: Hyderabad, India

Code:

////////////////////////////////////////////////////////////////////////////////
//  This program sends an XML message to create and start a process instance  //
//  of the CreditRequest ProcessTemplate.                                     //
//                                                                            //
//  Note: Before executing this program, the FDL of CreditRequest sample      //
//  shipped along with the product should be imported into the runtime.       //
//                                                                            //
//  Usage:                                                                    //
//  java ProcessTemplateCreateAndStartInstance <XMLInputQueue> <MQWF QMGR>    //
//                     <ReplyQMGR> <ReplyQueue>                               //
//                                                                            //
//  You must specify <XMLInputQueue> and <MQWF QMGR>                          //
//  If you wish to receive a reply you must also specify <ReplyQMGR> and      //
//  <ReplyQueue>.  NOTE that you must ensure that <ReplyQMGR> and <ReplyQueue>//
//  both are in existance.                                                    //
//                                                                            //
//  Eg:                                                                       //
//  java ProcessTemplateCreateAndStartInstance EXEXMLINPUTQ  FMCQM1           //
//                                                                            //
//  java ProcessTemplateCreateAndStartInstance EXEXMLINPUTQ  FMCQM1           //
//      FMCQM1 REPLYQUEUE                                                     //
//                                                                            //
//  THIS is simply an illustration.  Use this as a base to build a general    //
//  Purpose XMLProcessStarter for your installation.                          //
////////////////////////////////////////////////////////////////////////////////



import java.io.*;
import java.util.*;
import com.ibm.mq.*;
public class ProcessTemplateCreateAndStartInstance {

  private static final String INAMETAG = "<ProcInstName>";
  private static final String STATETAG = "<ProcInstState>";
  private static final String TIMETAG  = "<LastStateChangeTime>";
  private static final String ENDTAG = "</";

  /** Creates a new instance of ProcessTemplateCreateAndStartInstance */
  public ProcessTemplateCreateAndStartInstance() {
  }

  /**
   * @param args the command line arguments
   */
  public static void main(String[] args) {
    try {
      String WorkFlowQMGR = null;
      String UPESQueue = null;
      String ReplyQMGR = null;
      String ReplyQueue = null;
      boolean responseRequired = false;
      if ( args.length != 4 &&
            args.length != 2) {
        System.out.println("Paramters are: Queue, QueueManager, ReplyQMGR, ReplyQueue");
        System.out.println("Note that ReplyQMGR and ReplyQueue are OPTIONAL " +
            "And if one is specified BOTH must be specified");
        System.exit(-1);
      }
      UPESQueue = args[0];
      WorkFlowQMGR = args[1];
      if (args.length > 2) {
        responseRequired = true;
        ReplyQMGR = args[2];
        ReplyQueue = args[3];
      }
      System.out.println("WorkFlowQMGR: " + WorkFlowQMGR);
      System.out.println("UPESQueue: " + UPESQueue);
      if (responseRequired) {
        System.out.println("Response is required.  Qmgr is " + ReplyQMGR);
        System.out.println("                       Queue is " + ReplyQueue);
      }
      MQQueueManager qmgr = new MQQueueManager(WorkFlowQMGR ) ;
      System.out.println("Connected to QMGR " + WorkFlowQMGR);

      int openOptions = MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING  |
    MQC.MQOO_SET_IDENTITY_CONTEXT;

      MQQueue queue = qmgr.accessQueue(UPESQueue, openOptions,
                                        null, null, "ARTDIRECTOR1");
      String DEFAULT_MQUSERID = "ARTDIRECTOR1";
      MQMessage inMsg = new MQMessage();
      String MessageInXMLFmt;
      inMsg.userId = DEFAULT_MQUSERID;
      if (responseRequired) {
        inMsg.replyToQueueManagerName = ReplyQMGR;
        inMsg.replyToQueueName = ReplyQueue;
      }
      MessageInXMLFmt = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "\n";
      MessageInXMLFmt = MessageInXMLFmt + "<!-- This document is to create and start a process template  -->"  + "\n";
      MessageInXMLFmt = MessageInXMLFmt + "<WfMessage>"  + "\n";
      MessageInXMLFmt = MessageInXMLFmt + "   <WfMessageHeader>"  + "\n";
      MessageInXMLFmt = MessageInXMLFmt + "      <ResponseRequired>Yes</ResponseRequired>"  + "\n";
      MessageInXMLFmt = MessageInXMLFmt + "      <UserContext>I want this data back</UserContext>"  + "\n";
      MessageInXMLFmt = MessageInXMLFmt + "   </WfMessageHeader>"  + "\n";
      MessageInXMLFmt = MessageInXMLFmt + "   <ProcessTemplateCreateAndStartInstance>"  + "\n";
      MessageInXMLFmt = MessageInXMLFmt + "      <ProcTemplName>CreditRequest</ProcTemplName>"  + "\n";
      MessageInXMLFmt = MessageInXMLFmt + "      <ProcInstName>MyCreditRequest2</ProcInstName>"  + "\n";
      MessageInXMLFmt = MessageInXMLFmt + "      <KeepName>false</KeepName>"  + "\n";
      MessageInXMLFmt = MessageInXMLFmt + "      <ProcInstInputData>"  + "\n";
      MessageInXMLFmt = MessageInXMLFmt + "         <PersonInfo>"  + "\n";
      MessageInXMLFmt = MessageInXMLFmt + "            <FirstName>Sreenivas</FirstName>"  + "\n";
      MessageInXMLFmt = MessageInXMLFmt + "            <LastName>Bandaru</LastName>"  + "\n";
      MessageInXMLFmt = MessageInXMLFmt + "         </PersonInfo>"  + "\n";
      MessageInXMLFmt = MessageInXMLFmt + "      </ProcInstInputData>"  + "\n";
      MessageInXMLFmt = MessageInXMLFmt + "   </ProcessTemplateCreateAndStartInstance>"  + "\n";
      MessageInXMLFmt = MessageInXMLFmt + "</WfMessage>"  + "\n";


      inMsg.writeString(MessageInXMLFmt);
      MQPutMessageOptions pmo = new MQPutMessageOptions();
      pmo.options = MQC.MQPMO_SET_IDENTITY_CONTEXT;
      queue.put(inMsg, pmo);
      System.out.println("Start message sent");
      qmgr.disconnect() ;
      if (responseRequired) {
        MQQueueManager replyQM = new MQQueueManager(ReplyQMGR);
        System.out.println("ReplyQMGR accessed");
        int ReplyOpenOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_INQUIRE ;
        MQQueue replyQueue = replyQM.accessQueue(ReplyQueue,
                           ReplyOpenOptions, null, null, null);
        System.out.println("ReplyQueue accessed");
        MQMessage currentMessage = new MQMessage();
        MQGetMessageOptions gmo = new MQGetMessageOptions( );
        gmo.options      = MQC.MQGMO_WAIT;
        gmo.matchOptions = MQC.MQMO_MATCH_CORREL_ID;
        gmo.waitInterval = -1;
        replyQueue.get( currentMessage, gmo );
        byte buffer[] = new byte[ currentMessage.getDataLength() ];
        currentMessage.readFully( buffer, 0, currentMessage.getDataLength() );
        String curMsg = new String(buffer);
        if ( curMsg.indexOf("<Exception>") != -1 )
          System.out.println("An Error has occurred during Process Start\n" +
                curMsg);
        else {
          int inamePos = curMsg.indexOf(INAMETAG) + INAMETAG.length() ;
          int statePos = curMsg.indexOf(STATETAG) + STATETAG.length();
          int timePos  = curMsg.indexOf(TIMETAG) + TIMETAG.length();

          String PIName = new String( curMsg.substring( inamePos ,
                          curMsg.indexOf(ENDTAG,inamePos) ) );
          String PIState = new String( curMsg.substring( statePos,
                          curMsg.indexOf(ENDTAG,statePos) ) );
          String PITime = new String( curMsg.substring( timePos,
                          curMsg.indexOf(ENDTAG,timePos) ) );
          System.out.println("Instance '" + PIName +
            "' is in the " + PIState + " state as of " + PITime);
        }

        replyQM.disconnect();
      }

    }
    catch(MQException ex){
        System.out.println("MQ Error - Reason code :" + ex.reasonCode);
    }
    catch (Exception e){
        System.out.println("Error : " + e);
    }
  } // end main

} // end CLASS


I am not sure if I have changed the program (I guess not).
Brandon has to very soon fix the "tar" problem.

The user that PUTs the message on the XMLINPUTQ has to be defined in MQWF. In the above example "ARTDIRECTOR1" should be defined in MQWF runtime.


Good luck

-------
Venny
Back to top
View user's profile Send private message Send e-mail Visit poster's website
hbrahi1
PostPosted: Tue Apr 08, 2003 12:51 pm    Post subject: it works Reply with quote

Newbie

Joined: 08 Apr 2003
Posts: 3
Location: Montreal

hi venny,

It works, thank you.

bra.
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » Workflow Engines - IBM MQ Workflow & Business Process Choreographer » Starting a Workflow process from java
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.