10 Replies Latest reply on Jan 6, 2009 6:55 PM by pmuir

    can't lookup the manager

    freemant
      Hi,

      I'm trying to look up the manager using the code below:

      public class MyServlet extends HttpServlet {
          @Override
          protected void doGet(HttpServletRequest req, HttpServletResponse resp)
                  throws ServletException, IOException {
              try {
                  Context c = new InitialContext();
                  Object obj = c.lookup("java:comp/Manager");
                  Manager m = (Manager)PortableRemoteObject.narrow(obj, Manager.class);
                  PrintWriter writer = resp.getWriter();
                  writer.print("test");
                  writer.print(m != null);
              } catch (NamingException e) {
                  throw new RuntimeException(e);
              }
          }
      }

      However, it fails with the following exception. That is, what is returned is a
      MarshalledValuePair, not a Manager. Any idea?

      java.lang.ClassCastException
           at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:229)
           at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
           at foo.MyServlet.doGet(MyServlet.java:23)
           at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
           at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
           at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
           at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
           at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
           at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
           at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)
           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
           at java.lang.Thread.run(Thread.java:619)
      Caused by: java.lang.ClassCastException: org.jnp.interfaces.MarshalledValuePair cannot be cast to org.omg.CORBA.Object
           at com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:212)
           ... 24 more
        • 1. Re: can't lookup the manager
          graben

          To do a lookup is not the most elegant was to get the Manager. You should better let webbeans inject a Manager instance:


          @Current Manager manager



          If you want to do a native lookup try to cast the lookup result directly to Manager. That should solve to error since in my opinion no corba is needed.


          Regards Benjamin

          • 2. Re: can't lookup the manager
            freemant

            Thanks for the reply.


            I'm just testing how to obtain the Manager from some where other than a web bean.


            I had tried casting the lookup result directly to a Manager but it failed as a
            MarshalledValuePair cannot be cast to a Manager.

            • 3. Re: can't lookup the manager
              graben

              Hmm. Do you import the right Object type?



              cannot be cast to org.omg.CORBA.Object

              I think that should be of type java.lang.Object. Try this and than get the Manager out of that.

              • 4. Re: can't lookup the manager
                gavin.king

                The RI doesn't yet support injection into Servlets, so he can't (yet) do it that way in this case.

                • 5. Re: can't lookup the manager
                  freemant

                  The cast to org.omg.CORBA.Object is done inside PortableRemoteObject.narrow(), not
                  in my code, so this is not related to my code.

                  • 6. Re: can't lookup the manager
                    gavin.king

                    Have you tried with an ordinary Java typecast, instead of the whole PortableRemoteObject.narrow() crap?

                    • 7. Re: can't lookup the manager
                      freemant
                      Yeah, that was my first attempt and it failed with ClassCastException. In fact,
                      either the JNDI in JBoss AS5 is broken or the webbeans updater has messed it
                      up, as the following code also fails with a ClassCastException:

                      public class MyServlet extends HttpServlet {
                          @Override
                          protected void doGet(HttpServletRequest req, HttpServletResponse resp)
                                  throws ServletException, IOException {
                              try {
                                  PrintWriter writer = resp.getWriter();
                                  Context c = new InitialContext();
                                  c.rebind("java:comp/foo", "hello");
                                  String s = (String) c.lookup("java:comp/foo");
                                  writer.print(s);
                              } catch (NamingException e) {
                                  throw new RuntimeException(e);
                              }
                          }
                      }

                      The stack trace is:

                      java.lang.ClassCastException: org.jnp.interfaces.MarshalledValuePair cannot be cast to java.lang.String
                           foo.MyServlet.doGet(MyServlet.java:22)
                           javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
                           javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
                           org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                      • 8. Re: can't lookup the manager
                        pmuir

                        Can you try that without the Web Beans update, just to check. Then, if it's a problem, report in the JBoss 5 forum?

                        • 9. Re: can't lookup the manager
                          pmuir
                          • 10. Re: can't lookup the manager
                            pmuir

                            I think I fixed this, please test.