Ning Zhu wrote:
> Hi Ken,
> You are so helpful. As a matter of fact, we found more about EJB
> reference yesterday. And here are our findings.
> The line:
> @javax.ejb.EJB(name="dorp.Content") private dorp.Content _local;
> if the root cause of the problem, you can either use
> @javax.ejb.EJB(name="corbaname:iiop:localhost:3700#dorp.Content")
> private dorp.Content _local;
Hi Ning,
The name() attribute assigns a name to the ejb dependency within the
private component namespace. This value is relative to java:comp/env and
has the same semantics as the ejb-ref-name element. It only refers to
the entry within java:comp/env, *not* to the global JNDI name of the
target ejb. In many cases when injection is being used, the developer
doesn't ever have to explicitly refer to this java:comp/env name. That's
why any value you use works. Your second example actually doesn't do any
corba interoperable naming lookup. All it does is assign a location
within the private component environment called :
"java:comp/env/corbaname:iiop:localhost:3700#dorp.Content"
Each remote ejb dependency must be mapped to global JNDI name of the
target Remote EJB. This can be done via a sun-*.xml file (e.g.
sun-ejb-jar.xml) or by using the mappedName() attribute (more on that
below). However, in the absence of those the target global jndi name
will default to the fully-qualified name of the remote interface type of
the @EJB. So, both of the examples above will have a default target
global JNDI name of "dorp.Content", independent of the name of the
dependency itself.
Also, the fact that this worked in your app means the target EJB must be
deployed to the same server instance as the component that declared the
@EJB. There is indeed a bug that will prevent the corba interoperable
name from being used to map the remote ejb 30 dependency to an ejb in
another server instance. That's the issue filed as
https://glassfish.dev.java.net/issues/show_bug.cgi?id=735
> or
> @javax.ejb.EJB(mappedName="dorp.Content") private dorp.Content _local;
mappedName() is one way to assign the vendor-specific mapping name for
the environment dependency. It's equivalent to using the jndi-name
element in sun-*.xml. We have a presentation that covers many of these
topics available at :
https://glassfish.dev.java.net/javaee5/ejb/compdependencies_xmlforum_nov15.pdf.
> either one works fine. As for the reason, we are not 100% clear yet.
> We are thinking of that "name" property is fully qualified global jndi
> name
no, see above.
> (no need forejb-ref stuff in configuration files); while "mappedName"
> is NOT a fully qualified global jndi name (do need ejb-ref in the
> configuration files). This is just FYI.
> We have another question for you, which is about security. We
> successfully implement security on the same application server for all
> kinds of stuff. We want to know whether there is a way to secure
> 1. a standalone java client
First off, we recommend you use a Java EE client component called an
Application Client instead of a stand-alone java client. Stand-alone
java clients are not portable so in the long run you're better off using
a 1st-class Java EE component. That way, you can also take advantage of
all the ease-of-use features in Java EE 5 such as injection. There is
some more coverage of the difference between the two in our FAQ.
Here's a link on accessing a secure EJB from a stand-alone client :
http://java.sun.com/developer/EJTechTips/2006/tt0225.html#2
> 2. a web component onanother physical server running anotherSun
> Application Server Ver 9.0.
For Remote EJB invocations between server instances, the caller id
should automatically propagate.
> For standalone client, we tried to set up some IOR setting in
> <ior-security-config>
> <transport-config>
> <integrity>SUPPORTED</integrity>
> <confidentiality>SUPPORTED</confidentiality>
> <establish-trust-in-target>SUPPORTED</establish-trust-in-target>
> <establish-trust-in-client>SUPPORTED</establish-trust-in-client>
> </transport-config>
> <as-context>
> <auth-method>USERNAME_PASSWORD</auth-method>
> <realm>file</realm>
> <required>false</required>
> </as-context>
> <sas-context>
> <caller-propagation>SUPPORTED</caller-propagation>
> </sas-context>
> </ior-security-config>
> Also, we set up following properties to the InitialContext before lookup:
> java.naming.security.principal
> and
> java.naming.security.credentials
> with user name and password respectively.
> But we still hit by an unauthorized error.
> Can you direct us to some samples for this?
> Since we cannot even make a standalone client working for security, we
> stopped testing for security on remote web component. If you have
> sample in that area, please direct us as well.
> Thanks a lot,
> Ning
>
>
> -----Original Message-----
> *From:* Kenneth.Saks_at_Sun.COM [mailto:Kenneth.Saks_at_Sun.COM]
> *Sent:* Tuesday, June 13, 2006 5:23 PM
> *To:* Ning Zhu
> *Cc:* ejb_at_glassfish.dev.java.net
> *Subject:* Re: Remote EJB Access
>
> Ning Zhu wrote:
>
>>Thanks Ken,
>>
>>Your information is very helpful, we have made the java client working now,
>>which is cool!
>>
>>
> Hi Ning,
> Glad to hear it. I made the edits to our FAQ as well. Thanks for
> finding this error.
>
>>Here is code for EJB and Web Component (really basic and bare to bone stuff)
>>
> Regarding the Remote 3.0 lookup using the corbaname syntax, this
> looks like a bug in our implementation which we'll fix. It's filed
> as :
>
>https://glassfish.dev.java.net/issues/show_bug.cgi?id=735
>
>
> There's a workaround listed in the bug report involving the use of
> a adapted 2.x Home view. Let me know if you need any more info on
> getting that to work. Thanks.
>
> --ken
>
>>EJB:
>>
>>Content.java
>>
>>package dorp;
>>
>>import javax.ejb.Remote;
>>
>>@Remote
>>public interface Content {
>> String sayHello();
>>}
>>
>>ContentBean.java
>>
>>package dorp;
>>
>>import javax.ejb.Stateless;
>>
>>@Stateless
>>
>>public class ContentBean implements dorp.Content {
>> public ContentBean() {
>> }
>>
>> public String sayHello() {
>> return "Hello, World!";
>> }
>>}
>>
>>sun-ejb-jar.xml
>>
>><?xml version="1.0" encoding="UTF-8"?>
>><!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application
>>Server 9.0 EJB 3.0//EN"
>>"http://www.sun.com/software/appserver/dtds/sun-ejb-jar_3_0-0.dtd">
>><sun-ejb-jar>
>> <enterprise-beans/>
>></sun-ejb-jar>
>>
>>And here is the Web Component:
>>
>>/*
>> * ServletContent.java
>> *
>> * Created on June 8, 2006, 11:57 AM
>> */
>>
>>package dorpa;
>>
>>import java.io.*;
>>import java.net.*;
>>
>>import javax.servlet.*;
>>import javax.servlet.http.*;
>>
>>/**
>> *
>> * @author nzhu
>> * @version
>> */
>>public class ServletContent extends HttpServlet {
>> @javax.ejb.EJB(name="dorp.Content") private dorp.Content _local;
>>
>> /** Processes requests for both HTTP <code>GET</code> and
>><code>POST</code> methods.
>> * @param request servlet request
>> * @param response servlet response
>> */
>> protected void processRequest(HttpServletRequest request,
>>HttpServletResponse response)
>> throws ServletException, IOException {
>>
>> response.setContentType("text/html;charset=UTF-8");
>> PrintWriter out = response.getWriter();
>> /* TODO output your page here
>> out.println("<html>");
>> out.println("<head>");
>> out.println("<title>Servlet ServletContent</title>");
>> out.println("</head>");
>> out.println("<body>");
>> out.println("<h1>Servlet ServletContent at " +
>>request.getContextPath () + "</h1>");
>> out.println("</body>");
>> out.println("</html>");
>> */
>> String mystr = _local.getContentByID(0);
>> out.println(mystr);
>> out.close();
>> }
>>
>> // <editor-fold defaultstate="collapsed" desc="HttpServlet methods.
>>Click on the + sign on the left to edit the code.">
>> /** Handles the HTTP <code>GET</code> method.
>> * @param request servlet request
>> * @param response servlet response
>> */
>> protected void doGet(HttpServletRequest request, HttpServletResponse
>>response)
>> throws ServletException, IOException {
>> processRequest(request, response);
>> }
>>
>> /** Handles the HTTP <code>POST</code> method.
>> * @param request servlet request
>> * @param response servlet response
>> */
>> protected void doPost(HttpServletRequest request, HttpServletResponse
>>response)
>> throws ServletException, IOException {
>> processRequest(request, response);
>> }
>>
>> /** Returns a short description of the servlet.
>> */
>> public String getServletInfo() {
>> return "Short description";
>> }
>> // </editor-fold>
>>}
>>
>>web.xml:
>>
>><?xml version="1.0" encoding="UTF-8"?>
>><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
>>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
>>http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
>> <servlet>
>> <servlet-name>ServletContent</servlet-name>
>> <servlet-class>dorpa.ServletContent</servlet-class>
>> </servlet>
>> <servlet-mapping>
>> <servlet-name>ServletContent</servlet-name>
>> <url-pattern>/ServletContent</url-pattern>
>> </servlet-mapping>
>> <session-config>
>> <session-timeout>
>> 30
>> </session-timeout>
>> </session-config>
>> <welcome-file-list>
>> <welcome-file>
>> index.jsp
>> </welcome-file>
>> </welcome-file-list>
>> <ejb-ref>
>> <ejb-ref-name>dorp.Content</ejb-ref-name>
>> <ejb-ref-type>Session</ejb-ref-type>
>> <home/>
>> <remote>dorp.Content</remote>
>> </ejb-ref>
>> </web-app>
>>
>>sun-web.xml
>>
>><?xml version="1.0" encoding="UTF-8"?>
>><!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application
>>Server 9.0 Servlet 2.5//EN"
>>"http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd">
>><sun-web-app error-url="">
>> <context-root>/DORP-war</context-root>
>> <ejb-ref>
>> <ejb-ref-name>dorp.Content</ejb-ref-name>
>> <jndi-name>corbaname:iiop:localhost:3700#dorp.Content</jndi-name>
>> </ejb-ref>
>> <class-loader delegate="true"/>
>> <jsp-config>
>> <property name="classdebuginfo" value="true">
>> <description>Enable debug info compilation in the generated servlet
>>class</description>
>> </property>
>> <property name="mappedfile" value="true">
>> <description>Maintain a one-to-one correspondence between static
>>content and the generated servlet class' java code</description>
>> </property>
>> </jsp-config>
>></sun-web-app>
>>
>>The server we are on is SUN APP SERVER ver 9.0 and iiop port is 3700.
>>
>>Thanks,
>>Ning
>>
>>-----Original Message-----
>>From: Kenneth.Saks_at_Sun.COM [mailto:Kenneth.Saks_at_Sun.COM]
>>Sent: Tuesday, June 13, 2006 10:26 AM
>>To: Ning Zhu
>>Cc: ejb_at_glassfish.dev.java.net
>>Subject: Re: Remote EJB Access
>>
>>
>>Ning Zhu wrote:
>>
>>
>>
>>>Hi There,
>>>
>>>We are evaluating J2EE 5 for the company and now we are hitting by remote
>>>EJB access. We have followedd exact steps at the URL:
>>>
>>>https://glassfish.dev.java.net/java5ee/ejb/EJB_FAQ.html#StandaloneRemoteEJB
>>>
>>>However, at the line
>>>
>>>InitialContext ic = new InitialContext();
>>>
>>>
>>>
>>Hi Ning,
>>
>>Try adding javaee.jar as well. That's an omission in the ejb faq which
>>we'll fix.
>>
>>
>>
>>>Of the same importance, we are trying to access EJB through a web module.
>>>Here is the jdni mapping tags in
>>>
>>><ejb-ref>
>>> <ejb-ref-name>dorp.Content</ejb-ref-name>
>>> <jndi-name>dorp.Content</jndi-name>
>>></ejb-ref>
>>>
>>>
>>>This works perfect, when we have both EJB and Web component running in the
>>>same physical server in the same domain.
>>>
>>>However, when we try to deploy the Web component onto another server, so we
>>>try:
>>>
>>><ejb-ref>
>>> <ejb-ref-name>dorp.Content</ejb-ref-name>
>>> <jndi-name>corbaname:iiop:localhost:3700#dorp.Content</jndi-name>
>>></ejb-ref>
>>>
>>>
>>>
>>What kind of a Remote EJB is it? EJB 2.1 Home or an EJB 3.0 Remote
>>Business interface? What host/port is the target server running on? Are
>>you injecting it or looking it up via java:comp/env? There's no need to
>>define an ejb-ref if you're also defining an @EJB annotation. Please
>>post the source code snippet as well. Thanks.
>>
>>--ken
>>
>>
>>
>>>
>>>
>>
>>
>>
>
>