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 » WebSphere Message Broker (ACE) Support » Java Plugin Example that sets Environment

Post new topic  Reply to topic
 Java Plugin Example that sets Environment « View previous topic :: View next topic » 
Author Message
mverh
PostPosted: Wed May 11, 2005 12:22 pm    Post subject: Java Plugin Example that sets Environment Reply with quote

Voyager

Joined: 06 Mar 2002
Posts: 97

Hi, I am working on developing a java plugin to populate the environment tree with the broker name, execution group name and flow name. I have the methods to get these values.

I am looking for some plugin code (the evaluate method) to place these into the enviroment tree and pass the input message through unchanged. I am hoping someone has done something similar to this before and wouldn't mind sharing the code with the myself and the forum.

Thanks in advance

Marc
Back to top
View user's profile Send private message
mlafleur
PostPosted: Wed May 11, 2005 12:57 pm    Post subject: Reply with quote

Acolyte

Joined: 19 Feb 2004
Posts: 73

Why don't you use a java procedure instead of a plugin node?

This is assuming you are using at least WBIMB V5.0 CSD 4

What version of the broker are you using?
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Wed May 11, 2005 1:00 pm    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

mlafleur wrote:
Why don't you use a java procedure instead of a plugin node

The information he's looking for is not available through the java procedure interface, as far as I know.

Accessing the Environment through the plug-in API is no different than accessing any other tree. Ergo - any samples you have will tell you how to do what you want.

The only difference is the root object that you talk to. The API javadoc should be straightforward on how to get at the Environment tree.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
mlafleur
PostPosted: Wed May 11, 2005 1:04 pm    Post subject: Reply with quote

Acolyte

Joined: 19 Feb 2004
Posts: 73

All you have to do is pass in a reference to the Environment tree as an argument to your ESQL java procedure and you may manipulate it however you like in your java code.
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Wed May 11, 2005 1:07 pm    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

mlafleur wrote:
All you have to do is pass in a reference to the Environment tree as an argument to your ESQL java procedure and you may manipulate it however you like in your java code.


Why do you think I meant that the Environment was not available in a java procedure?

I'm fairly certain, although more than happy to be proved wrong, that you can't access any of the methods on an MbBroker object from within a Java procedure.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
EddieA
PostPosted: Wed May 11, 2005 1:25 pm    Post subject: Reply with quote

Jedi

Joined: 28 Jun 2001
Posts: 2453
Location: Los Angeles

Quote:
I'm fairly certain, although more than happy to be proved wrong, that you can't access any of the methods on an MbBroker object from within a Java procedure.

The help does specify "REFERENCE (to a message tree)" as a valid EQSL Data Type for EQSL to Java Mapping as an "com.ibm.broker.plugin.MbElement" object. But, there are a series of "restrictions".

** Update ** Sorry Jeff, I just re-read the thread and realised what you were pointing out. Extracts size 10s from mouth.

Cheers,
_________________
Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0


Last edited by EddieA on Wed May 11, 2005 1:39 pm; edited 1 time in total
Back to top
View user's profile Send private message
mverh
PostPosted: Wed May 11, 2005 1:30 pm    Post subject: Reply with quote

Voyager

Joined: 06 Mar 2002
Posts: 97

Jeff is correct...I originally developed this as a java procedure. I developed my own methods utilizing the getName method of MbBroker, MbExecutionGroup and MbMessageFlow to get the values.

It works...sort of. I got the broker name no problem, got the eg name no problem but when I tried to get the flow name the eg abended. I reported the problem as a defect and was told it is not supported to use MbNode in a java procedure, it can only be done via a plugin.

I know if I review the manuals I'll figure this out but like any good programmer I was hoping to find a sample that would shorten my development timeline.

Marc
Back to top
View user's profile Send private message
mlafleur
PostPosted: Wed May 11, 2005 2:02 pm    Post subject: Reply with quote

Acolyte

Joined: 19 Feb 2004
Posts: 73

If your message flow names are not changing, just make the name a constant in your ESQL and set it in the Environment and call java procedure to get broker and execution group names. Easier than creating a plugin...
Back to top
View user's profile Send private message
malammik
PostPosted: Wed May 11, 2005 4:47 pm    Post subject: Reply with quote

Partisan

Joined: 27 Jan 2005
Posts: 397
Location: Philadelphia, PA

import java.io.ByteArrayInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

import org.apache.log4j.FileAppender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.SimpleLayout;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;

import com.ibm.broker.plugin.MbElement;
import com.ibm.broker.plugin.MbException;
import com.ibm.broker.plugin.MbInputTerminal;
import com.ibm.broker.plugin.MbMessage;
import com.ibm.broker.plugin.MbMessageAssembly;
import com.ibm.broker.plugin.MbNode;
import com.ibm.broker.plugin.MbNodeInterface;
import com.ibm.broker.plugin.MbOutputTerminal;

/**
* @author mqadmin
*
* To change this generated comment edit the template variable "typecomment":
* Window>Preferences>Java>Templates.
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
public class ArchMsgRouterNode extends MbNode implements MbNodeInterface {

/**
* @see com.ibm.broker.plugin.MbNodeInterface#evaluate(MbMessageAssembly, MbInputTerminal)
*/
private String TraceFile = null;
private String TraceLevel = null;
private String RouterType = null;
private String Output = null;
private String data = null;
private FileWriter writer = null;

private Logger logger = null;
private FileAppender appender = null;
private MbElement xElement = null;
private MbElement eVarRootElement = null;

public void evaluate(MbMessageAssembly assembly, MbInputTerminal arg1)
throws MbException {

MbOutputTerminal match = getOutputTerminal("true");
MbOutputTerminal noMatch = getOutputTerminal("false");
logger.debug("################################################");
logger.debug("###########NEW MESSAGE###########################");
logger.debug("################################################");
logger.debug("Processing MessageAssembly " + assembly);
long startTime = System.currentTimeMillis();

MbMessage oldMsg = assembly.getMessage();
MbElement oldRootElement = oldMsg.getRootElement();
logger.debug("Attempting to retrieve byte data from old message");

byte[] byteData = null;

//byteData = oldRootElement.toBitstream("", "", "", 0, 0, 0);
//String message = null;

//message = new String(byteData);


MbMessage eVar = assembly.getGlobalEnvironment();

And off you go my friend.
_________________
Mikhail Malamud
http://www.netflexity.com
http://groups.google.com/group/qflex
Back to top
View user's profile Send private message Visit poster's website AIM Address
mverh
PostPosted: Wed May 11, 2005 5:00 pm    Post subject: Reply with quote

Voyager

Joined: 06 Mar 2002
Posts: 97

There is no guarantee moving forward that the methods that work today will work. Since it is not supported and there is risk it will fail, it is not something I want to propose to my customer.

FYI, the reason why we need this is we have multipe brokers each housing the same instance of a message flow. The input queues are clustered. So when a customer drives a service we don't know which particular broker service instance is processing the request. If an error is thrown we want to know the instance for problem diagnosis purposes.

I have thought of querying the broker database but this won't tell me the eg name or flow name.
Back to top
View user's profile Send private message
mverh
PostPosted: Wed May 11, 2005 5:07 pm    Post subject: Reply with quote

Voyager

Joined: 06 Mar 2002
Posts: 97

Thanks Mikhail, I've gotten to the point where I've got the globalEnvironment. I'm adding the logic to handle the situations where if the element doesn't exist I add it, if it does exist overwrite it etc. It's tedious and was hoping someone had already done it.
Back to top
View user's profile Send private message
malammik
PostPosted: Wed May 11, 2005 6:01 pm    Post subject: Reply with quote

Partisan

Joined: 27 Jan 2005
Posts: 397
Location: Philadelphia, PA

Tedious is what the computers are good at But there is a catch - you have to program them first so they can take all the credit. Good Luck. Post any problems you have.
_________________
Mikhail Malamud
http://www.netflexity.com
http://groups.google.com/group/qflex
Back to top
View user's profile Send private message Visit poster's website AIM Address
mverh
PostPosted: Thu May 12, 2005 9:59 am    Post subject: Reply with quote

Voyager

Joined: 06 Mar 2002
Posts: 97

For those of you who are interested here is my java plugin code that sets Environment.brokerName, Environment.executionGroupName and Environment.messageFlowName. Enjoy...

Code:
package com.ibm.customNodes;

import com.ibm.broker.plugin.*;

/**
 * Copyright IBM Canada LTD.
 * @author marc verhiel mverhiel@ca.ibm.com
 *
 */

public class getBrokerInfoNode extends MbNode implements MbNodeInterface {

   public getBrokerInfoNode() throws MbException
   {
         // create terminals here
         createInputTerminal ("in");
         createOutputTerminal ("out");
         createOutputTerminal ("failure");
   }

   
   public static String getNodeName()
   {
      return "getBrokerInfoNode";
   }

   /**
    * @see com.ibm.broker.plugin.MbNodeInterface#evaluate(MbMessageAssembly, MbInputTerminal)
    */
   public void evaluate(MbMessageAssembly assembly, MbInputTerminal in)
      throws MbException {
      
      String value;
         
      // The incoming message assembly and its embedded messages are read-only.
      // New objects must be created using the copy constructors
      MbMessage newGlobalEnv = new MbMessage(assembly.getGlobalEnvironment());
      MbMessage newLocalEnv = new MbMessage(assembly.getLocalEnvironment());
      MbMessage newExceptionList = new MbMessage(assembly.getExceptionList());
      MbMessage newMsg = new MbMessage(assembly.getMessage());
      
      MbMessageAssembly newAssembly = new MbMessageAssembly(assembly, newLocalEnv, newGlobalEnv,
                                                newExceptionList, newMsg);
      
      //navigate to Root of Environment
      MbElement rootEnvElement = newAssembly.getGlobalEnvironment().getRootElement();


      // get broker name      
      value = "error";
      MbBroker mb = getBroker();
      value = mb.getName();
   
      // navigate to Environment/brokerName
      MbElement brokerNameElement =
         rootEnvElement.getFirstElementByPath("/brokerName");
      
      if (brokerNameElement == null)
      {
         // set the Environment.brokerName
         MbElement newBrokerNameElement =
            rootEnvElement.createElementAsLastChild(
               MbElement.TYPE_NAME,
               "brokerName",
               value);
      }
      else
      {
         //overwrite the existing value
         brokerNameElement.setValue(value);
      }      
      
      // get execution group name
      value = "error";
      MbExecutionGroup eg = getExecutionGroup();
      value = eg.getName();

      // navigate to Environment/executionGroupName
      MbElement executionGroupNameElement =
         rootEnvElement.getFirstElementByPath("/executionGroupName");

      if (executionGroupNameElement == null)
      {   
         // set the Environment.executionGroupName   
         MbElement newExecutionGroupNameElement =
            rootEnvElement.createElementAsLastChild(
               MbElement.TYPE_NAME,
               "executionGroupName",
               value);
      }
      else
      {
         //overwrite the existing value
         executionGroupNameElement.setValue(value);         
      }
      
            
      // get message flow name
      value = "error";
      MbMessageFlow mf = getMessageFlow();
      value = mf.getName();

      // navigate to Environment/messageFlowName
      MbElement messageFlowNameElement =
         rootEnvElement.getFirstElementByPath("/messageFlowName");

      if (executionGroupNameElement == null)
      {   
         // set the Environment.messageFlowName   
         MbElement newMessageFlowNameElement =
            rootEnvElement.createElementAsLastChild(
               MbElement.TYPE_NAME,
               "messageFlowName",
               value);
      }
      else
      {
         //overwrite the existing value
         messageFlowNameElement.setValue(value);         
      }
      
      //propagate the message to the out terminal      
      MbOutputTerminal out = getOutputTerminal("out");
      out.propagate(newAssembly);
      
   }

}
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Thu May 12, 2005 10:06 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

To play nice with others, I might recommend moving your data from Environment.fieldname to something like Environment.PluginClassName.fieldname.

In other words, try and put it in a unique subtree so that someone else doesn't get hosed up trying to use Environment.brokerName.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
mverh
PostPosted: Thu May 12, 2005 10:20 am    Post subject: Reply with quote

Voyager

Joined: 06 Mar 2002
Posts: 97

Jeff, I agree that having elements as chiildren of Environment is not generally recommended and making the elements children of another child element of Environment i.e. Environment.Variables etc is. If you're so inclined I have no issues with you making the change and reposting.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Java Plugin Example that sets Environment
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.