Problem sending jms message from Web page button (JSF 1.2)

SJSAS PE 9.0 running on Windows

Some of the code

//imports:

import javax.jms.ConnectionFactory;

import javax.jms.Queue;

import javax.jms.Session;

import javax.jms.JMSException;

import javax.annotation.Resource;

//Injection

@Resource(mappedName = "jms/ConnectionFactory")

private ConnectionFactory connectionFactory;

@Resource(mappedName = "jms/Queue")

private Queue queue;

//Button action code

System.out.println("Trying to send message to EJB");

javax.jms.Session jmssession = null;

javax.jms.Connection connection = null;

javax.jms.MessageProducer messageProducer = null;

javax.jms.TextMessage message = null;

final int NUM_MSGS = 1;

try {

// This line is failing, java.lang.NullPointerException

connection = connectionFactory.createConnection();

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

messageProducer = jmssession.createProducer(queue);

message = jmssession.createTextMessage();

for (int i = 0; i < NUM_MSGS; i++) {

message.setText("PV interface jobid " + (i + 1));

message.setBooleanProperty("Gyldig", true); // Sample on how to use properties; can be used to collect necessary information

System.out.println("Sending message: " + message.getText());

messageProducer.send(message);

}

} catch (JMSException e) {

System.out.println("Exception occurred: " + e.toString());

} finally {

if (connection != null) {

try {

connection.close();

} catch (JMSException e) {

}

} // if

} // finally

}

}

ERROR MESSAGE

Log Entry Detail

Details

Timestamp:

May 8, 2007 15:24:26.608

Log Level:

SEVERE

Logger:

javax.enterprise.resource.webcontainer.jsf.application

Name-Value Pairs:

_ThreadID=12;_ThreadName=httpWorkerThread-8080-1;_RequestID=832ea681-575f-4126-9bcf-01dcdf010044;

Record Number:

2513

Message ID:

java.lang.NullPointerException javax.faces.el.EvaluationException

Complete Message

java.lang.NullPointerException

at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:97)

at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:96)

at com.sun.rave.web.ui.appbase.faces.ActionListenerImpl.processAction(ActionListenerImpl.java:57)

at javax.faces.component.UICommand.broadcast(UICommand.java:383)

at com.sun.webui.jsf.component.WebuiCommand.broadcast(WebuiCommand.java:160)

at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:450)

at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:759)

at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)

at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:244)

at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:113)

at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)

at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:397)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:278)

at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)

at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:240)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:179)

at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)

at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:182)

at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)

at com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:137)

at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)

at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:239)

at com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)

at com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)

at com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)

at com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)

at com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)

at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)

at com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)

Caused by: java.lang.NullPointerException

at com.company.testinterfaceportal.JmsSending.<init>(JmsSending.java:37)

at com.company.testinterfaceportal.MainApplicationBean.SendBeskjedNaa(MainApplicationBean.java:192)

at com.company.testinterfaceportal.Status.button1_action(Status.java:709)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at com.sun.el.parser.AstValue.invoke(AstValue.java:151)

at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:283)

at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:77)

... 34 more

[6231 byte] By [janir4a] at [2007-11-27 3:42:42]
# 1
Take a look at com.company.testinterfaceportal.JmsSending.<init>(JmsSending.java:37)
developer_jbsa at 2007-7-12 8:46:19 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Well, its

connection = connectionFactory.createConnection();

that is failing. (Nullpointer) It seems like the connectionFactory has not been injected.

I use identical code in another application; and there it works... But I'm unable to see why its failing here.

Thanks

janir

janir4a at 2007-7-12 8:46:19 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
Did you actually create the JMS ConnectionFactory and Queue ( typically, from the admin console or the command line) ?
karma-9a at 2007-7-12 8:46:19 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

Yes, the ConnectionFactory and the Queue are OK. Created from admin console. ( I test from another JSF application; and there it works.... The working application only has one simple JSF page and a button to send JMS messages. )

Tried static; just to see if the result differ; but no, same error.

Is is called from a

"public class Status extends AbractPageBean"

which is a backing bean for the Status.jsp page.

Thanks,

Janir

janir4a at 2007-7-12 8:46:19 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5
connectionFactory is declared in this class but never initialized
developer_jbsa at 2007-7-12 8:46:19 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 6

Well, is'nt that a part of the resource injection part?

@Resource(mappedName = "jms/ConnectionFactory")

private ConnectionFactory connectionFactory;

I know the code for the jms-sending is OK (I've tested in another application, copy of code), but i dont know why it isn't working in this particual Visual Web Project. It does seem like the injection isn't taking place here; and i have no clue to why.....

Thanks,

Janir

janir4a at 2007-7-12 8:46:19 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 7

> I know the code for the jms-sending is OK (I've

> tested in another application, copy of code), but i

> dont know why it isn't working in this particual

> Visual Web Project. It does seem like the injection

> isn't taking place here; and i have no clue to

> why.....

where does your web.xml schema location points to ?

Injection works only with JEE 5, which means that you have to point to the right version of the servlet spec, i.e version="2.5" and web-app_2_5.xsd.

karma-9a at 2007-7-12 8:46:19 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 8
> connectionFactory is declared in this class but never> initializedAnd that's the whole point of resource injection. It's the container who should initialize it.
karma-9a at 2007-7-12 8:46:19 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 9
Found the problem.It seemed like web.xml file had been corrupted; compared it to the working application. Copied the one from the working app, modified slightly the class name, and it worked.
janir4a at 2007-7-12 8:46:19 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 10
Thanks karma-9 for leading me to the solution!!Janir
janir4a at 2007-7-12 8:46:19 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...