Config JNDI from web interface - jboss

Is there any way to specify jndi resource through JBoss AS7 admin interface?
I have been looking around, but was unfortunate to find anything like that.

Open the Create Datasource Wizard->Profile->Datasource->Add->
Here you will be able to enter datasource name and JNDI name into the Create Datasource wizard
Hope it helps!

Related

What to put into jta-data-source of persistence.xml that works on all vendors?

Similar to What to put into jta-data-source of persistence.xml? and How to map jpa datasources in WildFly?
However, I am asking for something that would work on all vendors or at least WildFly, Glassfish/Payara, WebSphere Application Server classic, WebSphere Application Server Liberty, TomEE. I am not looking for something that works in a Java SE Unit test.
So far I found that java:comp/env/jdbc/xxx works in WebSphere Application Server and TomEE. There's a mapping exercise (which is expected) to get it working but I cannot get the same to work on GlassFish/Payara and JBoss/WildFly.
More specifically I do not wish to use default data source because for my scenario I am actually working on two different data sources. E.g. for reference data and another for transactional.
If all of the app servers you work with are Java EE 7 compliant, you can use the default data source, which is required per EE7 spec to be available at:
java:comp/DefaultDataSource
The app server you run on ought to let you customize the configuration of the DefaultDataSource.
Since I'm familiar with WebSphere Liberty, I can point you to this doc for default data sources on Liberty:
Configuring a default data source
If you are using WebSphere traditional, as of v9.0 it supports Java EE 7, and has a default data source available out of the box (under the spec mandated JNDI name).
If you want to use the same JNDI name that works on all servers, it's best to use resource references, as explained in What is resource-ref in web.xml used for?
Basically, you would define an arbitrary JNDI name (ideally without any java:comp prefix or similar, just something like "myDatasource") and then map it to the concrete JNDI name provided by the target server.You would need to define a server-specific descriptor for each server with the mapping the if the server cannot use the JNDI directly (e.g. glassfish-web.xml for GlassFish/Payara, jboss-web.xml for WildFly, ibm-web-bnd.xml for WebSphere Classic and Liberty). TomEE seems to support references without any prefix, so it should be able to configure a datasource without any additional mapping if you choose a name without a prefix.

overriding JNDI names in JBoss EJB3.1

We're using Maven and Artifactory, and therefore our ear files have names like
our-project-ear-0.0.1-20151215.151526-3.ear.
So JNDI names for our EJBs have names like
java:global/our-project-ear/our-project-ejb/AnEjbJar!com.acme.ourproject.SomeEjb.
These names are not just ugly and complex, they also embed temporary suffixes added by Maven/Artifactory.
I thought we could simplify the names via the JBoss-specific #RemoteHomeBinding annotation, but I do not find this annotation in EAP 6.3. Is there still a way to do this? If not, how can I control the JNDI name under which my EJBs are published?
Figured it out myself. The #RemoteBinding, #LocalBinding, #RemoteHomeBinding and #LocalHomeBinding annotations have been phased out in AS7.x. A version of the JBoss instructions for migrating from AS5/6 to AS7 (not the current one) states:
>In AS7 there is no possibility for custom JNDI names of EJB beans and it's not planned for 7.1.
>Therefor the annotation #RemoteBindings and #LocalBindings are not available.
The recommended approach is to use the default bindings. However, custom JNDI names can also be defined via the #EJB annotation, as stated in this Oracle blog:
The developer can select an additional JNDI name that resolves to a particular client view of a session bean by using the #EJB annotation. Starting with Java EE 6, the #EJB name() attribute value can be prefixed with any one of the three portable Java EE namespaces : java:global, java:app, java:module. This has the effect of exporting the dependency into the selected scope.
I think what you are looking for is :
#Ejb(lookup="java:/global/somecustomPath")
As this will not affect where in JNDI the bean is bound but rather where to find it in JNDI.
If I'm right this is because JBOSS7 is a JEE6 application server and JEE6 introduced the concept of Portable Global JNDI names in JEE6.

How to configure datasource jboss 4.2.3 for a jar library that initialize connection in the default context?

we have a jar library util that manage some of the logic of connection to db and store the data in memory. Well, this works fine in tomcat because we can configure the datasource in the $CATALINA_HOME/conf/context.xml and everything work's just fine.
How i can configure a datasource in jboss (4.2.3.GA) that's can be see by all the war, ear or apps deployed and of course this jar util that's it's deployed in the $JBOSS_HOME/server/<instance>/lib ?
Thanks :)
UPDATE:
I specifically want to do:
"2a. Shared resource configuration
Use this option if you wish to define a datasource that is shared across multiple JBoss Web applications, or if you just prefer defining your datasource in this file.
This author has not had success here, although others have reported so. Clarification would be appreciated here.
<Resource name="jdbc/postgres" auth="Container"
type="javax.sql.DataSource" driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://127.0.0.1:5432/mydb"
username="myuser" password="mypasswd" maxActive="20" maxIdle="10" maxWait="-1"/>
source: https://docs.jboss.org/jbossweb/2.1.x/jndi-datasource-examples-howto.html
Well, i'm in the part of "Clarification would be appreciated here"...
Create a JBoss Datasource
Add a datasource configuration (*-ds.xml file) into your $JBOSS_HOME/sever/<server-name>/deploy directory.
This StackOverflow answer has more details: How to create a DataSource in JBoss application server
The link is for JBoss 5, but I don't think the datasource configuration changed much between 4.2.3 and 5.
Configure the Tomcat Resource Reference
Configure a Tomcat resource reference to point to the JBoss datasource. This configuration will identify the datasource by JNDI name in order to retrieve connections from the JBoss datasource.
Step 1 of the accepted answer to this StackOverflow question has more details: JNDI path Tomcat vs. Jboss
Note that your Resource configuration is defining a new data source, not reusing the JBoss definition.
Look up the Data Source with JNDI
The same answer explains how to do this, but note that the URI is slightly different depending on whether the lookup is done from within client code outside of the EJB container, or from code within the EJB container.
Ok, this toke me about a week of researching:
Create a *-ds.xml file.
In the datasource definition add the following tag:
<use-java-context>false</use-java-context>
Then, in the java code we can call it like:
Properties env = new Properties();
env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
env.setProperty(Context.PROVIDER_URL, "localhost:1100");
initialContext = new InitialContext(env);
DataSource datasource = (DataSource) initialContext.lookup("myCustomDs");

JBOSS 7 - Osgi Bundles not present in JNDI TREE

I have a bundle in JBOSS7 Bundle Repository.
I want to lookup it from a WAR class throw JNDI, but in my JBOSS7.0.1.Final AS there is any trace of osgi in JNDI tree.
In JNDI tree I found only "java:" and "java:jboss", I think that when I deploy a bundle the AS should add the "osgi:" leaf to the tree.
Why not?
Osgi Alliance specific says that when an osgi bundle is deployed it should be reachable throw JNDI...
Some ideas?
Thanks a lot!
You are right, this part of the OSGi-JNDI spec is not yet done, you can track the progress here https://issues.jboss.org/browse/JBOSGI-81
Note: there is a way to get this working, see here for more details: Can't lookup OSGI services through JNDI

How to do Application specific Configuration for a Framework

i want to write a Java EE framework for a generic type of applications.
I'm looking for a way to handle application specific config values in my framework.
To give an example:
A component supplies a stateless session bean that handles persistence and i want to configure the name of the datasource that is used in a config file in my application (for example in the web-inf folder of the applications ear).
Now i have X>1 Applications that want to configure X different datasources for their specific persistence management.
Can anybody give me an example how to do that?
Greetings,
Alexander
You should use the JNDI provider thats bundled with the application container. One of its purposes it to access resources, data sources in your case, in a highly dynamic fashion.
For JBoss, setting up a data source involves the following steps:
deploy a *-ds.xml configuration file to the JBoss server's deploy directory. This defines the global JNDI name of the resources. There should be plenty of examples for a lot of databases available on the internet.
add a resource-ref to the jboss-web.xml of any WAR or to the jboss.xml of any EJB jar for any bean that needs the resource. This defines the global JNDI name to local/component JNDI name mapping.
add a resource-ref using the local JNDI name to the web.xml of any WAR or to the ejb-jar.xml of any EJB jar for any bean that needs the resource.
Once those things are in place, you can perform JNDI lookups to access the configured resource.
You can do these things to configure multiple data sources in JBoss and then make one or more of these data sources available to the web applications and EJBs.