[JBoss jBPM] - Message Driven Bean not working with jBPM
by chrisrjcox
Hi,
I have an issue where I send a simple test text message to a queue. Then the MDB is supposed to pick this message up and display the text. I can't see any issues with my coding, and I have tested to ensure that the message does get stored in the queue, by retrieving it straight after adding to the queue.
Here is the action handler sending the text to the queue.
| package com.distributed.action;
|
| import org.jbpm.graph.def.ActionHandler;
| import org.jbpm.graph.exe.ExecutionContext;
|
| import javax.jms.ConnectionFactory;
| import javax.jms.Connection;
| import javax.jms.MessageProducer;
| import javax.jms.Queue;
| import javax.jms.Session;
| import javax.jms.TextMessage;
| import javax.naming.InitialContext;
| /**
| import javax.jms.MessageConsumer;
| */
|
| public class SendMessageToQueueForPartTwo implements ActionHandler
| {
|
| private static final long serialVersionUID = 1L;
|
| InitialContext jndi = null;
| ConnectionFactory conFactory = null;
| Connection connection = null;
| Session session = null;
| MessageProducer producer = null;
| TextMessage textMessage = null;
| TextMessage receivedMessage = null;
|
| public void execute(ExecutionContext context) throws Exception
| {
| try
| {
| jndi = new InitialContext();
| System.out.println("SendMessageToQueueForPartTwo: jndi Initial Context created");
|
| conFactory = (ConnectionFactory)jndi.lookup("ConnectionFactory");
| System.out.println("SendMessageToQueueForPartTwo: ConnectionFactory created");
|
|
| connection = conFactory.createConnection();
| System.out.println("SendMessageToQueueForPartTwo: Connection created");
| session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
| System.out.println("SendMessageToQueueForPartTwo: Session created");
| Queue queue = (Queue) jndi.lookup("queue/jbpmQueue");
| System.out.println("SendMessageToQueueForPartTwo: Looked up jbpmQueue");
| if (queue == null)
| {
| System.out.println("SendMessageToQueueForPartTwo: Queue Not Found...Creating Queue");
| queue = session.createQueue("queue/jbpmQueue");
| }
| producer = session.createProducer(queue);
| System.out.println("SendMessageToQueueForPartTwo: Producer Created");
|
| textMessage = session.createTextMessage("Hello, has this worked?");
| System.out.println("SendMessageToQueueForPartTwo: textMessage Created");
| producer.send(textMessage);
| System.out.println("SendMessageToQueueForPartTwo: textMessage sent to " + queue.getQueueName() + " queue");
|
| /** The following code was to check that the message was passed to the Queue
| MessageConsumer consumer = session.createConsumer(queue);
| System.out.println("MessageConsumer created");
|
| connection.start();
| System.out.println("Connection started");
|
| receivedMessage = (TextMessage) consumer.receive();
| System.out.println("The Message "+ receivedMessage.getText());
| */
|
| }
| finally
| {
| if(jndi != null)
| {
| try
| {
| jndi.close();
| }
| catch(Exception e)
| {
| throw e;
| }
| }
| }
| }
| }
Here is the Message Driven Bean.
| package com.distributed.action;
|
| import javax.ejb.EJB;
| import javax.ejb.MessageDriven;
| import javax.ejb.ActivationConfigProperty;
| import javax.jms.JMSException;
| import javax.jms.Message;
| import javax.jms.MessageListener;
| import javax.jms.TextMessage;
|
| @MessageDriven(mappedName = "jms/PartTwoMDB", activationConfig =
| {
| @ActivationConfigProperty(propertyName="acknowledgeMode", propertyValue = "Auto-acknowledge"),
| @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
| @ActivationConfigProperty(propertyName="destination", propertyValue="/queue/jbpmQueue")
| })
|
| public class PartTwoMDB implements MessageListener
| {
| @EJB
| private static final long serialVersionUID = 1L;
|
| public void onMessage(Message inMessage)
| {
| TextMessage textMessage = null;
| try
| {
| if(inMessage instanceof TextMessage)
| {
| textMessage = (TextMessage) inMessage;
| System.out.println("PartTwoMDB: Message received: "+ textMessage.getText());
| }
| else
| {
| System.out.println("PartTwoMDB: MEssage of wrong type: " + inMessage.getClass().getName());
| }
| }
| catch (JMSException e)
| {
| e.printStackTrace();
| }
| catch (Throwable t)
| {
| t.printStackTrace();
| }
|
| }
| }
|
I would expect it to print the message text message but nothing happens.
Would anyone be able to assist?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4133497#4133497
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4133497
16 years, 10 months
[JBossCache] - Re: JBossCache, POJO Cache, Hibernate, field replication - h
by bstansberry@jboss.com
That's 3 questions. :-) Answered in order:
1) Yes, that's PojoCache's primary benefit.
2) No, it isn't.
3) A bit of both. Hibernate stores an entity in the 2nd level cache as an Object[], one element per field. To deal with such a representation, PojoCache would need to be able to handle detecting changes in elements in an array, which it currently cannot do. Jason is working to resolve that (perhaps in PojoCache 2.2). But even if that were solved the Hibernate folks would have to ensure that the same Object[] instance is consistently used throughout the Hibernate code (i.e. no creating a new Object[] with the same elements). I don't know how difficult that would be, but I imagine it would be very fragile.
In most cases you're better off using JBC invalidation for entity caching anyway, which in terms of intra-cluster message traffic is lighter than any replication-based strategy, including PojoCache.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4133496#4133496
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4133496
16 years, 10 months
[Beginners Corner] - error on accessing a web-service
by Fugee47
Hello, i have an ejb which contains following java-class "JBossEJBWS.java"
package org.me.ejbwss;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.ejb.Stateless;
@Stateless
@WebService
public class JBossEJBWS {
private String message = new String("Hello, ");
@WebMethod
public String greet(String name) {
return message + name + ".";
}
}
when i deploy it, i can access the wsdl-file:
http://localhost:8080/WSEJBModule/JBossEJBWS?wsdl
Now i want to create a war-file which contains a jsp-file, which executes the method "greet"
For this i created web.xml in WEB-INF:
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
version="2.5"
xmlns:xsi="http://www.w3.org/2001/XMLSchema"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>webclient</display-name>
<display-name>greeting</display-name>
<servlet-name>greeting</servlet-name>
<jsp-file>/index.jsp</jsp-file>
<servlet-mapping>
<servlet-name>greeting</servlet-name>
<url-pattern>/greeting</url-pattern>
</servlet-mapping>
<service-ref>
<service-ref-name>services/JBossEJBWS</service-ref-name>
<service-interface>javax.xml.ws.Service</service-interface>
<wsdl-file>WEB-INF/wsdl/JBossEJBWS.wsdl</wsdl-file>
<port-component-ref>
<service-endpoint-interface>org.me.ejbwss.JBossEJBWS</service-endpoint-interface>
</port-component-ref>
</service-ref>
</web-app>
And this is the jsp-file:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" import="java.util.*" %>
<%@ page import="java.io.*,javax.naming.InitialContext,javax.xml.ws.Service,org.me.ejbwss.JBossEJBWS"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
JSP Page
<h1>JSP Page</h1>
<%
try {out.println("ole");
InitialContext ctx = new InitialContext();
Service service = (Service)ctx.lookup("java:comp/env/services/JBossEJBWS");
JBossEJBWS port = (JBossEJBWS) service.getPort(JBossEJBWS.class);
} catch (Exception e) {
out.println("Error: " + e.getMessage());
}
String text = port.greet("Fugee");
out.println(text);
%>
The Problem is, when i open the URL (http://localhost:8080/WSCWebModule/) in a webbrowser, i get the following error:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 23 in the jsp file: /index.jsp
port cannot be resolved
20: } catch (Exception e) {
21: out.println("Error: " + e.getMessage());
22: }
23: String text = port.greet("Fugee");
24: out.println(text);
25: %>
26:
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:415)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:316)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
can someone tell me what i have done wrong ??
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4133492#4133492
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4133492
16 years, 10 months
[JBoss/Spring Integration] - Re: JBOSS5 + Spring Deployer version confusion
by alesj
"dlmiles" wrote :
| The point I was getting at, is that no deployer should mindlessly attempt to deploy all files it finds at any nesting depth ending in *-beans.xml.
|
It is not.
Like I said, only those that are in metadata path.
See StructureDeployers for more info.
"dlmiles" wrote :
| But I would be happy for it to have a look at all files and then attempt to parse the file as a JBoss specific deployment descriptor. Now during this process it should immediately see that my file has an XML Schema that belongs to Spring Framework. Upon seeing this the deployer should stop considering that file as a JBoss deployment descriptor and no exception should be thrown.
|
| This is the point of having XSDs to ensure an application that is not meant to process some data, does not attempt to process it!
|
| The JBoss deployer does not own all the files ending in *-beans.xml that the JBoss VFS can find, it only own those files that also match the DTD/XSD schemes that JBoss understands.
|
Feel free to open this discussion in 'Deployers on JBoss' or 'Design of POJO server' forum.
No point of discussing this here, since this is getting out of the scope of this forum.
"dlmiles" wrote :
| Of course it has to parse the file, its bl**dy well doing that now is not it!
|
:-)
The problem that I see here is, that most of the xml parsing/handling has the most awful exceptions, which would make it hard for us to distinguish between what's a real exception or just not the right combination of deployer+dtd/schema.
"dlmiles" wrote :
| The error I reported is due to a deployment failure because the contents of the XML appeared to be garbage to the MBean deployer when it attempted deployment.
|
No, it failed because the BeanDeployer expected that the outcome of unmarshalling would be KernelDeployment instance.
"dlmiles" wrote :
| Renaming my file in my WAR from /WEB-INF/spring-beans.xml to /WEB-INF/spring-context.xml did the trick.
|
"alesj" wrote :
| You can either rename the file or change the way BeanDeployer handles this file, e.g. perhaps not using the file if it also contains 'spring' in its name.
|
;-)
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4133484#4133484
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4133484
16 years, 10 months