Calling one EJB form another EJB
Hi,
i have 2 EJBs (Session Beans). Inside first EJB in one of its methods, i have to call the second EJB's one method. What are the steps invlovled in this operation?
Thanks
It's the same as calling an EJB from a client application. I'm not very good at it, but as much as I know, you need to lookup for the EJB Home object using JNDI and obtain the Remote object from it. Then you can call all the methods on the Remote object.
If the two EJBs reside in a different container, you would need to obtain a new InitialContext by passing the environment properties of the other container and then lookup as usual.
The only precaution you need to take is that you need the EJB-client JAR (containing the home and remote interfaces only) for the other EJB available so that ClassNotFoundException and similar exceptions are not thrown.
I hope I was helpful!
Regards,
UW
Similar Messages
-
How to call one EJB in another EJB?
How to call one EJB in another EJB? Please explain with some example code.
To refer a Ejb from another Ejb include <ejb-ref> element in ejb-jar.xml
<session>
<ejb-name>EjbA</ejb-name>
<ejb-ref>
<ejb-ref-name>EjbB</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<home>com.ejb.EjbBHome</home>
<remote>com.ejb.EjbB</remote>
</ejb-ref>
</session>
Include a <reference-descriptor> in weblogic-ejb-jar.xml
<weblogic-enterprise-bean>
<ejb-name>EjbA</ejb-name>
<reference-descriptor>
<ejb-reference-description>
<ejb-ref-name>EjbB</ejb-ref-name>
<jndi-name>com.ejb.EjbBHome</jndi-name>
</ejb-reference-description>
</reference-descriptor>
</weblogic-enterprise-bean>
In EjbA Bean class refer to EjbB with
a remote reference to EjbB.
InitialContext initialContext=new InitialContext();
EjbBHome EjbBHome=(EjbBHome)
initialContext.lookup("com.ejb.EjbBHome");
EjbB ejbB=EjbBHome.findByPrimaryKey(primarykey); -
I need to make a several calls to the methods inside EJB1 from EJB2. I was getting
the remote reference of the EJB2 inside the ejbCreate() of the EJB1, is it a good
practice ?? If not, do I need to get remote reference of the EJB2 every time I
need to call EJB2 method??
Thanks in advance.To refer a Ejb from another Ejb include <ejb-ref> in ejb-jar.xml
<session>
<ejb-name>Ejb1</ejb-name>
<ejb-ref>
<ejb-ref-name>Ejb2</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<home>com.ejb.Ejb2Home</home>
<remote>com.ejb.Ejb2</remote>
</ejb-ref>
<session>
Include a <reference-discriptor> in weblogic-ejb-jar.xml
<weblogic-enterprise-bean>
<ejb-name>EjbSession</ejb-name>
<reference-descriptor>
<ejb-reference-description>
<ejb-ref-name>Ejb2</ejb-ref-name>
<jndi-name>com.ejb.Ejb2Home</jndi-name>
</ejb-reference-description>
</reference-descriptor>
</weblogic-enterprise-bean>
In Ejb1 bean class refer to Ejb2 method with a remote reference to Ejb2.
InitialContext initialContext = new InitialContext();
Ejb2Home ejb2Home = (Ejb2Home)initialContext.lookup("com.ejb.Ejb2Home");
Ejb2 ejb2 = ejb2Home.findByPrimaryKey();
Alex Pratt wrote:
I need to make a several calls to the methods inside EJB1 from EJB2. I was getting
the remote reference of the EJB2 inside the ejbCreate() of the EJB1, is it a good
practice ?? If not, do I need to get remote reference of the EJB2 every time I
need to call EJB2 method??
Thanks in advance. -
Error in calling an EJB from another EJB
Hello All,
I have a scenario where i need to call a method of an ejb from another ejb.
Both the EJB's are in different DC's.
EG: DC1 using DC2
I have added the public part of DC2 in DC1.
The following code is written in DC1 to access the EJB of DC2
MyRemote l_remote;
MyHome l_home;
InitialContext l_ctx = new InitialContext();
>> l_home = (MyHome)l_ctx.lookup("JNDI Name");
l_remote = (MyRemote)l_home.create();
There is no error at build time and deploy time, but at run time "MyHome" class is not found.
Even i am not able to access the helper class defined in the DC2 at runtime.
Please help.
Thanks in AdvanceFirst off, wrong forum section.
Check if your JNDI name is correctly placed for the bean you're calling -- check j2ee-engine.xml for that. Check the EJB container if the ear file you deployed is there and updated.
Try placing "localejbs/JNDI name" on your lookup parameter.
Regards,
Jan -
CallerPrincipal when calling one sessionbean from another
Hi all,
I have a little problem when calling one sessionbean from another sessionbean. The problem is, that in the method, which is called, is used SessionContext's getCallerPrincipal().getName(). This works great from client, but from other sessionbeans getCallerPrincipal() retuns an "ANONYMOUS" principal. How can I set the correct principal (the principal from the first sessionbean)?
Thank you
My env: Glassfish 2.1.1, Netbeans 6.8, Eclipselink 2.0.0, Java 1.6.0.18
My code:
@Stateless
public class ABean implements ASessionRemote{
@Resource
SessionContext ctx;
@Override
public void aMethod(){
String name = ctx.getCallerPrincipal().getName(); // the name is ANONYMOUS, when the call is done from other sessionbean
@Stateless
public class BBean implements BSessionRemote{
@Resource
SessionContext ctx;
@EJB
private ASessionRemote aSessionBean;
@Override
public void bMethod(){
aSessionBean.aMethod();
}"This works great from client"
What do you mean by this, i.e what sort of client are you using (stand alone app, servlet) ?
what shows up if you printout the caller principal in the calling bean ?
are the two ejbs in the same ear ?
what security meta-information are you using in ejb-jar.xml and sun-ejb-jar.xml, if any ? -
How do I reference an EJB inside anothe EJB ,both are on different hosts
Hi,
I want to reference an EJB on one host inside another EJB in another
host. Even if i hardcode the url of the host on which the EJB is
deployed , it gives me the error regarding the no such ejb found.
I would appreciate your help.
ThanksRobert,
We've been trying to implement this type of multi-server setup for some
time now. Our application consists of 260+ EJBs with a large team of
developers actively working against it. The business logic in our
application puts the EJBS in a highly interrelated situation. This
degree of interrelation makes it necessary for each developer to deploy
the entire application before any work can get done.
Starting a weblogic server, on a Windows Workstation, with 260+ beans is
very time consuming. But to get around this development bottle neck, we
are attempting the same scenario described in this thread. We have
recently upgraded from WL4.5.x to WL5.1 SP8. With WL5.1, we get the
CommunicationException seen previously in this thread. But the Error
message in WL5.1 is less descriptive. The 5.1 error message is missing:
WL6.0 Error Text: "This error could indicate that a component was
deployed on a cluster member but not other members of that cluster. Make
sure that any component deployed on a server that is part of a cluster
is also deployed on all other members"
It is obvious that weblogic's clustering depends on classes being
available to each server in the cluster, including the ejbc generated
_WLStub classes. To me, it seems wrong that a weblogic server can only
use standard JNDI to lookup HomeInterfaces on other weblogic servers if
the hidden _WLStub classes are available to both servers. I say this
because non-weblogic clients have JNDI lookup abilities without these
requirements. This whole experience was frustrating because all along
I knew that the solution was simply to take the hacker route and put the
classes in the the client classpath. I guess I just want to know if
this is bug? If not, I think it should be.
Thanks for listening
Steve Dodge
Steve Dodge
Realeum Inc.
Robert Patrick wrote:
Here is an example:
On server1, I have a Bean called TellerBean that calls the AccountBean
that lives on server2. To make this work, I need to deploy the
TellerBean.jar file AND any/all AccountBean Stub classes (any file in the
deployed version of the AccountBean.jar file matching the pattern
AccountBean*Stub.class) on server1. Server2 only needs to deploy the
AccountBean.jar file
Hope this helps,
Robert
kamps wrote:
Thanks.
I did include the files using import and they are alsso packaged
into the jar file .
I have done this , TradeCheck is the ejb i am trying to reference
in Trader EJB.
I package them into the jar file as follows:-
@REM Compile EJB classes into the build directory (jar preparation)
javac -d build TradeCheck.java TradeCheckHome.java Trader.java
TraderHome.java TraderBean.java TradeResult.java
@REM Make a EJB jar file, including XML deployment descriptors
cd build
jar cv0f std_ejb20_basic_statelessSession2.jar META-INF examples
images
cd ..
@REM Run EJBC on jar file
java -classpath
%WL_HOME%/lib/weblogic_sp.jar;%WL_HOME%/lib/weblogic.jar weblogic.ejbc
-compiler javac build\std_ejb20_basic_statelessSession2.jar
%APPLICATIONS%\ejb20_basic_statelessSession2.jar
It still gives the same error not finding the stub class.... Could
you kindly elaborate on what needs to be done.
I would appreciate your help.
Thanks,
Sunitha
Robert Patrick <[email protected]> wrote:
The problem is that the client that downloads the stubs
at runtime cannot
be another WebLogic Server. We do not support downloading
classes into a
running server so you will need to make sure that the
stubs are
"available" to the server that is acting as a client (e.g.,
packaged in
the EAR file) on the server acting as a client.
kamps wrote:
Thanks Mahendra. I am using WebLogic 6.0. Should I importthe package
in the first ejb which references the 2nd ejb or evenin the client
which references the first ejb.
Thanks again,
Sunitha
"Mahendra Dhamdhere" <[email protected]> wrote:
You are not getting the reference of stub.
try this. In your client program, import the package
in
which ejb classes
are present. As client downloads the stub from weblogic,
you have to import
the package where your stubs are present.
which version of weblogic are you using?
Mahendra
kamps <[email protected]> wrote in message
news:[email protected]...
Thanks,
I have 2 ejbs: one is TraderBean and a client RefClient.
TraderBean in turn calls a method of another bean
TradeCheckBean.
I tried making the changes as suggested but I amgetting
the following
error on the client side.
java examples.ejb20.basic.tatelessSession.RefClient"t3://localhost:7001"
javax.naming.CommunicationException. Root exceptionis
java.rmi.UnmarshalException:
failed to unmarshal class java.lang.Object; nested
exception
is:
java.lang.ClassNotFoundException:examples.ejb20.basic.statelessSession.Trade
CheckBeanHomeImpl_WLStub: This error could indicatethat a component
was deployed on
a cluster member but not other members of that
cluster.
Make
sure that any componen
t deployed on a server that is part of a cluster
is
also deployed
on all other member
s of that cluster
java.lang.ClassNotFoundException:examples.ejb20.basic.statelessSession.TradeCheckBea
nHomeImpl_WLStub: This error could indicate that
a
component was
deployed on a clus
ter member but not other members of that cluster.
Make
sure that
any component deploy
ed on a server that is part of a cluster is also
deployed
on all
other members of tha
t cluster
<<no stack trace available>>
I would appreciate any help.
Thanks,
kamps
"Mahendra Dhamdhere" <[email protected]> wrote:
you need to get initialcontext of that server.
Context ctx = null;
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL, "t3://localhost:7001");
try
ctx = new InitialContext(ht); // Use
the
context
in your program
} catch (NamingException e)
{ // a failure occurred }
finally { try {ctx.close();}
catch (Exception e)
{ // a failure occurred } }
use url of that other server. After getting initialcontext,
lookup for your
ejb.
Mahendra
kampu S <[email protected]> wrote in message
news:[email protected]...
Hi,
I want to reference an EJB on one host inside
another
EJB in another
host. Even if i hardcode the url of the host on
which
the EJB is
deployed , it gives me the error regarding the
no
such
ejb found.
I would appreciate your help.
Thanks -
How tom invoke an EJB from another EJB using the sun rmi protocl in Weblogi
Hi,
I am particularly new to EJB.
My scenario is
client invoking-->EJB-----invoking ----(Either a webService or an EJB)
in WEBLOGIC
Is it possible that a call from EJB to another EJB or WebService use Sun's RMI as underlying protocol instead of t3 or IIOP which are used in Weblogic ?
Would be really a great help if you could provide me some sample on it on weblogic.Hi Stefan,
You don't need to provide the InitialContextFactory for running a standalone client. The following should work just fine:
Context initial = new InitialContext();
System.out.println("Looking up ...");
Object objref = initial.lookup(EJB); //the lookup name should be a global JNDI name //and not from the java:comp namespace
System.out.println("Looked up EJB");The JNDI implementation looks for the jndi.properties file in your classpath. So make sure that you have the appserv-rt.jar from your <server_installation>/lib directory in your classpath.
HTH,
Sheetal -
How to call one JSFF into another JSFF
Hi,
I am very new to ADf. Could you please tell me how to call one JSFF inside another JSFF. We have a common pop-up written in one JSFF. Is there any best approach to get this pop-up into other JSFF.
Thanks in Advance.
Regards
NarasimhaIf you want to resue the jsff code, make use of bounded task flow with page fragment and then use it as a region.
For more details you can refer: http://docs.oracle.com/cd/E21764_01/web.1111/b31974/taskflows_regions.htm
One more:
http://docs.oracle.com/cd/E18941_01/tutorials/jdtut_11r2_57/jdtut_11r2_57.html -
How to call one program from another program
Hai,
How to call one program through another program.
Example.
I have two programs 1.ZPROG1 2. ZPROG2.
When i execute ZPROG1 at that time it should call ZPROG2.Hi ,
u can use submit statement to call a program .
DATA: text TYPE c LENGTH 10,
rspar_tab TYPE TABLE OF rsparams,
rspar_line LIKE LINE OF rspar_tab,
range_tab LIKE RANGE OF text,
range_line LIKE LINE OF range_tab.
rspar_line-selname = 'SELCRIT1'.
rspar_line-kind = 'S'.
rspar_line-sign = 'I'.
rspar_line-option = 'EQ'.
rspar_line-low = 'ABAP'.
APPEND rspar_line TO rspar_tab.
range_line-sign = 'E'.
range_line-option = 'EQ'.
range_line-low = 'H'.
APPEND range_line TO range_tab.
range_line-sign = 'E'.
range_line-option = 'EQ'.
range_line-low = 'K'.
APPEND range_line TO range_tab.
SUBMIT report1 USING SELECTION-SCREEN '1100'
WITH SELECTION-TABLE rspar_tab
WITH selcrit2 BETWEEN 'H' AND 'K'
WITH selcrit2 IN range_tab
AND RETURN.
regards,
Santosh thorat -
How to call one .SWF from another?
How do I call one .SWF from another. I built a very beefy
base .SWF, and want to add music overlay, and an intro slide show
to the exsting Flash animation, but put it in a second .FLA/.SWF
file. How do I call one from the other?
This will be embedded in an HTML file but I assume this is
superfluous to my question.
F.Z.I think you should open that Another SWF (FLA),
and add some actionscript..
For example, you could create a movie clip, and write
actionscript in the
first keyframe:
loadMovie("
http://www.somewebpage.com/movie.swf",
this);
"FredZimmerman" <[email protected]> wrote in
message
news:ftnjas$mj5$[email protected]..
> How do I call one .SWF from another. I built a very
beefy base .SWF, and
> want
> to add music overlay, and an intro slide show to the
exsting Flash
> animation,
> but put it in a second .FLA/.SWF file. How do I call one
from the other?
>
> This will be embedded in an HTML file but I assume this
is superfluous to
> my
> question.
>
> F.Z.
> -
Calling one function in another function
Hi,
How to call one function in another function?
regards,
Kishore.example:
SQL> ed
Wrote file afiedt.buf
1 declare
2 function bob(x number) return number is
3 begin
4 return x*x;
5 end;
6 function fred(x number) return number is
7 begin
8 return x+bob(x);
9 end;
10 begin
11 dbms_output.put_line('Value: '||to_char(fred(5),'fm9999'));
12* end;
SQL> /
Value: 30
PL/SQL procedure successfully completed.
SQL> -
Calling one WDA by another WDA using Embeding view,
i am calling one WDA by another WDA using Embeding view,
how can i pass the value b/w two wda applicationHi,
checkthis example SALV_WD_TABL, this is a ALV component.check commponent controller context and methods how they made interface.
similarly if you make your used component context and methods are interface.so that they will be available in your current component.
also check this ALV example
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/3439404a-0801-0010-dda5-8c14514d690d -
Can an EJB extend another EJB?
Can an EJB extend another EJB?
Are there any limitations?
Thank you in advance, KostasRefer
http://archives.java.sun.com/cgi-bin/wa?A2=ind0106&L=ejb-interest&F=&S=&P=31185 -
hi all,
i have to call one wda by another wda by plug, i do not want to embed view in window,
i want when i call one wda by another, it comes in same window, and when press back it again call the calling window.
Points will be rewarded,
Yogesh nhttp://help.sap.com/SAPHELP_NW04S/helpdata/EN/45/19bf8c16f25d7ae10000000a11466f/frameset.htm
Use suspend and resume plugs
Abhi -
Calling one script from another
InDesign has a nice mechanism for calling one script from another, so code can be made modular. What about FrameMaker ExtendScript? What methods are people using to call one script from another? Thanks for any suggestions.
Rick QuatroHi Trevor,
Note that ExtendScript is Javascript plus FM objects and methods, so you need to stick to Javascript syntax rules. The right way to include another script source is as follows:
#include "scriptname.jsx";
If this works when running the main script from the ESTK, you know it finds the included script. When you then Export the script to Binary (from the File menu of the ESTK), the binary will include the embedded script as well. After this you have a jsxbin file, which you can drop into one of the two available startup folders to make it fire automatically when FM starts. Or you can move it anywhere else and run it via the File > Script > Run command. The main idea here is that when compiling a script into binary format, all include references are resolved and the script contains the complete code. If you run the jsx, the script is interpreted and requires a correct relative reference to any included script.
I hope this clarifies things a little
Ciao
Jang
Maybe you are looking for
-
Why can't I access the internet via ethernet port on my Airport Express?
I have an Airport Extreme base station and two Airport Express units. The Extreme is connected by ethernet to a BT Home Hub (BT is the internet provider). The network works for all the other computers that have Airport cards BUT I want to connect a M
-
How to remove Batch Management Check in the Material
I have one requirement to remove batch management check in the materials which should not be deleted. I created a testing material with batch management check on and put in material through 561, then did good issue for scrapping to remove the stock o
-
Hi All, I have two queries one is displaying Current week Sales and the other one is displaying Previous week sales.I have assigned the column Chart for Current week query in WAD,i want to display the last week data also in the same chart as a Line g
-
I need to reboot a crio-9004 remotely, how is this done in LV?
A cRIO-9004 needs to be rebooted remotely. Our software development platform is LabVIEW 8.0. How can this be done?
-
Entrance Test Scenario Capturing on SLCM
Dear SLCM Gurus, I have a scenario which need to be configured in SLCM. Student applies thru Enterprise portal for applying for Entrance Examination for a body u2018AIEEEu2019 . When the student applies he also submits his transcript for 12th(High Sc