User: peterbraswell
  Date: 02/04/11 20:42:03

  Modified:    jboss.net/src/main/org/jboss/net/jmx/server
                        MBeanProvider.java
  Log:
  added support in JMX->WSDL generation for attributes!
  
  Revision  Changes    Path
  1.7       +88 -76    
contrib/jboss.net/src/main/org/jboss/net/jmx/server/MBeanProvider.java
  
  Index: MBeanProvider.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/contrib/jboss.net/src/main/org/jboss/net/jmx/server/MBeanProvider.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- MBeanProvider.java        12 Apr 2002 02:32:52 -0000      1.6
  +++ MBeanProvider.java        12 Apr 2002 03:42:03 -0000      1.7
  @@ -6,7 +6,7 @@
    * See terms of license at gnu.org.
    */
   
  -// $Id: MBeanProvider.java,v 1.6 2002/04/12 02:32:52 peterbraswell Exp $
  +// $Id: MBeanProvider.java,v 1.7 2002/04/12 03:42:03 peterbraswell Exp $
   package org.jboss.net.jmx.server;
   
   
  @@ -66,8 +66,6 @@
   import java.util.Map;
   
   
  -
  -
   /**
    * Exposes mbeans as targets (pivot-handlers) of web-services. To
    * deploy a particular mbean as a web-service, a deployment descriptor
  @@ -95,7 +93,7 @@
    *
    * @created 1. Oktober 2001, 16:38
    * @author <a href="mailto:[EMAIL PROTECTED]";>Christoph G. Jung</a>
  - * @version $Revision: 1.6 $
  + * @version $Revision: 1.7 $
    */
   
   public class MBeanProvider
  @@ -127,8 +125,14 @@
      protected boolean initialized;
   
      /** Creates new MBeanProvider */
  -   
  -       private String allowedMethodsOption = "allowedMethods";
  +
  +   private String allowedMethodsOption = "allowedMethods";
  +
  +   /**
  +    * Constructor MBeanProvider
  +    *
  +    *
  +    */
   
      public MBeanProvider ()
      {
  @@ -367,24 +371,18 @@
               {
                  throw new AxisFault(Constants.EXCEPTION_OCCURED, e);
               }
  -         }   // if(nextBody instanceof RPCElement)
  -      }      // // while(allBodies.hasNext())
  -   }         // invoke
  -
  -   /**
  -    * ToDo, inspect mbean-interfaces or so?
  -    */
  +         }
  +      }
  +   }
   
      public void generateWSDL (MessageContext msgCtx)
         throws AxisFault
      {
  -     
  -       initialize(msgCtx);
  +      initialize(msgCtx);
   
  -      EngineConfiguration engineConfig =
  -         msgCtx.getAxisEngine().getConfig();
  +      EngineConfiguration engineConfig = msgCtx.getAxisEngine().getConfig();
   
  -     if (!(engineConfig instanceof XMLResourceProvider)) return;
  +      if (!(engineConfig instanceof XMLResourceProvider)) return;
   
         XMLResourceProvider config        =
            ( XMLResourceProvider ) engineConfig;
  @@ -397,65 +395,75 @@
         try
         {
            Thread.currentThread().setContextClassLoader(newLoader);
  -                 /* Find the service we're invoking so we can grab it's options */
  -        /***************************************************************/
  -        String serviceName = msgCtx.getTargetService();
  -        SOAPService service = msgCtx.getService();
  -
  -        /* Now get the service (RPC) specific info  */
  -        /********************************************/
  -        String  allowedMethods = getAllowedMethods(service);
  -
  -        /** ??? Should we enforce setting methodName?  As it was,
  -         * if it's null, we allowed any method.  This seems like it might
  -         * be considered somewhat insecure (it's an easy mistake to
  -         * make).  Tossing an Exception if it's not set, and using "*"
  -         * to explicitly indicate "any method" is probably better.
  -         */
  -        if ((allowedMethods == null) || allowedMethods.equals(""))
  -          throw new AxisFault("Server.NoMethodConfig",
  -            JavaUtils.getMessage("noOption00", info.getClassName(), serviceName),
  -            null, null);
   
  -        if (allowedMethods.equals("*"))
  +         String      serviceName    = msgCtx.getTargetService();
  +         SOAPService service        = msgCtx.getService();
  +         String      allowedMethods = getAllowedMethods(service);
  +
  +         if ((allowedMethods == null) || allowedMethods.equals(""))
  +            throw new AxisFault(
  +               "Server.NoMethodConfig",
  +               JavaUtils.getMessage(
  +               "noOption00", info.getClassName(), serviceName), null, null);
  +
  +         // Okay we want to expose everything.  Iterate through all the methods in 
the
  +         // MBeanInfo structure and pull out all operations and attribute accessors.
  +         if (allowedMethods.equals("*"))
            {
  -             
  -             
  -             
  -         }
   
  +            // Get the operations
  +            StringBuffer         exposedMethods = new StringBuffer();
  +            MBeanOperationInfo[] mboi           = info.getOperations();
  +            int                  i              = 0;
  +
  +            for (i = 0; i < mboi.length; i++)
  +               exposedMethods.append(mboi [i].getName() + " ");
  +
  +            // Get the attributes
  +            MBeanAttributeInfo[] mbai = info.getAttributes();
  +
  +            for (i = 0; i < mbai.length; i++)
  +            {
  +               if (mbai [i].isReadable())
  +                  exposedMethods.append("get" + mbai [i].getName() + " ");
  +
  +               if (mbai [i].isWritable())
  +                  exposedMethods.append("set" + mbai [i].getName() + " ");
  +            }
   
  -            String url = msgCtx.getStrProp(MessageContext.TRANS_URL);
  -            String urn = (String)msgCtx.getTargetService();
  -            String description = "JMX MBean exposed as a WebService";
  -
  -            Class cls = Class.forName(info.getClassName());
  -
  -            Emitter emitter = new Emitter();
  -            emitter.setMode(service.getStyle());
  -            emitter.setClsSmart(cls,url);
  -            emitter.setAllowedMethods(allowedMethods);
  -            emitter.setIntfNamespace(url);
  -            emitter.setLocationUrl(url);
  -            emitter.setTypeMapping((TypeMapping)msgCtx.getTypeMappingRegistry().
  -                                   
getTypeMapping(org.apache.axis.Constants.URI_CURRENT_SOAP_ENC));
  -            
emitter.setDefaultTypeMapping((TypeMapping)msgCtx.getTypeMappingRegistry().
  -                                          getDefaultTypeMapping());
  -            Document  doc = emitter.emit(Emitter.MODE_ALL);
  +            allowedMethods = exposedMethods.toString();
  +         }
   
  -            msgCtx.setProperty("WSDL", doc);
  +         String  url         = msgCtx.getStrProp(MessageContext.TRANS_URL);
  +         String  urn         = ( String ) msgCtx.getTargetService();
  +         String  description = "JMX MBean exposed as a WebService";
  +         Class   cls         = Class.forName(info.getClassName());
  +         Emitter emitter     = new Emitter();
  +
  +         emitter.setMode(service.getStyle());
  +         emitter.setClsSmart(cls, url);
  +         emitter.setAllowedMethods(allowedMethods);
  +         emitter.setIntfNamespace(url);
  +         emitter.setLocationUrl(url);
  +         emitter.setTypeMapping(
  +            ( TypeMapping ) msgCtx.getTypeMappingRegistry().getTypeMapping(
  +               org.apache.axis.Constants.URI_CURRENT_SOAP_ENC));
  +         emitter.setDefaultTypeMapping(
  +            ( TypeMapping ) 
msgCtx.getTypeMappingRegistry().getDefaultTypeMapping());
   
  +         Document doc = emitter.emit(Emitter.MODE_ALL);
  +
  +         msgCtx.setProperty("WSDL", doc);
         }
         catch (Exception ex)
         {
  -               ex.printStackTrace();
  -          Thread.currentThread().setContextClassLoader(currentLoader);
  -         throw new AxisFault(Constants.COULDNT_GEN_WSDL, ex);
  +         ex.printStackTrace();
  +         Thread.currentThread().setContextClassLoader(currentLoader);
   
  +         throw new AxisFault(Constants.COULDNT_GEN_WSDL, ex);
         }
  -      
  -      Thread.currentThread().setContextClassLoader(currentLoader);
   
  +      Thread.currentThread().setContextClassLoader(currentLoader);
      }
   
      /**
  @@ -467,17 +475,21 @@
   
         // unbelievable this foresight
      }
  -   
  -       private String getAllowedMethods(Handler service)
  -    {
  -        String val = (String)service.getOption(allowedMethodsOption);
  -        if (val == null || val.length() == 0) {
  -            // Try the old option for backwards-compatibility
  -            val = (String)service.getOption("methodName");
  -        }
  -        return val;
  -    }
  +
  +   private String getAllowedMethods (Handler service)
  +   {
  +      String val = ( String ) service.getOption(allowedMethodsOption);
  +
  +      if (val == null || val.length() == 0)
  +      {
  +
  +         // Try the old option for backwards-compatibility
  +         val = ( String ) service.getOption("methodName");
  +      }
  +
  +      return val;
  +   }
   }
   
   
  -/*------ Formatted by Jindent 3.23 Basic 1.0 --- http://www.jindent.de ------*/
  +
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to