JMS

Hello Experts,
Iam trying to put message in topic through java program , Iam getting the following error.

Error:
java.lang.ClassCastException: com.webmethods.jms.impl.WmConnectionFactoryImpl cannot be cast to javax.jms.TopicConnectionFactoryjava.lang.ClassCastException: com.webmethods.jms.impl.WmConnectionFactoryImpl cannot be cast to javax.jms.TopicConnectionFactory

Thanks in advance.

Hi Lavanya,

can you check your code aginst this sample?


import com.webmethods.jms.WmTopicConnection;
import com.webmethods.jms.WmTopicConnectionFactory;
import com.webmethods.jms.WmConnection;
import com.webmethods.jms.WmConnectionFactory;

import com.webmethods.jms.WmJMSConfig;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.jms.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.File;

public class SampleClient {
    public SampleClient(String username, String password, List messageText) {
        System.out.println("running SampleClient.");

        Properties jndiProperties = null;
        Context jndiContext = null;

        TopicConnectionFactory tcf = null;
        TopicConnection connection = null;
        Topic topic = null;

        try {
            // load the jndi.properties file
            try {
                jndiProperties = new Properties();
                File file = new File("jms.properties");
                jndiProperties.load(new FileInputStream(file));
                System.out.println("loaded " + file.getAbsolutePath());
                System.out.println(jndiProperties.toString());
            } catch (IOException ex) {
                System.out.println("ERROR: jndi.properties not loaded");
                ex.printStackTrace();
                System.exit(0);
            }
        
            // connect to JNDI using jndi.properties
            try {
                jndiContext = new InitialContext(jndiProperties);
                System.out.println("connected to JNDI provider");
            } catch (NamingException ex) {
                System.out.println("ERROR: failed to connect to JNDI provider");
                ex.printStackTrace();
                System.exit(0);
            }
        
            // lookup the administered objects
            try {
                tcf = (TopicConnectionFactory) jndiContext.lookup("<ConnectionFactoryName>");
                System.out.println("found SampleClientConnectionFactory in JNDI");

                topic = (Topic) jndiContext.lookup("<TopicName>");
                System.out.println("found SampleTopic in JNDI");
            } catch (NamingException ex) {
                System.out.println("ERROR: JNDI lookup failed");
                ex.printStackTrace();
                System.exit(0);
            }
        
            // create a connection to the Broker
            try {
                System.out.println(((WmConnectionFactory)tcf).getSSLEncrypted());
                System.out.println(((WmConnectionFactory)tcf).getSSLKeystore());
                System.out.println(((WmConnectionFactory)tcf).getSSLKeystoreType());
                System.out.println(((WmConnectionFactory)tcf).getSSLTruststore());
                System.out.println(((WmConnectionFactory)tcf).getSSLTruststoreType());
                ((WmConnectionFactory)tcf).setSSLKeystore(jndiProperties.getProperty("com.webMethods.jms.naming.keystore"));
                ((WmConnectionFactory)tcf).setSSLTruststore(jndiProperties.getProperty("com.webMethods.jms.naming.truststore"));
                connection = tcf.createTopicConnection(username, password);
                System.out.println("connected to Broker \"" +
                                   ((WmTopicConnection) connection).getBroker() + "\"");
                System.out.println(((WmConnection) connection).getSSLEncryptionLevel());
            } catch (JMSException ex) {
                String broker = ((WmTopicConnectionFactory) tcf).getBrokerList();
                System.out.println("ERROR: unable to connect to Broker \"" + broker + "\"");
                ex.printStackTrace();
                System.exit(0);
            }
        
            // publish the message(s)
            try {
                TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
                TopicSender sender = session.createSender(topic);
                for (int i = 0; i < messageText.size(); i++) {
                    TextMessage msg = session.createTextMessage((String) messageText.get(i));
                    sender.send(msg);
                    System.out.println("published message \"" + messageText.get(i) + "\"");
                }
                System.out.println("published " + messageText.size() + " message(s)");
            } catch (Exception ex) {
                System.out.println("ERROR: unable to publish message(s)");
                ex.printStackTrace();
                System.exit(0);
            }
            
            // close the connection
            connection.close();
            System.out.println("connection closed");
        } catch (Exception ex) {
            System.out.println("ERROR: unexpected error");
            ex.printStackTrace();
        }
    }
}

Please note that this originally for using Queues, I have modifiied it for Topics for this post.
It is using WmJMSNaming as JNDI-Provider and is prepared to use Authentication and Encryption.
Replace the values in “<>” with your real names.

But I think it point put how to achieve a connectivity to Broker JMS from external Java Programs.

Please check Broker Java API documenation (contains Broker JMS API documentation as well) for correct ClassNames and fruther informations.

A glance at the Broker_Messaging_Programmers_Guide might also be helpful.

Regards,
Holger

Thank you Holger, I will go through that docs as you suggested.

And also help me to solve this.
while consuming the message iam getting following error,the error is attached.
Error:
com.wm.app.b2b.server.ServiceException: javax.jms.IllegalStateException: [BRM.10.1211] JMS: Message consumer is closed.
at pub.jms.receive(jms.java:89)
at sun.reflect.GeneratedMethodAccessor313.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.wm.app.b2b.server.JavaService.baseInvoke(JavaService.java:439)
at com.wm.app.b2b.server.invoke.InvokeManager.process(InvokeManager.java:643)
at com.wm.app.b2b.server.util.tspace.ReservationProcessor.process(ReservationProcessor.java:46)
at com.wm.app.b2b.server.invoke.StatisticsProcessor.process(StatisticsProcessor.java:44)
at com.wm.app.b2b.server.invoke.ServiceCompletionImpl.process(ServiceCompletionImpl.java:243)
at com.wm.app.b2b.server.invoke.ValidateProcessor.process(ValidateProcessor.java:51)
at com.wm.app.b2b.server.invoke.PipelineProcessor.process(PipelineProcessor.java:171)
at com.wm.app.b2b.server.ACLManager.process(ACLManager.java:276)
at com.wm.app.b2b.server.invoke.DispatchProcessor.process(DispatchProcessor.java:30)
at com.wm.app.b2b.server.AuditLogManager.process(AuditLogManager.java:363)
at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:547)
at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:386)
at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:234)
at com.wm.app.b2b.server.BaseService.invoke(BaseService.java:194)
at com.wm.lang.flow.FlowInvoke.invoke(FlowInvoke.java:324)
at com.wm.lang.flow.FlowState.invokeNode(FlowState.java:584)
at com.wm.lang.flow.FlowState.stepIncremental(FlowState.java:494)
at com.wm.lang.flow.FlowState.invoke(FlowState.java:382)
at wm.server.flowimpl.stepFlow(flowimpl.java:210)
at sun.reflect.GeneratedMethodAccessor262.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.wm.app.b2b.server.JavaService.baseInvoke(JavaService.java:449)
at com.wm.app.b2b.server.invoke.InvokeManager.process(InvokeManager.java:643)
at com.wm.app.b2b.server.util.tspace.ReservationProcessor.process(ReservationProcessor.java:46)
at com.wm.app.b2b.server.invoke.StatisticsProcessor.process(StatisticsProcessor.java:44)
at com.wm.app.b2b.server.invoke.ServiceCompletionImpl.process(ServiceCompletionImpl.java:243)
at com.wm.app.b2b.server.invoke.ValidateProcessor.process(ValidateProcessor.java:51)
at com.wm.app.b2b.server.invoke.PipelineProcessor.process(PipelineProcessor.java:171)
at com.wm.app.b2b.server.ACLManager.process(ACLManager.java:276)
at com.wm.app.b2b.server.invoke.DispatchProcessor.process(DispatchProcessor.java:30)
at com.wm.app.b2b.server.AuditLogManager.process(AuditLogManager.java:363)
at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:547)
at com.wm.app.b2b.server.invoke.InvokeManager.invoke(InvokeManager.java:386)
at com.wm.app.b2b.server.ServiceManager.invoke(ServiceManager.java:234)
at com.wm.app.b2b.server.comm.DefaultServerRequestHandler.handleMessage(DefaultServerRequestHandler.java:119)
at com.wm.app.b2b.server.HTTPMessageHandler.process(HTTPMessageHandler.java:160)
at com.wm.app.b2b.server.HTTPDispatch.handleRequest(HTTPDispatch.java:181)
at com.wm.app.b2b.server.Dispatch.run(Dispatch.java:355)
at com.wm.util.pool.PooledThread.run(PooledThread.java:131)
at java.lang.Thread.run(Thread.java:662)
Caused by: javax.jms.IllegalStateException: [BRM.10.1211] JMS: Message consumer is closed.
at com.webmethods.jms.impl.WmMessageConsumerImpl.checkState(WmMessageConsumerImpl.java:612)
at com.webmethods.jms.impl.WmMessageConsumerImpl.receive(WmMessageConsumerImpl.java:324)
at com.wm.app.b2b.server.jms.consumer.OnDemandConsumer.receive(OnDemandConsumer.java:118)
at pub.jms.receive(jms.java:85)

Hello Lavanya,

Could you please share what you did to resolve this error.
com.wm.app.b2b.server.ServiceException: javax.jms.IllegalStateException: [BRM.10.1211] JMS: Message consumer is closed.

Even I am facing the same issue while consuming message.

Regards,
Nikhil Pardeshi

What is your Messaging system currently used? Is it Broker JMS or UM JMS?

IS core fix levels?

While invoking pub.jms:receive do you specify any timeout value? If yes what is the value?

I am using UM JMS.

IS fixes:
IS_9.9_Core_Fix2
IS_9.9_SPM_Fix2

I have not specified any timeout value since it is an optional field. But I tried with 10secs/60secs. It is still failing with below error.
javax.jms.IllegalStateException: Consumer already closed

Suggest you to increse the timeout and test.

Also make sure you have the latest fix levels, kindly refer the readme if there is any fix levels release from JMS.

Hello,

I was receiving that error since I was debugging it. When I tried to ran the service, it executed successfully.
Since it is NO_TRASACTION, i dont think so if we can debug.

You cannot debug the flow service with start, commit and rollback Tx services enabled. Disable them while debuging the flow service. Or you can capture debug info by adding debugLog or tracePipeline from WmPublic to see the details on server.log