<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>freedom is an illusion &#187; JMS</title>
	<atom:link href="http://theaveragelife.wordpress.com/tag/jms/feed/" rel="self" type="application/rss+xml" />
	<link>http://theaveragelife.wordpress.com</link>
	<description>Accidentally cool</description>
	<lastBuildDate>Wed, 15 Jul 2009 08:27:04 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='theaveragelife.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/278aac3acf9df3c6e2a3c2d21ca416c5?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>freedom is an illusion &#187; JMS</title>
		<link>http://theaveragelife.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://theaveragelife.wordpress.com/osd.xml" title="freedom is an illusion" />
		<item>
		<title>Writing a standalone JMS Java Client to connect to Websphere MQ 6.0 via Websphere Application Server 6.1</title>
		<link>http://theaveragelife.wordpress.com/2009/07/02/writing-a-standalone-jms-java-client-to-connect-to-websphere-mq-6-0-via-websphere-application-server-6-1/</link>
		<comments>http://theaveragelife.wordpress.com/2009/07/02/writing-a-standalone-jms-java-client-to-connect-to-websphere-mq-6-0-via-websphere-application-server-6-1/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 08:43:21 +0000</pubDate>
		<dc:creator>Swen</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Office]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[techstuff]]></category>
		<category><![CDATA[Exception]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JMS]]></category>
		<category><![CDATA[MQ]]></category>
		<category><![CDATA[WAS]]></category>
		<category><![CDATA[Websphere]]></category>

		<guid isPermaLink="false">http://theaveragelife.wordpress.com/?p=261</guid>
		<description><![CDATA[Somehow, when I tried to write a standalone client I kept coming across the following exception
&#8220; java.lang.ClassCastException: javax.naming.Reference incompatible with javax.jms.ConnectionFactory &#8220;.
I followed intructions from here to setup the Queue, after which I created a simple java client to post a message to the Queue:
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, &#8220;com.ibm.websphere.naming.WsnInitialContextFactory&#8221;);
env.put(Context.PROVIDER_URL, &#8220;iiop://localhost:2809&#8243;);
Context jndiContext = null;
try {
jndiContext [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theaveragelife.wordpress.com&blog=1383996&post=261&subd=theaveragelife&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Somehow, when I tried to write a standalone client I kept coming across the following exception<br />
&#8220;<span style="text-decoration:underline;"> java.lang.ClassCastException: javax.naming.Reference incompatible with javax.jms.ConnectionFactory </span>&#8220;.</p>
<p>I followed intructions from <a href="http://www.ibm.com/developerworks/websphere/techjournal/0505_woolf/0505_woolf.html" target="_blank">here</a> to setup the Queue, after which I created a simple java client to post a message to the Queue:</p>
<blockquote><p><em>Hashtable env = new Hashtable();<br />
env.put(Context.INITIAL_CONTEXT_FACTORY, &#8220;com.ibm.websphere.naming.WsnInitialContextFactory&#8221;);<br />
env.put(Context.PROVIDER_URL, &#8220;iiop://localhost:2809&#8243;);</em></p>
<p><em>Context jndiContext = null;<br />
try {<br />
jndiContext = new InitialContext(env);<br />
} catch (NamingException e) {</em></p>
<p><em>System.out.println(&#8220;Could not create JNDI API context: &#8221; + e.toString());<br />
System.exit(1);<br />
}</em></p>
<p><em>ConnectionFactory connectionFactory = (ConnectionFactory)  jndiContext.lookup(&#8220;jms/JMSExampleConnectionFactory&#8221;);<br />
Connection qConn = connectionFactory.createConnection();<br />
Session qSession = qConn.createSession(false, Session.AUTO_ACKNOWLEDGE);<br />
Queue q = (Queue) jndiContext.lookup(&#8220;jms/JMSExampleQueue&#8221;);</em></p>
<p><em>MessageProducer producer = qSession.createProducer(q);<br />
TextMessage message = qSession.createTextMessage();<br />
message.setText(&#8220;test message&#8221;);<br />
producer.send(message);</em></p>
<p><em>producer.close();<br />
qSession.close();<br />
qConn.close();</em></p></blockquote>
<p>Even after switching to the IBM JRE and adding the relevant Jars (as suggested in most places.) the program kept throwing the ClassCast Exception. Just in case you are wondering, the relevant Jars ( found in <em>&lt;Websphere Installation Path&gt;/runtimes/</em> and <em>&lt;Websphere Installation Path&gt;/lib/WMQ/java/lib/</em> ) are:</p>
<blockquote><p><em>com.ibm.mq.jar<br />
com.ibm.mqjms.jar<br />
com.ibm.ws.webservices.thinclient_6.1.0.jar<br />
dhbcore.jar<br />
ws_runtime.jar</em></p></blockquote>
<p>After googling and reading through lot of forum threads I finally stumbled on the solution. To resolve this you also need to add added the <em><strong>&lt;Websphere Installation Path&gt;/plugins/com.ibm.ws.runtime_6.1.0.jar</strong></em> to the classpath.  Seems simple enough, but it took me ages to find. Hence the post.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/theaveragelife.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/theaveragelife.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/theaveragelife.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/theaveragelife.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/theaveragelife.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/theaveragelife.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/theaveragelife.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/theaveragelife.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/theaveragelife.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/theaveragelife.wordpress.com/261/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=theaveragelife.wordpress.com&blog=1383996&post=261&subd=theaveragelife&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://theaveragelife.wordpress.com/2009/07/02/writing-a-standalone-jms-java-client-to-connect-to-websphere-mq-6-0-via-websphere-application-server-6-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/822985a305f317d5c0fc29ca429e6d5c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">swengeorge</media:title>
		</media:content>
	</item>
	</channel>
</rss>