Robert Falcone
Robert Falcone

Reputation: 21

#solace ClassCastException jms ConectionFactory

I am trying to test JMS messaging on solace appliance. Trying to get the JMS Hello World Publisher sample to work. I am getting a Casting exception when trying to assign ConnectionFactory.

Any help appreciated.

    Hashtable<String, Object> env = new Hashtable<String, Object>();
    env.put(InitialContext.INITIAL_CONTEXT_FACTORY, "com.solacesystems.jndi.SolJNDIInitialContextFactory");

    env.put(InitialContext.PROVIDER_URL, "smf://xxx,xxx.com:55555");
    env.put(SupportedProperty.SOLACE_JMS_VPN, "VPN");
    env.put(Context.SECURITY_PRINCIPAL, "User");
    env.put(InitialContext.SECURITY_CREDENTIALS, "Pwd");

    // InitialContext is used to lookup the JMS administered objects.
    InitialContext initialContext = new InitialContext(env);
    // Lookup ConnectionFactory.
    ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("JNDI/CF/TEST");        

xception in thread "main" java.lang.ClassCastException: com.solacesystems.jms.impl.SolTopicImpl cannot be cast to javax.jms.ConnectionFactory at com.solacesystems.jms.samples.intro.SolJMSHelloWorldPub.main(SolJMSHelloWorldPub.java:99)

Upvotes: 1

Views: 1797

Answers (2)

Russell Sim
Russell Sim

Reputation: 1733

JNDI/CF/TEST is most likely configured to be a topic on the Solace router. This results in a class cast exception because topics cannot be casted into connection factories.

Please ensure that JNDI/CF/TEST is a JMS connection factory, and not a JMS topic on your router.

The list of configured JMS connection factories can be verified via SolAdmin, or through the output of show jndi connection-factory * via the CLI on the router.

Similarly, the list of configured JMS topics can be verified via SolAdmin, or through the output of show jndi topic * via the CLI on the router.

Upvotes: 0

Robert Falcone
Robert Falcone

Reputation: 21

I was able to get it working by using SolJmsUtility.createConnectionFactory and doing a lookup on the JNDI name.

    SolConnectionFactory solCF = SolJmsUtility.createConnectionFactory(env);

    // Connection connection = cf.createConnection();
    Connection connection = solCF.createConnection();

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

    Destination destination = (Destination)initialContext.lookup("JNDI/CF/TEST");

    MessageProducer producer = session.createProducer(destination);

Upvotes: 1

Related Questions