jruby-jms icon indicating copy to clipboard operation
jruby-jms copied to clipboard

cannot load Java class javax.jms.DeliveryMode

Open arif-muhammad-wmc-tech opened this issue 8 years ago • 7 comments

I'm connecting to WebSphere MQ. My code is

require 'jms'
require 'yaml'
require 'java'

  jms_provider = 'wmq'
  config       = YAML.load_file("#{Rails.root}/lib/tasks/wmq.yml")[jms_provider]

  JMS::Connection.session(config) do |session|
    session.consume(queue_name: 'ExampleQueue', timeout: 1000) do |message|
      p message
    end
  end

Here is the yml

wmq:
  :factory: com.ibm.mq.jms.MQQueueConnectionFactory
  :queue_manager: xxxx
  :host_name: some_host
  :channel: xxxxxxx
  :ssl_cipher_spec: TLS_RSA_WITH_AES_256_CBC_SHA256
  :port: 1417
  # Transport Type: com.ibm.mq.jms.JMSC::MQJMS_TP_CLIENT_MQ_TCPIP
  :transport_type: 1
  :username: cs-ws-s-wsmc
  :require_jars:
    - /opt/mqm/lib/com.ibm.mqjms.jar

I got the following error:

NameError: cannot load Java class javax.jms.DeliveryMode

Also I want to specify ssl cipher and key repository. How to setup SSL for wmq. I have the ssl key files.

arif-muhammad-wmc-tech avatar Apr 11 '16 14:04 arif-muhammad-wmc-tech

Can you please give me an example of how to specify SSL options for connection using the above code?

arif-muhammad-wmc-tech avatar Apr 13 '16 06:04 arif-muhammad-wmc-tech

Any news on this ?

geniusit avatar Jan 20 '17 16:01 geniusit

Anyone have an example on how to use WebSphere MQ with SSL?

Essentially JRuby JMS is a thin layer on top of and mixed into the existing Java JMS classes. If you can setup a Java program to talk to WebSphere MQ using SSL via JMS it should be relatively straight forward to supply the same values via JRuby JMS.

reidmorrison avatar Jan 20 '17 16:01 reidmorrison

I connected successfully to WebSphere MQ with SSL via JRuby JMS and pulled messages from replaying queue. Replace your credentials like HOST, QUEUE_MANAGER, CHANNEL etc and path to your keys.jks file.

Here is my working JRuby class:

require "java"
require "bouncy-castle-java"
require "/opt/mqm/java/lib/com.ibm.mqjms.jar"

java_import java.security.KeyManagementException
java_import java.security.NoSuchAlgorithmException
java_import java.security.Security

java_import javax.jms.JMSException
java_import javax.jms.QueueConnection
java_import javax.jms.QueueSender
java_import javax.jms.QueueReceiver
java_import javax.jms.QueueSession
java_import javax.jms.Session
java_import javax.jms.TextMessage
java_import javax.net.ssl.SSLContext
java_import javax.net.ssl.SSLSocketFactory

java_import org.bouncycastle.jce.provider.BouncyCastleProvider

java_import com.ibm.mq.MQMessage
java_import com.ibm.mq.jms.MQQueueConnectionFactory
java_import com.ibm.msg.client.wmq.WMQConstants

class WebSphereMQ

  def perform
    begin
      puts "Setting Factory ...."
      factory = MQQueueConnectionFactory.new
      factory.setHostName("YOUR_HOSTNAME")

      factory.setQueueManager("YOUR_QUEUE_MANAGER")
      factory.setChannel("YOUR CHANNEL")
      factory.setPort(1415)
      factory.setIntProperty(WMQConstants::WMQ_CONNECTION_MODE, WMQConstants::WMQ_CM_CLIENT)

      puts "Configuring SSL ...."
      Security.addProvider(BouncyCastleProvider.new)
      java.lang.System.setProperty("javax.net.ssl.keyStore", "PATH_TO_jks_FILE")
      java.lang.System.setProperty("javax.net.ssl.keyStorePassword", 'YOUR_PASSWORD')
      java.lang.System.setProperty("javax.net.ssl.trustStore", "PATH_TO_jks_FILE")
      factory.setSSLSocketFactory(SSLSocketFactory.getDefault)

      factory.setSSLFipsRequired(false)
      java.lang.System.setProperty("com.ibm.mq.cfg.useIBMCipherMappings", "false")
      factory.setSSLCipherSuite("TLS_RSA_WITH_AES_256_CBC_SHA256")

      puts "Creating Connection ...."
      con = factory.createQueueConnection

      puts "Creating Session ...."
      session = con.createQueueSession(false, QueueSession::AUTO_ACKNOWLEDGE)

      puts "Receiving Response ...."
      receiver = session.createReceiver(session.createQueue("YOUR_QUEUE_NAME"))

      con.start
      while true
        data = receiver.receive(1000)

        if data.nil?
          puts "*** No Data Found ****"          
        else
          puts "Data Found #{data.getText}" 
        end
      end

      receiver.close
      session.close
      con.close
    rescue => e
      puts e.message
    ensure
      receiver.close if receiver
      session.close if session
      con.close if con
    end
  end
end

arif-muhammad-wmc-tech avatar Jan 23 '17 07:01 arif-muhammad-wmc-tech

Did someone manage to get this working with the YAML configuration?

jfconavarrete avatar Mar 14 '17 14:03 jfconavarrete

I don't know why the error : cannot load Java class javax.jms.DeliveryMode occurs. I succeed to connect to the broker (webMethods) with my own computer but every time I tried to connect with an other computer with the SAME configuration I get the error : cannot load Java class javax.jms.DeliveryMode occurs. I don't work anymore on this stuff but it's a really strange behaviour and still doesn't have the answer to this thread ... :/

geniusit avatar Mar 14 '17 14:03 geniusit

It seems you also should include javax.jms-api-2.0.1.jar lib

:require_jars: - /usr/share/logstash/config/mqm/lib/com.ibm.mqjms.jar - /usr/share/logstash/config/mqm/lib/javax.jms-api-2.0.1.jar

ZhukovAlexey avatar Oct 17 '18 11:10 ZhukovAlexey