I am trying to create EJBContainer in order to do some integration testing. here is the code:
Map properties = new HashMap();
properties.put(EJBContainer.MODULES,
new File[]{new File("target/classes"),
new File("target/test-classes")});
ec = EJBContainer.createEJBContainer(properties);
ctx = ec.getContext();
It throws exception: javax.ejb.EJBException: Can't find directory D:\jboss-4.2.3.GA\jboss-4.2.3.GA\common\lib
Actually there is no common/lib directory in Jboss folder. When I debug the code inside of EJBContainer i see that the problem is in JBossStandaloneEJBContainerProvider class which seems the default container provider class. Is there a way to change this provider? Or maybe I am doing something incompatible?
Related
I am trying to write a simple query using QueryDSL, but my attempt fails with the following exception.
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
I tried executing query the following ways.
SessionFactory sf = new Configuration().configure().buildSessionFactory();
Session session = sf.openSession();
JPQLQuery query = new HibernateQuery(session);
QClient t = QClient.client;
List<Client> lst = query.from(t).list(t);
System.out.println(lst.size());
And another way.
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("my.package.entities");
EntityManager em = emf.createEntityManager();
JPAQuery query = new JPAQuery(em);
QClient t = QClient.client;
List<Client> lst = query.from(t).list(t);
System.out.println(lst.size());
As stated, both this ways failed with the same exception.
I am using Postrges DB, and the parameters are specified in hibernate.cfg.xml.
Do I need to setup something more for this to work?
The javax.naming package comprises the JNDI API. Since it's just an API, rather than an implementation, you need to tell it which implementation of JNDI to use. The implementations are typically specific to the server you're trying to talk to.
To specify an implementation, you pass in a Properties object when you construct the InitialContext. These properties specify the implementation to use, as well as the location of the server. The default InitialContext constructor is only useful when there are system properties present, but the properties are the same as if you passed them in manually.
As to which properties you need to set, that depends on your server. You need to hunt those settings down and plug them in.
Sample:
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
properties.put("jnp.socket.Factory", "org.jnp.interfaces.TimedSocketFactory");
properties.setProperty("java.naming.provider.url", "jnp://" + remoteHost + :1099");
context = new InitialContext(properties);
or
look for this
Issue
In my Shiro application, I am using the JndiRealmFactory to define my realms. I Register my realms like this:
Hashtable<String, String> args = new Hashtable<>();
args.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
InitialContext ctx = new InitialContext(args);
ctx.bind("realms/MyRealm", myRealm);
However, Shiro cannot find realms/MyRealm. I think the reason is, that I Need to define the JndiRealmFactory's jndiEnvironment, which contains the Context.INITIAL_CONTEXT_FACTORY property. However, I don't know how to set this property in my shiro.ini:
realmFactory.jndiEnvironment = ?
I am running my application on TomEE.
My current shiro.ini looks like this:
realmFactory = org.apache.shiro.realm.jndi.JndiRealmFactory
realmFactory.jndiNames = realms/MyRealm
you are not supposed to bind at runtime anything in the EE context. You can probably define it in tomcat as a resource or resources.xml (tomee specific) then just use a standard lookup to read the value (no special properties passed to InitialContext.
We have an app that does not run in a web container so I am trying to start Spring up. In the "main" function we have this:
public static void main(String[] args) throws InterruptedException, IOException, AlreadyAliveException, InvalidTopologyException, AuthorizationException {
// starting up spring...
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath*:/applicationContext.xml");
DataSourceTransactionManager dstm = applicationContext.getBean("markiscool", DataSourceTransactionManager.class);
dstm.toString();
}
And my applicationContext.xml contains:
<bean id="markiscool" class="blah.entities.LocationEntity" />
The app, on startup, logs this:
[INFO] ClassPathXmlApplicationContext - Refreshing
org.springframework.context.support.ClassPathXmlApplicationContext#295cd6e5:
startup date
[Thu Dec 17 10:28:28 CST 2015]; root of context hierarchy
Exception in thread "main"
org.springframework.beans.factory.NoSuchBeanDefinitionException: No
bean named 'markiscool' is defined
I have tried putting garbage in the xml file but it doesn't fail so it must not be finding the file. Also, the file is on the classpath:
I have also stuck the file in about every place I can think of. It does not load. Help!
Try to use FileSystemXmlApplicationContext:
ApplicationContext applicationContext = new FileSystemXmlApplicationContext("/conf/applicationContext.xml");
Instead of:
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath*:/applicationContext.xml");
Try this:
Right click -> properties -> Deployment Assembly
Put an entry: conf -> /
try
new ClassPathXmlApplicationContext("applicationContext.xml");
1) Put applicationContext.xml into the config folder
2) Tell Maven to include applicationContext.xml in the jar it creates
3) Use the function ClassPathXmlApplicationContext to pull in the file
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath*:conf/applicationContext.xml");
Note: FileSystemXmlApplicationContext will not work if you are trying to access a file inside of a jar. For this reason I recommend using ClassPathXmlApplicationContext because it works whether you are running the project in eclipse or via the jar
I'm using jbpm-console (6.0.0.Final) with custom work item handlers. I've embedded a custom work item handlers JAR in my jbpm-console WAR as described in post #7 here:
https://community.jboss.org/thread/221748
This is all fine so far, as I can successful start a process definition in jbpm-console, and it kicks off my custom WorkItemHandler code.
However, in my WorkItemHandler, I want to set some variables on the ProcessInstance. When I try something like this:
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
KieServices ks = KieServices.Factory.get();
KieContainer kContainer = ks.getKieClasspathContainer();
// BLOWS UP HERE
//
KieSession session = kContainer.newKieSession();
WorkflowProcessInstance processInstance =
session.getProcessInstance(workItem.getProcessInstanceId());
// SET VARIABLE
processInstance.setVariable("foo", "bar");
}
It "Cannot find a default KieSession":
11:21:03,177 ERROR Exception: java.lang.RuntimeException: Cannot find a default KieSession
at org.drools.compiler.kie.builder.impl.KieContainerImpl.findKieSessionModel(KieContainerImpl.java:302) [drools-compiler-6.0.0.Final.jar:6.0.0.Final]
at org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieSession(KieContainerImpl.java:295) [drools-compiler-6.0.0.Final.jar:6.0.0.Final]
at org.drools.compiler.kie.builder.impl.KieContainerImpl.newKieSession(KieContainerImpl.java:278) [drools-compiler-6.0.0.Final.jar:6.0.0.Final]
What am I missing here? Do I have to set something additional up? I'm just using the out-of-the-box (with the exception of the custom work item handler embedded jar) "demo" install from here:
http://sourceforge.net/projects/jbpm/files/jBPM%206/jbpm-6.0.0.Final
Thanks!
Do you have a kmodule.xml in your resources folder? If not maybe that's the problem. You can have a pretty simple xml file like:
<kmodule xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://jboss.org/kie/6.0.0/kmodule">
</kmodule>
Pass your kieSession into your workItemHandler as a constructor parameter.
Then your kieSession is available to your workItemHandler.
You can register your workItemHandler when you need it with the appropriate kieSession, you do not have to do it only once.
Or you pass the rulesManager at the start and generate a kieSession on demand
I want to create Queue and the MessageDrivenBean in Oracle 11g.
I created the JMS Module on Weblogic and into it I created Queue and ConnectionFactory.
JDBC names looks like:
Queue: jms/EvZahQueue
ConnectionFactory: jms/ConnectionFactory
I tried to get them with:
Context context = new InitialContext();
connectionFactory = (QueueConnectionFactory) context.lookup("jms/QueueConnector");
queue = (Queue) context.lookup("jms/EvZahQueue");
But, I've got an exception like this:
javax.naming.NameNotFoundException: While trying to look up comp/env/jms/QueueConnector in /app/webapp/registri-view/31900933.; remaining name 'comp/env/jms/QueueConnector'
Also, I tried with:
Context context = new InitialContext();
connectionFactory = (QueueConnectionFactory) context.lookup("java:comp/env/jms/QueueConnector");
queue = (Queue) context.lookup("java:comp/env/jms/EvZahQueue");
And I tried to create default properties and to put them into new InitialContext() but nothing changed.
What should I do? Maybe I need to write something in web.xml, ejb-jar.xml, weblogic-ejb-jar.xml?
From the WebLogic console, Environment -> Servers -> View
JNDI Tree.
From there, find the queue, take note of the nested path where it's
located, then use that path in the lookup.
I resolve the problem.
In Weblogic, I must create subdeployment of my JMS module (Oracle said it is not mandatory, but in my case it seems it is) and then everything works fine.