0 Replies Latest reply on Aug 9, 2005 4:41 AM by aho

    Remote Access Between Two Servers

    aho

      I have written a JSP to perform a remote access to a session bean which in turn call an entity bean. The programs were packaged into a EAR file and deployed successfully and the programs works fine with the database updated correctly. The JSP was running in the Web Container and the session bean and entity bean in the EJB Container in the same JBOSS AS. I am trying to deploy the JSP(packaged as WAR file) in another server also with JBOSS AS installed, just to test the remote access across two physical diferrent servers. The EAR files deployed in the first server remains the same but for the WAR files I have made some changes so that it can be deployed in the second server. However, the JSP return an exception error when I load the page. Here are my codes and WAR file structure. Have any one tried remote access between two servers successfully? Would appreciate some advise.

      <<< Error Meesage return by JSP >>>
      type Exception report
      message

      description The server encountered an internal error () that prevented it from fulfilling this request.

      exception

      javax.servlet.ServletException: example.bean.session.AccountMaintenance not bound
      org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)
      org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
      org.apache.jsp.accountsetup_jsp._jspService(org.apache.jsp.accountsetup_jsp:189)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)

      root cause

      javax.naming.NameNotFoundException: example.bean.session.AccountMaintenance not bound
      org.jnp.server.NamingServer.getBinding(NamingServer.java:491)
      org.jnp.server.NamingServer.getBinding(NamingServer.java:499)
      org.jnp.server.NamingServer.getObject(NamingServer.java:505)
      org.jnp.server.NamingServer.lookup(NamingServer.java:278)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      java.lang.reflect.Method.invoke(Method.java:585)
      sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
      sun.rmi.transport.Transport$1.run(Transport.java:153)
      java.security.AccessController.doPrivileged(Native Method)
      sun.rmi.transport.Transport.serviceCall(Transport.java:149)
      sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
      sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
      java.lang.Thread.run(Thread.java:595)
      sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
      sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
      sun.rmi.server.UnicastRef.invoke(UnicastRef.java:126)
      org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
      org.jnp.interfaces.NamingContext.lookup(NamingContext.java:610)
      org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
      javax.naming.InitialContext.lookup(InitialContext.java:351)
      org.apache.jsp.accountsetup_jsp._jspService(org.apache.jsp.accountsetup_jsp:58)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)

      note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.
      Apache Tomcat/5.5.9

      <<< WAR file>
      accountsetup.jsp
      jndi.properties
      META-INF
      MANIFEST.MF
      WEB-INF
      web.xml
      jboss-web.xml
      classes
      example
      bean
      entity
      Account.class
      sesssion
      AccountMaintenance.class
      AccountMaintenanceBean.class




      <<<< JNDI Properties 192.168.0.54 is the IP addr of first server >>>
      java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
      java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
      java.naming.provider.url=192.168.0.54


      <<<< entity bean >>>>>
      package example.bean.entity;

      import javax.persistence.*;

      @Entity
      @Table(name = "ACCOUNT")
      public class Account implements java.io.Serializable {
      private int id;
      private String actName;
      private String actType;
      private double actBalance;
      private boolean actActive;

      @Id
      @Column(name="actName", nullable=false, length=50)
      public String getActName(){
      return this.actName;
      }

      public void setActName(String actName){
      this.actName = actName;
      }

      @Column(name="actType", nullable=false, length=50)
      public String getActType(){
      return this.actType;
      }

      public void setActType(String actType){
      this.actType = actType;
      }

      @Column(name="actBalance", nullable=false)
      public double getActBalance(){
      return this.actBalance;
      }

      public void setActBalance(double actBalance){
      this.actBalance = actBalance;
      }

      public void add(String actName, String actType, double actBalance){
      this.actName = actName;
      this.actType = actType;
      this.actActive = actActive;
      this.actBalance += actBalance;
      }

      @Column(name="actActive", nullable=false)
      public boolean getActActive(){
      return this.actActive;
      }

      public void setActActive(boolean actActive){
      this.actActive = actActive;
      }
      }

      <<<<<< Remote Interface >>>>
      package example.bean.session;

      import example.bean.entity.*;
      import java.util.*;

      public interface AccountMaintenance {
      void add(String actName, String actType, double actBalance);

      void update(String actName, String actType, double actBalance);

      void delete(String actName);

      Account find(String actName);

      Collection findByName(String actName);

      Collection getAccounts();
      }

      <<< Session Bean >>>>>
      package example.bean.session;

      import example.bean.entity.*;
      import javax.ejb.*;
      import javax.persistence.*;
      import java.util.*;

      @Stateless
      @Remote(AccountMaintenance.class)
      public class AccountMaintenanceBean implements AccountMaintenance {
      @PersistenceContext(unitName="MySqlMgr")
      private EntityManager manager;

      public void add(String actName, String actType, double actBalance) {
      try {
      Account account = new Account();
      account.setActActive(true);
      account.add(actName, actType, actBalance);
      manager.persist(account);
      }
      catch (Exception e) {
      }
      }

      public Account find(String actName) {
      return manager.find(Account.class, actName);
      }

      public Collection findByName(String actName){
      return manager.createQuery("from Account c where c.actName = :actName").setParameter("actName", actName).getResultList();
      }

      public Collection getAccounts(){
      return manager.createQuery("from Account c").getResultList();
      }

      public void update(String actName, String actType, double actBalance) {
      try {
      Account account = manager.find(Account.class, actName);
      account.setActType(actType);
      account.setActBalance(actBalance);
      }
      catch (Exception e) {
      }
      }

      public void delete(String actName) {
      try {
      Account account = manager.find(Account.class, actName);
      manager.remove(account);
      }
      catch (Exception e) {
      }
      }
      }

      <<<< JSP >>>>
      <%@ page import="example.bean.session.*, example.bean.entity.*, javax.naming.*, java.util.*, java.text.*" %>

      <%
      String errormsg = "";
      String name = "";
      String type = "";
      String command = "";
      double balance = 0;
      AccountMaintenance account = null;
      InitialContext ctx = new InitialContext();
      account = (AccountMaintenance) ctx.lookup(AccountMaintenance.class.getName());

      if ((request.getParameter ("name") != null) && (request.getParameter ("type") != null) &&
      (request.getParameter ("balance") != null)) {
      command = request.getParameter ("action");
      name = request.getParameter ("name");
      type = request.getParameter ("type");
      balance = Double.parseDouble(request.getParameter ("balance"));
      if (command.equals("Add")) {
      try {
      Account myAccount = account.find(name);
      if (myAccount != null) {
      errormsg = "Account already exists";
      } else {
      account.add(name, type, balance);
      }
      } catch (Exception e) {
      errormsg = e.toString();
      }
      }

      if (command.equals("Update")) {
      try {
      Account myAccount = account.find(name);
      if (myAccount == null) {
      errormsg = "Account not found";
      } else {
      account.update(name, type, balance);
      }
      } catch (Exception e) {
      errormsg = e.toString();
      }
      }

      if (command.equals("Delete")) {
      try {
      Account myAccount = account.find(name);
      if (myAccount == null) {
      errormsg = "Account not found";
      } else {
      account.delete(name);
      name = "";
      type = "";
      balance = 0.0;
      }
      } catch (Exception e) {
      errormsg = e.toString();
      }
      }

      } else {
      }
      Collection accountsCollection = account.getAccounts();
      %>




      Account Setup



      Name
      <input type="text" name="name" value=<%=name%>>


      Account Type
      <input type="text" name="type" value=<%=type%>>


      Balance
      <input type="text" name="balance" value=<%=Double.toString(balance)%>>









      System Message : <%=errormsg%>




      Name
      Account Type
      Balance
      Active

      <%
      for (Iterator iter = accountsCollection.iterator(); iter.hasNext();) {
      Account myAccount = (Account) iter.next();
      %>

      <%=myAccount.getActName()%>
      <%=myAccount.getActType()%>
      <%=Double.toString(myAccount.getActBalance())%>
      <%=myAccount.getActActive()%>

      <%
      }
      %>