Sunday, October 26, 2008

Sample JMS Bean with Standalone Client on Weblogic 10.2 Platform

I have created Sample JMS Bean with Standalone Java client on weblogic 10.2 platform. We can use this approach for testing a JMS Bean which deployed on server without j2ee client.

Tools Used are Bea Weblogic Workspace Studio ver1.1, Weblogic 10.2 server.

JMS Listener Class is

@MessageDriven(ejbName = "SampleMessageListener",
destinationJndiName = "SampleMessageListenerJndiName",
destinationType = "javax.jms.Queue",
defaultTransaction = MessageDriven.DefaultTransaction.REQUIRED
)
public class SampleMessageListener extends GenericMessageDrivenBean implements
MessageDrivenBean, MessageListener {
private static final long serialVersionUID = 1L;
/* (non-Javadoc)
* @see javax.jms.MessageListener#onMessage(javax.jms.Message)
*/
public void onMessage(Message msg) {
TextMessage txtMsg = (TextMessage) msg;
try {
System.out.println("txtMsge " + txtMsg.getText());
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

And for Standalone Client code is:


public class SampleJMSClient {
private static InitialContext initialContext;
public static void main(String[] args) {
InitialContext context = getInitialContext();
try {
System.out.println("1");
QueueConnectionFactory queueConnectionFacory = (QueueConnectionFactory) context.lookup("weblogic.examples.jms.QueueConnectionFactory");
System.out.println("2");
QueueConnection queueConnection = (QueueConnection) queueConnectionFacory.createConnection();
System.out.println("3");
QueueSession queueSession = queueConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
System.out.println("4");
Queue queue = (Queue) context.lookup("SampleMessageListenerJndiName");
System.out.println("5");
QueueSender sender = queueSession.createSender(queue);
System.out.println("6");
TextMessage txtMessage = queueSession.createTextMessage("Hello, World");
System.out.println("7");
sender.send(txtMessage);
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static InitialContext getInitialContext() {
if(initialContext == null){
try {
initialContext = new InitialContext();
System.out.println("1asfaf");
initialContext.addToEnvironment(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
System.out.println("asdff");
initialContext.addToEnvironment(Context.PROVIDER_URL,"t3://localhost:7001");
System.out.println("11111111");
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return initialContext;
}
}

For Client, weblogic jars used are

api.jar,com.bea.core.annogen_1.0.1.0.jar,com.bea.core.antlr.runtime_2.7.5.jar,com.bea.core.antlr_2.7.5.jar,com.bea.core.apache.bcel_5.2.0.0.jar,com.bea.core.apache.commons.collections_3.2.0.jar,
com.bea.core.apache.commons.lang_2.1.0.jar,com.bea.core.apache.commons.logging.api_1.1.0.jar,com.bea.core.apache.commons.logging_1.1.0.jar,com.bea.core.apache.commons.net_1.4.1.jar,com.bea.core.apache.commons.pool_1.3.0.jar,
com.bea.core.apache.dom_1.0.0.0.jar,com.bea.core.apache.log4j_1.2.13.jar,com.bea.core.apache.logging_1.0.0.0.jar,com.bea.core.apache.oro_2.0.8.jar,com.bea.core.apache.regexp_1.4.0.jar,com.bea.core.apache.velocity.dep_1.4.jar,com.bea.core.apache.velocity_1.4.jar,
com.bea.core.apache.xalan_2.7.0.jar,com.bea.core.apache.xerces.resolver_2.8.1.jar,com.bea.core.apache.xerces.xmlapis_2.8.1.jar,com.bea.core.apache.xercesImpl_2.8.1.jar,com.bea.core.apache.xml.security_1.3.0.jar,com.bea.core.apache.xml.serializer_2.7.0.jar,com.bea.core.apache_1.0.1.0.jar,com.bea.core.bea.opensaml_2.0.0.0.jar,com.bea.core.beangen_1.0.1.0.jar,com.bea.core.beaninfo_1.0.1.0.jar,
com.bea.core.common.engine.api_2.0.1.0.jar,com.bea.core.common.engine.impl_2.0.1.0.jar,com.bea.core.common.security.api_2.0.1.0.jar,com.bea.core.common.security.impl_2.0.1.0.jar,com.bea.core.common.security.jdkutils_2.0.1.0.jar,
com.bea.core.common.security.providers.env_2.0.1.0.jar,com.bea.core.common.security.providers.utils_2.0.1.0.jar,com.bea.core.common.security.utils_2.0.1.0.jar,com.bea.core.datasource_1.0.1.0.jar,com.bea.core.descriptor_1.0.1.0.jar,
com.bea.core.diagnostics.core_1.0.1.0.jar,com.bea.core.diagnostics.instrumentor_1.0.1.0.jar,com.bea.core.i18n.generator_1.0.1.0.jar,com.bea.core.i18n_1.0.1.0.jar,com.bea.core.jar,builder_1.0.1.0.jar,com.bea.core.jatmi_1.0.1.0.jar,com.bea.core.jmspool_1.0.1.0.jar,
com.bea.core.jsafe_3.5.0.jar,com.bea.core.kodo.integration.tools_1.0.1.0.jar,com.bea.core.kodo.integration_1.0.1.0.jar,com.bea.core.kodo_4.1.3.1.jar,com.bea.core.logging_1.0.1.0.jar,com.bea.core.management.core_1.0.1.0.jar,
com.bea.core.mbean.maker_1.0.1.0.jar,com.bea.core.mbean.support_1.0.1.0.jar,com.bea.core.messaging.kernel_1.0.1.0.jar,com.bea.core.nodemanager.plugin_1.0.1.0.jar,com.bea.core.process_5.3.0.0.jar,com.bea.core.repackaged.apache.bcel_5.2.0.0.jar,com.bea.core.repackaged.apache.commons.logging_1.1.0.jar,
com.bea.core.repackaged.asm_1.5.2.jar,com.bea.core.repackaged.aspectj.aspectjweaver_5.0.0.jar,com.bea.core.repackaged.springframework.pitchfork_1.0.0.jar,com.bea.core.repackaged.springframework.spring_2.0.2.jar,com.bea.core.resourcepool_1.0.1.0.jar,com.bea.core.serp_1.12.0.jar,
com.bea.core.store.gxa_1.0.1.0.jar,com.bea.core.store_1.0.1.0.jar,com.bea.core.timers_1.0.1.0.jarcom.bea.core.transaction_2.0.1.0.jarcom.bea.core.utils.classloaders_1.0.1.0.jarcom.bea.core.utils.expressions_1.0.1.0.jarcom.bea.core.utils.full_1.0.1.0.jarcom.bea.core.utils.wrapper_1.0.1.0.jarcom.bea.core.utils_1.0.1.0.jarcom.bea.core.weblogic.commons.logging_1.0.1.0.jarcom.bea.core.weblogic.rmi.client_1.0.1.0.jarcom.bea.core.weblogic.saaj_1.0.1.0.jarcom.bea.core.weblogic.security.wls_2.0.1.0.jarcom.bea.core.weblogic.security_2.0.1.0.jarcom.bea.core.weblogic.stax_1.0.1.0.jarcom.bea.core.weblogic.workmanager_1.0.1.0.jarcom.bea.core.workarea_1.0.1.0.jarcom.bea.core.ws.axis_1.0.0.0.jarcom.bea.core.ws.wsdl4j_1.5.1.jarcom.bea.core.xml.beaxmlbeans_2.2.0.0.jarcom.bea.core.xml.beaxmlbeans_2.3.1.0.jarcom.bea.core.xml.staxb.buildtime_1.0.1.0.jarcom.bea.core.xml.staxb.runtime_1.0.1.0.jarcom.bea.core.xml.stax_1.0.0.0.jarcom.bea.core.xml.xmlbeans_2.2.0.0.jarcom.bea.core.xml.xmlbeans_2.3.1.0.jarweblogic.jarwlclient.jarwljmsclient.jar,w-api.jar


And

Connection Factory Configuration is

JNdi name is
weblogic.examples.jms.QueueConnectionFactory

QUeue Jndi name is

SampleMessageListenerJndiName

If you need more info, please contact me at AM.Vijay@gmail.com

No comments: