You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by di...@apache.org on 2004/12/09 13:49:30 UTC

cvs commit: ws-axis/java/src/org/apache/axis/transport/http AxisServletBase.java

dims        2004/12/09 04:49:30

  Modified:    java/src/org/apache/axis/transport/http AxisServletBase.java
  Log:
  Fix for AXIS-1527 - Using multiple AxisServlet in webapp share the same AxisEngine
  from  Guillaume Sauthier (guillaume.sauthier@objectweb.org)
  
  Revision  Changes    Path
  1.27      +46 -20    ws-axis/java/src/org/apache/axis/transport/http/AxisServletBase.java
  
  Index: AxisServletBase.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/transport/http/AxisServletBase.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- AxisServletBase.java	11 Jun 2004 19:09:07 -0000	1.26
  +++ AxisServletBase.java	9 Dec 2004 12:49:30 -0000	1.27
  @@ -17,6 +17,18 @@
   
   package org.apache.axis.transport.http;
   
  +import java.io.File;
  +import java.io.IOException;
  +import java.util.Enumeration;
  +import java.util.HashMap;
  +import java.util.Map;
  +
  +import javax.servlet.ServletContext;
  +import javax.servlet.ServletException;
  +import javax.servlet.http.HttpServlet;
  +import javax.servlet.http.HttpServletRequest;
  +import javax.servlet.http.HttpServletResponse;
  +
   import org.apache.axis.AxisEngine;
   import org.apache.axis.AxisFault;
   import org.apache.axis.AxisProperties;
  @@ -27,16 +39,6 @@
   import org.apache.axis.utils.JavaUtils;
   import org.apache.commons.logging.Log;
   
  -import javax.servlet.ServletContext;
  -import javax.servlet.ServletException;
  -import javax.servlet.http.HttpServlet;
  -import javax.servlet.http.HttpServletRequest;
  -import javax.servlet.http.HttpServletResponse;
  -import java.io.File;
  -import java.io.IOException;
  -import java.util.HashMap;
  -import java.util.Map;
  -
   /**
    * Base class for servlets used in axis, has common methods
    * to get and save the engine to a common location, currently the
  @@ -133,7 +135,7 @@
                       axisServer.cleanup();
                       //and erase our history of it
                       axisServer =null;
  -                    storeEngine(getServletContext(),null);
  +                    storeEngine(this,null);
                   }
               }
           }
  @@ -165,7 +167,7 @@
   
           ServletContext context = servlet.getServletContext();
           synchronized (context) {
  -            engine = retrieveEngine(context);
  +            engine = retrieveEngine(servlet);
               if (engine == null) {
                   Map environment = getEngineEnvironment(servlet);
   
  @@ -181,7 +183,7 @@
                   // also means we put the standard configuration pattern in one
                   // place.
                   engine = AxisServer.getServer(environment);
  -                storeEngine(context, engine);
  +                storeEngine(servlet, engine);
               }
           }
   
  @@ -196,11 +198,31 @@
        * @param context servlet context to use
        * @param engine reference to the engine. If null, the engine is removed
        */
  -    private static void storeEngine(ServletContext context, AxisServer engine) {
  +    private static void storeEngine(HttpServlet servlet, AxisServer engine) {
  +        ServletContext context = servlet.getServletContext();
  +        String axisServletName = servlet.getServletName();
           if (engine == null) {
  -            context.removeAttribute(ATTR_AXIS_ENGINE);
  +            context.removeAttribute(axisServletName + ATTR_AXIS_ENGINE);
  +            // find if there is other AxisEngine in Context
  +            boolean otherAxisEengine = false;
  +            for (Enumeration e = context.getAttributeNames(); e.hasMoreElements();) {
  +                String name = (String) e.nextElement();
  +                if (!ATTR_AXIS_ENGINE.equals(name) && name.endsWith(ATTR_AXIS_ENGINE)) {
  +                    // name is not "AxisEngine" but finish with "AxisEngine"
  +                    otherAxisEengine = true;
  +                }
  +            }
  +            // no other AxisEngine in ServletContext
  +            if (!otherAxisEengine) {
  +                context.removeAttribute(ATTR_AXIS_ENGINE);
  +            }
           } else {
  -            context.setAttribute(ATTR_AXIS_ENGINE, engine);
  +            if (context.getAttribute(ATTR_AXIS_ENGINE) == null) {
  +                // first Axis servlet to store its AxisEngine
  +                // use default name
  +                context.setAttribute(ATTR_AXIS_ENGINE, engine);
  +            }
  +            context.setAttribute(axisServletName + ATTR_AXIS_ENGINE, engine);
           }
       }
   
  @@ -209,12 +231,17 @@
        * issues of hot-updated webapps. Remember than if a webapp is marked
        * as distributed, there is more than 1 servlet context, hence more than
        * one AxisEngine instance
  -     * @param context
  +     * @param servlet
        * @return the engine or null if either the engine couldnt be found or
        *         the attribute wasnt of the right type
        */
  -    private static AxisServer retrieveEngine(ServletContext context) {
  -        Object contextObject = context.getAttribute(ATTR_AXIS_ENGINE);
  +    private static AxisServer retrieveEngine(HttpServlet servlet) {
  +        Object contextObject = servlet.getServletContext().getAttribute(servlet.getServletName() + ATTR_AXIS_ENGINE);
  +        if (contextObject == null) {
  +            // if AxisServer not found :
  +            // fall back to the "default" AxisEngine
  +            contextObject = servlet.getServletContext().getAttribute(ATTR_AXIS_ENGINE);
  +        }
           if (contextObject instanceof AxisServer) {
               return (AxisServer) contextObject;
           }
  @@ -222,7 +249,6 @@
               return null;
           }
        }
  -
   
       /**
        * extract information from the servlet configuration files
  
  
  

Re: cvs commit: ws-axis/java/src/org/apache/axis/transport/http AxisServletBase.java

Posted by Guillaume Sauthier <Gu...@objectweb.org>.
for #2
Yes this is a big change, but we only add another place in the 
ServletContext where AxisEngine can be found
-> if users are using multiple engine, they must lookup the 
servletcontext for "<servlet-name>AxisEngine" to find their engine
-> existing users that use only 1 engine will always find their engine 
under "AxisEngine" AND under "<servlet-name>AxisEngine"

BTW, I tried the in JOnAS and there is a problem. I research the cause 
and provide you a corrective patch ...

Regards
Guillaume

Davanum Srinivas wrote:

>+1 to #1 and #2.
>
>BTW, this tiny bookmarklet let's you highlight a keyword and browse to
>JIRA directly.
>
>javascript:q=document.getSelection();for(i=0;i<frames.length;i++){q=frames[i].document.getSelection();if(q)break;}if(!q)void(q=prompt('Bug',''));if(q)location.href='http://nagoya.apache.org/jira/browse/'+escape(q)
>
>-- dims
>
>
>On Thu, 9 Dec 2004 08:00:08 -0500, Glen Daniels <gl...@thoughtcraft.com> wrote:
>  
>
>>Hey dims:
>>
>>1) Just out of convenience, would you mind terribly putting the JIRA URL
>>into your commits?  That way it's easy to just click on the commit email to
>>get to the bug.  Not a big deal.
>>
>>2) This change is a fairly serious alteration - the one AxisEngine per
>>webapp decision was a conscious one, and I'm just wanting to make sure the
>>ramifications have been thought through.  If people were depending on this
>>behavior to share state/config, they may break as a result of this change,
>>right?  We should at least light this up in BIG RED LETTERS.
>>
>>--Glen 
>>
>>
>>    
>>

Re: cvs commit: ws-axis/java/src/org/apache/axis/transport/http AxisServletBase.java

Posted by Davanum Srinivas <da...@gmail.com>.
+1 to #1 and #2.

BTW, this tiny bookmarklet let's you highlight a keyword and browse to
JIRA directly.

javascript:q=document.getSelection();for(i=0;i<frames.length;i++){q=frames[i].document.getSelection();if(q)break;}if(!q)void(q=prompt('Bug',''));if(q)location.href='http://nagoya.apache.org/jira/browse/'+escape(q)

-- dims


On Thu, 9 Dec 2004 08:00:08 -0500, Glen Daniels <gl...@thoughtcraft.com> wrote:
> 
> Hey dims:
> 
> 1) Just out of convenience, would you mind terribly putting the JIRA URL
> into your commits?  That way it's easy to just click on the commit email to
> get to the bug.  Not a big deal.
> 
> 2) This change is a fairly serious alteration - the one AxisEngine per
> webapp decision was a conscious one, and I'm just wanting to make sure the
> ramifications have been thought through.  If people were depending on this
> behavior to share state/config, they may break as a result of this change,
> right?  We should at least light this up in BIG RED LETTERS.
> 
> --Glen 
> 
> 
> 
> > -----Original Message-----
> > From: dims@apache.org [mailto:dims@apache.org]
> > Sent: Thursday, December 09, 2004 7:50 AM
> > To: ws-axis-cvs@apache.org
> > Subject: cvs commit:
> > ws-axis/java/src/org/apache/axis/transport/http AxisServletBase.java
> >
> > dims        2004/12/09 04:49:30
> >
> >   Modified:    java/src/org/apache/axis/transport/http
> > AxisServletBase.java
> >   Log:
> >   Fix for AXIS-1527 - Using multiple AxisServlet in webapp
> > share the same AxisEngine
> >   from  Guillaume Sauthier (guillaume.sauthier@objectweb.org)
> >
> >   Revision  Changes    Path
> >   1.27      +46 -20
> > ws-axis/java/src/org/apache/axis/transport/http/AxisServletBase.java
> >
> >   Index: AxisServletBase.java
> >   ===================================================================
> >   RCS file:
> > /home/cvs/ws-axis/java/src/org/apache/axis/transport/http/Axis
> > ServletBase.java,v
> >   retrieving revision 1.26
> >   retrieving revision 1.27
> >   diff -u -r1.26 -r1.27
> >   --- AxisServletBase.java    11 Jun 2004 19:09:07 -0000      1.26
> >   +++ AxisServletBase.java    9 Dec 2004 12:49:30 -0000       1.27
> >   @@ -17,6 +17,18 @@
> >
> >    package org.apache.axis.transport.http;
> >
> >   +import java.io.File;
> >   +import java.io.IOException;
> >   +import java.util.Enumeration;
> >   +import java.util.HashMap;
> >   +import java.util.Map;
> >   +
> >   +import javax.servlet.ServletContext;
> >   +import javax.servlet.ServletException;
> >   +import javax.servlet.http.HttpServlet;
> >   +import javax.servlet.http.HttpServletRequest;
> >   +import javax.servlet.http.HttpServletResponse;
> >   +
> >    import org.apache.axis.AxisEngine;
> >    import org.apache.axis.AxisFault;
> >    import org.apache.axis.AxisProperties;
> >   @@ -27,16 +39,6 @@
> >    import org.apache.axis.utils.JavaUtils;
> >    import org.apache.commons.logging.Log;
> >
> >   -import javax.servlet.ServletContext;
> >   -import javax.servlet.ServletException;
> >   -import javax.servlet.http.HttpServlet;
> >   -import javax.servlet.http.HttpServletRequest;
> >   -import javax.servlet.http.HttpServletResponse;
> >   -import java.io.File;
> >   -import java.io.IOException;
> >   -import java.util.HashMap;
> >   -import java.util.Map;
> >   -
> >    /**
> >     * Base class for servlets used in axis, has common methods
> >     * to get and save the engine to a common location, currently the
> >   @@ -133,7 +135,7 @@
> >                        axisServer.cleanup();
> >                        //and erase our history of it
> >                        axisServer =null;
> >   -                    storeEngine(getServletContext(),null);
> >   +                    storeEngine(this,null);
> >                    }
> >                }
> >            }
> >   @@ -165,7 +167,7 @@
> >
> >            ServletContext context = servlet.getServletContext();
> >            synchronized (context) {
> >   -            engine = retrieveEngine(context);
> >   +            engine = retrieveEngine(servlet);
> >                if (engine == null) {
> >                    Map environment = getEngineEnvironment(servlet);
> >
> >   @@ -181,7 +183,7 @@
> >                    // also means we put the standard
> > configuration pattern in one
> >                    // place.
> >                    engine = AxisServer.getServer(environment);
> >   -                storeEngine(context, engine);
> >   +                storeEngine(servlet, engine);
> >                }
> >            }
> >
> >   @@ -196,11 +198,31 @@
> >         * @param context servlet context to use
> >         * @param engine reference to the engine. If null, the
> > engine is removed
> >         */
> >   -    private static void storeEngine(ServletContext
> > context, AxisServer engine) {
> >   +    private static void storeEngine(HttpServlet servlet,
> > AxisServer engine) {
> >   +        ServletContext context = servlet.getServletContext();
> >   +        String axisServletName = servlet.getServletName();
> >            if (engine == null) {
> >   -            context.removeAttribute(ATTR_AXIS_ENGINE);
> >   +            context.removeAttribute(axisServletName +
> > ATTR_AXIS_ENGINE);
> >   +            // find if there is other AxisEngine in Context
> >   +            boolean otherAxisEengine = false;
> >   +            for (Enumeration e =
> > context.getAttributeNames(); e.hasMoreElements();) {
> >   +                String name = (String) e.nextElement();
> >   +                if (!ATTR_AXIS_ENGINE.equals(name) &&
> > name.endsWith(ATTR_AXIS_ENGINE)) {
> >   +                    // name is not "AxisEngine" but finish
> > with "AxisEngine"
> >   +                    otherAxisEengine = true;
> >   +                }
> >   +            }
> >   +            // no other AxisEngine in ServletContext
> >   +            if (!otherAxisEengine) {
> >   +                context.removeAttribute(ATTR_AXIS_ENGINE);
> >   +            }
> >            } else {
> >   -            context.setAttribute(ATTR_AXIS_ENGINE, engine);
> >   +            if (context.getAttribute(ATTR_AXIS_ENGINE) == null) {
> >   +                // first Axis servlet to store its AxisEngine
> >   +                // use default name
> >   +                context.setAttribute(ATTR_AXIS_ENGINE, engine);
> >   +            }
> >   +            context.setAttribute(axisServletName +
> > ATTR_AXIS_ENGINE, engine);
> >            }
> >        }
> >
> >   @@ -209,12 +231,17 @@
> >         * issues of hot-updated webapps. Remember than if a
> > webapp is marked
> >         * as distributed, there is more than 1 servlet
> > context, hence more than
> >         * one AxisEngine instance
> >   -     * @param context
> >   +     * @param servlet
> >         * @return the engine or null if either the engine
> > couldnt be found or
> >         *         the attribute wasnt of the right type
> >         */
> >   -    private static AxisServer
> > retrieveEngine(ServletContext context) {
> >   -        Object contextObject =
> > context.getAttribute(ATTR_AXIS_ENGINE);
> >   +    private static AxisServer retrieveEngine(HttpServlet servlet) {
> >   +        Object contextObject =
> > servlet.getServletContext().getAttribute(servlet.getServletNam
> > e() + ATTR_AXIS_ENGINE);
> >   +        if (contextObject == null) {
> >   +            // if AxisServer not found :
> >   +            // fall back to the "default" AxisEngine
> >   +            contextObject =
> > servlet.getServletContext().getAttribute(ATTR_AXIS_ENGINE);
> >   +        }
> >            if (contextObject instanceof AxisServer) {
> >                return (AxisServer) contextObject;
> >            }
> >   @@ -222,7 +249,6 @@
> >                return null;
> >            }
> >         }
> >   -
> >
> >        /**
> >         * extract information from the servlet configuration files
> >
> >
> >
> >
> >
> 


-- 
Davanum Srinivas - http://webservices.apache.org/~dims/