[EJB/JBoss] - Re: Accessing JBoss service from EJB
by je.a.le
"vlotarev" wrote : Dear guru!
|
| Coudl you please tell me how is it possible to access JBoss service (POJO marked with @Service and @Local/@Remote) from EJB? Is it possible just to inject such bean? What will be a JNDI name of a @Service POJO?
|
| Thanks in advance,
| Vadim
from an ejb, if the service has @Service & @Remote |& @Local, simply use @EJB :
| @Service(name = "InitMarchePublicJMX", objectName = "org.portal.marchep.jmx.initialization:name=InitMarchePublicJMX,type=ManagementInterface")
| @Management(InitMarchePublicJMXManagement.class)
| @Local(InitMarchePublicJMXLocal.class)
| public class InitMarchePublicJMX implements InitMarchePublicJMXManagement, InitMarchePublicJMXLocal {
| ....
| }
|
| in the ejb :
| @EJB
| InitMarchePublicJMXLocal jmxinstance;
|
|
if the service is a jmx (@management) (like the one of the code over) :
| MBeanServer mbeanServer = MBeanServerLocator.locateJBoss();
| InitMarchePublicJMXManagement bean = () MBeanProxy.get(InitMarchePublicJMXManagement.class,
| new OjectName(
| "org.portal.marchep.jmx.initialization:name=InitMarchePublicJMX,type=ManagementInterface"),
| mbeanServer);
|
and last, you can go with :
| MBeanServer mbeanServer = MBeanServerLocator.locateJBoss();
| ObjectName mbeanName = new ObjectName(Config.FILTRELINGUISTIQUEJMX);
| String str = (String) mbeanServer.invoke(mbeanName, "FiltrerList", new Object[]{str, true}, new String[]{"java.lang.String", "boolean"});
|
What's really interesting with this one is you do not need dependencies, though you should stick with default type.
A+
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4235698#4235698
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4235698
16 years, 10 months
[EJB/JBoss] - Re: dependence of libraries - the wide scope of EAR
by je.a.le
Your ear tree doesn't look right (you should use netbeans...)
Here one :
zip:/opt/jboss-4.2.1.GA/server/all/deploy/WebTv.ear
zip:/opt/jboss-4.2.1.GA/server/all/deploy/WebTv.ear/META-INF
zip:/opt/jboss-4.2.1.GA/server/all/deploy/WebTv.ear/META-INF/application.xml
zip:/opt/jboss-4.2.1.GA/server/all/deploy/WebTv.ear/META-INF/jboss-app.xml
zip:/opt/jboss-4.2.1.GA/server/all/deploy/WebTv.ear/META-INF/MANIFEST.MF
zip:/opt/jboss-4.2.1.GA/server/all/deploy/WebTv.ear/jai_codec.jar <--lib ejb and war depend on (if not on class path, e.i. in a jboss lib dir already)
zip:/opt/jboss-4.2.1.GA/server/all/deploy/WebTv.ear/jai_core.jar
zip:/opt/jboss-4.2.1.GA/server/all/deploy/WebTv.ear/JaiExt.jar
zip:/opt/jboss-4.2.1.GA/server/all/deploy/WebTv.ear/JBoss4.dpf
zip:/opt/jboss-4.2.1.GA/server/all/deploy/WebTv.ear/jstl.jar
zip:/opt/jboss-4.2.1.GA/server/all/deploy/WebTv.ear/lucene-analyzers-2.3.2.jar
zip:/opt/jboss-4.2.1.GA/server/all/deploy/WebTv.ear/lucene-core-2.3.2.jar
zip:/opt/jboss-4.2.1.GA/server/all/deploy/WebTv.ear/mlibwrapper_jai.jar
zip:/opt/jboss-4.2.1.GA/server/all/deploy/WebTv.ear/VostokStringUtilLib.jar
zip:/opt/jboss-4.2.1.GA/server/all/deploy/WebTv.ear/WebTv-ejb.jar <--- jar with ejb
zip:/opt/jboss-4.2.1.GA/server/all/deploy/WebTv.ear/WebTv-ejb.jar/META-INF
zip:/opt/jboss-4.2.1.GA/server/all/deploy/WebTv.ear/WebTv-ejb.jar/META-INF/jboss.xml
zip:/opt/jboss-4.2.1.GA/server/all/deploy/WebTv.ear/WebTv-ejb.jar/META-INF/MANIFEST.MF
zip:/opt/jboss-4.2.1.GA/server/all/deploy/WebTv.ear/WebTv-ejb.jar/webtv <--- tree of classes...
.... (etc)
zip:/opt/jboss-4.2.1.GA/server/all/deploy/WebTv.ear/WebTv-war.war <--- war archive !
zip:/opt/jboss-4.2.1.GA/server/all/deploy/WebTv.ear/WebTv-war.war/META-INF
zip:/opt/jboss-4.2.1.GA/server/all/deploy/WebTv.ear/WebTv-war.war/META-INF/MANIFEST.MF
zip:/opt/jboss-4.2.1.GA/server/all/deploy/WebTv.ear/WebTv-war.war/WEB-INF
zip:/opt/jboss-4.2.1.GA/server/all/deploy/WebTv.ear/WebTv-war.war/WEB-INF/web.xml
zip:/opt/jboss-4.2.1.GA/server/all/deploy/WebTv.ear/WebTv-war.war/WEB-INF/portlet.xml
.... (jsp, xml for jboss portal , etc...)
zip:/opt/jboss-4.2.1.GA/server/all/deploy/WebTv.ear/WebTv-war.war/index.jsp <-- everything that's public inside this domain
content of application.xml :
| <?xml version="1.0" encoding="UTF-8"?>
| <application version="1.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
| <display-name>WebTv</display-name>
| <module>
| <ejb>WebTv-ejb.jar</ejb>
| </module>
| <module>
| <web>
| <web-uri>WebTv-war.war</web-uri>
| <context-root>/WebTv-war</context-root>
| </web>
| </module>
| </application>
|
content of jboss-app.xml :
| <?xml version="1.0" encoding="UTF-8"?>
| <jboss-app>
| <loader-repository>
| webtv:archive=WebTv.ear
| </loader-repository>
| </jboss-app>
|
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4235691#4235691
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4235691
16 years, 10 months
[JNDI/Naming/Network] - JNDI-lookup returns
by happy_robot
hi all,
i'm developing an application under JBoss 5.0.0 with EJB3.
I'm using stateful EJBs, what works really fine inside the AS (i'm calling them from a deployed web-app).
All JNDI lookups from the webapp do return Proxy-interfaces as expected.
I also try to get my EJBs from an J2SE-client.
But here i get only references to "javax.naming.Reference"-objects.
Where's my fault?
Output of my J2SE-application:
| Context <javax.naming.InitialContext@6d632c2d>
| >>>> jndi.properties
| java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
| java.naming.provider.url=localhost:1099
| java.naming.factory.url.pkgs=org.jnp.interfaces
| <<<<<
|
| Proxy</CSDatabase/ServerWebClientRemote/remote> class<javax.naming.Reference>
|
JNDI-View (Extract):
| java:comp namespace of the component jboss.j2ee:ear=CSDatabase.ear,jar=CSDatabaseEJB.jar,name=ServerWebClientRemote,service=EJB3 :
| +- EJBContext (class: javax.ejb.EJBContext)
| +- TransactionSynchronizationRegistry[link -> java:TransactionSynchronizationRegistry] (class: javax.naming.LinkRef)
| +- UserTransaction (class: org.jboss.ejb3.tx.UserTransactionImpl)
| +- env (class: org.jnp.interfaces.NamingContext)
| | +- entityManager (class: org.jboss.jpa.tx.TransactionScopedEntityManager)
| | +- de.myapplication.general.database.server.services.ServerWebClientRemote (class: org.jnp.interfaces.NamingContext)
| | | +- entityManager (class: org.jboss.jpa.tx.TransactionScopedEntityManager)
| +- ORB[link -> java:/JBossCorbaORB] (class: javax.naming.LinkRef)
|
|
|
| Global JNDI Namespace
|
| +- CSDatabase (class: org.jnp.interfaces.NamingContext)
| | +- ServerWebClientRemote (class: org.jnp.interfaces.NamingContext)
| | | +- remote (class: Proxy for: de.myapplication.general.database.server.services.IServerWebClientRemote)
| | | +- remote-de.myapplication.general.database.server.services.IServerWebClientRemote (class: Proxy for: de.myapplication.general.database.server.services.IServerWebClientRemote)
|
J2SE-Clientapp (see jndi.properties in Output above):
| import java.util.Properties;
| import javax.naming.Context;
| import javax.naming.InitialContext;
|
|
| public class JNDITest {
|
| private Context context = null;
| private Properties contextProperties = null;
|
| public JNDITest() {
| }
|
| public void connect() throws Exception {
| if(context == null) {
| context = contextProperties == null ? new InitialContext() : new InitialContext(contextProperties);
| System.out.println("Context <"+context+">");
| System.out.println(">>>> jndi.properties");
| for(Object key : context.getEnvironment().keySet()) {
| System.out.println(key+"="+context.getEnvironment().get(key));
| }
| System.out.println("<<<<<");
| System.out.println("");
| }
| }
|
| public Object loadBean(String key) throws Exception {
| Object proxy = null;
| try {
| proxy = context.lookup(key);
| } catch(Exception excp) {
| System.out.println("Key<"+key+"> Proxy<"+proxy+"> Exception<"+excp.getMessage()+">");
| throw excp;
| }
| System.out.println("Proxy<"+key+"> class<"+proxy.getClass().getName()+">");
| return proxy;
| }
|
|
| public static void main(String[] args) throws Exception {
| JNDITest test = new JNDITest();
| test.connect();
| test.loadBean("/CSDatabase/ServerWebClientRemote/remote");
| }
| }
|
Additional information:
- My EAR does not use JBoss-specific JARs (i want to stay portable).
| hibernate-annotations.jar (for setting indexes)
| log4j.jar
| commons-beanutils-1.8.0.jar
| javaee.jar
| jsf-impl.jar
| jsf-api.jar
| jstl-1.2.jar
|
- My J2SE client only imports the necessary jars
| jnp-client.jar
| commons-logging.jar
| jboss-logging-spi.jar
| log4j.jar
| slf4j-jboss-logging.jar
| jboss-messaging-client.jar
| jboss-javaee.jar
| jboss-aop-client.jar
| jboss-mdr.jar
|
Thanks in advance
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4235681#4235681
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4235681
16 years, 10 months