I have a ejb3 using a web service and configure the host name of the web service in the ejb-jar.xml file (or #WebServiceRef(wsdlLocation = "http:://myserver/service.wsdl") ). Can I do the same configure outside of the ejb-jar.xml file, similar to how a DataSource is configured?
You can use deployment descriptors to override settings made by annotations.
Maybe you can inject the values from outside, declaring a class similar to that what is described here:
http://publib.boulder.ibm.com/infocenter/wasinfo/v7r0/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/ae/twbs_devwbsjaxwsclient_dyn.html
Related
I'm using #EnableMBeanExport in a SpringBoot application to make my beans with #ManagedResource be available to the JMX server. This works fine in simple local processes with VisualVM.
I'm now trying to add Jolokia into the mix, so I can reference those beans remotely with a REST service instead of setting up a remote RMI connection, which is annoying.
The Jolokia doc page at https://jolokia.org/reference/html/jmx.html says to use the following:
MBeanServer jolokiaServer = JolokiaMBeanServerUtil.getJolokiaMBeanServer();
However, there doesn't appear to be a "JolokiaMBeanServerUtil" class in Jolokia.
Update:
Ok, I found the artifact with the class, but the solution doesn't appear to be as simple as just declaring a bean with this value. When I attempt to call a jmx method with a jolokia url, I get an exception like the following:
java.lang.IllegalArgumentException: Invalid object name. Key properties cannot be empty
at org.jolokia.request.JmxRequestFactory.createGetRequest(JmxRequestFactory.java:99)
at org.jolokia.http.HttpRequestHandler.handleGetRequest(HttpRequestHandler.java:79)
at org.jolokia.http.AgentServlet$4.handleRequest(AgentServlet.java:470)
It is possible to configure dynamically an in-server ClientContext (server-to-server EJB invocations) in order to add remoting ejb receiver outbound connections?
Something like changing the jboss-ejb-client.xml configuration at runtime.
Initially I tried to configure the InitialContext with the remote.connection.xxxx.host properties. But the server simply ignores. Also ignores the jboss-ejb-client.properties file in classpath. After that, I tried to configure dynamically with EJBClientContext.setSelector(someSelector), but apparently I can't due security reasons (SecurityException or so).
I have 2 session beans, OrderBean and InventoryBean which are deployed at different weblogic servers.
The OrderBean needs to access the InventoryBean to check if the supply is sufficient.
Currently, I use JNDI look up to locate the InventoryBean and it works fine.
Now I'm wondering if it is possible to use #EJB to inject InventoryBean by providing the JNDI name and the URL in xml or somewhere else.
Finally I found a way to do this.
i. Configure the foreign JNDI on the weblogic server and link the remote EJB to a local JNDI name.
For example:
Local JNDI:
InventoryBean#com.pkg.InventoryBean (MAPPEDNAME#FULLNAME)
link to
Remote JNDI:
ServiceBean#com.pkg.InventoryBean
ii. Configure ejb-ref in ejb-jar.xml
ejb-ref-name -> ejb/InventoryBean
remote -> com.pkg.InventoryService
mapped-name -> InventoryBean
iii. Add the #EJB annotation in OrderBean
#EJB(name = "ejb/InventoryBean")
private InventoryService inventoryService;
I think it is not possible through EJB annotations, but you can configure foreign JNDI on your WebLogic server and refer to your remote EJB as a local JNDI name. Though, I never tried that, but I think it should work.
It is very AS-specific.
JBoss 7+ makes it possible if you:
Define outbound-socket-binding, security-realm and remote-outbound-connection in the standalone file (all referring to the remote JBoss instance).
Add a jboss-ejb-client.xml to the META-INF folder of your packaged application, with a remoting-ejb-receiver for every connection needed by the application.
Inject the remote EJB with#EJB(lookup = "<jndi_name>")
Let me know if further details are needed.
Give a look at:
JBoss configuration for remote connections
An article about Glassfish-Glassfish remote connections
Would it be possible to programmaticly create a data source in jboss and still have a valid jndi entry for the entity manager to use?
Creating the data source is where I am lost, I hope I can use a MBean that runs on stat-up to handle this.
This would not be my preferred method, but the application I am working on has a global configuration file hosted on another server I am suppose to use for configuration.
update: In this instance I need to create a data source programticly or change the jdbc url of an exsiting datasource. I don't know the DB server url until runtime.
Rather than poking around in the guts of JBoss in order to do this, I suggest using a 3rd-party connection pool utility, such as Apache Commons DBCP. There are instructions on how to programmatically register a DBCP datasource on JNDI here.
The first two lines of the sample code should be unnecessary, just create the default InitialContext and then rebind the datasource reference into it as described.
Here's a post that describes how to create a jboss service archive (SAR) that you can put in your EAR that will deploy a data source when the EAR is deployed, and remove it when the EAR in undeployed.
When I try the following lookup in my code:
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
return (DataSource) envCtx.lookup("jdbc/mydb");
I get the following exception:
java.sql.SQLException: QueryResults: Unable to initialize naming context:
Name java:comp is not bound in this Context at
com.onsitemanager.database.ThreadLocalConnection.getConnection
(ThreadLocalConnection.java:130) at
...
I installed embedded JBoss following the JBoss wiki instructions. And I configured Tomcat using the "Scanning every WAR by default" deployment as specified in the configuration wiki page.
Quoting the config page:
JNDI
Embedded JBoss components like connection pooling, EJB, JPA, and transactions make
extensive use of JNDI to publish services. Embedded JBoss overrides Tomcat's JNDI
implementation by layering itself on top of Tomcat's JNDI instantiation. There are a few > reasons for this:
To avoid having to declare each and every one of these services within server.xml
To allow seemeless integration of the java:comp namespace between web apps and
EJBs.
Tomcat's JNDI implementation has a few critical bugs in it that hamper some JBoss
components ability to work
We want to provide the option for you of remoting EJBs and other services that can > be remotely looked up
Anyone have any thoughts on how I can configure the JBoss naming service which according to the above quote is overriding Tomcat's JNDI implementation so that I can do a lookup on java:comp/env?
FYI - My environment Tomcat 5.5.9, Seam 2.0.2sp, Embedded JBoss (Beta 3),
Note: I do have a -ds.xml file for my database connection properly setup and accessible on the class path per the instructions.
Also note: I have posted this question in embedded Jboss forum and seam user forum.
Thanks for the response toolkit.... yes, I can access my datasource by going directly to java:jdbc/mydb, but I'm using an existing code base that connects via the ENC. Here's some interesting info that I've found out ....
The above code works with JBoss 4.2.2.GA and here's the JNDI ctx parameters being used:
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces:
org.jboss.naming:org.jnp.interfaces
The above code works with Tomcat 5.5.x and here's the JNDI ctx parameters being used:
java.naming.factory.initial=org.apache.naming.java.javaURLContextFactory
java.naming.factory.url.pkgs=org.apache.naming
The above code fails with Embedded JBoss (Beta 3) in Tomcat 5.5.x with the above error message.
java.naming.factory.initial=org.apache.naming.java.javaURLContextFactory
java.naming.factory.url.pkgs=org.apache.namingThe above code fails with the above error using JBoss Embedded in tomcat 5.5.x
Anyone have any thoughts I what I need to do with configuring embedded JBoss JNDI configuration?
java:comp/env is known as the Enterprise Naming Context (ENC) and is not globally visible. See here for more information. You will need to locate the global JNDI name which your datasource is regsitered at.
The easiest way to do this is to navigate to JBoss' web-based JMX console and look for a 'JNDIView' (not exactly sure of the name - currently at home) mbean. This mbean should have a list method which you can invoke, which will display the context path for all of the JNDI-bound objects.
I had some similar issue with Jboss Embedded and i finally fix playing in the file:
test-Datasource-ds.xml
adding
<mbean code="org.jboss.naming.NamingAlias" name="jboss.jmx:alias=testDatasource">
<attribute name="FromName">jdbc/Example DataSource</attribute>
<attribute name="ToName">java:/testDatasource</attribute>
</mbean>
The problem was jboss add the prefix java:/ for all data source declared. So finally i had a datasource named testDatasource, overrided with that directive to jdbc/Example DataSource
Hope it works