in my login servlet I'm using this way to access the container, and it works, if the user and credentials is valid, I store it in the session to reference it later. In other servlet in my application, when I need to access the container to get other ejb, I get the context stored in the session. I use the following code:
Context context = (context)session.getAttribute("context");
SomeHome someHome = (SomeHome)context.lookup("java:comp/env/ejb/application.SomeHome");
But at this time, it didn't work.
Any idea ?
Regards
Marcelo Bellezo
Scott Stirling wrote:
Hi Marcello,The reason it didn't work from a servlet is that the JRun servlet container
doesn't completely share the same JNDI context with the Ejipt EJB container,
even though they are in the same JVM. You just instantiated the default
InitialContext in a servlet without passing the InitialContext() constructor the
information it needs to access the EJB server's context. Get it? In future
releases, JRun and Ejipt will better be able to share resources and communicate
more easily internally, thereby making it easier for you to do stuff like you
were trying to. In the meantime, please see the example below.Sample9a shows how to properly initialize a Context object for a servlet
accessing an EJB:
(This is in JRun/samples/sample9a/webapp/WEB-INF/classes/LoginServlet.java)try
{
final Properties properties = new Properties();properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"allaire.ejipt.ContextFactory");
properties.setProperty(Context.PROVIDER_URL, "ejipt://localhost:2323");
properties.setProperty(Context.SECURITY_PRINCIPAL,
request.getParameter("User"));
properties.setProperty(Context.SECURITY_CREDENTIALS,
request.getParameter("Password"));final Context context = new InitialContext(properties);
// new InitialContext effectively calls user.begin() so
// we need to make sure we disassociate ourselves with the
// current thread.
final UserSession user =
(UserSession)context.lookup("allaire.ejipt.UserSession");
user.end();final HttpSession session = request.getSession(true);
session.putValue("context", context);
response.sendRedirect("balance");
}
catch (AuthenticationException authentication)
{
response.sendError(HttpServletResponse.SC_FORBIDDEN, "Authentication
failed");
}
catch (Exception exception)
{
throw new ServletException(exception);
}Scott Stirling
West Newton, MA> -----Original Message-----
> From: Marcelo Bellezo [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, September 20, 2000 10:46 AM
> To: [EMAIL PROTECTED]
> Subject: Re: [JRun-Talk] Non-Jrun specific way to get local
> EJBHomeObject?
>
>
> Hi,
>
> good point, to you have portability, use the following:
>
> Context context = new InitialContext();
> UserHome userHome =
> (UserHome)context.lookup("java:comp/env/ejb/sample10a.UserHome");
> final User user = userHome.findByPrimaryKey(name);
>
> But it only worked inside another EJB, I tryed it on a servlet and it
> doesn't worked.
>
> Regard's
>
> Marcelo Bellezo
>
> "Rhodes, Phillip C." wrote:
>
> > In JRun examples, they have the following code snippet that will get the
> > local EJBHome object for this bean.
> > final User user =
> > ((UserHome)ResourceManager.getLocalEJBHome("sample10a.UserHome")).findByPrim
> > aryKey(name);
> >
> > Although I love JRun :) I would like my code to not depend upon the
> > container. If I have already have an existing javax.ejb.SessionContext
> > object, how may I use this to objtain a reference to a local ejb home
> > object?
> >
> > Thanks.
> >
> > Phillip Rhodes
> > [EMAIL PROTECTED]
> > Alcoa eCommerce
> > https://www.ALCOADIRECT.COM
> > 826B Two Allegheny Center Pittsburgh, PA 15212
> > (412) 553-4900 (phone) (412) 553-2484 (fax)------------------------------------------------------------------------------
Archives: http://www.egroups.com/group/jrun-interest/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/jrun_talk
or send a message to [EMAIL PROTECTED] with 'unsubscribe' in the body.
