All,
I am trying to invoke an EJB from remote standalone program. EJB is properly deployed on JBOSS 7.0. I am using the below code to do the lookup:
Properties jndiProps = new Properties();
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
jndiProps.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
jndiProps.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
jndiProps.put(Context.SECURITY_PRINCIPAL, "user1");
jndiProps.put(Context.SECURITY_CREDENTIALS, "password#123?");
jndiProps.put("jboss.naming.client.ejb.context", true);
try {
Context ctx = new InitialContext(jndiProps);
HelloWorld d= (HelloWorld) ctx.lookup("HelloWorldSessionBean/HelloWorldBean!com.ibytecode.business.HelloWorld");
// String s=d.sayHello();
// System.out.println(s);
}
catch(Exception ne) {
ne.printStackTrace();
}
But I am getting the below exception and unable to proceed further. Can anyone let me know what I am missing:
Failed to connect to any server. Servers tried: [http-remoting://localhost:8080]
javax.naming.NamingException: Failed to connect to any server. Servers tried: [http-remoting://localhost:8080]
My Server is up and running and I am using standalone-full.xml file
I think http-remoting: protocol is not available in your version of JBoss (AS 7).
Change your provider URL from
jndiProps.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
to
jndiProps.put(Context.PROVIDER_URL, "remote://localhost:4447");
Also, make sure you have all the necessary JBoss EJB remoting project libraries in your classpath of your client.
Related
I have this exception when I lookup jndi datasource from weblogic from spring boot application...only after one successful deployment...I mean from the second deployment on.If I restart the container, it will work fine for the first deployment only.
Caused by: javax.naming.NameNotFoundException: Unable to resolve 'jdbc.payment'. Resolved 'jdbc'; remaining name 'payment'
the datasource with the same name and attached to the admin server.
I use docker image : store/oracle/weblogic:12.2.1.4-dev with environment variable PRODUCTION_MODE=dev
update : if I deattach the data source from the server then reattche it again then start the war, It runs successfully for one time againŲ²
update : switched to local installation of weblogic not dockerized any more and the behavior still happens
It's a spring issue...has nothing to do with weblogic.
In the war shutdown, Spring remove the data source form the server JNDI tree, however the data source still up and running on the server.
The action of recreating or even reattaching the data source to target server, add it again to the JNDI tree.
The workaround to solve this behavior is to prevent spring from calling the destroy method of the data source bean
#Primary
#Bean(name = "dataSource",destroyMethod = "")
#Profile("weblogic")
public DataSource dataSourceWeblogic() throws NamingException {
JndiTemplate jndiTemplate = new JndiTemplate();
InitialContext ctx = (InitialContext) jndiTemplate.getContext();
return (javax.sql.DataSource) ctx.lookup(jndi);
}
I'm experiencing a side effect with the following scenario:
I'm looking up a URL via JNDI in a J2EE 5.0 web application running on Websphere Application Server 8.5.5 this way:
URL jndiLmcUrl = null;
try {
Context initialContext = new InitialContext();
jndiLmcUrl = (URL) initialContext.lookup("java:comp/env/url/ENLMC);
} catch (NamingException ne) {
String message = "Unable to found middleware configuration file specified with Jndi property java:/comp/env/url/" + systemPropertyName + " as URI/URL. Trying as system property";
LOG.error(message);
}
My web.xml configuration is:
<resource-ref>
<res-ref-name>url/ENLMC</res-ref-name>
<res-type>java.net.URL</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
In addition i have defined the URL Resource using WAS Console under Resources/URL/Urls with server scope.
ALL IS WORKING FINE as expected.
But, for some reasons (primarily WS Metro usage) i've to move the application to PARENT_LAST using MyApplication/ManageModules/Class loaded with local class loader first (parent last).
After this operation the JNDI lookup fails raising a Naming Exception.
Thank you for your precious help.
I want deploy a Stateful EJB Bean in my standalone JavaFx Client without an application server. The EJB Class has a entitymanager reference and makes transactions against db. The Project is a maven archetype and i added the EJB class in a package.
From my main method i make a JNDI lookup like this
Properties props = new Properties();
props.put(EJBContainer.APP_NAME, "testejb");
props.put(EJBContainer.MODULES, new File("target/classes"));
EJBContainer ec = EJBContainer.createEJBContainer(props);
Context ctx = ec.getContext();
myEjbClass = (MyEjbClass) ctx.lookup("java:global/testejb/MyEjbClass");
I become exception javax.ejb.EJBException: No EJBContainer provider available: no provider names had been found. I have added the javaee-7 and glassfish-embedded-shell to my pom.xml.Why?
Have you configured and started the embedded Glassfish in your program?
This can be done by doing this:
BootstrapProperties bootstrapProperties = new BootstrapProperties();
bootstrapProperties.setInstallRoot("C:\\applicationserverdir");
GlassFishRuntime glassfishRuntime = GlassFishRuntime.bootstrap(bootstrapProperties);
GlassFishProperties glassfishProperties = new GlassFishProperties();
glassfishProperties.setInstanceRoot("C:\\applicationserverdir\\domains\\myJavaFXAppDomain");
glassfishProperties.setPort("http-listener", 8080);
glassfishProperties.setPort("https-listener", 8181);
GlassFish glassfish = glassfishRuntime.newGlassFish(glassfishProperties);
glassfish.start();
More information on setup embedded Glassfish here: http://docs.oracle.com/cd/E18930_01/html/821-2424/giijw.html#scrolltoc
Also, which Maven archetype are you using?
I'm trying to subscribe to a HornetQ instance running on a JBoss AS7 server. I've managed to connect and publish/receive messages with a test application which exists outside of the application server, but when I try to run a similar example deployed within the server I get the following exception at the point of creating an InitialContext instance in my message subscriber class:
javax.naming.NamingException: JBAS011843: Failed instantiate InitialContextFactory org.jboss.naming.remote.client.InitialContextFactory from classloader ModuleClassLoader for Module "deployment.Test.war:main" from Service Module Loader
at org.jboss.as.naming.InitialContextFactoryBuilder.createInitialContextFactory(InitialContextFactoryBuilder.java:64)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:681)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
at javax.naming.InitialContext.init(InitialContext.java:242)
at javax.naming.InitialContext.<init>(InitialContext.java:216)
at uk.co.test.MessageSubscriber.startSubscription(MessageSubscriber.java:127)
at uk.co.test.MessageSubscriber.access$0(MessageSubscriber.java:114)
at uk.co.test.MessageSubscriber$1.run(MessageSubscriber.java:47)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
And here's the code where I'm attempting to create the context (I've excluded the actual subscription, topic setup code etc out for clarity):
String factoryName = "jms/RemoteConnectionFactory";
String topicName = "jms/topic/test";
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
props.put(Context.PROVIDER_URL, "remote://server:4447");
props.put(Context.SECURITY_PRINCIPAL, "testuser");
props.put(Context.SECURITY_CREDENTIALS, "password");
props.put("jboss.naming.client.ejb.context", true);
InitialContext context = new InitialContext(props); // Exception
The context creation works fine when I connect remotely to the server, so I assume there's a different approach for discovering the HornetQ that I've overlooked. Or maybe I'm missing a dependency somewhere, or it's a general configuration issue...either way I'm struggling to find any examples I can use to push forward with this.
Any ideas where I'm going wrong?
Thanks.
I think following shall be enough to connect locally:
InitialContext jndiContext = new InitialContext();
QueueConnectionFactory qf = (QueueConnectionFactory) jndiContext.lookup( "java:/ConnectionFactory" );
when connection factory is defined as
<jms-connection-factories>
<connection-factory name="InVmConnectionFactory">
<connectors>
<connector-ref connector-name="in-vm"/>
</connectors>
<entries>
<entry name="ConnectionFactory"/>
</entries>
</connection-factory>
</jms-connection-factories>
I have a standalone client that I do not want to deploy on my Glassfish server. With the client I want to post message via the Point to Point communication pattern. I found this great tutorial, which uses annotations I cannot use because I have a standalone client. I found the following solution on stackoverflow:
Context jndiContext;
private ConnectionFactory connectionFactory;
private static Queue queue;
public TweetSender() throws NamingException{
jndiContext = new InitialContext();
connectionFactory = (ConnectionFactory) jndiContext.lookup("JMS/KwetterConnectionFactory");
queue = (Queue) jndiContext.lookup("JMS/KwetterQueue");
}
I also found out that I had to import some libraries from the glassfish directory. So I did:
I get the following error:
javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.impl.SerialInitContextFactory [Root exception is java.lang.ClassNotFoundException: com.sun.enterprise.naming.impl.SerialInitContextFactory]
What am I doing wrong?
EDIT
I found a temporary solution for the problem though I feel it's not the right one (I think I might get problems when I want to migrate the project. I removed the libraries which I retrieved from the Glassfish lib folder and added them using the "Absolute path".
A solution can be packing your standalone client application in a jar file, eg: myclient.jar.
And run it as an application client using appclient utility of GlassFish:
applcient -client myclient.jar
The appclient utility can be found here: [glassfish home dir]/glassfish/bin.