[JBoss jBPM] - Combining hibernate classes
by merinshaji
Hi,
I am trying to combine my hibernate classes with jbpm's persistence classes. I have configured jbpm to use my application specific hibernate.cfg.xml. Things are working fine except for session.getNamedQuery method call in TaskMgmtSession.findPooledTaskInstances(). I have added hibernate.queries.hbm.xml to my hibernate configuration programmatically (using the code configuration.addResource()). But when I execute getNamedQuery, I get the following exception:
org.jbpm.JbpmException: couldn't get pooled task instances list for actors '[UW]'
Caused by: org.hibernate.SessionException: Session is closed!
at org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:49)
at org.hibernate.impl.SessionImpl.getNamedQuery(SessionImpl.java:1258)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
at $Proxy21.getNamedQuery(Unknown Source)
at org.jbpm.db.TaskMgmtSession.findPooledTaskInstances(TaskMgmtSession.java:119)
Could any one help me to solve this?
Thanks in advance
Merin
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4087159#4087159
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4087159
18 years, 9 months
[JBoss Portal] - Re: INFO / error repeated -
by konstandinos
Thanks Thomas.
I'm still getting these errors every now and then:
| 12:19:38,048 ERROR [IOTools] Error while closing outstream
| ClientAbortException: java.net.SocketException: Broken pipe
| at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:358)
| at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:434)
| at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:309)
| at org.apache.catalina.connector.OutputBuffer.close(OutputBuffer.java:273)
| at org.apache.catalina.connector.CoyoteOutputStream.close(CoyoteOutputStream.java:104)
| at org.jboss.portal.common.io.IOTools.safeClose(IOTools.java:133)
| at org.jboss.portal.core.controller.handler.HTTPResponse$2.sendResponse(HTTPResponse.java:80)
|
Everything is working though. I guess it's just an output stream failing to close, not really a fatal error, but still cause for concern.
Further down (it's quite a long error) I also see this (they might be related though):
| 12:19:38,049 ERROR [Controller] Cound not send http response
| ClientAbortException: java.net.SocketException: Broken pipe
| at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:358)
| at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:434)
| at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:349)
| at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:381)
| at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:370)
| at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:89)
| at org.jboss.portal.core.controller.handler.HTTPResponse$2.sendResponse(HTTPResponse.java:73)
|
Any ideas?
Thanks for your speedy replies. They are greatly appreciated.
Cheers,
Kosta
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4087157#4087157
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4087157
18 years, 9 months
[Microcontainer] - Re: Injecting beans into Unit Tests under 1.02
by alesj
You can use MicrocontainerTest and MicrocontainerTestDelegate to do your injection.
They have all the handy methods to provide you the beans you deployed, e.g.:
| /**
| * Get a bean
| *
| * @param name the bean name
| * @return the bean
| * @throws IllegalStateException when the bean does not exist
| */
| protected Object getBean(Object name)
| {
| return getBean(name, ControllerState.INSTALLED);
| }
|
| /**
| * Get a bean
| *
| * @param name the name of the bean
| * @param state the state of the bean
| * @return the bean
| * @throws IllegalStateException when the bean does not exist at that state
| */
| protected Object getBean(Object name, ControllerState state)
| {
| return getMCDelegate().getBean(name, state);
| }
|
| /**
| * Get a context
| *
| * @param name the bean name
| * @return the context
| * @throws IllegalStateException when the context does not exist
| */
| protected KernelControllerContext getControllerContext(Object name)
| {
| return getControllerContext(name, ControllerState.INSTALLED);
| }
|
| /**
| * Get a context
| *
| * @param name the name of the bean
| * @param state the state of the bean
| * @return the context
| * @throws IllegalStateException when the context does not exist at that state
| */
| protected KernelControllerContext getControllerContext(Object name, ControllerState state)
| {
| return getMCDelegate().getControllerContext(name, state);
| }
|
You simply provide the XML file with the beans, how you actually use that injection is up to you.
Check out how we use it in our tons of test cases.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4087155#4087155
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4087155
18 years, 9 months
[JBoss jBPM] - Re: dynamic commands
by gogoasa
Here is my current implementation of BshCommand in case anybody needs it.
It supports passing optional parameters to scripts (in case you keep your script as a resource and want to pass it a parameter without having to String.replaceAll(...):
package org.jbpm.command;
|
| import java.util.HashMap;
| import java.util.Iterator;
| import java.util.Map;
|
| import org.jbpm.JbpmContext;
|
| import bsh.Interpreter;
|
| /**
| * this Command executes a BeanShell script, optionally binding some variables.
| * This way you can dynamically execute arbitrary code on your jBPM installation.
| */
| public class BshCommand implements Command {
|
| String JBPMCONTEXT_BINDING_VARIABLE = "jbpmContext";
|
| // the script code
| protected String code;
|
| // variables to bind
| protected Map scriptVariables;
|
| public BshCommand(String code) {
| this(code, new HashMap());
| }
|
| public BshCommand(String code, Map scriptVariables) {
| this.setCode(code);
| this.setScriptVariables(scriptVariables);
| }
|
| /**
| * as Java does not have inline constructors for Maps but it does have constructors for arrays, you may prefer to provide
| * arguments using this constructor.
| *
| * @see BshCommand(String code, Map scriptVariables)
| */
| public BshCommand(String code, String[] keys, Object[] values) {
| if (keys == null || values == null)
| throw new NullPointerException("cannot accept null keys or values");
| if (keys.length != values.length)
| throw new IllegalArgumentException("keys and values arrays must be of the same length");
|
| Map map = new HashMap();
| for (int i = 0; i < keys.length; i++)
| map.put(keys, values);
|
| this.setCode(code);
| this.setScriptVariables(map);
| }
|
| /**
| * convenient alias for BshCommand(String code, String[] keys, Object[] values) if you only want to pass one argument to
| * your script
| */
| public BshCommand(String code, String key, Object value) {
| this(code, new String[] {key}, new Object[] {value});
| }
|
|
| public Object execute(JbpmContext jbpmContext) throws Exception {
| Interpreter interpreter = new Interpreter();
|
| interpreter.set(JBPMCONTEXT_BINDING_VARIABLE, jbpmContext);
|
| if (this.scriptVariables != null) {
| for (Iterator i = this.scriptVariables.keySet().iterator(); i.hasNext();) {
| String varName = (String) i.next();
| if (varName.equals(JBPMCONTEXT_BINDING_VARIABLE))
| continue;
| Object o = this.scriptVariables.get(varName);
| interpreter.set(varName, o);
| }
| }
| Object result = interpreter.eval(this.getCode());
| return result;
| }
|
| // accessors
|
| public String getCode() {
| return code;
| }
|
| public void setCode(String code) {
| this.code = code;
| }
|
| public Map getScriptVariables() {
| return scriptVariables;
| }
|
| public void setScriptVariables(Map scriptVariables) {
| this.scriptVariables = scriptVariables;
| }
|
| private static final long serialVersionUID = 1L;
| }
|
some usage example. Suppose you have a script like this as a classpath resource (do not call it script.bsh if you deploy under jboss because jboss will think it must deploy it as an ejb. Call it moveTokenToNodeAndSignal.bsh.command for example):
| // forcibly move a process instance's token to "System error" node and signal it to "restart".
|
| pi = jbpmContext.getProcessInstance(pid);
| tk = pi.getRootToken();
|
| pdef = pi.getProcessDefinition();
| node = pdef.getNode("System error");
|
| tk.addLog(new org.jbpm.logging.log.MessageLog("forcing restart of process that has no 'restart' leaving transition"));
| tk.setNode(node);
| tk.signal("restart");
| String script = IOUtils.toString(this.getClass().getClassLoader().getResourceAsStream("moveTokenToNodeAndSignal.bsh.command"));
| commandService.execute(script, "pid", 4);
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4087147#4087147
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4087147
18 years, 9 months