continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eveni...@apache.org
Subject svn commit: r537892 - in /maven/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server: ./ src/main/java/org/apache/maven/continuum/xmlrpc/server/
Date Mon, 14 May 2007 15:52:28 GMT
Author: evenisse
Date: Mon May 14 08:52:26 2007
New Revision: 537892

URL: http://svn.apache.org/viewvc?view=rev&rev=537892
Log:
Load a new xmlrpc component for each request and use Plexus for that. The component is released
at the end of the request to prevent OOME

Added:
    maven/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/src/main/java/org/apache/maven/continuum/xmlrpc/server/ContinuumXmlRpcMetaDataHandler.java
  (with props)
Modified:
    maven/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/pom.xml
    maven/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/src/main/java/org/apache/maven/continuum/xmlrpc/server/ConfiguredBeanProcessorFactory.java
    maven/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/src/main/java/org/apache/maven/continuum/xmlrpc/server/ContinuumServiceImpl.java
    maven/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/src/main/java/org/apache/maven/continuum/xmlrpc/server/PropertiesHandlerMapping.java

Modified: maven/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/pom.xml
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/pom.xml?view=diff&rev=537892&r1=537891&r2=537892
==============================================================================
--- maven/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/pom.xml (original)
+++ maven/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/pom.xml Mon May 14 08:52:26
2007
@@ -59,7 +59,7 @@
         <configuration>
           <roleDefaults>
             <roleDefault>
-              <role>org.apache.maven.continuum.xmlrpc.ContinuumXmlRpcComponent</role>
+              <role>org.apache.maven.continuum.xmlrpc.server.ContinuumXmlRpcComponent</role>
               <instantiation-strategy>per-lookup</instantiation-strategy>
             </roleDefault>
           </roleDefaults>

Modified: maven/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/src/main/java/org/apache/maven/continuum/xmlrpc/server/ConfiguredBeanProcessorFactory.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/src/main/java/org/apache/maven/continuum/xmlrpc/server/ConfiguredBeanProcessorFactory.java?view=diff&rev=537892&r1=537891&r2=537892
==============================================================================
--- maven/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/src/main/java/org/apache/maven/continuum/xmlrpc/server/ConfiguredBeanProcessorFactory.java
(original)
+++ maven/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/src/main/java/org/apache/maven/continuum/xmlrpc/server/ConfiguredBeanProcessorFactory.java
Mon May 14 08:52:26 2007
@@ -22,6 +22,12 @@
 import org.apache.xmlrpc.XmlRpcException;
 import org.apache.xmlrpc.XmlRpcRequest;
 import org.apache.xmlrpc.server.RequestProcessorFactoryFactory;
+import org.codehaus.plexus.PlexusConstants;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+import org.codehaus.plexus.context.Context;
+import org.codehaus.plexus.context.ContextException;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
 
@@ -35,10 +41,10 @@
  * @plexus.component role="org.apache.xmlrpc.server.RequestProcessorFactoryFactory"
  */
 public class ConfiguredBeanProcessorFactory
-    implements RequestProcessorFactoryFactory, Initializable
+    implements RequestProcessorFactoryFactory, Initializable, Contextualizable
 {
     /**
-     * @plexus.requirement role="org.apache.maven.continuum.xmlrpc.ContinuumXmlRpcComponent"
+     * @plexus.requirement role="org.apache.maven.continuum.xmlrpc.server.ContinuumXmlRpcComponent"
      */
     private Map xmlrpcComponents;
 
@@ -49,6 +55,8 @@
 
     private Map componentsMapping = new HashMap();
 
+    PlexusContainer container;
+
     public void initialize()
         throws InitializationException
     {
@@ -85,14 +93,22 @@
     {
         listener.getLogger().debug( "Load '" + cls.getName() + "' handler." );
 
-        Object o = getComponent( cls );
+        Object obj = null;
+        try
+        {
+            obj = getComponent( cls );
+        }
+        catch ( ComponentLookupException e )
+        {
+            listener.getLogger().error( "Can't load component.", e );
+        }
 
-        if ( o == null )
+        if ( obj == null )
         {
             throw new XmlRpcException( "Handler bean not found for: " + cls );
         }
 
-        return o;
+        return obj;
     }
 
     private String getComponentKey( Class cls )
@@ -101,7 +117,16 @@
     }
 
     private Object getComponent( Class cls )
+        throws ComponentLookupException
+    {
+        String key = getComponentKey( cls );
+        listener.getLogger().debug( "load component:" );
+        return container.lookup( ContinuumXmlRpcComponent.class.getName(), key );
+    }
+
+    public void contextualize( Context context )
+        throws ContextException
     {
-        return xmlrpcComponents.get( getComponentKey( cls ) );
+        container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
     }
 }

Modified: maven/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/src/main/java/org/apache/maven/continuum/xmlrpc/server/ContinuumServiceImpl.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/src/main/java/org/apache/maven/continuum/xmlrpc/server/ContinuumServiceImpl.java?view=diff&rev=537892&r1=537891&r2=537892
==============================================================================
--- maven/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/src/main/java/org/apache/maven/continuum/xmlrpc/server/ContinuumServiceImpl.java
(original)
+++ maven/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/src/main/java/org/apache/maven/continuum/xmlrpc/server/ContinuumServiceImpl.java
Mon May 14 08:52:26 2007
@@ -43,7 +43,7 @@
 /**
  * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
  * @version $Id$
- * @plexus.component role="org.apache.maven.continuum.xmlrpc.ContinuumXmlRpcComponent" role-hint="org.apache.maven.continuum.xmlrpc.ContinuumService"
+ * @plexus.component role="org.apache.maven.continuum.xmlrpc.server.ContinuumXmlRpcComponent"
role-hint="org.apache.maven.continuum.xmlrpc.ContinuumService"
  */
 public class ContinuumServiceImpl
     implements ContinuumService, ContinuumXmlRpcComponent

Added: maven/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/src/main/java/org/apache/maven/continuum/xmlrpc/server/ContinuumXmlRpcMetaDataHandler.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/src/main/java/org/apache/maven/continuum/xmlrpc/server/ContinuumXmlRpcMetaDataHandler.java?view=auto&rev=537892
==============================================================================
--- maven/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/src/main/java/org/apache/maven/continuum/xmlrpc/server/ContinuumXmlRpcMetaDataHandler.java
(added)
+++ maven/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/src/main/java/org/apache/maven/continuum/xmlrpc/server/ContinuumXmlRpcMetaDataHandler.java
Mon May 14 08:52:26 2007
@@ -0,0 +1,193 @@
+package org.apache.maven.continuum.xmlrpc.server;
+
+import org.apache.xmlrpc.XmlRpcException;
+import org.apache.xmlrpc.XmlRpcHandler;
+import org.apache.xmlrpc.XmlRpcRequest;
+import org.apache.xmlrpc.common.TypeConverter;
+import org.apache.xmlrpc.common.TypeConverterFactory;
+import org.apache.xmlrpc.common.XmlRpcNotAuthorizedException;
+import org.apache.xmlrpc.metadata.Util;
+import org.apache.xmlrpc.server.AbstractReflectiveHandlerMapping;
+import org.apache.xmlrpc.server.RequestProcessorFactoryFactory;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+/**
+ * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
+ * @version $Id$
+ */
+public class ContinuumXmlRpcMetaDataHandler
+    implements XmlRpcHandler
+{
+    private static class MethodData
+    {
+        final Method method;
+
+        final TypeConverter[] typeConverters;
+
+        MethodData( Method pMethod, TypeConverterFactory pTypeConverterFactory )
+        {
+            method = pMethod;
+            Class[] paramClasses = method.getParameterTypes();
+            typeConverters = new TypeConverter[paramClasses.length];
+            for ( int i = 0; i < paramClasses.length; i++ )
+            {
+                typeConverters[i] = pTypeConverterFactory.getTypeConverter( paramClasses[i]
);
+            }
+        }
+    }
+
+    private final AbstractReflectiveHandlerMapping mapping;
+
+    private final MethodData[] methods;
+
+    private final Class clazz;
+
+    private final RequestProcessorFactoryFactory.RequestProcessorFactory requestProcessorFactory;
+
+    private final String[][] signatures;
+
+    private final String methodHelp;
+
+    private PlexusContainer container;
+
+    /**
+     * Creates a new instance.
+     *
+     * @param pMapping   The mapping, which creates this handler.
+     * @param pClass     The class, which has been inspected to create
+     *                   this handler. Typically, this will be the same as
+     *                   <pre>pInstance.getClass()</pre>. It is used for diagnostic
+     *                   messages only.
+     * @param pMethods   The method, which will be invoked for
+     *                   executing the handler.
+     * @param signatures The signature, which will be returned by
+     *                   {@link #getSignatures()}.
+     * @param methodHelp The help string, which will be returned
+     *                   by {@link #getMethodHelp()}.
+     * @param container  The container that loaded the component
+     */
+    public ContinuumXmlRpcMetaDataHandler( AbstractReflectiveHandlerMapping pMapping,
+                                           TypeConverterFactory pTypeConverterFactory, Class
pClass,
+                                           RequestProcessorFactoryFactory.RequestProcessorFactory
pFactory,
+                                           Method[] pMethods, String[][] signatures, String
methodHelp,
+                                           PlexusContainer container )
+    {
+        mapping = pMapping;
+        clazz = pClass;
+        methods = new MethodData[pMethods.length];
+        requestProcessorFactory = pFactory;
+        for ( int i = 0; i < methods.length; i++ )
+        {
+            methods[i] = new MethodData( pMethods[i], pTypeConverterFactory );
+        }
+        this.signatures = signatures;
+        this.methodHelp = methodHelp;
+        this.container = container;
+    }
+
+    private Object getInstance( XmlRpcRequest pRequest )
+        throws XmlRpcException
+    {
+        return requestProcessorFactory.getRequestProcessor( pRequest );
+    }
+
+    public Object execute( XmlRpcRequest pRequest )
+        throws XmlRpcException
+    {
+        AbstractReflectiveHandlerMapping.AuthenticationHandler authHandler = mapping.getAuthenticationHandler();
+        if ( authHandler != null && !authHandler.isAuthorized( pRequest ) )
+        {
+            throw new XmlRpcNotAuthorizedException( "Not authorized" );
+        }
+        Object[] args = new Object[pRequest.getParameterCount()];
+        for ( int j = 0; j < args.length; j++ )
+        {
+            args[j] = pRequest.getParameter( j );
+        }
+        Object instance = getInstance( pRequest );
+        for ( int i = 0; i < methods.length; i++ )
+        {
+            MethodData methodData = methods[i];
+            TypeConverter[] converters = methodData.typeConverters;
+            if ( args.length == converters.length )
+            {
+                boolean matching = true;
+                for ( int j = 0; j < args.length; j++ )
+                {
+                    if ( !converters[j].isConvertable( args[j] ) )
+                    {
+                        matching = false;
+                        break;
+                    }
+                }
+                if ( matching )
+                {
+                    for ( int j = 0; j < args.length; j++ )
+                    {
+                        args[j] = converters[j].convert( args[j] );
+                    }
+                    return invoke( instance, methodData.method, args );
+                }
+            }
+        }
+        throw new XmlRpcException( "No method matching arguments: " + Util.getSignature(
args ) );
+    }
+
+    private Object invoke( Object pInstance, Method pMethod, Object[] pArgs )
+        throws XmlRpcException
+    {
+        try
+        {
+            return pMethod.invoke( pInstance, pArgs );
+        }
+        catch ( IllegalAccessException e )
+        {
+            throw new XmlRpcException( "Illegal access to method " + pMethod.getName() +
" in class " + clazz.getName(),
+                                       e );
+        }
+        catch ( IllegalArgumentException e )
+        {
+            throw new XmlRpcException(
+                "Illegal argument for method " + pMethod.getName() + " in class " + clazz.getName(),
e );
+        }
+        catch ( InvocationTargetException e )
+        {
+            Throwable t = e.getTargetException();
+            if ( t instanceof XmlRpcException )
+            {
+                throw (XmlRpcException) t;
+            }
+            throw new XmlRpcException(
+                "Failed to invoke method " + pMethod.getName() + " in class " + clazz.getName()
+ ": " + t.getMessage(),
+                t );
+        }
+        finally
+        {
+            try
+            {
+                container.release( pInstance );
+            }
+            catch ( ComponentLifecycleException e )
+            {
+                //Do nothing
+            }
+        }
+    }
+
+    public String[][] getSignatures()
+        throws XmlRpcException
+    {
+        return signatures;
+    }
+
+    public String getMethodHelp()
+        throws XmlRpcException
+    {
+        return methodHelp;
+    }
+
+}

Propchange: maven/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/src/main/java/org/apache/maven/continuum/xmlrpc/server/ContinuumXmlRpcMetaDataHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/src/main/java/org/apache/maven/continuum/xmlrpc/server/ContinuumXmlRpcMetaDataHandler.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/src/main/java/org/apache/maven/continuum/xmlrpc/server/PropertiesHandlerMapping.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/src/main/java/org/apache/maven/continuum/xmlrpc/server/PropertiesHandlerMapping.java?view=diff&rev=537892&r1=537891&r2=537892
==============================================================================
--- maven/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/src/main/java/org/apache/maven/continuum/xmlrpc/server/PropertiesHandlerMapping.java
(original)
+++ maven/continuum/trunk/continuum-xmlrpc/continuum-xmlrpc-server/src/main/java/org/apache/maven/continuum/xmlrpc/server/PropertiesHandlerMapping.java
Mon May 14 08:52:26 2007
@@ -20,8 +20,16 @@
  */
 
 import org.apache.xmlrpc.XmlRpcException;
+import org.apache.xmlrpc.XmlRpcHandler;
 import org.apache.xmlrpc.server.PropertyHandlerMapping;
+import org.apache.xmlrpc.server.RequestProcessorFactoryFactory;
+import org.codehaus.plexus.PlexusConstants;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.context.Context;
+import org.codehaus.plexus.context.ContextException;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
 
+import java.lang.reflect.Method;
 import java.util.Iterator;
 import java.util.Map;
 
@@ -32,9 +40,10 @@
  */
 public class PropertiesHandlerMapping
     extends PropertyHandlerMapping
+    implements Contextualizable
 {
     /**
-     * @plexus.requirement role="org.apache.maven.continuum.xmlrpc.ContinuumXmlRpcComponent"
+     * @plexus.requirement role="org.apache.maven.continuum.xmlrpc.server.ContinuumXmlRpcComponent"
      */
     private Map xmlrpcComponents;
 
@@ -43,6 +52,8 @@
      */
     private Listener listener;
 
+    private PlexusContainer container;
+
     public void load()
         throws XmlRpcException
     {
@@ -65,4 +76,20 @@
         }
     }
 
+    protected XmlRpcHandler newXmlRpcHandler( final Class pClass, final Method[] pMethods
)
+        throws XmlRpcException
+    {
+        String[][] sig = getSignature( pMethods );
+        String help = getMethodHelp( pClass, pMethods );
+        RequestProcessorFactoryFactory.RequestProcessorFactory factory =
+            getRequestProcessorFactoryFactory().getRequestProcessorFactory( pClass );
+        return new ContinuumXmlRpcMetaDataHandler( this, getTypeConverterFactory(), pClass,
factory, pMethods, sig,
+                                                   help, container );
+    }
+
+    public void contextualize( Context context )
+        throws ContextException
+    {
+        container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
+    }
 }



Mime
View raw message