I have wrote a simple EJB application and going to test it through a java application client. For that i am fetching the bean as below,
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
// glassfish default port value will be 3700,
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
initialContext = new InitialContext(props);
helloWorld = (HelloWorldBean) initialContext
.lookup("HelloWorldBean/remote");
But i am getting below exception followed by lot of other null pointers,
03-Dec-2012 22:37:37
com.sun.enterprise.v3.server.CommonClassLoaderServiceImpl
findDerbyClient INFO: Cannot find javadb client jar file, derby jdbc
driver will not be available by default. java.lang.RuntimeException:
Orb initialization erorr at
org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:148)
I add this jar even in to build path but still the exception occured. Even i can found the derbyclient jar is there under glassfish\javadb\lib
Also i need to verify whether i run this client correctly?
its just after deploy the application, right click on client class and run as java application right?
Related
I'm trying to use fxcontext.jar to get IBM MQ connection factory from JNDI.
My environment properties are:
environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
environment.put(Context.PROVIDER_URL, "file:///");
...
Then JNDI Object Factory Bean creation code like this:
private JndiObjectFactoryBean createJndiObjectFactoryBean(String connectionFactoryJndi) {
JndiObjectFactoryBean jndiObjectFactoryBean = new JndiObjectFactoryBean();
jndiObjectFactoryBean.setCache(true);
jndiObjectFactoryBean.setProxyInterface(QueueConnectionFactory.class);
jndiObjectFactoryBean.setLookupOnStartup(false);
jndiObjectFactoryBean.setJndiName(connectionFactoryJndi);
return jndiObjectFactoryBean;
}
...
JndiObjectFactoryBean jndiObjectFactoryBean = createJndiObjectFactoryBean(connectionFactoryName);
jndiObjectFactoryBean.setJndiEnvironment(environment);
...
applicationContext.getAutowireCapableBeanFactory().initializeBean(jndiObjectFactoryBean, "QM1Bean");
QueueConnectionFactory connectionFactory = (QueueConnectionFactory) jndiObjectFactoryBean.getObject();
I have configured .bindings file using JMSAdmin from IBM MQ java\bin directory and put it into root directories:
on my host OS (path "d:\.bindings", OS Windows);
on my docker-image based on openjdk:8-jdk-alpine (path "/.bindings", OS Linux).
This code successfully works on my host system, so the message exchange between Spring Boot application and IBM MQ is ok.
But when I start it inside my docker-container there is a problem with JNDI Lookup. The last log entry is:
2021-08-06 10:36:29.119 DEBUG 1 --- [ForkJoinPool.commonPool-worker-1] org.springframework.jndi.JndiTemplate : Looking up JNDI object with name [QCF]
... and nothing happens at all: no exceptions, no errors, no message exchange.
What I'm doing wrong?
I had to rebuild my solution using "ancient" mqcontext.jar and it works fine in both cases. But now I have "a sports interest" to understand the problem with fscontext.jar usage inside docker-container.
Thanks in advance!
I am trying to learn about JMS Queue in JBoss, however I have run into an error. I am following the tutorial on this page: https://docs.jboss.org/jbossas/docs/Server_Configuration_Guide/4/html/JMS_Examples-A_Point_To_Point_Example.html
I get an error on this line: Object tmp = iniCtx.lookup("ConnectionFactory")
Here's the full error:
Jul 7, 2016 3:10:23 PM com.cloudlet.jms.SendRecvClient main
INFO: Begin SendRecvClient, now = 1467918623762
Jul 7, 2016 3:10:23 PM com.cloudet.jms.SendRecvClient sendRecvAsync
INFO: Begin sendRecvAsync
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
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at com.cloudlet.jms.SendRecvClient.setupPointToPoint(SendRecvClient.java:49)
at com.cloudlet.jms.SendRecvClient.sendRecvAsync(SendRecvClient.java:67)
at com.cloudlet.jms.SendRecvClient.main(SendRecvClient.java:106)
Exception in thread "main" java.lang.NullPointerException
at com.cloudlet.jms.SendRecvClient.sendRecvAsync(SendRecvClient.java:71)
at com.cloudlet.jms.SendRecvClient.main(SendRecvClient.java:106)
My code is exactly the same as the one in the link provided. I looked it up and found out I need some jndi.properties file inside the JBoss folder. Unfortunately, that file is not in the JBoss folder. I looked up some examples on what it would look like but every example was different.
How would I fix this? Thanks in advance!
Fixed it by manually making a Properties object with the necessary key/value pairs then passing it to the InitialContext constructor.
JBoss properties:
Properties properties = new Properties();
properties.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.provider.url", "jnp://localhost:1099");
properties.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
InitialContext context = new InitialContext(properties);
I get the same output from the provided link in the opening post.
I am trying to connect to the ejb service in glassfish server through Java Web start.
I am getting the following error while getting the initial context. I have also added the code snippet for getting the initial context.
One interesting is when I run the program as a simple java program outside of java web start in a netbeans IDE, it is working fine.
I added all the relevant jar files from the glassfish modules folder into the java web start.
java.lang.NullPointerException
at com.sun.enterprise.naming.impl.SerialContext.<init>(SerialContext.java:275)
at com.sun.enterprise.naming.impl.SerialContext.<init>(SerialContext.java:334)
at com.sun.enterprise.naming.impl.SerialInitContextFactory.createInitialContext(SerialInitContextFactory.java:358)
at com.sun.enterprise.naming.impl.SerialInitContextFactory.getInitialContext(SerialInitContextFactory.java:353)
at com.sun.enterprise.naming.SerialInitContextFactory.getInitialContext(SerialInitContextFactory.java:69)
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.init(Unknown Source)
at javax.naming.InitialContext.<init>(Unknown Source)
at gov.ca.lc.util.ServiceLocator.getInitialContext(ServiceLocator.java:140)
at gov.ca.lc.util.ServiceLocator.getVotesEJB(ServiceLocator.java:103)
at gov.ca.lc.scenemanagement.AbstractVotingScene.getCommitteeList(AbstractVotingScene.java:143)
at gov.ca.lc.scenemanagement.AbstractVotingScene.<init>(AbstractVotingScene.java:65)
at gov.ca.lc.scenes.MenuScene.<init>(MenuScene.java:56)
at gov.ca.lc.menu.StartVoting.startUp(StartVoting.java:47)
at org.mt4j.MTApplication.setup(MTApplication.java:328)
at processing.core.PApplet.handleDraw(PApplet.java:1580)
at processing.core.PApplet.run(PApplet.java:1502)
at java.lang.Thread.run(Unknown Source)
Exception in thread "Animation Thread" java.lang.NullPointerException
at gov.ca.lc.scenemanagement.AbstractVotingScene.getCommitteeList(AbstractVotingScene.java:143)
at gov.ca.lc.scenemanagement.AbstractVotingScene.<init>(AbstractVotingScene.java:65)
at gov.ca.lc.scenes.MenuScene.<init>(MenuScene.java:56)
at gov.ca.lc.menu.StartVoting.startUp(StartVoting.java:47)
at org.mt4j.MTApplication.setup(MTApplication.java:328)
at processing.core.PApplet.handleDraw(PApplet.java:1580)
at processing.core.PApplet.run(PApplet.java:1502)
at java.lang.Thread.run(Unknown Source)
Following is my code to get the initial context
private static InitialContext getInitialContext()
throws NamingException {
Properties props = null;
try{
// props=new Properties();
// props.load(new FileInputStream(new File("jndi.properties")));
// System.out.println(props.get("java.naming.factory.initial"));
props=new Properties();
props.setProperty("java.naming.factory.initial","com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("java.naming.factory.url.pkgs ", "com.sun.enterprise.naming");//ur server ip
props.setProperty("java.naming.factory.state ", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");//ur server ip
props.setProperty("org.omg.CORBA.ORBInitialHost", "165.107.33.181");//ur server ip
props.setProperty("org.omg.CORBA.ORBInitialPort","3700"); //default is 3700
}catch(Exception ex){
ex.printStackTrace();
}
return new InitialContext(props);
}
I have the same problem. I use JMS and I need to add other jars. At first I tried using gf-client.jar, but it does not work through Java Web start. So I've added jars listed in
Connecting a remote JMS client to GlassFish 3 . It works outside of Java Web start.
I don't know what the relevant jar files are for you, but just in case we have a different view on that area: I use just appserv-rt.jar and java-ee.jar using the same properties you use for initial context and it works fine. Don't add anything else you don't need and try again.
package-appclient in glassfish/bin creates appclient.jar that include jars for client. Then unpack it on a client and use gf-client.jar as usual.
I would like to add that all these set up will work only if you have the glassfish installed in your machine. If you deploy the java webstart app in a machine which doesn't have the glassfish server then we will end up getting the same exception. The reason is that if you open the appserv-rt.jar it points to the gf-client.jar and if you look into the gf-client.jar it points to a whole bunch of jar files in modules folder. So I suppose, essentially we need the all the jar files pointed by the gf-client.jar.
I am tring to lookup the resource defined on the Websphere aplication server 7.0 from the out side of the Container with using the iiop protocol as below:
Java code for (RMI client)Test.jar:
public static void main(String[] args){
Hashtable<Object, Object> properties = new Hashtable<Object, Object>();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"com.ibm.websphere.naming.WsnInitialContextFactory");
properties.put(Context.PROVIDER_URL, "iiop://localhost:2809");
InitialContext intCt;
try {
InitialContext initCtx = new InitialContext(properties);
Object obj = intCt.lookup(JNDI_NAME);
}catch (NamingException namingE) {
System.out.println("Naming Exception occurred :");
namingE.printStackTrace();
}
}
Cmmand file to call the Test.jar:
set appClassPath=C:\WebSphere\AppServer7.0\deploytool\itp\plugins\com.ibm.websphere.v7_7.0.1.v20090422_1423\wasJars\naming.jar;C:\WebSphere\AppServer7.0\deploytool\itp\plugins\com.ibm.websphere.v7_7.0.1.v20090422_1423\wasJars\namingclient.jar;C:\WebSphere\AppServer7.0\properties;C:\Batch\CommandFiles\JobServer\Test.jar
C:\WebSphere\AppServer7.0\java\jre\bin\java -jar -cp "%appClassPath%" C:\Batch\CommandFiles\JobServer\Test.jar %Parameters%
NOTE : Please not that I am runnig the client on my local machin and bootstrap host is : localhost and the port is 2809.
At the time of running the Test.jar code form the command file I am getting the following error:
javax.naming.NoInitialContextException: Failed to create InitialContext using factory specified in hashtable {java.naming.provider.url=iiop://localhost:2809, java.naming.factory.initial=com.ibm.websphere.naming.WsnInitialContextFactory} [Root exception is java.lang.NullPointerException]
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:243)
at javax.naming.InitialContext.initializeDefaultInitCtx(InitialContext.java:327)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:357)
at javax.naming.InitialContext.internalInit(InitialContext.java:295)
at javax.naming.InitialContext.(InitialContext.java:212)
at com.uuic.ets.rmi.server.client.Client.main(Client.java:130)
Caused by: java.lang.NullPointerException
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:235)
... 5 more
I have no idea that why this code is not able to instantiat the InitialContext(Hashmap env). This same code is running in Websphere application server version 5.1 but having problem in Websphere application server version 7.0.
Using JARs from WAS_HOME/deploytool for the classpath is not supported. Try using the documented EJB thinclient with WAS_HOME/runtimes/com.ibm.ws.ejb.thinclient_7.0.0.jar.
I want to basically upgrade my tomcat version(on RHEL).
Always worked in an environment where my war file would be dumped into */webapps, on restart of tomcat, the war file would expand and the rest is history.
Now, the system I'm working on, has completely different folder structure.
Something like this:
[root#bliss ~]# ls /usr/local/blah/blu-app/WEB-INF/
accounts faces-reports.xml logging.properties web-app_2_3.dtd
bin faces-syscfg.xml logging.properties-production web-app_2_4.xsd
buildnum.txt framework2007 perl web.xml
classes host.xsd settings work
deploy-root java.policy tags
events.xsd lib tld
[root#bliss ~]#
I can see some tomcat related jars here:
/usr/local/blah/blu-app/WEB-INF/lib/tomcat-http.jar
/usr/local/blah/blu-app/WEB-INF/lib/tomcat-util.jar
/usr/local/blah/blu-app/WEB-INF/lib/tomcat-coyote.jar
UPDATE
So I did find out that the tomcat is embedded 'cuz I found the following code starting it:
tomcat = new Embedded();
tomcat.setCatalinaHome(targetPath);
Host host = tomcat.createHost("localhost", targetPath);
Context rootCtx = tomcat.createContext("", targetPath);
((StandardContext)rootCtx).setWorkDir("WEB-INF/work");
ServletContext servletContext = rootCtx.getServletContext();
servletContext.setAttribute("version", version);
ApplRealm realm = new ApplRealm(servletContext);
tomcat.setRealm(realm);
rootCtx.setPrivileged(true);
Engine engine = tomcat.createEngine();
engine.setName("tomcat");
engine.setDefaultHost("localhost");
host.addChild(rootCtx);
engine.addChild(host);
tomcat.addEngine(engine);
LOG.debug("starting tomcat");
tomcat.start();
LOG.debug("tomcat started");
// clear out any old sessions: see bug 17882
Session[] sessions = rootCtx.getManager().findSessions();
for (int i = 0; i < sessions.length; i++)
{
sessions[i].expire();
}
ServerSocket socket = null;
socket = new ServerSocket(CmcUtils.getControlPort(), 2, InetAddress.getByName("127.0.0.1"));
socket.accept();
LOG.info("Received shutdown command. Exiting !");
tomcat.stop();
The question then is, how do I upgrade this tomcat to say Tomcat6?
Replace with the latest jars in WEB-INF/lib? Which all jars?
It depends. It could be an embedded tomcat but it could also be a heavily customised tomcat configuration.
Check the startup script to determine which class is being invoked. If its the usual catalina its not embedded its just that they changed the config to point to another folder instead of webapps.
If it is indeed embedded then to upgrade u would need to replace the tomcat jars with new ones.
In tomcat we can create virtual hosts,i.e, making tomcat recognize application's which are deployed in external folders.
A lot more information can be found here.
http://tomcat.apache.org/tomcat-5.5-doc/config/host.html
In your given scenario, try to lookup in server.xml, which is usually found in conf folder of tomcat home.