File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes BEA/Weblogic and the fly likes Running Servlets in Weblogic Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » BEA/Weblogic
Bookmark "Running Servlets in Weblogic" Watch "Running Servlets in Weblogic" New topic
Author

Running Servlets in Weblogic

Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362
Hi,
I want to know what the following code does in Weblogic.I am using Jbuilder4.0 and when I create a testclient , Jbuilder creates the default code.
Pl tell me whether it is necessary to include the below code if I access the EJB from Servlets.
private Context getInitialContext() throws Exception {
Properties properties = null;
try {
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, url);
if (user != null) {
properties.put(Context.SECURITY_PRINCIPAL, user);
properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
}

Thanx in advance
Asuthosh Borikar
Ranch Hand

Joined: Sep 29, 2000
Posts: 75
The following two lines in your code :
properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, url);
help the client get an Initial Context from the Server, which can then be used to get any server resources(database connections, references to EJBs etc.). On my machine, the value of 'url' above is : t3://localhost:7001. If your server is running on a different machine, you would have to use the URL for that machine, along with the port number.
The last two lines, I think, have to do with User Authorization and User Authentication.
Hope this helps.
Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362
Hi Asuthosh Borikar,
Thanx for ur reply.
But you have answered my question partly.
My question was whether its necessary to use the above method when I access the EJB from Servlets
Do reply

Asuthosh Borikar
Ranch Hand

Joined: Sep 29, 2000
Posts: 75
No, you need not use them, to get InitialContext in your servlet.
Servlets are deployed in the webserver part of the Weblogic server and the InitialContext is available to them without all this fuss. You can create an instance of InitialContext and start using it, like in:
InitialContext ctx = new InitialContext();
Object objref = ctx.lookup("Company.CompanyHome");
CompanyHome companyHome = (CompanyHome)object.narrow(objref,CompanyHome.class);
Where CompanyHome is a reference to the HomeInterface of the Company EJB.
Hope this answers your question.
George Brown
Ranch Hand

Joined: Sep 26, 2000
Posts: 919
Just to expand on the last post... If however your servlet resides on a different instance of WLS (which is also a different JVM) from your EJBs you certainly would need to provide the context details to get (through the Context) access to the EJBs.
So if you're not sure where your servlets could be deployed, it would certainly be safest to provide all the details to get the correct Context (and EJBs).
Asuthosh Borikar
Ranch Hand

Joined: Sep 29, 2000
Posts: 75
Yes, I totally agree with you.
Mary Cole
Ranch Hand

Joined: Dec 02, 2000
Posts: 362
Hi All,
Thanx a lot for your advice
It helped me alot
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running Servlets in Weblogic