Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

cannot load Java class javax.jms.DeliveryMode #21

Open
arif-muhammad-wmc-tech opened this issue Apr 11, 2016 · 7 comments
Open

cannot load Java class javax.jms.DeliveryMode #21

arif-muhammad-wmc-tech opened this issue Apr 11, 2016 · 7 comments

Comments

@arif-muhammad-wmc-tech
Copy link

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
Copy link
Author

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

@geniusit
Copy link

Any news on this ?

@reidmorrison
Copy link
Owner

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.

@arif-muhammad-wmc-tech
Copy link
Author

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

@jfconavarrete
Copy link

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

@geniusit
Copy link

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 ... :/

@ZhukovAlexey
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants