2 Replies Latest reply on Jul 28, 2005 1:11 PM by Abby Pad

    Unable to catch the naming exception - please help!

    Abby Pad Newbie

      I have the following code segment in my code. We need to access this bean for several things, and for multiple app servers - the ip addresses and names of which are configurable. So based on the requirement, we pass the name or ip address to the code, and it first sets the context via the following piece of code and then accesses the services of the bean. This works fine when the ip address or name is correct. However if the ip address or name is incorrect (a) The machine is up, but app server is not or (b) no such machine exists or (c) we dont have access to the machine, it throws a javax.naming.communicationException. However, I am not able to catch this exception - i.e., it never goes to my catch block. It just appears on the log, and my code continues. This causes a lot of problems..I need to be able to get the exception and handle it. Am I missing something? Please help!! Very urgent! I am attaching a more detailed exception below. The exception varies slightly based on exactly what went wrong - but in all cases I never get to catch the exception.

      public void setMonitorContext(String appserverName) {
      Hashtable env = new Hashtable();

      env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
      env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
      env.put(Context.PROVIDER_URL, "jnp://" + appserverName + ":1099/");
      try {
      monitorEJB = null;
      ejbHome = null;
      ref = null;
      Context initialContext = new InitialContext(env);
      ref = initialContext.lookup("webservice/beans/MonitorHome");
      ejbHome = (MonitorHome) PortableRemoteObject.narrow(ref,MonitorHome.class);
      monitorEJB = ejbHome.create();
      } catch (NamingException e) {
      logger.info("Naming context for " + appserverName + " not found.");
      } catch (RemoteException re){
      logger.info("Create Exception in initial context:" + re);
      } catch (CreateException ce) {
      logger.info("Create Exception in initial context:" + ce);
      } catch (Exception justE) {
      logger.info("Caught exception in setMonitorContext" + justE);
      justE.printStackTrace();
      }
      }

      Exception trace:

      2005-07-27 14:35:15,908 64994 DEBUG [org.jnp.interfaces.NamingContext] (TP-Processor2:) Failed to connect to bocalhost:1099
      javax.naming.CommunicationException: Failed to connect to server bocalhost:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to
      connect to server bocalhost:1099 [Root exception is java.net.UnknownHostException: bocalhost: bocalhost]]
      at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:213)
      at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1187)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:516)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:509)
      at javax.naming.InitialContext.lookup(InitialContext.java:347)
      at com.mirra.webservice.beans.ManageMonitor.setMonitorContext(ManageMonitor.java:121)
      at com.mirra.webservice.beans.ManageMonitor.getCurrentTimeInMilliSeconds(ManageMonitor.java:246)
      at com.mirra.webservice.beans.ManageMonitor.getTimeInMillis(ManageMonitor.java:260)
      at com.mirra.webservice.account.Login.addFailedLogin(Login.java:253)
      at com.mirra.webservice.account.Login.checkUser(Login.java:413)
      at com.mirra.webservice.account.Login.checkUser(Login.java:353)
      at com.mirra.webservice.account.Login.setCommonSignIn(Login.java:1818)
      at com.mirra.webservice.account.Login.getRegularSignInRedirectLink(Login.java:1823)
      at org.apache.jsp.falcon.handleSignin_jsp._jspService(handleSignin_jsp.java:117)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
      at org.jboss.web.tomcat.tc5.JvmRouteFilter.doFilter(JvmRouteFilter.java:111)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
      at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
      at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:66)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:158)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
      at org.jboss.web.tomcat.tc5.session.ClusteredSessionValve.invoke(ClusteredSessionValve.java:80)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
      at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
      at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:300)
      at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:374)
      at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:743)
      at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:675)
      at org.apache.jk.common.SocketConnection.runIt(ChannelSocket.java:866)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
      at java.lang.Thread.run(Thread.java:534)
      Caused by: javax.naming.ServiceUnavailableException: Failed to connect to server bocalhost:1099 [Root exception is java.net.UnknownHostException: boca
      lhost: bocalhost]
      at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:187)
      ... 57 more
      Caused by: java.net.UnknownHostException: bocalhost: bocalhost
      at java.net.InetAddress.getAllByName0(InetAddress.java:1011)
      at java.net.InetAddress.getAllByName0(InetAddress.java:981)
      at java.net.InetAddress.getAllByName(InetAddress.java:975)
      at java.net.InetAddress.getByName(InetAddress.java:889)
      at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:61)
      at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:183)
      ... 57 more