We are running portlets in WebSphere 6.01, using Java 1.4. We want to send JMS messages to a JBoss 5 queue, running Java 5 (or maybe 6, but it's certainly newer than 1.4). Trying to connect using JNDI is not working, since we have to include the JBoss client jars in the classpath of the portlet, and they are Java 1.5. So I get an unsupported major/minor error when I try to create the InitialContext.
Can we connect straight to JBoss without using JNDI? Or is there some way to get around this issue I can't think of?
Even if you were able to connect to JMS without going through JBoss's JNDI, you would still need to include the JBoss client JAR in order to use JMS. Both JNDI and JMS are APIs, and you need the server's implementation of that client API in order to talk to the server.
If it's just your JNDI classes that prereq Java 5 and not the JBoss classes then you can do this. But you would have to set all of the properties of the objects and that is provider-specific. The WebSphere MQ JMS samples show how to do this with WMQ and you would need to know the property and value names for JBoss to make the equivalent code. Here is a code snippet from the WMQ JmsProducer.java sample:
JmsFactoryFactory ff = JmsFactoryFactory.getInstance(WMQConstants.WMQ_PROVIDER);
JmsConnectionFactory cf = ff.createConnectionFactory();
// Set the properties
cf.setStringProperty(WMQConstants.WMQ_HOST_NAME, host);
cf.setIntProperty(WMQConstants.WMQ_PORT, port);
cf.setStringProperty(WMQConstants.WMQ_CHANNEL, channel);
cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT);
cf.setStringProperty(WMQConstants.WMQ_QUEUE_MANAGER, queueManagerName);
// Create JMS objects
connection = cf.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
if (isTopic) {
destination = session.createTopic(destinationName);
}
else {
destination = session.createQueue(destinationName);
}
producer = session.createProducer(destination);
On the other hand, if your JBoss classes prereq Java 1.5 then you need to run Java 1.5 or better.
Depending on the JBoss version you can directly instantiate all the JMS objects.
One particular version:
see http://www.jboss.org/file-access/default/members/jbossmessaging/freezone/docs/usermanual-2.0.0.beta1/html/using-jms.html
(Section 5.5. Directly instantiating JMS Resources without using JNDI)
I think JNDI is the only way that you can create JMS connection factories and destinations (queue or topic), and these are your means of communication.
In fact using JNDI is a way to be independant of the JMS provider, because you can easly change it.
But if you've got no problem with that most provider offer facilities to create a connection factory and destinations
It sounds like the problem isn't with JNDI but with the conflicting classnames between the environments.
You could try doing the classloading yourself when you try to instantiate the JBOSS client classes. That way you get a separate classloader from the one that loaded the Portlet. Just make sure you understand whether you need Parent-first or Parent-last behavior. Also on that page is debugging classloading which can show you how to set the Classpath for the classloader so you can isolate the JBOSS libraries and avoid classname collisions. It is a good resource for understanding even advanced classloading issues.
Related
I am new to JMS and WAS. I am grateful if someone provides any reference that helps me to create a web application in eclipse with JMS and WAS 7.0.
Also want to get answers for below questions..
How to inject ConnectionFactory or Destination object (created in WAS) into application using jndi?
How to install and run JMS web application on WAS server?
First you need to decide on the provider for JMS. It could be WebSphere MQ, the JMS provider that comes inbuilt with WAS or some other provider too.
Refer to the redbooks https://www.redbooks.ibm.com/Redbooks.nsf/RedbookAbstracts/sg247770.html?Open.
You can use InitialContext to lookup connection factory and Destination.
You can deploy the JMS app just like any other app. But ensure that JNDI objects are configured.
This is also a nice info-center to use for reference: http://pic.dhe.ibm.com/infocenter/prodconn/v1r0m0/topic/com.ibm.scenarios.wmqwasusing.doc/topics/scenario_overview.htm
I'm trying to deploy a Java EE web application with RESTful web services and an EJB connexion to another Java EE application.
I'm experiencing several problems and I fail to write down every specific question, so I have no choice but tell you all in a row.
1) First, I am using Tomcat to run the app and I cannot get EJB connexion to work. No matter what, I get a JNDI error : NamingContextFactory class not found. Why ?
My JNDI connexion is as follows :
String hostname = "localhost";
String port = "1099";
String url = "jnp://" + hostname + ":" + port + "/";
Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
h.put(Context.PROVIDER_URL, url);
h.put(Context.URL_PKG_PREFIXES, "org.jboss.naming.client");
initialContext = new InitialContext(h);
2) Therefore, as the server used is not relevant, and as the app I'm trying to connect to is using JBoss (4.4.2.GA), I tried to deploy my app under the same JBoss. I cannot get it to deploy, I have a REST problem: ClassNotFoundException: javax.ws.rs.core.ApplicationConfig at deploy time.
2.1) I am compiling with Netbeans and the ApplicationConfig.class is not part of the 1.1 version of the JAX-RS api jsr311-api-1.1.jar I'm using at compile time. The implementation of the library was changed since 0.8 version, which I was using before, but I had to upgrade the jar because it didn't include #FormParam. Until now, I had found a workaround using com.sun.jersey.api.representation.FormParam instead but Jersey is not compatible with JBoss as far as I understand.
Why is the server looking for ApplicationConfig while it's not used in the war?
2.2) I understood I had to use RESTEasy, and JBoss 4 does not include it, so have to install it manually. But the RESTEasy doc suggest that I thoroughly modify my project my adding a lot of jars, servlets etc. From my point of view, I simply need a RESTful implementation on the server libs to which my JAX-RS API, which is only an interface, will refer once the app is deployed. I may have some serious misconceptions about how Java EE libraries linking work. Please help.
So I know there are several different problems here but I couldn't manage to separate them. I have lost so much time on this that I'm worried for my project. Thanks in advance.
I am new to jboss and would like to know what are the differences between ServiceMBean and load-on-startup servlet tag in web.xml? Also, I would like to know which one will always get loaded first or they are loaded at the same time? In what situation, I should use MBean and when I should use startup servlet or it doesn't matter?
I need to write a a class/servlet to validate if all the required system properties (e.g -DINSTALL_DIR=blah ) is set. If not, then stop right there. else proceed and start the application.
Thanks in advance
-A
ServiceMBean is JMX, it is part of your JVM. load-on-startup servlet tag in web.xml is part of your J2EE application.
JMX is part of J2SE starting from JDK 1.5. So, you can have one ServiceMBean per JVM. not per application. JMX is used mostely for monitoring and managing the JVM. It provides access to information such as: number of classes loaded and threads running, memory consumption, garbage collection statistics, on-demand deadlock detection, and others. Another common use, is to refresh your cache.
JMX will allow you to instrument your application and control/monitor it using what-ever management console that your JMX container supports. An example would be a web application that implements a reference data cache...
A problem we had before was we would occasionally need to refresh the cache because a customer name changed in the database. If we had a refresh method on the MBean interface then we should be able to trigger this event using the JMX console. The JMX console may be a web or fat client that comes with our J2EE server. Our J2EE server may also support SNMP. This means that we may be able to invoke the method from a standard Tivoli or UniCenter console.
http://www.theserverside.com/news/1364664/J2EE-Application-Management-The-Power-of-JMX
You don't need remote access to ServiceMBean in order to trigger some asynchrious action. Moreover, you need validation on scope of application, not the whole JVM (while, you can, theoretically, handle this issue in the ServiceMBean). So, it is more naturally, to do it as load-on-startup servlet tag in web.xml. In this way, in every start up of your application validation will happen.
One more clarification: ServiceMBean is JBoss-way to write JMX. All MBeans are server wide (not application wide). That's why I use MBean and ServiceMBean freely above.
We are currently using JMS queue in Weblogic.
Can we use same JMS queue in Websphere as part of weblogic to websphere migration.
Is there any other concept available in websphere which can replace JMS queue?
WebSphere Application Server has a built-in JMS provider, due to the Java EE standard which defines it as mandatory (as Arjan Tijms already stated).
Setting up the JMS provider requires a so called Service Integration Bus, which is a simple Messaging Bus inside WebSphere. The Service Integration Bus also allows to setup High Available JMS queues/topics when using WebSphere Application Server Network Deployment.
Using this queues/topics outside of a WebSphere context - by putting messages into the queues from external clients or reading them from external clients - is hard.
Mainly due to the WebSphere internal CORBA communication it is quite tricky to setup a working and stable
configuration - and you need to know some internal WebSphere tricks.
My recommandation is to use internal jms configuration only for applications which are deployed on the same WebSphere Application Server-Configuration.
If you really need external access to the JMS queues/topics, you should write a adapter to access it.
This blog post describes in detail how to setup a simple WebSphere internal JMS configuration.
WebSphere has indeed an internal JMS provider. It's accessed using the SIB (Service Integration Bus). See http://www.packtpub.com/article/messaging-with-websphere-application-server-7.0-part1
WepSphere has JMS queues as well. Are you wanting to have the queue running within WebSphere, or are you trying to point to a queue running elsewhere?
Yes, you can.
Configuration depends on your JMS System.
If your JMS Middleware is running external like ApacheMQ or Swift JMS, you can normally install an Resource Adapter and then use that specific configuration (at least for the Jms configuration). Then you can use Websphere's JMS Configuration (like Queues and Topics) and therefor your normal MDB configuration.
Besides ActivationSpec (like above) at least with Websphere MQ you could use Listener Ports. I don't know if Listener Ports are available for other JMS Products.
If you want to use a built in Messaging System, you can use SIB I guess.
So plenty of options depending on your System.
A JMS provider is mandated by the Java EE specs so every application server has an inbuilt JMS Provider.
You have to make the right calls about your application needs. There might be valid reasons to use an external JMS provider such as WebSphere MQ.
I am doing a POC for runnig JMS on JBoss 4.0.5 GA. can anyone privide me a link which shows examples on how to
Create a queue in Jboss
Crate a factory in Jboss.
Configuration
If the above are not applicable, the is there a default que, topic, factory in Jboss.
http://www.jboss.org/file-access/default/members/jbossas/freezone/docs/Server_Configuration_Guide/4/html/Messaging_on_JBoss.html
http://www.outwardmotion.com/outwardmotion/jmsjboss1.php
The first thing to note is that JBoss 4.0.5 will be running JBossMQ by default (As opposed to the newer JBoss Messaging). The answers to some of your questions depend on what you're doing, i.e. MDBs/EJB3 or not?
Note, you'll have to add http:// to the beginning of these links, Stackoverflow is being lame and not letting me post links.
Take a look at this URL: www.java2s.com/Code/Java/EJB3/EJBTutorialfromJBossdemoformessagedrivenbean.htm
The Queue will be created for you automatically when JBoss loads the MDB in the example
Assuming you mean a JMS Connection Factory, you can inject factories and destinations into EJB3s using something like the following:
#Resource(mappedName = "queue/notification.EmailSender")
private javax.jms.Destination emailSenderQueue;
#Resource(mappedName = "QueueConnectionFactory")
private javax.jms.ConnectionFactory connectionFactory;
This is a good starting point: www.jboss.org/file-access/default/members/jbossas/freezone/docs/Server_Configuration_Guide/4/html/Messaging_on_JBoss.html
Also if you're not doing EJB3 yet in Jboss 4.0.3, see: rwatsh.blogspot.com/2006/12/ejb3-development-using-jboss-405ga.html