WebSphere Message Broker, Version 8.0.0.7 Operating Systems: AIX, HP-Itanium, Linux, Solaris, Windows, z/OS

See information about the latest product version

Calling an Enterprise Java Bean

You can call an Enterprise Java™ Bean (EJB) from a JavaCompute node.

Before you start:
  • Ensure that all required Java classes are in the WebSphere® Message Broker shared-classes directories, or are referenced in the CLASSPATH environment variable. You can use the wildcard character (*) at the end of a directory path specifier to load all JARs in that directory path.
  • Ensure that the user JAR files that are needed for EJB access are referenced in CLASSPATH. For more information, see the documentation for the application server that is hosting the EJB.
  • If you are using a version of WebSphere Message Broker before Version 6.0 Fix Pack 3, you must set the context loader by including the following statement in the node's Java code before the InitialContext is set:
    Thread currentThread().setContextClassLoader(this.getClass().getClassLoader());
The following example shows how to call an EJB from a JavaCompute node:
public class CallAckNoAckEJB_JavaCompute extends MbJavaComputeNode { 

		 public void evaluate(MbMessageAssembly inAssembly) throws MbException { 
                MbOutputTerminal out = getOutputTerminal("out"); 
                MbOutputTerminal alt = getOutputTerminal("alternate"); 

                MbMessage inMessage = inAssembly.getMessage(); 

                // create new message 
                MbMessage outMessage = new MbMessage(inMessage); 
                MbMessageAssembly outAssembly = new MbMessageAssembly(inAssembly,outMessage); 

                try { 
                        // ---------------------------------------------------------- 
                        // Add user code below 
                
                        String response = null; 
                        String responseMessage = null; 
                                                
                        Properties properties = new Properties(); 
                        properties.put(Context.PROVIDER_URL, "iiop://localhost:2809"); 
                        properties.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.
WsnInitialContextFactory"); 
                
                        try { 
                            
                        		 Context initialContext = new InitialContext(properties); 
                                Object obj = initialContext.lookup("ejb/com/acme/ejbs/AckNoAckHome"); 
                                AckNoAckHome ejbHome = (AckNoAckHome)javax.rmi.PortableRemoteObject.
narrow(obj,AckNoAckHome.class); 
                                
                                AckNoAck ackNoAck = ejbHome.create(); 
                                responseMessage = ackNoAck.getAck(); 
                                response = "Ack"; 
                        } catch(Exception e) { 
                                responseMessage = e.getMessage(); 
                                response = "NoAck"; 
                        } 

                        MbElement cursor = outMessage.getRootElement().getFirstElementByPath("/XML/AckNoAck"); 
                        cursor.createElementAsLastChild(MbElement.TYPE_NAME,"Response",null); 
                        cursor.getLastChild().createElementAsLastChild(MbElement.TYPE_NAME,response,null); 
                        cursor.getLastChild().getLastChild().createElementAsLastChild(MbElement.TYPE_VALUE,null,
responseMessage); 
                                                
                        // End of user code 
                        // ---------------------------------------------------------- 

                        // The following should only be changed 
                        // if not propagating message to the 'out' terminal 
                        out.propagate(outAssembly); 

                } finally { 
                        // clear the outMessage 
                        outMessage.clearMessage(); 
                } 
		 } 
} 
Notices | Trademarks | Downloads | Library | Support | Feedback

Copyright IBM Corporation 1999, 2016Copyright IBM Corporation 1999, 2016.

        
        Last updated:
        
        Last updated: 2016-05-23 14:46:17


Task topicTask topic | Version 8.0.0.7 | ac37120_