FileDocCategorySizeDatePackage
AdminAPIEntryServlet.javaAPI DocGlassfish v2 API14794Fri May 04 22:34:08 BST 2007com.sun.enterprise.admin.server.core.servlet

AdminAPIEntryServlet

public class AdminAPIEntryServlet extends HttpServlet
This is the entry point to the Admin Framework's API layer. For each HTTP Request it receives, its principal functionality is to
  • deserialize the serialized java objects on its input stream sent by the client.
  • send the deserialized java objects to dispatcher available to it.
  • wait on dispatcher to return with response.
  • send the response on output stream after serializing it. Hence it is to be noted that this class deals with serialized java objects.
  • Fields Summary
    private static com.sun.enterprise.util.i18n.StringManager
    localStrings
    private MBeanServer
    mMBeanServer
    private Logger
    mLogger
    private final int
    SUPPORTED_CLIENT_MAJOR_VERSION
    private final int
    SUPPORTED_CLIENT_MINOR_VERSION
    Constructors Summary
    Methods Summary
    private synchronized com.sun.enterprise.admin.common.AdminResponsecallGetAttribute(com.sun.enterprise.admin.common.AdminRequest req)

            Object  invokeResult = null;
            AdminResponse response = new AdminResponse();
            AdminResponseConfigurator responseConfig = new 
                AdminResponseConfigurator(response);
            AdminRequestConfigurator requestConfig = new
                AdminRequestConfigurator(req);
            ObjectName	objName	    = requestConfig.getObjectName();
            String      attrName    = requestConfig.getAttributeName();
            try
            {
                invokeResult = mMBeanServer.getAttribute(objName, attrName);
                responseConfig.setReturnValue((Serializable)invokeResult);
                mLogger.log(Level.FINE, "comm.get_attr_ok", objName);
            }
            catch(Exception e)
            {
                mLogger.log(Level.WARNING, "comm.get_attr_failed", unwrapMBeanException(e));
    	        responseConfig.setException(e);
            }
            return ( response );
        
    private synchronized com.sun.enterprise.admin.common.AdminResponsecallGetAttributes(com.sun.enterprise.admin.common.AdminRequest req)

            Object  invokeResult = null;
            AdminResponse response = new AdminResponse();
            AdminResponseConfigurator responseConfig = new 
                AdminResponseConfigurator(response);
            AdminRequestConfigurator requestConfig = new
                AdminRequestConfigurator(req);
            ObjectName  mbeanName   = requestConfig.getObjectName();
            String[]    attributes  = requestConfig.getAttributeNames();
            try
            {
                AttributeList values = mMBeanServer.getAttributes(mbeanName, 
                                                                  attributes);
                responseConfig.setReturnValue(values);
                mLogger.log(Level.FINE, "comm.get_attrs_ok", mbeanName);
            }
            catch(Exception t)
            {
                mLogger.log(Level.WARNING, "comm.get_attrs_failed", unwrapMBeanException(t));
                responseConfig.setException(t);
            }
            return ( response );
        
    private synchronized com.sun.enterprise.admin.common.AdminResponsecallInvoke(com.sun.enterprise.admin.common.AdminRequest req)

            Object  invokeResult = null;
            AdminResponse response = new AdminResponse();
            AdminResponseConfigurator responseConfig = new 
                AdminResponseConfigurator(response);
            AdminRequestConfigurator requestConfig = new
                AdminRequestConfigurator(req);
            ObjectName	objName	    = requestConfig.getObjectName();
            String		oprName	    = requestConfig.getOperationName();
            Object[]	params	    = requestConfig.getOperationParams();
            String[]	signature   = requestConfig.getOperationSignature();
            try
            {
                invokeResult = 
                    mMBeanServer.invoke(objName, oprName, params, signature);
                responseConfig.setReturnValue((Serializable)invokeResult);
                mLogger.log(Level.FINE, "comm.remote_invoke_ok", objName);
            }
            catch(Exception e)
            {
                mLogger.log(Level.WARNING, "comm.remote_invoke_failed", unwrapMBeanException(e));
    	        responseConfig.setException(e);
    	    }
    	    return ( response );
        
    private synchronized com.sun.enterprise.admin.common.AdminResponsecallMBean(com.sun.enterprise.admin.common.AdminRequest req)

            String type = req.getRequestType();
            AdminResponse response =  null;
    
            if (type.equals(AdminRequestType.INVOKE))
    	    {
    		    response = callInvoke(req);
    	    }
            else if(type.equals(AdminRequestType.GET_ATTRIBUTE))
            {
                response = callGetAttribute(req);
            }
            else if(type.equals(AdminRequestType.SET_ATTRIBUTE))
            {
                response = callSetAttribute(req);
            }
            else if (type.equals(AdminRequestType.GET_ATTRIBUTES))
            {
                response = callGetAttributes(req);
            }
            else if (type.equals(AdminRequestType.SET_ATTRIBUTES))
            {
                response = callSetAttributes(req);
            }
            else
            {
                response = new AdminResponse();
                AdminResponseConfigurator config = new 
                    AdminResponseConfigurator(response);
                config.setException(new Exception("No Such Type"));
    	    }
    	    return ( response );
        
    private synchronized com.sun.enterprise.admin.common.AdminResponsecallSetAttribute(com.sun.enterprise.admin.common.AdminRequest req)

            Object  invokeResult = null;
            AdminResponse response = new AdminResponse();
            AdminResponseConfigurator responseConfig = new 
                AdminResponseConfigurator(response);
            AdminRequestConfigurator requestConfig = new
                AdminRequestConfigurator(req);
            ObjectName	objName	    = requestConfig.getObjectName();
            Attribute   attribute   = requestConfig.getAttribute();
            try
            {
                mMBeanServer.setAttribute(objName, attribute);
                String setValue = "value set: " + attribute.getValue();
                responseConfig.setReturnValue(setValue);
                mLogger.log(Level.FINE, "comm.set_attr_ok", objName);
            }
            catch(Exception e)
            {
                mLogger.log(Level.WARNING, "comm.set_attr_failed", unwrapMBeanException(e));
    	        responseConfig.setException(e);
            }
            return ( response );
        
    private synchronized com.sun.enterprise.admin.common.AdminResponsecallSetAttributes(com.sun.enterprise.admin.common.AdminRequest req)

            Object  invokeResult = null;
            AdminResponse response = new AdminResponse();
            AdminResponseConfigurator responseConfig = new 
                AdminResponseConfigurator(response);
            AdminRequestConfigurator requestConfig = new
                AdminRequestConfigurator(req);
            ObjectName      mbeanName   = requestConfig.getObjectName();
            AttributeList   attributes  = requestConfig.getAttributeList();
            try
            {
                AttributeList values = mMBeanServer.setAttributes(mbeanName, 
                                                                  attributes);
                responseConfig.setReturnValue(values);
                mLogger.log(Level.FINE, "comm.set_attrs_ok", mbeanName);
            }
            catch(Exception e)
            {
                mLogger.log(Level.WARNING, "comm.set_attrs_failed", unwrapMBeanException(e));
                responseConfig.setException(e);
            }
            return ( response );
        
    private com.sun.enterprise.admin.common.AdminResponseclientVersionCheck(com.sun.enterprise.admin.common.AdminRequest req)

            AdminRequestConfigurator requestConfig = new
                AdminRequestConfigurator(req);
            String	clientVersion = null;
            try
            {
                clientVersion  = requestConfig.getClientVersion();
                int dotIdx = clientVersion.indexOf('.");
                int majorVersion = (Integer.valueOf(clientVersion.substring(0, dotIdx))).intValue();
                int minorVersion = (Integer.valueOf(clientVersion.substring(dotIdx+1))).intValue();
                if(majorVersion == SUPPORTED_CLIENT_MAJOR_VERSION &&
                   minorVersion <= SUPPORTED_CLIENT_MINOR_VERSION /* backward compartibility */)
                    return null;
            }
            catch (Exception e)
            {
            }
            
            // here we are only in case of non-matching version
            // prepare and wrap exception
            AdminResponse response = new AdminResponse();
            AdminResponseConfigurator config = new AdminResponseConfigurator(response);
            String msg;
            if(clientVersion == null)
                msg = localStrings.getString( "admin.server.core.servlet.no_client_version" );
            else
                msg = localStrings.getString( "admin.server.core.servlet.nonsupported_client_version", clientVersion);
            config.setException(new AFRuntimeException(msg));
            return response;
    	
    public voiddoGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)

            Serializable resultObject = "TEST";
            try
            {
                mLogger.log(Level.FINE, "comm.recd_request");
                ObjectInputStream inpStream = new ObjectInputStream (
    			new BufferedInputStream(
    				request.getInputStream()));
                Object obj = inpStream.readObject();
                AdminRequest adminRequest = (AdminRequest)obj;
                
                resultObject = clientVersionCheck(adminRequest);
    			if(resultObject == null)
    				resultObject = callMBean(adminRequest);
    
                ObjectOutputStream oos = new ObjectOutputStream (
                       new BufferedOutputStream (response.getOutputStream ()));
    
                response.setHeader("Content-type", "application/octet-stream");
                final int contentLength = getContentLength(resultObject);
                response.setContentLength(contentLength);
                response.setStatus(HttpServletResponse.SC_OK);
    
                oos.writeObject(resultObject);
                oos.flush();
    
            }
            catch(Exception e)
            {
                throw new ServletException(e.getMessage());
            }
        
    public voiddoPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)

            doGet(request, response);
        
    private intgetContentLength(java.io.Serializable serObject)
    Returns the size of given seialized object in bytes. The size is calculated from the underlying ByteArrayOutputStream backing an ObjectStream, onto which the Object is written.

            int size = 0;
            ObjectOutputStream oos = null;
    
            try
            {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                oos = new ObjectOutputStream(baos);
                oos.writeObject(serObject);
                size = baos.size();
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
            finally 
            {
                try
                {
                    if (oos != null)
                    {
                        oos.close();
                    }
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }
            }
            return size;
        
    public voidinit()
    Populates the recipients in the dispatcher. These are the recipients to whom the admin request will be forwarded. This needs to be done only when the Servlet is loaded by the servlet container.

    throws
    ServletException when some configuration error occurs.

                                                                                  
            
        
            super.init();
    	    mMBeanServer = MBeanServerFactory.getMBeanServer();
            mLogger.log(Level.FINE, "comm.init_ok");
        
    private java.lang.ExceptionunwrapMBeanException(java.lang.Exception e)

            while(e instanceof MBeanException)
            {
                e = ((MBeanException)e).getTargetException();    
            }
            return e;