4 Replies Latest reply on May 29, 2007 7:22 AM by nappinc

    Local JNDI lookup in local JMX bean?

      I have a J2EE 1.4 web application (a single .war packaged in a single .ear) that contains includes both Web Service client code and some JMX beans. I can successfully invoke the web service in the web app via a JNDI lookup, but when invoking the web service from one of the JMX beans (via the JBoss Web Console) JNDI lookup fails with "service not bound".

      My service reference (in web.xml) is as follows:

      <service-ref>
       <description>Web Service Client</description>
       <service-ref-name>service/GMS</service-ref-name>
       <service-interface>javax.xml.rpc.Service</service-interface>
       <wsdl-file>WEB-INF/wsdl/gms.wsdl</wsdl-file>
       <jaxrpc-mapping-file>WEB-INF/gms-mapping.xml</jaxrpc-mapping-file>
       <service-qname xmlns:tns="http://..snip../gms">tns:GMS</service-qname>
      </service-ref>


      And my JNDI lookup is as follows:

      Context context = new InitialContext();
      Service service = (Service) context.lookup("java:comp/env/service/GMS");


      The lookup code is called both from JMX and from code invoked by a servlet. In the servlet the lookup works, but in JMX the lookup fails.

      We're using JBoss 4.0.4, Java 1.4.2, and Spring 1.2.5 to handle publishing the JMX MBeans.

        • 1. Re: Local JNDI lookup in local JMX bean?
          genman

          "java:comp/env" is a context only provided to EJBs and Servlets, it's not available from your MBeans.

          You need to use a different strategy to access your web client. For this particular service, I don't really know. But take a look at the JNDI tree through the JNDI viewer and see if it's also available under a different name. Or look for docs that explain how to use this client external to EJBs...

          • 2. Re: Local JNDI lookup in local JMX bean?

             

            "genman" wrote:
            "java:comp/env" is a context only provided to EJBs and Servlets, it's not available from your MBeans.

            You need to use a different strategy to access your web client. For this particular service, I don't really know. But take a look at the JNDI tree through the JNDI viewer and see if it's also available under a different name. Or look for docs that explain how to use this client external to EJBs...


            Sounds like I've managed to find a corner case that J2EE 1.4 doesn't cope for...

            The JNDIView MBean shows that my service-ref is not published under the java: or global JNDI contexts. Is there any way that I can do that, in addition to publishing it under the local java:comp/env context?

            Alternatively I guess I'll have to revert to J2SE-style Service invocation, which seems bizarre and excessive given all this code is in the same .war file... ;(

            • 3. Re: Local JNDI lookup in local JMX bean?

               

              "nappinc" wrote:

              The JNDIView MBean shows that my service-ref is not published under the java: or global JNDI contexts. Is there any way that I can do that, in addition to publishing it under the local java:comp/env context?


              I assume from the lack of replies that this isn't possible?

              "nappinc" wrote:

              Alternatively I guess I'll have to revert to J2SE-style Service invocation, which seems bizarre and excessive given all this code is in the same .war file... ;(


              I'm trying this now, using the J2SE Dynamic Proxy style, and am struggling to get it to work in a JMX context in JBoss.

              My web service client code is as follows:

              URL wsdl = servletContext.getResource("/WEB-INF/wsdl/gms.wsdl");
              
              // debug the contents of the URL
              
              ServiceFactory factory = ServiceFactory.newInstance();
              Service service = factory.createService(
               wsdl, new QName("..namespace..", "GMS"));
              GMSPort gms = (GMSPort) service.getPort(
               new QName("..namespace..", "GMSPort"), GMSPort.class);
              


              However this fails with:

              java.io.FileNotFoundException
               at org.apache.naming.resources.DirContextURLConnection.getInputStream(DirContextURLConnection.java:297)
               at java.net.URL.openStream(URL.java:1007)
               at org.jboss.ws.metadata.wsdl.WSDLDefinitionsFactory.getDocument(WSDLDefinitionsFactory.java:181)
               ... 44 more
              


              Note that the URL (wsdl.toExternalForm()) is jndi:/localhost/pegasus/WEB-INF/wsdl/gms.wsdl, and a little debug code in the JMX bean is able to open this URL as an InputStream and output all the WSDL file's contents.

              If I simply create a JAX-RPC Service instance without providing the wsdl URL, I get a "Unable to obtain Service Meta Data" error.

              Can anyone suggest an alternative, preferably one that doesn't require hard-coding file locations on the app server?

              This is using JBoss 4.0.4, with JBossWS 1.0.3GA and a version of JBossXB 1.0.0 CR6 (with JBoss patch JBAS-3581).

              • 4. Re: Local JNDI lookup in local JMX bean?

                 

                "nappinc" wrote:

                Note that the URL (wsdl.toExternalForm()) is jndi:/localhost/pegasus/WEB-INF/wsdl/gms.wsdl, and a little debug code in the JMX bean is able to open this URL as an InputStream and output all the WSDL file's contents.

                If I simply create a JAX-RPC Service instance without providing the wsdl URL, I get a "Unable to obtain Service Meta Data" error.


                If I change using servlet-context relative URLs for an external URL (http://someserver:someport/blah?WSDL) - not really something I want to do but there you go - I can still successfully debug the contents of the WSDL file but I get an error related to a method in the WSDL that I'm not even calling:

                org.jboss.ws.WSException: Cannot obtain java type mapping for: {http://www.abm-uk.com/abmpegasus/v5.0/gms}>Search
                 at org.jboss.ws.deployment.JSR109MetaDataBuilder.buildParameterMetaDataDoc(JSR109MetaDataBuilder.java:451)
                 at org.jboss.ws.deployment.JSR109MetaDataBuilder.setupOperationsFromWSDL(JSR109MetaDataBuilder.java:200)
                 at org.jboss.ws.deployment.JSR109ClientMetaDataBuilder.buildMetaDataInternal(JSR109ClientMetaDataBuilder.java:208)
                 at org.jboss.ws.deployment.JSR109ClientMetaDataBuilder.buildMetaData(JSR109ClientMetaDataBuilder.java:126)
                 at org.jboss.ws.deployment.JSR109ClientMetaDataBuilder.buildMetaData(JSR109ClientMetaDataBuilder.java:82)
                 at org.jboss.ws.jaxrpc.ServiceImpl.<init>(ServiceImpl.java:96)
                 at org.jboss.ws.jaxrpc.ServiceFactoryImpl.createService(ServiceFactoryImpl.java:157)
                 at org.jboss.ws.jaxrpc.ServiceFactoryImpl.createService(ServiceFactoryImpl.java:128)