ejb@glassfish.java.net

Re: Remote EJB Access

From: Kenneth Saks <Kenneth.Saks_at_Sun.COM>
Date: Tue, 13 Jun 2006 17:23:01 -0400

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
>
>
>
>>
>>
>>
>
>
>