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;
or
@javax.ejb.EJB(mappedName="dorp.Content") private dorp.Content _local;
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
need for ejb-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
2. a web component on another physical server running another Sun
Application Server Ver 9.0.
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