felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1679612 - in /felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal: handler/holder/ logger/ whiteboard/
Date Fri, 15 May 2015 18:00:22 GMT
Author: cziegeler
Date: Fri May 15 18:00:22 2015
New Revision: 1679612

URL: http://svn.apache.org/r1679612
Log:
FELIX-4888 : ServletHandler's are not sorted by longest matching path. Split servlet holder
from mapping.

Added:
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/AbstractHolder.java
  (with props)
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/HttpServiceServletHolder.java
  (with props)
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/ServletHolder.java
  (with props)
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/WhiteboardServletHolder.java
  (with props)
Modified:
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/logger/SystemLogger.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardHttpService.java

Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/AbstractHolder.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/AbstractHolder.java?rev=1679612&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/AbstractHolder.java
(added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/AbstractHolder.java
Fri May 15 18:00:22 2015
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.felix.http.base.internal.handler.holder;
+
+import javax.servlet.ServletContext;
+
+import org.osgi.service.http.runtime.dto.DTOConstants;
+
+public abstract class AbstractHolder<T extends AbstractHolder<?>> implements
Comparable<T>
+{
+    private final ServletContext context;
+
+    public AbstractHolder(final ServletContext context)
+    {
+        this.context = context;
+    }
+
+    public ServletContext getContext()
+    {
+        return this.context;
+    }
+
+    /**
+     * Initialize the object
+     * @return {code -1} on success, a failure reason according to {@link DTOConstants} otherwise.
+     */
+    public abstract int init();
+
+    public abstract void destroy();
+}

Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/AbstractHolder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/AbstractHolder.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/AbstractHolder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/HttpServiceServletHolder.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/HttpServiceServletHolder.java?rev=1679612&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/HttpServiceServletHolder.java
(added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/HttpServiceServletHolder.java
Fri May 15 18:00:22 2015
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.felix.http.base.internal.handler.holder;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletContext;
+
+import org.apache.felix.http.base.internal.runtime.ServletInfo;
+
+/**
+ * Servlet holder for servlets registered through the http service.
+ */
+public final class HttpServiceServletHolder extends ServletHolder
+{
+    public HttpServiceServletHolder(final ServletContext context,
+            final ServletInfo servletInfo,
+            final Servlet servlet)
+    {
+        super(context, servletInfo);
+        this.setServlet(servlet);
+    }
+}

Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/HttpServiceServletHolder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/HttpServiceServletHolder.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/HttpServiceServletHolder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/ServletHolder.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/ServletHolder.java?rev=1679612&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/ServletHolder.java
(added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/ServletHolder.java
Fri May 15 18:00:22 2015
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.felix.http.base.internal.handler.holder;
+
+import java.io.IOException;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.apache.felix.http.base.internal.handler.ServletConfigImpl;
+import org.apache.felix.http.base.internal.logger.SystemLogger;
+import org.apache.felix.http.base.internal.runtime.ServletInfo;
+import org.osgi.service.http.runtime.dto.DTOConstants;
+
+/**
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public abstract class ServletHolder extends AbstractHolder<ServletHolder>
+{
+    private final ServletInfo servletInfo;
+
+    private volatile Servlet servlet;
+
+    public ServletHolder(final ServletContext context,
+            final ServletInfo servletInfo)
+    {
+        super(context);
+
+        this.servletInfo = servletInfo;
+    }
+
+    protected Servlet getServlet()
+    {
+        return servlet;
+    }
+
+    protected void setServlet(final Servlet s)
+    {
+        this.servlet = s;
+    }
+
+    @Override
+    public int compareTo(final ServletHolder other)
+    {
+        return this.servletInfo.compareTo(other.servletInfo);
+    }
+
+    public void handle(final ServletRequest req, final ServletResponse res)
+            throws ServletException, IOException
+    {
+        this.servlet.service(req, res);
+    }
+
+    protected ServletInfo getServletInfo()
+    {
+        return this.servletInfo;
+    }
+
+    protected String getName()
+    {
+        String name = this.servletInfo.getName();
+        if (name == null)
+        {
+            name = servlet.getClass().getName();
+        }
+        return name;
+    }
+
+    @Override
+    public int init()
+    {
+        if (this.servlet == null)
+        {
+            return DTOConstants.FAILURE_REASON_SERVICE_NOT_GETTABLE;
+        }
+
+        try {
+            servlet.init(new ServletConfigImpl(getName(), getContext(), getServletInfo().getInitParameters()));
+        } catch (final ServletException e) {
+            SystemLogger.error(this.getServletInfo().getServiceReference(),
+                    "Error during calling init() on servlet " + this.servlet,
+                    e);
+            return DTOConstants.FAILURE_REASON_EXCEPTION_ON_INIT;
+        }
+        return -1;
+    }
+
+    @Override
+    public void destroy()
+    {
+        if (this.servlet == null)
+        {
+            return;
+        }
+
+        try {
+            servlet.destroy();
+        } catch ( final Exception ignore ) {
+            // we ignore this
+            SystemLogger.error(this.getServletInfo().getServiceReference(),
+                    "Error during calling destroy() on servlet " + this.servlet,
+                    ignore);
+        }
+
+        servlet = null;
+    }
+}

Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/ServletHolder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/ServletHolder.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/ServletHolder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/WhiteboardServletHolder.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/WhiteboardServletHolder.java?rev=1679612&view=auto
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/WhiteboardServletHolder.java
(added)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/WhiteboardServletHolder.java
Fri May 15 18:00:22 2015
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.felix.http.base.internal.handler.holder;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletContext;
+
+import org.apache.felix.http.base.internal.runtime.ServletInfo;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceObjects;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Servlet holder for servlets registered through the http whiteboard.
+ */
+public final class WhiteboardServletHolder extends ServletHolder
+{
+    private final BundleContext bundleContext;
+
+    public WhiteboardServletHolder(final ServletContext context,
+            final ServletInfo servletInfo,
+            final BundleContext bundleContext)
+    {
+        super(context, servletInfo);
+        this.bundleContext = bundleContext;
+    }
+
+    @Override
+    public int init()
+    {
+        final ServiceReference<Servlet> serviceReference = getServletInfo().getServiceReference();
+        final ServiceObjects<Servlet> so = this.bundleContext.getServiceObjects(serviceReference);
+
+        this.setServlet((so == null ? null : so.getService()));
+
+        final int reason = super.init();
+        if ( reason != -1 )
+        {
+            so.ungetService(this.getServlet());
+            this.setServlet(null);
+        }
+        return -reason;
+    }
+
+    @Override
+    public void destroy()
+    {
+        final Servlet s = this.getServlet();
+        if ( s != null )
+        {
+            super.destroy();
+
+            final ServiceObjects<Servlet> so = this.bundleContext.getServiceObjects(getServletInfo().getServiceReference());
+            if (so != null)
+            {
+                so.ungetService(s);
+            }
+        }
+    }
+}

Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/WhiteboardServletHolder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/WhiteboardServletHolder.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/holder/WhiteboardServletHolder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/logger/SystemLogger.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/logger/SystemLogger.java?rev=1679612&r1=1679611&r2=1679612&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/logger/SystemLogger.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/logger/SystemLogger.java
Fri May 15 18:00:22 2015
@@ -18,6 +18,7 @@
  */
 package org.apache.felix.http.base.internal.logger;
 
+import org.osgi.framework.ServiceReference;
 import org.osgi.service.log.LogService;
 
 public final class SystemLogger
@@ -59,4 +60,9 @@ public final class SystemLogger
     {
         getLogger().log(LogService.LOG_ERROR, message, cause);
     }
+
+    public static void error(ServiceReference<?> ref, String message, Throwable cause)
+    {
+        getLogger().log(ref, LogService.LOG_ERROR, message, cause);
+    }
 }

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardHttpService.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardHttpService.java?rev=1679612&r1=1679611&r2=1679612&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardHttpService.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardHttpService.java
Fri May 15 18:00:22 2015
@@ -55,12 +55,19 @@ public final class WhiteboardHttpService
      * Register a servlet.
      * @param contextInfo The servlet context helper info
      * @param servletInfo The servlet info
-     * @throws RegistrationFailureException 
+     * @throws RegistrationFailureException
      */
     public void registerServlet(@Nonnull final ContextHandler contextHandler,
             @Nonnull final ServletInfo servletInfo)
             throws RegistrationFailureException
     {
+        // we need to check each and every pattern individually
+        if ( servletInfo.getPatterns() != null )
+        {
+            for(final String pattern : servletInfo.getPatterns() ) {
+
+            }
+        }
         try
         {
             ServletHandler handler = new WhiteboardServletHandler(contextHandler.getContextInfo(),
@@ -80,7 +87,7 @@ public final class WhiteboardHttpService
      * Unregister a servlet
      * @param contextInfo The servlet context helper info
      * @param servletInfo The servlet info
-     * @throws RegistrationFailureException 
+     * @throws RegistrationFailureException
      */
     public void unregisterServlet(@Nonnull final ContextHandler contextHandler, @Nonnull
final ServletInfo servletInfo) throws RegistrationFailureException
     {
@@ -92,7 +99,7 @@ public final class WhiteboardHttpService
      * Register a filter
      * @param contextInfo The servlet context helper info
      * @param filterInfo The filter info
-     * @throws RegistrationFailureException 
+     * @throws RegistrationFailureException
      */
     public void registerFilter(@Nonnull  final ContextHandler contextHandler,
             @Nonnull final FilterInfo filterInfo) throws RegistrationFailureException
@@ -141,7 +148,7 @@ public final class WhiteboardHttpService
      * Register a resource.
      * @param contextInfo The servlet context helper info
      * @param resourceInfo The resource info
-     * @throws RegistrationFailureException 
+     * @throws RegistrationFailureException
      */
     public void registerResource(@Nonnull final ContextHandler contextHandler,
             @Nonnull final ResourceInfo resourceInfo) throws RegistrationFailureException
@@ -166,7 +173,7 @@ public final class WhiteboardHttpService
      * Unregister a resource.
      * @param contextInfo The servlet context helper info
      * @param resourceInfo The resource info
-     * @throws RegistrationFailureException 
+     * @throws RegistrationFailureException
      */
     public void unregisterResource(@Nonnull final ContextHandler contextHandler, @Nonnull
final ResourceInfo resourceInfo) throws RegistrationFailureException
     {



Mime
View raw message