You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2023/11/27 08:58:55 UTC
(felix-dev) branch jakarta-servlet-6 updated: Replaced by FELIX-6671
This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch jakarta-servlet-6
in repository https://gitbox.apache.org/repos/asf/felix-dev.git
The following commit(s) were added to refs/heads/jakarta-servlet-6 by this push:
new da0e5e8bc6 Replaced by FELIX-6671
da0e5e8bc6 is described below
commit da0e5e8bc677cc16582e5cf34e687b1b3bdbd471
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Mon Nov 27 09:58:42 2023 +0100
Replaced by FELIX-6671
---
http/base/README | 5 -
http/base/pom.xml | 87 --
.../http/base/internal/AbstractActivator.java | 49 --
.../http/base/internal/AbstractHttpActivator.java | 42 -
.../felix/http/base/internal/EventDispatcher.java | 72 --
.../felix/http/base/internal/HttpConfig.java | 169 ----
.../http/base/internal/HttpServiceController.java | 147 ----
.../base/internal/context/ExtServletContext.java | 49 --
.../internal/context/ExtServletContextWrapper.java | 384 ---------
.../http/base/internal/dispatch/Dispatcher.java | 183 -----
.../base/internal/dispatch/DispatcherServlet.java | 51 --
.../internal/dispatch/IncludeResponseWrapper.java | 124 ---
.../base/internal/dispatch/InvocationChain.java | 99 ---
.../base/internal/dispatch/MultipartConfig.java | 113 ---
.../internal/dispatch/RequestDispatcherImpl.java | 120 ---
.../http/base/internal/dispatch/RequestInfo.java | 98 ---
.../internal/dispatch/ServletRequestWrapper.java | 622 ---------------
.../internal/dispatch/ServletResponseWrapper.java | 146 ----
.../base/internal/handler/FilterConfigImpl.java | 65 --
.../http/base/internal/handler/FilterHandler.java | 208 -----
.../base/internal/handler/HttpSessionWrapper.java | 471 -----------
.../base/internal/handler/ListenerHandler.java | 154 ----
.../base/internal/handler/PreprocessorHandler.java | 166 ----
.../base/internal/handler/ServletConfigImpl.java | 67 --
.../http/base/internal/handler/ServletHandler.java | 251 ------
.../internal/handler/WhiteboardServletHandler.java | 158 ----
.../http/base/internal/logger/SystemLogger.java | 87 --
.../base/internal/registry/ErrorPageRegistry.java | 609 --------------
.../internal/registry/EventListenerRegistry.java | 474 -----------
.../base/internal/registry/FilterRegistry.java | 268 -------
.../base/internal/registry/HandlerRegistry.java | 266 -------
.../http/base/internal/registry/ListenerMap.java | 292 -------
.../base/internal/registry/PathResolution.java | 39 -
.../http/base/internal/registry/PathResolver.java | 33 -
.../internal/registry/PathResolverFactory.java | 413 ----------
.../registry/PerContextHandlerRegistry.java | 256 ------
.../base/internal/registry/ServletRegistry.java | 528 ------------
.../base/internal/registry/ServletResolution.java | 26 -
.../http/base/internal/runtime/AbstractInfo.java | 270 -------
.../runtime/DefaultServletContextHelperInfo.java | 45 --
.../http/base/internal/runtime/FilterInfo.java | 241 ------
.../http/base/internal/runtime/ListenerInfo.java | 157 ----
.../base/internal/runtime/PreprocessorInfo.java | 81 --
.../http/base/internal/runtime/ResourceInfo.java | 107 ---
.../internal/runtime/ServletContextHelperInfo.java | 146 ----
.../http/base/internal/runtime/ServletInfo.java | 289 -------
.../internal/runtime/WhiteboardServiceInfo.java | 114 ---
.../runtime/dto/BaseServletDTOBuilder.java | 54 --
.../internal/runtime/dto/BuilderConstants.java | 63 --
.../internal/runtime/dto/ErrorPageDTOBuilder.java | 64 --
.../base/internal/runtime/dto/FailedDTOHolder.java | 128 ---
.../internal/runtime/dto/FilterDTOBuilder.java | 101 ---
.../internal/runtime/dto/ListenerDTOBuilder.java | 51 --
.../runtime/dto/PreprocessorDTOBuilder.java | 49 --
.../base/internal/runtime/dto/RegistryRuntime.java | 55 --
.../runtime/dto/RequestInfoDTOBuilder.java | 69 --
.../internal/runtime/dto/ResourceDTOBuilder.java | 80 --
.../internal/runtime/dto/RuntimeDTOBuilder.java | 76 --
.../runtime/dto/ServletContextDTOBuilder.java | 98 ---
.../internal/runtime/dto/ServletDTOBuilder.java | 72 --
.../internal/service/HttpServiceRuntimeImpl.java | 237 ------
.../base/internal/service/ServletContextImpl.java | 616 --------------
.../http/base/internal/util/InternalIdFactory.java | 39 -
.../felix/http/base/internal/util/MimeTypes.java | 211 -----
.../felix/http/base/internal/util/PatternUtil.java | 144 ----
.../http/base/internal/util/ServiceUtils.java | 89 ---
.../felix/http/base/internal/util/UriUtils.java | 368 ---------
.../internal/whiteboard/FailureStateHandler.java | 184 -----
.../whiteboard/PerBundleServletContextImpl.java | 469 -----------
.../whiteboard/RegistrationFailureException.java | 58 --
.../base/internal/whiteboard/ResourceServlet.java | 176 ----
.../whiteboard/SharedServletContextImpl.java | 499 ------------
.../whiteboard/WhiteboardContextHandler.java | 194 -----
.../internal/whiteboard/WhiteboardManager.java | 884 ---------------------
.../internal/whiteboard/tracker/FilterTracker.java | 43 -
.../whiteboard/tracker/ListenersTracker.java | 66 --
.../whiteboard/tracker/PreprocessorTracker.java | 45 --
.../whiteboard/tracker/ResourceTracker.java | 39 -
.../tracker/ServletContextHelperTracker.java | 109 ---
.../whiteboard/tracker/ServletTracker.java | 43 -
.../tracker/WhiteboardServiceTracker.java | 129 ---
.../internal/context/ServletContextImplTest.java | 854 --------------------
.../dispatch/IncludeResponseWrapperTest.java | 101 ---
.../internal/handler/FilterConfigImplTest.java | 72 --
.../base/internal/handler/FilterHandlerTest.java | 277 -------
.../internal/handler/HttpSessionWrapperTest.java | 214 -----
.../internal/handler/ServletConfigImplTest.java | 72 --
.../internal/registry/ErrorPageRegistryTest.java | 299 -------
.../registry/EventListenerRegistryTest.java | 129 ---
.../base/internal/registry/FilterRegistryTest.java | 160 ----
.../internal/registry/HandlerRegistryTest.java | 345 --------
.../internal/registry/PathResolverFactoryTest.java | 110 ---
.../registry/PerContextHandlerRegistryTest.java | 116 ---
.../internal/registry/ServletRegistryTest.java | 281 -------
.../internal/runtime/AbstractInfoOrderingTest.java | 157 ----
.../base/internal/runtime/ListenerInfoTest.java | 98 ---
.../http/base/internal/util/MimeTypesTest.java | 53 --
.../http/base/internal/util/PatternUtilTest.java | 58 --
.../http/base/internal/util/UriUtilsTest.java | 139 ----
.../whiteboard/FailureStateHandlerTest.java | 97 ---
.../felix/http/base/internal/context/resource.txt | 17 -
101 files changed, 18092 deletions(-)
diff --git a/http/base/README b/http/base/README
deleted file mode 100644
index 3acb0c8806..0000000000
--- a/http/base/README
+++ /dev/null
@@ -1,5 +0,0 @@
-This directory contains a proof of concept for a new version of the Apache Felix Http Service.
-
-It is based on Servlet API 5.
-
-This module contains code below the package org.osgi.service.servlet. The API in these packages is NOT official OSGi API, it is work in progress for a new OSGi specifications being worked in the [Eclipse OSGi working group](https://www.osgi.org/). The source is copied from the [design 381 branch](https://github.com/osgi/osgi/tree/design/381). This API might change in any way at any time.
diff --git a/http/base/pom.xml b/http/base/pom.xml
deleted file mode 100644
index e096d16211..0000000000
--- a/http/base/pom.xml
+++ /dev/null
@@ -1,87 +0,0 @@
-<!--
- 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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.http.parent</artifactId>
- <version>16-SNAPSHOT</version>
- <relativePath>../parent/pom.xml</relativePath>
- </parent>
-
- <name>Apache Felix Http Base</name>
- <artifactId>org.apache.felix.http.base</artifactId>
- <version>6.0.0-SNAPSHOT</version>
- <packaging>jar</packaging>
-
- <scm>
- <connection>scm:git:https://github.com/apache/felix-dev.git</connection>
- <developerConnection>scm:git:https://github.com/apache/felix-dev.git</developerConnection>
- <url>https://gitbox.apache.org/repos/asf?p=felix-dev.git</url>
- <tag>org.apache.felix.http.base-5.0.0-RC2</tag>
- </scm>
-
- <properties>
- <felix.java.version>17</felix.java.version>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>1.7.36</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>jakarta.servlet</groupId>
- <artifactId>jakarta.servlet-api</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>osgi.core</artifactId>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.service.servlet</artifactId>
- <version>3.0.0-SNAPSHOT</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.service.useradmin</artifactId>
- <version>1.1.1</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-fileupload2-core</artifactId>
- <version>2.0.0-M3-SNAPSHOT</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-fileupload2-jakarta-servlet6</artifactId>
- <version>2.0.0-M3-SNAPSHOT</version>
- <scope>provided</scope>
- </dependency>
- </dependencies>
-</project>
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractActivator.java b/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractActivator.java
deleted file mode 100644
index 38cb1c43b3..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractActivator.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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;
-
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-
-public abstract class AbstractActivator
- implements BundleActivator {
-
- private volatile BundleContext context;
-
- protected final BundleContext getBundleContext() {
- return this.context;
- }
-
- @Override
- public final void start(final BundleContext context)
- throws Exception {
- this.context = context;
- doStart();
- }
-
- @Override
- public final void stop(final BundleContext context)
- throws Exception {
- doStop();
- }
-
- protected abstract void doStart()
- throws Exception;
-
- protected abstract void doStop()
- throws Exception;
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractHttpActivator.java b/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractHttpActivator.java
deleted file mode 100644
index 937c7ad88d..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractHttpActivator.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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;
-
-public abstract class AbstractHttpActivator
- extends AbstractActivator
-{
- private HttpServiceController controller;
-
- protected final HttpServiceController getHttpServiceController()
- {
- return this.controller;
- }
-
- @Override
- protected void doStart()
- throws Exception
- {
- this.controller = new HttpServiceController(getBundleContext());
- }
-
- @Override
- protected void doStop()
- throws Exception
- {
- this.controller.unregister();
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/EventDispatcher.java b/http/base/src/main/java/org/apache/felix/http/base/internal/EventDispatcher.java
deleted file mode 100644
index 7ea85c014e..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/EventDispatcher.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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;
-
-import jakarta.servlet.http.HttpSessionEvent;
-import jakarta.servlet.http.HttpSessionIdListener;
-import jakarta.servlet.http.HttpSessionListener;
-
-/**
- * The <code>EventDispatcher</code> dispatches events sent from the servlet
- * container (embedded Jetty or container in which the framework is running
- * in bridged mode) to any {@link HttpSessionListener} or
- * {@link HttpSessionIdListener} services.
- */
-public class EventDispatcher implements HttpSessionListener, HttpSessionIdListener
-{
- private volatile boolean active = false;
-
- private final HttpServiceController controller;
-
- EventDispatcher(final HttpServiceController controller)
- {
- this.controller = controller;
- }
-
- public void setActive(final boolean flag)
- {
- this.active = flag;
- }
-
- @Override
- public void sessionCreated(final HttpSessionEvent se)
- {
- if ( this.active )
- {
- controller.getSessionListener().sessionCreated(se);
- }
- }
-
- @Override
- public void sessionDestroyed(final HttpSessionEvent se)
- {
- if ( this.active )
- {
- controller.getSessionListener().sessionDestroyed(se);
- }
- }
-
- @Override
- public void sessionIdChanged(final HttpSessionEvent event, final String oldSessionId) {
- if ( this.active )
- {
- controller.getSessionIdListener().sessionIdChanged(event, oldSessionId);
- }
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/HttpConfig.java b/http/base/src/main/java/org/apache/felix/http/base/internal/HttpConfig.java
deleted file mode 100644
index c06c47af70..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/HttpConfig.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * 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;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Dictionary;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.jetbrains.annotations.NotNull;
-
-public class HttpConfig {
-
- public static final String PROP_INVALIDATE_SESSION = "org.apache.felix.http.session.invalidate";
-
- public static final boolean DEFAULT_INVALIDATE_SESSION = true;
-
- public static final String PROP_UNIQUE_SESSION_ID = "org.apache.felix.http.session.uniqueid";
-
- public static final boolean DEFAULT_UNIQUE_SESSION_ID = true;
-
- /**
- * Type must be compatible with return type of {@link org.apache.felix.http.base.internal.handler.ServletHandler#getContextServiceId()}
- */
- public static final long DEFAULT_CONTEXT_SERVICE_ID = Integer.MIN_VALUE;
-
- private volatile boolean uniqueSessionId;
-
- private volatile boolean invalidateContainerSession;
-
- public static final String PROP_CONTAINER_ADDED_ATTRIBUTE = "org.apache.felix.http.session.container.attribute";
-
- private volatile Set<String> containerAddedAttribueSet;
-
- public boolean isUniqueSessionId() {
- return uniqueSessionId;
- }
-
- public void setUniqueSessionId(boolean appendSessionId) {
- this.uniqueSessionId = appendSessionId;
- }
-
- public boolean isInvalidateContainerSession() {
- return invalidateContainerSession;
- }
-
- public void setInvalidateContainerSession(boolean invalidateContainerSession) {
- this.invalidateContainerSession = invalidateContainerSession;
- }
-
- public Set<String> getContainerAddedAttribueSet() {
- return containerAddedAttribueSet;
- }
-
- public void setContainerAddedAttribueSet(Set<String> containerAddedAttribueSet) {
- this.containerAddedAttribueSet = containerAddedAttribueSet;
- }
-
-
- public void configure(@NotNull final Dictionary<String, Object> props) {
- this.setUniqueSessionId(this.getBooleanProperty(props, PROP_UNIQUE_SESSION_ID, DEFAULT_UNIQUE_SESSION_ID));
- this.setInvalidateContainerSession(this.getBooleanProperty(props, PROP_INVALIDATE_SESSION, DEFAULT_INVALIDATE_SESSION));
- this.setContainerAddedAttribueSet(this.getStringSetProperty(props, PROP_CONTAINER_ADDED_ATTRIBUTE));
- }
-
-
- private boolean getBooleanProperty(final Dictionary<String, Object> props, final String name, final boolean defValue)
- {
- final Object v = props.get(name);
- if ( v != null )
- {
- final String value = String.valueOf(v);
- return "true".equalsIgnoreCase(value) || "yes".equalsIgnoreCase(value);
- }
-
- return defValue;
- }
-
-
- /**
- * Get the property value as a string array.
- * Empty values are filtered out - if the resulting array is empty
- * the default value is returned.
- */
- private String[] getStringArrayProperty(final Dictionary<String, Object> props,String name, String[] defValue)
- {
- Object value = props.get(name);
- if (value instanceof String)
- {
- final String stringVal = ((String) value).trim();
- if (stringVal.length() > 0)
- {
- return stringVal.split(",");
- }
- }
- else if (value instanceof String[])
- {
- final String[] stringArr = (String[]) value;
- final List<String> list = new ArrayList<>();
- for (final String stringVal : stringArr)
- {
- if (stringVal.trim().length() > 0)
- {
- list.add(stringVal.trim());
- }
- }
- if (list.size() > 0)
- {
- return list.toArray(new String[list.size()]);
- }
- }
- else if (value instanceof Collection)
- {
- final ArrayList<String> conv = new ArrayList<>();
- for (Iterator<?> vi = ((Collection<?>) value).iterator(); vi.hasNext();)
- {
- Object object = vi.next();
- if (object != null)
- {
- conv.add(String.valueOf(object));
- }
- }
- if (conv.size() > 0)
- {
- return conv.toArray(new String[conv.size()]);
- }
- }
- return defValue;
- }
-
- /**
- * get Property values in set format,so that it can directly compare with remaining
- * attributes of session.using set, as it will take O(1) time for searching.
- * @param props
- * @param name
- * @return
- */
- private Set<String> getStringSetProperty(final Dictionary<String, Object> props,String name) {
-
- String array[] = getStringArrayProperty(props,name,new String[0]) ;
- Set<String> propertySet = new HashSet<>();
-
- for(String property : array){
-
- if(property != null && !"".equals(property.trim())){
- propertySet.add(property);
- }
- }
-
- return propertySet;
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java b/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java
deleted file mode 100644
index 15dc1aef96..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/HttpServiceController.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * 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;
-
-import java.util.Hashtable;
-
-import org.apache.felix.http.base.internal.dispatch.Dispatcher;
-import org.apache.felix.http.base.internal.dispatch.DispatcherServlet;
-import org.apache.felix.http.base.internal.handler.HttpSessionWrapper;
-import org.apache.felix.http.base.internal.registry.HandlerRegistry;
-import org.apache.felix.http.base.internal.whiteboard.WhiteboardManager;
-import org.jetbrains.annotations.NotNull;
-import org.osgi.framework.BundleContext;
-
-import jakarta.servlet.Servlet;
-import jakarta.servlet.ServletContext;
-import jakarta.servlet.http.HttpSessionEvent;
-import jakarta.servlet.http.HttpSessionIdListener;
-import jakarta.servlet.http.HttpSessionListener;
-
-/**
- * Controller for the http service
- */
-public final class HttpServiceController
-{
- private final BundleContext bundleContext;
- private final HandlerRegistry registry;
- private final Dispatcher dispatcher;
- private final EventDispatcher eventDispatcher;
- private final WhiteboardManager whiteboardManager;
-
- private final HttpConfig config = new HttpConfig();
-
- private volatile HttpSessionListener httpSessionListener;
-
- /**
- * Create new controller
- * @param bundleContext The bundle context
- */
- public HttpServiceController(final BundleContext bundleContext)
- {
- this.bundleContext = bundleContext;
- this.registry = new HandlerRegistry(config);
- this.dispatcher = new Dispatcher(this.registry);
- this.eventDispatcher = new EventDispatcher(this);
- this.whiteboardManager = new WhiteboardManager(bundleContext, this.registry);
- }
-
- /**
- * Stop the controller
- */
- public void stop()
- {
- this.unregister();
- }
-
- /**
- * Create a new dispatcher servlet
- * @return The dispatcher servlet.
- */
- public @NotNull Servlet createDispatcherServlet()
- {
- return new DispatcherServlet(this.dispatcher);
- }
-
- /**
- * Get the event dispatcher
- * @return The event dispatcher
- */
- public @NotNull EventDispatcher getEventDispatcher()
- {
- return this.eventDispatcher;
- }
-
- @NotNull HttpSessionListener getSessionListener()
- {
- // we don't need to sync here, if the object gets created several times
- // its not a problem
- if ( httpSessionListener == null )
- {
- httpSessionListener = new HttpSessionListener() {
-
- @Override
- public void sessionDestroyed(final HttpSessionEvent se) {
- whiteboardManager.sessionDestroyed(se.getSession(), HttpSessionWrapper.getSessionContextNames(se.getSession()));
- }
-
- @Override
- public void sessionCreated(final HttpSessionEvent se) {
- // nothing to do, session created event is sent from within the session
- }
- };
- }
- return httpSessionListener;
- }
-
- @NotNull HttpSessionIdListener getSessionIdListener()
- {
- return new HttpSessionIdListener() {
-
- @Override
- public void sessionIdChanged(final HttpSessionEvent event, final String oldSessionId) {
- whiteboardManager.sessionIdChanged(event, oldSessionId, HttpSessionWrapper.getSessionContextNames(event.getSession()));
- }
- };
- }
-
- /**
- * Start the http and http whiteboard service in the provided context.
- * @param containerContext The container context.
- */
- public void register(@NotNull final ServletContext containerContext, @NotNull final Hashtable<String, Object> props)
- {
- this.config.configure(props);
-
- this.whiteboardManager.start(containerContext, props);
-
- this.dispatcher.setWhiteboardManager(this.whiteboardManager);
- }
-
- /**
- * Stops the http and http whiteboard service.
- */
- public void unregister()
- {
- this.dispatcher.setWhiteboardManager(null);
-
- this.whiteboardManager.stop();
-
- this.registry.shutdown();
- this.httpSessionListener = null;
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/context/ExtServletContext.java b/http/base/src/main/java/org/apache/felix/http/base/internal/context/ExtServletContext.java
deleted file mode 100644
index a9a6c1e78a..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/context/ExtServletContext.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.context;
-
-import java.io.IOException;
-
-import org.apache.felix.http.base.internal.HttpConfig;
-
-import jakarta.servlet.ServletContext;
-import jakarta.servlet.ServletRequestAttributeListener;
-import jakarta.servlet.ServletRequestListener;
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpServletResponse;
-import jakarta.servlet.http.HttpSessionAttributeListener;
-import jakarta.servlet.http.HttpSessionListener;
-
-/**
- * Internal extension of the servlet context
- */
-public interface ExtServletContext extends ServletContext
-{
- boolean handleSecurity(HttpServletRequest req, HttpServletResponse res) throws IOException;
-
- void finishSecurity(HttpServletRequest req, HttpServletResponse res);
-
- HttpSessionAttributeListener getHttpSessionAttributeListener();
-
- HttpSessionListener getHttpSessionListener();
-
- ServletRequestListener getServletRequestListener();
-
- ServletRequestAttributeListener getServletRequestAttributeListener();
-
- HttpConfig getConfig();
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/context/ExtServletContextWrapper.java b/http/base/src/main/java/org/apache/felix/http/base/internal/context/ExtServletContextWrapper.java
deleted file mode 100644
index 2071d7adf2..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/context/ExtServletContextWrapper.java
+++ /dev/null
@@ -1,384 +0,0 @@
-/*
- * 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.context;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Enumeration;
-import java.util.EventListener;
-import java.util.Map;
-import java.util.Set;
-
-import jakarta.servlet.Filter;
-import jakarta.servlet.FilterRegistration;
-import jakarta.servlet.RequestDispatcher;
-import jakarta.servlet.Servlet;
-import jakarta.servlet.ServletContext;
-import jakarta.servlet.ServletException;
-import jakarta.servlet.ServletRegistration;
-import jakarta.servlet.ServletRegistration.Dynamic;
-import jakarta.servlet.ServletRequestAttributeListener;
-import jakarta.servlet.ServletRequestListener;
-import jakarta.servlet.SessionCookieConfig;
-import jakarta.servlet.SessionTrackingMode;
-import jakarta.servlet.descriptor.JspConfigDescriptor;
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpServletResponse;
-import jakarta.servlet.http.HttpSessionAttributeListener;
-import jakarta.servlet.http.HttpSessionListener;
-
-/**
- * Wrapper of an {code ExtServletContex}.
- * This implementation simply forwards to the delegate.
- */
-public abstract class ExtServletContextWrapper implements ExtServletContext
-{
- private final ExtServletContext delegate;
-
- public ExtServletContextWrapper(final ExtServletContext delegate)
- {
- this.delegate = delegate;
- }
-
- @Override
- public boolean handleSecurity(final HttpServletRequest req,
- final HttpServletResponse res) throws IOException
- {
- return delegate.handleSecurity(req, res);
- }
-
- @Override
- public HttpSessionAttributeListener getHttpSessionAttributeListener()
- {
- return delegate.getHttpSessionAttributeListener();
- }
-
- @Override
- public HttpSessionListener getHttpSessionListener()
- {
- return delegate.getHttpSessionListener();
- }
-
- @Override
- public ServletRequestListener getServletRequestListener()
- {
- return delegate.getServletRequestListener();
- }
-
- @Override
- public ServletRequestAttributeListener getServletRequestAttributeListener()
- {
- return delegate.getServletRequestAttributeListener();
- }
-
- @Override
- public String getContextPath()
- {
- return delegate.getContextPath();
- }
-
- @Override
- public ServletContext getContext(final String uripath)
- {
- return delegate.getContext(uripath);
- }
-
- @Override
- public int getMajorVersion()
- {
- return delegate.getMajorVersion();
- }
-
- @Override
- public int getMinorVersion()
- {
- return delegate.getMinorVersion();
- }
-
- @Override
- public int getEffectiveMajorVersion()
- {
- return delegate.getEffectiveMajorVersion();
- }
-
- @Override
- public int getEffectiveMinorVersion()
- {
- return delegate.getEffectiveMinorVersion();
- }
-
- @Override
- public String getMimeType(final String file)
- {
- return delegate.getMimeType(file);
- }
-
- @Override
- public Set<String> getResourcePaths(final String path)
- {
- return delegate.getResourcePaths(path);
- }
-
- @Override
- public URL getResource(final String path) throws MalformedURLException
- {
- return delegate.getResource(path);
- }
-
- @Override
- public InputStream getResourceAsStream(final String path)
- {
- return delegate.getResourceAsStream(path);
- }
-
- @Override
- public RequestDispatcher getRequestDispatcher(final String path)
- {
- return delegate.getRequestDispatcher(path);
- }
-
- @Override
- public RequestDispatcher getNamedDispatcher(final String name)
- {
- return delegate.getNamedDispatcher(name);
- }
-
- @Override
- public void log(final String msg)
- {
- delegate.log(msg);
- }
-
- @Override
- public void log(final String message, final Throwable throwable)
- {
- delegate.log(message, throwable);
- }
-
- @Override
- public String getRealPath(final String path)
- {
- return delegate.getRealPath(path);
- }
-
- @Override
- public String getServerInfo()
- {
- return delegate.getServerInfo();
- }
-
- @Override
- public String getInitParameter(final String name)
- {
- return delegate.getInitParameter(name);
- }
-
- @Override
- public Enumeration<String> getInitParameterNames()
- {
- return delegate.getInitParameterNames();
- }
-
- @Override
- public boolean setInitParameter(final String name, final String value)
- {
- return delegate.setInitParameter(name, value);
- }
-
- @Override
- public Object getAttribute(final String name)
- {
- return delegate.getAttribute(name);
- }
-
- @Override
- public Enumeration<String> getAttributeNames()
- {
- return delegate.getAttributeNames();
- }
-
- @Override
- public void setAttribute(final String name, final Object object)
- {
- delegate.setAttribute(name, object);
- }
-
- @Override
- public void removeAttribute(final String name)
- {
- delegate.removeAttribute(name);
- }
-
- @Override
- public String getServletContextName() {
- return delegate.getServletContextName();
- }
-
- @Override
- public Dynamic addServlet(final String servletName, final String className)
- {
- return delegate.addServlet(servletName, className);
- }
-
- @Override
- public Dynamic addServlet(final String servletName, final Servlet servlet)
- {
- return delegate.addServlet(servletName, servlet);
- }
-
- @Override
- public Dynamic addServlet(final String servletName,
- final Class<? extends Servlet> servletClass)
- {
- return delegate.addServlet(servletName, servletClass);
- }
-
- @Override
- public <T extends Servlet> T createServlet(final Class<T> clazz)
- throws ServletException
- {
- return delegate.createServlet(clazz);
- }
-
- @Override
- public ServletRegistration getServletRegistration(final String servletName)
- {
- return delegate.getServletRegistration(servletName);
- }
-
- @Override
- public Map<String, ? extends ServletRegistration> getServletRegistrations()
- {
- return delegate.getServletRegistrations();
- }
-
- @Override
- public jakarta.servlet.FilterRegistration.Dynamic addFilter(
- final String filterName, final String className)
- {
- return delegate.addFilter(filterName, className);
- }
-
- @Override
- public jakarta.servlet.FilterRegistration.Dynamic addFilter(
- final String filterName, final Filter filter)
- {
- return delegate.addFilter(filterName, filter);
- }
-
- @Override
- public jakarta.servlet.FilterRegistration.Dynamic addFilter(
- final String filterName, final Class<? extends Filter> filterClass)
- {
- return delegate.addFilter(filterName, filterClass);
- }
-
- @Override
- public <T extends Filter> T createFilter(final Class<T> clazz)
- throws ServletException
- {
- return delegate.createFilter(clazz);
- }
-
- @Override
- public FilterRegistration getFilterRegistration(final String filterName)
- {
- return delegate.getFilterRegistration(filterName);
- }
-
- @Override
- public Map<String, ? extends FilterRegistration> getFilterRegistrations()
- {
- return delegate.getFilterRegistrations();
- }
-
- @Override
- public SessionCookieConfig getSessionCookieConfig()
- {
- return delegate.getSessionCookieConfig();
- }
-
- @Override
- public void setSessionTrackingModes(
- final Set<SessionTrackingMode> sessionTrackingModes)
- {
- delegate.setSessionTrackingModes(sessionTrackingModes);
- }
-
- @Override
- public Set<SessionTrackingMode> getDefaultSessionTrackingModes()
- {
- return delegate.getDefaultSessionTrackingModes();
- }
-
- @Override
- public Set<SessionTrackingMode> getEffectiveSessionTrackingModes()
- {
- return delegate.getEffectiveSessionTrackingModes();
- }
-
- @Override
- public void addListener(final String className)
- {
- delegate.addListener(className);
- }
-
- @Override
- public <T extends EventListener> void addListener(final T t)
- {
- delegate.addListener(t);
- }
-
- @Override
- public void addListener(final Class<? extends EventListener> listenerClass)
- {
- delegate.addListener(listenerClass);
- }
-
- @Override
- public <T extends EventListener> T createListener(final Class<T> clazz)
- throws ServletException
- {
- return delegate.createListener(clazz);
- }
-
- @Override
- public JspConfigDescriptor getJspConfigDescriptor()
- {
- return delegate.getJspConfigDescriptor();
- }
-
- @Override
- public ClassLoader getClassLoader()
- {
- return delegate.getClassLoader();
- }
-
- @Override
- public void declareRoles(final String... roleNames)
- {
- delegate.declareRoles(roleNames);
- }
-
- @Override
- public String getVirtualServerName()
- {
- return delegate.getVirtualServerName();
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java b/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
deleted file mode 100644
index 243ad2d61f..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/Dispatcher.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * 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.dispatch;
-
-import java.io.IOException;
-import java.util.Set;
-
-import org.apache.felix.http.base.internal.context.ExtServletContext;
-import org.apache.felix.http.base.internal.handler.FilterHandler;
-import org.apache.felix.http.base.internal.handler.HttpSessionWrapper;
-import org.apache.felix.http.base.internal.logger.SystemLogger;
-import org.apache.felix.http.base.internal.registry.HandlerRegistry;
-import org.apache.felix.http.base.internal.registry.PathResolution;
-import org.apache.felix.http.base.internal.registry.PerContextHandlerRegistry;
-import org.apache.felix.http.base.internal.whiteboard.WhiteboardManager;
-import org.jetbrains.annotations.Nullable;
-import org.osgi.service.servlet.whiteboard.Preprocessor;
-
-import jakarta.servlet.FilterChain;
-import jakarta.servlet.FilterConfig;
-import jakarta.servlet.RequestDispatcher;
-import jakarta.servlet.ServletException;
-import jakarta.servlet.ServletRequest;
-import jakarta.servlet.ServletRequestEvent;
-import jakarta.servlet.ServletResponse;
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpServletResponse;
-import jakarta.servlet.http.HttpSession;
-
-public final class Dispatcher
-{
- private final HandlerRegistry handlerRegistry;
-
- private volatile WhiteboardManager whiteboardManager;
-
- public Dispatcher(final HandlerRegistry handlerRegistry)
- {
- this.handlerRegistry = handlerRegistry;
- }
-
- /**
- * Set or unset the whiteboard manager.
- * @param service The whiteboard manager or {@code null}
- */
- public void setWhiteboardManager(@Nullable final WhiteboardManager service)
- {
- this.whiteboardManager = service;
- }
-
- /**
- * Responsible for dispatching a given request to the actual applicable servlet and/or filters in the local registry.
- *
- * @param req the {@link ServletRequest} to dispatch;
- * @param res the {@link ServletResponse} to dispatch.
- * @throws ServletException in case of exceptions during the actual dispatching;
- * @throws IOException in case of I/O problems.
- */
- public void dispatch(final HttpServletRequest req, final HttpServletResponse res) throws ServletException, IOException
- {
- final WhiteboardManager mgr = this.whiteboardManager;
- if ( mgr == null )
- {
- // not active, always return 404
- if ( !res.isCommitted() )
- {
- res.sendError(404);
- }
- return;
- }
-
- // check for invalidating session(s) first
- final HttpSession session = req.getSession(false);
- if ( session != null )
- {
- final Set<String> names = HttpSessionWrapper.getExpiredSessionContextNames(session);
- mgr.sessionDestroyed(session, names);
- }
-
- // invoke preprocessors and then dispatching
- mgr.invokePreprocessors(req, res, new Preprocessor() {
-
- @Override
- public void init(final FilterConfig filterConfig) throws ServletException
- {
- // nothing to do
- }
-
- @Override
- public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
- throws IOException, ServletException
- {
- final HttpServletRequest req = (HttpServletRequest)request;
- final HttpServletResponse res = (HttpServletResponse)response;
- // get full decoded path for dispatching
- // we can't use req.getRequestURI() or req.getRequestURL() as these are returning the encoded path
- String path = req.getServletPath();
- if ( path == null )
- {
- path = "";
- }
- if ( req.getPathInfo() != null )
- {
- path = path.concat(req.getPathInfo());
- }
- final String requestURI = path;
-
- // Determine which servlet we should forward the request to...
- final PathResolution pr = handlerRegistry.resolveServlet(requestURI);
-
- final PerContextHandlerRegistry errorRegistry = (pr != null ? pr.handlerRegistry : handlerRegistry.getBestMatchingRegistry(requestURI));
- final String servletName = (pr != null ? pr.handler.getName() : null);
- final HttpServletResponse wrappedResponse = new ServletResponseWrapper(req, res, servletName, errorRegistry);
- if ( pr == null )
- {
- if ( !wrappedResponse.isCommitted() )
- {
- wrappedResponse.sendError(404);
- }
- return;
- }
-
- final ExtServletContext servletContext = pr.handler.getContext();
- final RequestInfo requestInfo = new RequestInfo(pr.servletPath, pr.pathInfo, null, req.getRequestURI(),
- pr.handler.getName(), pr.matchedPattern, pr.matchValue, pr.match, false);
- final HttpServletRequest wrappedRequest = new ServletRequestWrapper(req, servletContext, requestInfo, null,
- pr.handler.getServletInfo().isAsyncSupported(),
- pr.handler.getMultipartConfig(),
- pr.handler.getMultipartSecurityContext());
- final FilterHandler[] filterHandlers = handlerRegistry.getFilters(pr, req.getDispatcherType(), pr.requestURI);
-
- try
- {
- if ( servletContext.getServletRequestListener() != null )
- {
- servletContext.getServletRequestListener().requestInitialized(new ServletRequestEvent(servletContext, wrappedRequest));
- }
- final FilterChain filterChain = new InvocationChain(pr.handler, filterHandlers);
- filterChain.doFilter(wrappedRequest, wrappedResponse);
-
- }
- catch ( Exception e)
- {
- SystemLogger.LOGGER.error("Exception while processing request to " + requestURI, e);
- req.setAttribute(RequestDispatcher.ERROR_EXCEPTION, e);
- req.setAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE, e.getClass().getName());
-
- if ( !wrappedResponse.isCommitted() )
- {
- wrappedResponse.sendError(500);
- }
- }
- finally
- {
- if ( servletContext.getServletRequestListener() != null )
- {
- servletContext.getServletRequestListener().requestDestroyed(new ServletRequestEvent(servletContext, wrappedRequest));
- }
- }
- }
-
- @Override
- public void destroy()
- {
- // nothing to do
- }
- });
-
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/DispatcherServlet.java b/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/DispatcherServlet.java
deleted file mode 100644
index ccb3e7520f..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/DispatcherServlet.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.dispatch;
-
-import java.io.IOException;
-
-import jakarta.servlet.ServletException;
-import jakarta.servlet.http.HttpServlet;
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpServletResponse;
-
-import org.apache.felix.http.base.internal.HttpServiceController;
-
-/**
- * The dispatcher servlet is registered in the container.
- * It is dispatching requests to the http implementation.
- * It does not start the http service, this needs to be done
- * through the {@link HttpServiceController}.
- */
-public class DispatcherServlet extends HttpServlet
-{
- private static final long serialVersionUID = -7692620012572476116L;
-
- private final Dispatcher controller;
-
- public DispatcherServlet(final Dispatcher controller)
- {
- this.controller = controller;
- }
-
- @Override
- protected void service(final HttpServletRequest req, final HttpServletResponse res)
- throws ServletException, IOException
- {
- this.controller.dispatch(req, res);
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/IncludeResponseWrapper.java b/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/IncludeResponseWrapper.java
deleted file mode 100644
index 5dea672570..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/IncludeResponseWrapper.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * 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.dispatch;
-
-import java.io.IOException;
-import java.util.Locale;
-
-import jakarta.servlet.http.Cookie;
-import jakarta.servlet.http.HttpServletResponse;
-import jakarta.servlet.http.HttpServletResponseWrapper;
-
-/**
- * Wrapper to handle dispatching of includes where all changes to headers
- * are simply silently ignored (see section 9.3 of the servlet specification)
- */
-public class IncludeResponseWrapper extends HttpServletResponseWrapper {
-
- public IncludeResponseWrapper(final HttpServletResponse response) {
- super(response);
- }
-
- @Override
- public void reset() {
- // ignore if not committed
- if (getResponse().isCommitted()) {
- getResponse().reset();
- }
- }
-
- @Override
- public void setContentLength(final int len) {
- // ignore
- }
-
- @Override
- public void setContentLengthLong(final long len) {
- // ignore
- }
-
- @Override
- public void setContentType(final String type) {
- // ignore
- }
-
- @Override
- public void setLocale(final Locale loc) {
- // ignore
- }
-
- @Override
- public void setBufferSize(final int size) {
- // ignore
- }
-
- @Override
- public void addCookie(final Cookie cookie) {
- // ignore
- }
-
-
- @Override
- public void addDateHeader(final String name, final long value) {
- // ignore
- }
-
- @Override
- public void addHeader(final String name, final String value) {
- // ignore
- }
-
- @Override
- public void addIntHeader(final String name, final int value) {
- // ignore
- }
-
- @Override
- public void sendError(final int sc) throws IOException {
- // ignore
- }
-
- @Override
- public void sendError(final int sc, final String msg) throws IOException {
- // ignore
- }
-
- @Override
- public void sendRedirect(final String location) throws IOException {
- // ignore
- }
-
- @Override
- public void setDateHeader(final String name, final long value) {
- // ignore
- }
-
- @Override
- public void setHeader(final String name, final String value) {
- // ignore
- }
-
- @Override
- public void setIntHeader(final String name, final int value) {
- // ignore
- }
-
- @Override
- public void setStatus(final int sc) {
- // ignore
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/InvocationChain.java b/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/InvocationChain.java
deleted file mode 100644
index 78af52dc57..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/InvocationChain.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * 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.dispatch;
-
-import static jakarta.servlet.http.HttpServletResponse.SC_FORBIDDEN;
-import static jakarta.servlet.http.HttpServletResponse.SC_OK;
-
-import java.io.IOException;
-
-import org.jetbrains.annotations.NotNull;
-import jakarta.servlet.FilterChain;
-import jakarta.servlet.ServletException;
-import jakarta.servlet.ServletRequest;
-import jakarta.servlet.ServletResponse;
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpServletResponse;
-
-import org.apache.felix.http.base.internal.handler.FilterHandler;
-import org.apache.felix.http.base.internal.handler.ServletHandler;
-
-public class InvocationChain implements FilterChain
-{
- private final ServletHandler servletHandler;
- private final FilterHandler[] filterHandlers;
-
- private int index = -1;
-
- public InvocationChain(@NotNull final ServletHandler servletHandler, @NotNull final FilterHandler[] filterHandlers)
- {
- this.filterHandlers = filterHandlers;
- this.servletHandler = servletHandler;
- }
-
- @Override
- public final void doFilter(@NotNull final ServletRequest req, @NotNull final ServletResponse res) throws IOException, ServletException
- {
- boolean callFinish = false;
- if ( this.index == -1 )
- {
- final HttpServletRequest hReq = (HttpServletRequest) req;
- final HttpServletResponse hRes = (HttpServletResponse) res;
-
- // invoke security
- if ( !servletHandler.getContext().handleSecurity(hReq, hRes))
- {
- // FELIX-3988: If the response is not yet committed and still has the default
- // status, we're going to override this and send an error instead.
- if (!res.isCommitted() && (hRes.getStatus() == SC_OK || hRes.getStatus() == 0))
- {
- hRes.sendError(SC_FORBIDDEN);
- }
-
- // we're done
- return;
- }
- else
- {
- callFinish = true;
- }
- }
- this.index++;
-
- try
- {
- if (this.index < this.filterHandlers.length)
- {
- this.filterHandlers[this.index].handle(req, res, this);
- }
- else
- {
- // Last entry in the chain...
- this.servletHandler.handle(req, res);
- }
- }
- finally {
- if ( callFinish )
- {
- final HttpServletRequest hReq = (HttpServletRequest) req;
- final HttpServletResponse hRes = (HttpServletResponse) res;
-
- servletHandler.getContext().finishSecurity(hReq, hRes);
- }
- }
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/MultipartConfig.java b/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/MultipartConfig.java
deleted file mode 100644
index aa75be6d83..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/MultipartConfig.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * 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.dispatch;
-
-import java.util.Objects;
-
-import org.apache.commons.fileupload2.core.DiskFileItemFactory;
-
-public final class MultipartConfig
-{
- public static final MultipartConfig DEFAULT_CONFIG = new MultipartConfig(null, null, -1, -1, -1);
-
- public static final MultipartConfig INVALID_CONFIG = new MultipartConfig(null, null, -1, -1, -1);
-
- /**
- * Specifies the multipart threshold
- */
- public final int multipartThreshold;
-
- /**
- * Specifies the multipart location
- */
- public final String multipartLocation;
-
- /**
- * Specifies the multipart max file size
- */
- public final long multipartMaxFileSize;
-
- /**
- * Specifies the multipart max request size
- */
- public final long multipartMaxRequestSize;
-
- /**
- * Specifies the multipart max files
- */
- public final long multipartMaxFileCount;
-
- public MultipartConfig(final Integer threshold,
- final String location,
- final long maxFileSize,
- final long maxRequestSize,
- final long maxFileCount)
- {
- if ( threshold != null && threshold > 0)
- {
- this.multipartThreshold = threshold;
- }
- else
- {
- this.multipartThreshold = DiskFileItemFactory.DEFAULT_THRESHOLD;
- }
- this.multipartLocation = location;
- if ( maxFileSize > 0 || maxFileSize == -1 ) {
- this.multipartMaxFileSize = maxFileSize;
- }
- else
- {
- this.multipartMaxFileSize = -1;
- }
- if ( maxRequestSize > 0 || maxRequestSize == -1 ) {
- this.multipartMaxRequestSize = maxRequestSize;
- }
- else
- {
- this.multipartMaxRequestSize = -1;
- }
- if ( maxFileCount > 0 ) {
- this.multipartMaxFileCount = maxFileCount;
- }
- else
- {
- this.multipartMaxFileCount = 50;
- }
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(multipartThreshold, multipartLocation, multipartMaxFileSize, multipartMaxRequestSize,
- multipartMaxFileCount);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- MultipartConfig other = (MultipartConfig) obj;
- return multipartThreshold == other.multipartThreshold
- && Objects.equals(multipartLocation, other.multipartLocation)
- && multipartMaxFileSize == other.multipartMaxFileSize
- && multipartMaxRequestSize == other.multipartMaxRequestSize
- && multipartMaxFileCount == other.multipartMaxFileCount;
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/RequestDispatcherImpl.java b/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/RequestDispatcherImpl.java
deleted file mode 100644
index f95fef94ac..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/RequestDispatcherImpl.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * 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.dispatch;
-
-import java.io.IOException;
-
-import jakarta.servlet.DispatcherType;
-import jakarta.servlet.FilterChain;
-import jakarta.servlet.RequestDispatcher;
-import jakarta.servlet.ServletException;
-import jakarta.servlet.ServletRequest;
-import jakarta.servlet.ServletResponse;
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpServletResponse;
-
-import org.apache.felix.http.base.internal.handler.FilterHandler;
-import org.apache.felix.http.base.internal.registry.ServletResolution;
-import org.apache.felix.http.base.internal.util.UriUtils;
-import org.jetbrains.annotations.NotNull;
-
-/**
- * Wrapper implementation for {@link RequestDispatcher}.
- */
-public final class RequestDispatcherImpl implements RequestDispatcher
-{
- private final RequestInfo requestInfo;
- private final ServletResolution resolution;
-
- /**
- * Create new dispatcher
- * @param resolution The resolution
- * @param requestInfo The request info
- */
- public RequestDispatcherImpl(@NotNull final ServletResolution resolution,
- @NotNull final RequestInfo requestInfo)
- {
- this.resolution = resolution;
- this.requestInfo = requestInfo;
- }
-
- @Override
- public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException
- {
- if (response.isCommitted())
- {
- throw new ServletException("Response has been committed");
- }
- else
- {
- // See section 9.4 of Servlet 3.0 spec
- response.resetBuffer();
- }
-
- try
- {
- final ServletRequestWrapper req = new ServletRequestWrapper((HttpServletRequest) request,
- this.resolution.handler.getContext(),
- this.requestInfo,
- DispatcherType.FORWARD,
- this.resolution.handler.getServletInfo().isAsyncSupported(),
- this.resolution.handler.getMultipartConfig(),
- this.resolution.handler.getMultipartSecurityContext());
- final String requestURI = UriUtils.concat(this.requestInfo.servletPath, this.requestInfo.pathInfo);
- final FilterHandler[] filterHandlers = this.resolution.handlerRegistry.getFilterHandlers(this.resolution.handler, DispatcherType.FORWARD, requestURI);
-
- final FilterChain filterChain = new InvocationChain(resolution.handler, filterHandlers);
- filterChain.doFilter( req, response);
- }
- finally
- {
- // After a forward has taken place, the results should be committed,
- // see section 9.4 of Servlet 3.0 spec...
- if (!request.isAsyncStarted())
- {
- response.flushBuffer();
- try {
- try {
- response.getWriter().close();
- } catch ( final IllegalStateException ise ) {
- // output stream has been used
- response.getOutputStream().close();
- }
- } catch ( final Exception ignore ) {
- // ignore everything, see FELIX-5053
- }
- }
- }
- }
-
- @Override
- public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException
- {
- final ServletRequestWrapper req = new ServletRequestWrapper((HttpServletRequest) request,
- this.resolution.handler.getContext(),
- this.requestInfo,
- DispatcherType.INCLUDE,
- this.resolution.handler.getServletInfo().isAsyncSupported(),
- this.resolution.handler.getMultipartConfig(),
- this.resolution.handler.getMultipartSecurityContext());
- final String requestURI = UriUtils.concat(this.requestInfo.servletPath, this.requestInfo.pathInfo);
- final FilterHandler[] filterHandlers = this.resolution.handlerRegistry.getFilterHandlers(this.resolution.handler, DispatcherType.INCLUDE, requestURI);
-
- final FilterChain filterChain = new InvocationChain(resolution.handler, filterHandlers);
- filterChain.doFilter( req, new IncludeResponseWrapper((HttpServletResponse)response));
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/RequestInfo.java b/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/RequestInfo.java
deleted file mode 100644
index 9a01930b17..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/RequestInfo.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * 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.dispatch;
-
-import jakarta.servlet.http.HttpServletMapping;
-import jakarta.servlet.http.MappingMatch;
-
-/**
- * Information about the request
- */
-public final class RequestInfo implements HttpServletMapping
-{
- final String servletPath;
- final String pathInfo;
- final String queryString;
- final String requestURI;
- private final String matchServletName;
- private final String matchPattern;
- private final String matchValue;
- private final MappingMatch match;
- final boolean nameMatch;
-
- /**
- * Create a new request info
- * @param servletPath The servlet path
- * @param pathInfo The path info
- * @param queryString The query string
- * @param requestURI The request uri
- * @param matchServletName The servlet name
- * @param matchPattern The servlet pattern
- * @param matchValue The value matching
- * @param match The match type
- * @param nameMatch Is named dispatcher
- */
- public RequestInfo(final String servletPath,
- final String pathInfo,
- final String queryString,
- final String requestURI,
- final String matchServletName,
- final String matchPattern,
- final String matchValue,
- final MappingMatch match,
- final boolean nameMatch)
- {
- this.servletPath = servletPath;
- this.pathInfo = pathInfo;
- this.queryString = queryString;
- this.requestURI = requestURI;
- this.matchServletName = matchServletName;
- this.matchPattern = matchPattern;
- this.matchValue = matchValue;
- this.match = match;
- this.nameMatch = nameMatch;
- }
-
- @Override
- public String getMatchValue() {
- return this.matchValue;
- }
-
- @Override
- public String getPattern() {
- return this.matchPattern;
- }
-
- @Override
- public String getServletName() {
- return this.matchServletName;
- }
-
- @Override
- public MappingMatch getMappingMatch() {
- return this.match;
- }
-
- @Override
- public String toString()
- {
- StringBuilder sb = new StringBuilder("RequestInfo[servletPath =");
- sb.append(this.servletPath).append(", pathInfo = ").append(this.pathInfo);
- sb.append(", queryString = ").append(this.queryString).append("]");
- return sb.toString();
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/ServletRequestWrapper.java b/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/ServletRequestWrapper.java
deleted file mode 100644
index 59eae58b05..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/ServletRequestWrapper.java
+++ /dev/null
@@ -1,622 +0,0 @@
-/*
- * 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.dispatch;
-
-import static jakarta.servlet.RequestDispatcher.FORWARD_CONTEXT_PATH;
-import static jakarta.servlet.RequestDispatcher.FORWARD_MAPPING;
-import static jakarta.servlet.RequestDispatcher.FORWARD_PATH_INFO;
-import static jakarta.servlet.RequestDispatcher.FORWARD_QUERY_STRING;
-import static jakarta.servlet.RequestDispatcher.FORWARD_REQUEST_URI;
-import static jakarta.servlet.RequestDispatcher.FORWARD_SERVLET_PATH;
-import static jakarta.servlet.RequestDispatcher.INCLUDE_CONTEXT_PATH;
-import static jakarta.servlet.RequestDispatcher.INCLUDE_MAPPING;
-import static jakarta.servlet.RequestDispatcher.INCLUDE_PATH_INFO;
-import static jakarta.servlet.RequestDispatcher.INCLUDE_QUERY_STRING;
-import static jakarta.servlet.RequestDispatcher.INCLUDE_REQUEST_URI;
-import static jakarta.servlet.RequestDispatcher.INCLUDE_SERVLET_PATH;
-import static org.apache.felix.http.base.internal.util.UriUtils.concat;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.security.AccessControlContext;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.commons.fileupload2.core.DiskFileItemFactory;
-import org.apache.commons.fileupload2.core.FileItem;
-import org.apache.commons.fileupload2.core.FileUploadException;
-import org.apache.commons.fileupload2.jakarta.servlet6.JakartaServletFileUpload;
-import org.apache.commons.fileupload2.jakarta.servlet6.JakartaServletRequestContext;
-import org.apache.felix.http.base.internal.context.ExtServletContext;
-import org.apache.felix.http.base.internal.handler.HttpSessionWrapper;
-import org.osgi.framework.Bundle;
-import org.osgi.service.servlet.context.ServletContextHelper;
-import org.osgi.service.useradmin.Authorization;
-
-import jakarta.servlet.AsyncContext;
-import jakarta.servlet.DispatcherType;
-import jakarta.servlet.RequestDispatcher;
-import jakarta.servlet.ServletContext;
-import jakarta.servlet.ServletException;
-import jakarta.servlet.ServletRequest;
-import jakarta.servlet.ServletRequestAttributeEvent;
-import jakarta.servlet.ServletResponse;
-import jakarta.servlet.http.HttpServletMapping;
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpServletRequestWrapper;
-import jakarta.servlet.http.HttpSession;
-import jakarta.servlet.http.Part;
-
-final class ServletRequestWrapper extends HttpServletRequestWrapper
-{
- private static final List<String> FORWARD_ATTRIBUTES = Arrays.asList(FORWARD_CONTEXT_PATH,
- FORWARD_MAPPING, FORWARD_PATH_INFO, FORWARD_QUERY_STRING, FORWARD_REQUEST_URI, FORWARD_SERVLET_PATH);
-
- private static final List<String> INCLUDE_ATTRIBUTES = Arrays.asList(INCLUDE_CONTEXT_PATH,
- INCLUDE_MAPPING, INCLUDE_PATH_INFO, INCLUDE_QUERY_STRING, INCLUDE_REQUEST_URI, INCLUDE_SERVLET_PATH);
-
- /**
- * Constant for HTTP POST method.
- */
- private static final String POST_METHOD = "POST";
-
- private final DispatcherType type;
- private final RequestInfo requestInfo;
- private final ExtServletContext servletContext;
- private final boolean asyncSupported;
- private final MultipartConfig multipartConfig;
- private final Bundle bundleForSecurityCheck;
-
- private Collection<Part> parts;
-
- public ServletRequestWrapper(final HttpServletRequest req,
- final ExtServletContext servletContext,
- final RequestInfo requestInfo,
- final DispatcherType type,
- final boolean asyncSupported,
- final MultipartConfig multipartConfig,
- final Bundle bundleForSecurityCheck)
- {
- super(req);
-
- this.asyncSupported = asyncSupported;
- this.multipartConfig = multipartConfig;
- this.servletContext = servletContext;
- this.requestInfo = requestInfo;
- this.type = type;
- this.bundleForSecurityCheck = bundleForSecurityCheck;
- }
-
- @Override
- public Object getAttribute(String name)
- {
- HttpServletRequest request = (HttpServletRequest) getRequest();
- if (isInclusionDispatcher() && !this.requestInfo.nameMatch)
- {
- // The jakarta.servlet.include.* attributes refer to the information of the *included* request,
- // meaning that the request information comes from the *original* request...
- if (INCLUDE_REQUEST_URI.equals(name))
- {
- return this.requestInfo.requestURI;
- }
- else if (INCLUDE_CONTEXT_PATH.equals(name))
- {
- return request.getContextPath();
- }
- else if (INCLUDE_SERVLET_PATH.equals(name))
- {
- return this.requestInfo.servletPath;
- }
- else if (INCLUDE_PATH_INFO.equals(name))
- {
- return this.requestInfo.pathInfo;
- }
- else if (INCLUDE_QUERY_STRING.equals(name))
- {
- return this.requestInfo.queryString;
- }
- else if (INCLUDE_MAPPING.equals(name))
- {
- return this.requestInfo;
- }
- // include might be contained within a forward, allow forward attributes
- else if (FORWARD_ATTRIBUTES.contains(name) ) {
- return super.getAttribute(name);
- }
- }
- else if (isForwardingDispatcher() && !this.requestInfo.nameMatch)
- {
- // The jakarta.servlet.forward.* attributes refer to the information of the *original* request,
- // meaning that the request information comes from the *forwarded* request...
- if (FORWARD_REQUEST_URI.equals(name))
- {
- return super.getRequestURI();
- }
- else if (FORWARD_CONTEXT_PATH.equals(name))
- {
- return request.getContextPath();
- }
- else if (FORWARD_SERVLET_PATH.equals(name))
- {
- return super.getServletPath();
- }
- else if (FORWARD_PATH_INFO.equals(name))
- {
- return super.getPathInfo();
- }
- else if (FORWARD_QUERY_STRING.equals(name))
- {
- return super.getQueryString();
- }
- else if (FORWARD_MAPPING.equals(name))
- {
- return super.getHttpServletMapping();
- }
- }
- // block all special attributes
- if (INCLUDE_ATTRIBUTES.contains(name) || FORWARD_ATTRIBUTES.contains(name))
- {
- return null;
- }
- return super.getAttribute(name);
- }
-
- @Override
- public Enumeration<String> getAttributeNames() {
- if ( isForwardingDispatcher() || isInclusionDispatcher() ) {
- final Set<String> allNames = new HashSet<>(Collections.list(super.getAttributeNames()));
- if ( isForwardingDispatcher() ) {
- allNames.addAll(FORWARD_ATTRIBUTES);
- } else {
- allNames.addAll(INCLUDE_ATTRIBUTES);
- }
- return Collections.enumeration(allNames);
- }
- return super.getAttributeNames();
- }
-
- @Override
- public String getAuthType()
- {
- String authType = (String) getAttribute(ServletContextHelper.AUTHENTICATION_TYPE);
- if (authType == null)
- {
- authType = super.getAuthType();
- }
- return authType;
- }
-
- @Override
- public String getContextPath()
- {
- return this.getServletContext().getContextPath();
- }
-
- @Override
- public DispatcherType getDispatcherType()
- {
- return (this.type == null) ? super.getDispatcherType() : this.type;
- }
-
- @Override
- public String getPathInfo()
- {
- if ( this.isInclusionDispatcher() )
- {
- return super.getPathInfo();
- }
- return this.requestInfo.pathInfo;
- }
-
- @Override
- public String getPathTranslated()
- {
- final String info = getPathInfo();
- return (null == info) ? null : this.servletContext.getRealPath(info);
- }
-
- @Override
- public String getRemoteUser()
- {
- String remoteUser = (String) getAttribute(ServletContextHelper.REMOTE_USER);
- if (remoteUser != null)
- {
- return remoteUser;
- }
-
- return super.getRemoteUser();
- }
-
- @Override
- public RequestDispatcher getRequestDispatcher(String path)
- {
- // See section 9.1 of Servlet 3.0 specification...
- if (path == null)
- {
- return null;
- }
- // Handle relative paths, see Servlet 3.0 spec, section 9.1 last paragraph.
- boolean relPath = !path.startsWith("/") && !"".equals(path);
- if (relPath)
- {
- path = concat(getServletPath(), path);
- }
- return this.servletContext.getRequestDispatcher(path);
- }
-
- @Override
- public String getRequestURI()
- {
- if ( isInclusionDispatcher() )
- {
- return super.getRequestURI();
- }
- return this.requestInfo.requestURI;
- }
-
- @Override
- public ServletContext getServletContext()
- {
- return this.servletContext;
- }
-
- @Override
- public String getServletPath()
- {
- if ( isInclusionDispatcher() )
- {
- return super.getServletPath();
- }
- return this.requestInfo.servletPath;
- }
-
- @Override
- public HttpSession getSession() {
- return this.getSession(true);
- }
-
- @Override
- public HttpSession getSession(boolean create)
- {
- // FELIX-2797: wrap the original HttpSession to provide access to the correct ServletContext...
- final HttpSession session = super.getSession(create);
- if (session == null)
- {
- return null;
- }
- // check if internal session is available
- if ( !create && !HttpSessionWrapper.hasSession(this.servletContext.getServletContextName(), session) )
- {
- return null;
- }
- return new HttpSessionWrapper(session, this.servletContext, this.servletContext.getConfig(), false);
- }
-
- @Override
- public boolean isUserInRole(String role)
- {
- final Object authorization = getAttribute(ServletContextHelper.AUTHORIZATION);
- if (authorization instanceof Authorization )
- {
- return ((Authorization)authorization).hasRole(role);
- }
-
- return super.isUserInRole(role);
- }
-
- @Override
- public void setAttribute(final String name, final Object value)
- {
- if ( value == null )
- {
- this.removeAttribute(name);
- }
- final Object oldValue = this.getAttribute(name);
- super.setAttribute(name, value);
- if ( this.servletContext.getServletRequestAttributeListener() != null )
- {
- if ( oldValue == null )
- {
- this.servletContext.getServletRequestAttributeListener().attributeAdded(new ServletRequestAttributeEvent(this.servletContext, this, name, value));
- }
- else
- {
- this.servletContext.getServletRequestAttributeListener().attributeReplaced(new ServletRequestAttributeEvent(this.servletContext, this, name, oldValue));
- }
- }
- }
-
- @Override
- public void removeAttribute(final String name) {
- final Object oldValue = this.getAttribute(name);
- if ( oldValue != null )
- {
- super.removeAttribute(name);
- if ( this.servletContext.getServletRequestAttributeListener() != null )
- {
- this.servletContext.getServletRequestAttributeListener().attributeRemoved(new ServletRequestAttributeEvent(this.servletContext, this, name, oldValue));
- }
- }
- }
-
- @Override
- public String toString()
- {
- return getClass().getSimpleName() + "->" + super.getRequest();
- }
-
- private boolean isForwardingDispatcher()
- {
- return DispatcherType.FORWARD == this.type;
- }
-
- private boolean isInclusionDispatcher()
- {
- return DispatcherType.INCLUDE == this.type;
- }
-
- @Override
- public AsyncContext startAsync() throws IllegalStateException
- {
- if ( !this.asyncSupported )
- {
- throw new IllegalStateException();
- }
- return super.startAsync();
- }
-
- @Override
- public AsyncContext startAsync(final ServletRequest servletRequest,
- final ServletResponse servletResponse) throws IllegalStateException
- {
- if ( !this.asyncSupported )
- {
- throw new IllegalStateException();
- }
- return super.startAsync(servletRequest, servletResponse);
- }
-
- @Override
- public boolean isAsyncSupported()
- {
- return this.asyncSupported;
- }
-
-
- private Collection<Part> checkMultipart() throws IOException, ServletException
- {
- if ( parts == null )
- {
- final JakartaServletRequestContext multipartContext;
- if (!POST_METHOD.equalsIgnoreCase(this.getMethod())) {
- multipartContext = null;
- } else {
- multipartContext = new JakartaServletRequestContext( (HttpServletRequest) getRequest()) {
-
- @Override
- public InputStream getInputStream() throws IOException {
- return ServletRequestWrapper.this.getInputStream();
- }
-
- @Override
- public String getContentType() {
- return ServletRequestWrapper.this.getContentType();
- }
-
- @Override
- public long getContentLength() {
- return ServletRequestWrapper.this.getContentLength();
- }
-
- @Override
- public String getCharacterEncoding() {
- return ServletRequestWrapper.this.getCharacterEncoding();
- }
- };
- }
- if ( multipartContext != null && JakartaServletFileUpload.isMultipartContent(multipartContext) )
- {
- if ( this.multipartConfig == null)
- {
- throw new IllegalStateException("Multipart not enabled for servlet.");
- }
-
- if ( System.getSecurityManager() == null )
- {
- handleMultipart(multipartContext);
- }
- else
- {
- final AccessControlContext ctx = bundleForSecurityCheck.adapt(AccessControlContext.class);
- final IOException ioe = AccessController.doPrivileged(new PrivilegedAction<IOException>()
- {
-
- @Override
- public IOException run()
- {
- try
- {
- handleMultipart(multipartContext);
- }
- catch ( final IOException ioe)
- {
- return ioe;
- }
- return null;
- }
- }, ctx);
- if ( ioe != null )
- {
- throw ioe;
- }
- }
-
- }
- else
- {
- throw new ServletException("Not a multipart request");
- }
- }
- return parts;
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- private void handleMultipart(final JakartaServletRequestContext multipartContext) throws IOException
- {
- // Create a new file upload handler
- final JakartaServletFileUpload upload = new JakartaServletFileUpload();
- upload.setSizeMax(this.multipartConfig.multipartMaxRequestSize);
- upload.setFileSizeMax(this.multipartConfig.multipartMaxFileSize);
- upload.setFileItemFactory(DiskFileItemFactory.builder().setBufferSize(this.multipartConfig.multipartThreshold)
- .setFile(new File(this.multipartConfig.multipartLocation)).get());
- upload.setFileCountMax(this.multipartConfig.multipartMaxFileCount);
- // Parse the request
- List<FileItem> items = null;
- try
- {
- items = upload.parseRequest(multipartContext);
- }
- catch (final FileUploadException fue)
- {
- throw new IOException("Error parsing multipart request", fue);
- }
- parts = new ArrayList<>();
- for(final FileItem item : items)
- {
- parts.add(new Part() {
-
- @Override
- public InputStream getInputStream() throws IOException
- {
- return item.getInputStream();
- }
-
- @Override
- public String getContentType()
- {
- return item.getContentType();
- }
-
- @Override
- public String getName()
- {
- return item.getFieldName();
- }
-
- @Override
- public String getSubmittedFileName()
- {
- return item.getName();
- }
-
- @Override
- public long getSize()
- {
- return item.getSize();
- }
-
- @Override
- public void write(String fileName) throws IOException
- {
- try
- {
- item.write(new File(fileName).toPath());
- }
- catch (IOException e)
- {
- throw e;
- }
- catch (Exception e)
- {
- throw new IOException(e);
- }
- }
-
- @Override
- public void delete() throws IOException
- {
- item.delete();
- }
-
- @Override
- public String getHeader(String name)
- {
- return item.getHeaders().getHeader(name);
- }
-
- @Override
- public Collection<String> getHeaders(String name)
- {
- final List<String> values = new ArrayList<>();
- final Iterator<String> iter = item.getHeaders().getHeaders(name);
- while ( iter.hasNext() )
- {
- values.add(iter.next());
- }
- return values;
- }
-
- @Override
- public Collection<String> getHeaderNames()
- {
- final List<String> names = new ArrayList<>();
- final Iterator<String> iter = item.getHeaders().getHeaderNames();
- while ( iter.hasNext() )
- {
- names.add(iter.next());
- }
- return names;
- }
- });
- }
- }
- @Override
- public Collection<Part> getParts() throws IOException, ServletException
- {
- return checkMultipart();
-
- }
-
- @Override
- public Part getPart(String name) throws IOException, ServletException
- {
- Collection<Part> parts = this.checkMultipart();
- for(final Part p : parts)
- {
- if ( p.getName().equals(name) )
- {
- return p;
- }
- }
- return null;
- }
-
- @Override
- public HttpServletMapping getHttpServletMapping() {
- return this.requestInfo;
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/ServletResponseWrapper.java b/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/ServletResponseWrapper.java
deleted file mode 100644
index cd1491d5cd..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/dispatch/ServletResponseWrapper.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * 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.dispatch;
-
-import java.io.IOException;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import org.jetbrains.annotations.Nullable;
-import org.jetbrains.annotations.NotNull;
-import jakarta.servlet.DispatcherType;
-import jakarta.servlet.FilterChain;
-import jakarta.servlet.RequestDispatcher;
-import jakarta.servlet.ServletException;
-import jakarta.servlet.http.HttpServletRequest;
-import jakarta.servlet.http.HttpServletResponse;
-import jakarta.servlet.http.HttpServletResponseWrapper;
-
-import org.apache.felix.http.base.internal.handler.FilterHandler;
-import org.apache.felix.http.base.internal.handler.ServletHandler;
-import org.apache.felix.http.base.internal.registry.PerContextHandlerRegistry;
-
-final class ServletResponseWrapper extends HttpServletResponseWrapper
-{
-
- private final HttpServletRequest request;
-
- private final AtomicInteger invocationCount = new AtomicInteger();
-
- private final PerContextHandlerRegistry errorRegistry;
-
- private final String servletName;
-
- public ServletResponseWrapper(@NotNull final HttpServletRequest req,
- @NotNull final HttpServletResponse res,
- @Nullable final String servletName,
- @Nullable final PerContextHandlerRegistry errorRegistry)
- {
- super(res);
- this.request = req;
- this.servletName = servletName;
- this.errorRegistry = errorRegistry;
- }
-
- @Override
- public void sendError(int sc) throws IOException
- {
- sendError(sc, null);
- }
-
- @Override
- public void sendError(final int code, final String message) throws IOException
- {
- resetBuffer();
-
- setStatus(code);
-
- boolean invokeSuper = true;
-
- if ( invocationCount.incrementAndGet() == 1 )
- {
- // If we are allowed to have a body
- if (code != SC_NO_CONTENT &&
- code != SC_NOT_MODIFIED &&
- code != SC_PARTIAL_CONTENT &&
- code >= SC_OK)
- {
- final Throwable exception = (Throwable)request.getAttribute(RequestDispatcher.ERROR_EXCEPTION);
- final ServletHandler errorResolution = (errorRegistry == null ? null :
- errorRegistry.getErrorHandler(code, exception));
-
- if ( errorResolution != null )
- {
- try
- {
- request.setAttribute(RequestDispatcher.ERROR_STATUS_CODE, code);
- if ( message != null )
- {
- request.setAttribute(RequestDispatcher.ERROR_MESSAGE, message);
- }
- request.setAttribute(RequestDispatcher.ERROR_REQUEST_URI, request.getRequestURI());
- if ( this.servletName != null )
- {
- request.setAttribute(RequestDispatcher.ERROR_SERVLET_NAME, this.servletName);
- }
-
- final String servletPath = null;
- final String pathInfo = request.getRequestURI();
- final String queryString = null;
-
- final RequestInfo requestInfo = new RequestInfo(servletPath, pathInfo, queryString, pathInfo,
- request.getHttpServletMapping().getServletName(),
- request.getHttpServletMapping().getPattern(),
- request.getHttpServletMapping().getMatchValue(),
- request.getHttpServletMapping().getMappingMatch(),
- false);
-
- final FilterHandler[] filterHandlers = errorRegistry.getFilterHandlers(errorResolution, DispatcherType.ERROR, request.getRequestURI());
-
- final ServletRequestWrapper reqWrapper = new ServletRequestWrapper(request,
- errorResolution.getContext(),
- requestInfo,
- DispatcherType.ERROR,
- false,
- null,
- null);
- final FilterChain filterChain = new InvocationChain(errorResolution, filterHandlers);
- filterChain.doFilter(reqWrapper, this);
-
- invokeSuper = false;
- }
- catch (final ServletException e)
- {
- // ignore
- }
- finally
- {
- request.removeAttribute(RequestDispatcher.ERROR_STATUS_CODE);
- request.removeAttribute(RequestDispatcher.ERROR_MESSAGE);
- request.removeAttribute(RequestDispatcher.ERROR_REQUEST_URI);
- request.removeAttribute(RequestDispatcher.ERROR_SERVLET_NAME);
- request.removeAttribute(RequestDispatcher.ERROR_EXCEPTION);
- request.removeAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE);
- }
- }
- }
- }
- if ( invokeSuper )
- {
- super.sendError(code, message);
- }
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterConfigImpl.java b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterConfigImpl.java
deleted file mode 100644
index 2fa2cbc8b9..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterConfigImpl.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * 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;
-
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.Map;
-
-import jakarta.servlet.FilterConfig;
-import jakarta.servlet.ServletContext;
-
-/**
- * Implementation of the filter configuration.
- */
-public final class FilterConfigImpl implements FilterConfig
-{
- private final String name;
- private final ServletContext context;
- private final Map<String, String> initParams;
-
- public FilterConfigImpl(final String name, final ServletContext context, final Map<String, String> initParams)
- {
- this.name = name;
- this.context = context;
- this.initParams = initParams;
- }
-
- @Override
- public String getFilterName()
- {
- return this.name;
- }
-
- @Override
- public ServletContext getServletContext()
- {
- return this.context;
- }
-
- @Override
- public String getInitParameter(final String name)
- {
- return this.initParams.get(name);
- }
-
- @Override
- public Enumeration<String> getInitParameterNames()
- {
- return Collections.enumeration(this.initParams.keySet());
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterHandler.java b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterHandler.java
deleted file mode 100644
index 18dd13154f..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/FilterHandler.java
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * 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;
-
-import java.io.IOException;
-
-import org.apache.felix.http.base.internal.context.ExtServletContext;
-import org.apache.felix.http.base.internal.logger.SystemLogger;
-import org.apache.felix.http.base.internal.runtime.FilterInfo;
-import org.jetbrains.annotations.NotNull;
-import org.osgi.framework.BundleContext;
-import org.osgi.service.servlet.runtime.dto.DTOConstants;
-
-import jakarta.servlet.Filter;
-import jakarta.servlet.FilterChain;
-import jakarta.servlet.ServletException;
-import jakarta.servlet.ServletRequest;
-import jakarta.servlet.ServletResponse;
-
-/**
- * The filter handler handles the initialization and destruction of filter
- * objects.
- */
-public class FilterHandler implements Comparable<FilterHandler>
-{
- private final long contextServiceId;
-
- private final FilterInfo filterInfo;
-
- private final ExtServletContext context;
-
- private final BundleContext bundleContext;
-
- private volatile Filter filter;
-
- protected volatile int useCount;
-
- public FilterHandler(final long contextServiceId,
- final ExtServletContext context,
- final FilterInfo filterInfo,
- final BundleContext bundleContext)
- {
- this.contextServiceId = contextServiceId;
- this.context = context;
- this.filterInfo = filterInfo;
- this.bundleContext = bundleContext;
- }
-
- @Override
- public int compareTo(final FilterHandler other)
- {
- return this.filterInfo.compareTo(other.filterInfo);
- }
-
- public long getContextServiceId()
- {
- return this.contextServiceId;
- }
-
- public ExtServletContext getContext()
- {
- return this.context;
- }
-
- public Filter getFilter()
- {
- return filter;
- }
-
- public FilterInfo getFilterInfo()
- {
- return this.filterInfo;
- }
-
- public String getName()
- {
- String name = this.filterInfo.getName();
- if (name == null)
- {
- final Filter local = this.filter;
- if ( local != null )
- {
- name = this.filterInfo.getClassName(local);
- }
- }
- return name;
- }
-
- /**
- * Initialize the object
- * @return {code -1} on success, a failure reason according to {@link DTOConstants} otherwise.
- */
- public int init()
- {
- if ( this.useCount > 0 )
- {
- this.useCount++;
- return -1;
- }
-
- this.filter = getFilterInfo().getService(this.bundleContext);
-
- if (this.filter == null)
- {
- return DTOConstants.FAILURE_REASON_SERVICE_NOT_GETTABLE;
- }
-
- try
- {
- this.filter.init(new FilterConfigImpl(getName(), getContext(), getFilterInfo().getInitParameters()));
- }
- catch (final Exception e)
- {
- SystemLogger.LOGGER.error(SystemLogger.formatMessage(this.getFilterInfo().getServiceReference(),
- "Error during calling init() on filter ".concat(this.filterInfo.getClassName(this.filter))), e);
- getFilterInfo().ungetService(this.bundleContext, this.filter);
- return DTOConstants.FAILURE_REASON_EXCEPTION_ON_INIT;
- }
-
- this.useCount++;
- return -1;
- }
-
- public void handle(@NotNull final ServletRequest req,
- @NotNull final ServletResponse res,
- @NotNull final FilterChain chain) throws ServletException, IOException
- {
- final Filter local = this.filter;
- if ( local != null )
- {
- local.doFilter(req, res, chain);
- }
- else
- {
- throw new ServletException("Filter has been unregistered.");
- }
- }
-
- public boolean destroy()
- {
- final Filter f = this.getFilter();
- if ( f != null )
- {
- this.useCount--;
- if ( this.useCount == 0 )
- {
- filter = null;
- try
- {
- f.destroy();
- }
- catch ( final Exception ignore )
- {
- // we ignore this
- SystemLogger.LOGGER.error(SystemLogger.formatMessage(this.getFilterInfo().getServiceReference(),
- "Error during calling destroy() on filter ".concat(this.getFilterInfo().getClassName(f))), ignore);
- }
-
- getFilterInfo().ungetService(this.bundleContext, f);
-
- return true;
- }
- }
- return false;
- }
-
- public boolean dispose()
- {
- // fully destroy the filter
- this.useCount = 1;
- return this.destroy();
- }
-
- @Override
- public int hashCode()
- {
- return 31 + filterInfo.hashCode();
- }
-
- @Override
- public boolean equals(final Object obj)
- {
- if (this == obj)
- {
- return true;
- }
- if (obj == null || getClass() != obj.getClass() )
- {
- return false;
- }
- final FilterHandler other = (FilterHandler) obj;
- return filterInfo.equals(other.filterInfo);
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HttpSessionWrapper.java b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HttpSessionWrapper.java
deleted file mode 100644
index c09375eba1..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/HttpSessionWrapper.java
+++ /dev/null
@@ -1,471 +0,0 @@
-/*
- * 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;
-
-import java.io.Serializable;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.NoSuchElementException;
-import java.util.Set;
-
-import org.apache.felix.http.base.internal.HttpConfig;
-import org.apache.felix.http.base.internal.context.ExtServletContext;
-
-import jakarta.servlet.ServletContext;
-import jakarta.servlet.http.HttpSession;
-import jakarta.servlet.http.HttpSessionBindingEvent;
-import jakarta.servlet.http.HttpSessionBindingListener;
-import jakarta.servlet.http.HttpSessionEvent;
-
-/**
- * The session wrapper keeps track of the internal session, manages their attributes
- * separately and also handles session timeout.
- */
-public class HttpSessionWrapper implements HttpSession
-{
- /** All special attributes are prefixed with this prefix. */
- private static final String PREFIX = "org.apache.felix.http.session.context.";
-
- /** For each internal session, the attributes are prefixed with this followed by the context id */
- private static final String ATTR_PREFIX = PREFIX + "attr.";
-
- /** The created time for the internal session (appended with context id) */
- private static final String ATTR_CREATED = PREFIX + "created.";
-
- /** The last accessed time for the internal session (appended with context id), as Epoch time (milliseconds). */
- private static final String ATTR_LAST_ACCESSED = PREFIX + "lastaccessed.";
-
- /** The max inactive time (appended with context id), in seconds. */
- private static final String ATTR_MAX_INACTIVE = PREFIX + "maxinactive.";
-
- /** The underlying container session. */
- private final HttpSession delegate;
-
- /** The corresponding servlet context. */
- private final ExtServletContext context;
-
- /** The id for this session. */
- private final String sessionId;
-
- /** The key prefix for attributes belonging to this session. */
- private final String keyPrefix;
-
- /** Flag to handle the validity of this session. */
- private volatile boolean isInvalid = false;
-
- /** The time this has been created. */
- private final long created;
-
- /** The time this has been last accessed. */
- private final long lastAccessed;
-
- /** The max timeout interval. */
- private int maxTimeout;
-
- /**
- * Is this a new session?
- */
- private final boolean isNew;
-
- /**
- * Session handling configuration
- */
- private final HttpConfig config;
-
-
-
- public static boolean hasSession(final String contextName, final HttpSession session)
- {
- return session.getAttribute(ATTR_CREATED.concat(contextName)) != null;
- }
-
- public static Set<String> getExpiredSessionContextNames(final HttpSession session)
- {
- final long now = System.currentTimeMillis();
-
- final Set<String> names = new HashSet<>();
- final Enumeration<String> attrNames = session.getAttributeNames();
- while (attrNames.hasMoreElements())
- {
- final String name = attrNames.nextElement();
- if (name.startsWith(ATTR_LAST_ACCESSED))
- {
- final String id = name.substring(ATTR_LAST_ACCESSED.length());
-
- final long lastAccess = (Long) session.getAttribute(name);
- final long maxTimeout = 1000L * ((Integer) session.getAttribute(ATTR_MAX_INACTIVE + id));
-
- if ((maxTimeout > 0) && (lastAccess + maxTimeout) < now)
- {
- names.add(id);
- }
- }
- }
- return names;
- }
-
- /**
- * Get the names of all contexts using a session.
- * @param session The underlying session
- * @return The set of names
- */
- public static Set<String> getSessionContextNames(final HttpSession session)
- {
- final Set<String> names = new HashSet<>();
- final Enumeration<String> attrNames = session.getAttributeNames();
- while (attrNames.hasMoreElements())
- {
- final String name = attrNames.nextElement();
- if (name.startsWith(ATTR_LAST_ACCESSED))
- {
- final String id = name.substring(ATTR_LAST_ACCESSED.length());
- names.add(id);
- }
- }
-
- return names;
- }
-
- /**
- * Creates a new {@link HttpSessionWrapper} instance.
- */
- public HttpSessionWrapper(final HttpSession session,
- final ExtServletContext context,
- final HttpConfig config,
- final boolean terminate)
- {
- this.config = config;
- this.delegate = session;
- this.context = context;
- this.sessionId = context.getServletContextName();
- this.keyPrefix = ATTR_PREFIX.concat(this.sessionId).concat(".");
-
- final String createdAttrName = ATTR_CREATED.concat(this.sessionId);
-
- final long now = System.currentTimeMillis();
- if ( session.getAttribute(createdAttrName) == null )
- {
- this.created = now;
- this.maxTimeout = session.getMaxInactiveInterval();
- this.isNew = true;
-
- session.setAttribute(createdAttrName, this.created);
- session.setAttribute(ATTR_MAX_INACTIVE.concat(this.sessionId), this.maxTimeout);
-
- context.getHttpSessionListener().sessionCreated(new HttpSessionEvent(this));
- }
- else
- {
- this.created = (Long)session.getAttribute(createdAttrName);
- this.maxTimeout = (Integer)session.getAttribute(ATTR_MAX_INACTIVE.concat(this.sessionId));
- this.isNew = false;
- }
-
- this.lastAccessed = now;
- if ( !terminate )
- {
- session.setAttribute(ATTR_LAST_ACCESSED.concat(this.sessionId), this.lastAccessed);
- }
- }
-
- /**
- * Helper method to get the real key within the real session.
- */
- private String getKey(final String name)
- {
- return this.keyPrefix.concat(name);
- }
-
- /**
- * Check whether this session is still valid.
- * @throws IllegalStateException if session is not valid anymore
- */
- private void checkInvalid()
- {
- if ( this.isInvalid )
- {
- throw new IllegalStateException("Session is invalid.");
- }
- }
-
- @Override
- public Object getAttribute(final String name)
- {
- this.checkInvalid();
- Object result = this.delegate.getAttribute(this.getKey(name));
- if ( result instanceof SessionBindingValueListenerWrapper )
- {
- result = ((SessionBindingValueListenerWrapper)result).getHttpSessionBindingListener();
- }
- return result;
- }
-
- @Override
- public Enumeration<String> getAttributeNames()
- {
- this.checkInvalid();
- final Enumeration<String> e = this.delegate.getAttributeNames();
- return new Enumeration<String>() {
-
- String next = peek();
-
- private String peek()
- {
- while ( e.hasMoreElements() )
- {
- final String name = e.nextElement();
- if ( name.startsWith(keyPrefix))
- {
- return name.substring(keyPrefix.length());
- }
- }
- return null;
- }
-
- @Override
- public boolean hasMoreElements() {
- return next != null;
- }
-
- @Override
- public String nextElement() {
- if ( next == null )
- {
- throw new NoSuchElementException();
- }
- final String result = next;
- next = this.peek();
- return result;
- }
- };
-
- }
-
- @Override
- public long getCreationTime()
- {
- this.checkInvalid();
- return this.created;
- }
-
- @Override
- public String getId()
- {
- // no validity check conforming to the javadocs
- if ( this.config.isUniqueSessionId() )
- {
- return this.delegate.getId().concat("-").concat(this.sessionId);
- }
- return this.delegate.getId();
- }
-
- @Override
- public long getLastAccessedTime()
- {
- this.checkInvalid();
- return this.lastAccessed;
- }
-
- @Override
- public int getMaxInactiveInterval()
- {
- // no validity check conforming to the javadocs
- return this.maxTimeout;
- }
-
- @Override
- public ServletContext getServletContext()
- {
- // no validity check conforming to the javadocs
- return this.context;
- }
-
- @Override
- public void invalidate()
- {
- this.checkInvalid();
-
- // session listener must be called before the session is invalidated
- context.getHttpSessionListener().sessionDestroyed(new HttpSessionEvent(this));
-
- this.delegate.removeAttribute(ATTR_CREATED + this.sessionId);
- this.delegate.removeAttribute(ATTR_LAST_ACCESSED + this.sessionId);
- this.delegate.removeAttribute(ATTR_MAX_INACTIVE + this.sessionId);
-
- // remove all attributes belonging to this session
- final Enumeration<String> names = this.delegate.getAttributeNames();
- while ( names.hasMoreElements() )
- {
- final String name = names.nextElement();
-
- if ( name.startsWith(this.keyPrefix) ) {
- this.removeAttribute(name.substring(this.keyPrefix.length()));
- }
- }
-
- if ( this.config.isInvalidateContainerSession() )
- {
- // if the session is empty we can invalidate
- final Enumeration<String> remainingNames = this.delegate.getAttributeNames();
- if ( (!remainingNames.hasMoreElements()) || (isRemainingAttributeAddedByContainer(remainingNames)))
- {
- this.delegate.invalidate();
- }
- }
- this.isInvalid = true;
- }
-
- private boolean isRemainingAttributeAddedByContainer(Enumeration<String> names){
- final Set<String> attributeAddedByContainerSet = this.config.getContainerAddedAttribueSet() ;
-
- if(attributeAddedByContainerSet != null && !attributeAddedByContainerSet.isEmpty()) {
-
- while (names.hasMoreElements()) {
-
- final String name = names.nextElement();
- if (name == null || !attributeAddedByContainerSet.contains(name)) {
- return false;
- }
- }
- return true ;
- }
- return false ;
- }
-
- @Override
- public boolean isNew()
- {
- this.checkInvalid();
- return this.isNew;
- }
-
- @Override
- public void removeAttribute(final String name)
- {
- this.checkInvalid();
- final Object oldValue = this.getAttribute(name);
- if ( oldValue != null )
- {
- this.delegate.removeAttribute(this.getKey(name));
- if ( oldValue instanceof HttpSessionBindingListener )
- {
- ((HttpSessionBindingListener)oldValue).valueUnbound(new HttpSessionBindingEvent(this, name));
- }
- if ( this.context.getHttpSessionAttributeListener() != null )
- {
- this.context.getHttpSessionAttributeListener().attributeRemoved(new HttpSessionBindingEvent(this, name, oldValue));
- }
- }
- }
-
- @Override
- public void setAttribute(final String name, final Object value)
- {
- this.checkInvalid();
- if ( value == null )
- {
- this.removeAttribute(name);
- return;
- }
-
- final Object oldValue = this.getAttribute(name);
- // wrap http session binding listener to avoid container calling it!
- if ( value instanceof HttpSessionBindingListener )
- {
- this.delegate.setAttribute(this.getKey(name),
- new SessionBindingValueListenerWrapper((HttpSessionBindingListener)value));
- }
- else
- {
- this.delegate.setAttribute(this.getKey(name), value);
- }
- if ( value instanceof HttpSessionBindingListener )
- {
- ((HttpSessionBindingListener)value).valueBound(new HttpSessionBindingEvent(this, name));
- }
-
- if ( this.context.getHttpSessionAttributeListener() != null )
- {
- if ( oldValue != null )
- {
- this.context.getHttpSessionAttributeListener().attributeReplaced(new HttpSessionBindingEvent(this, name, oldValue));
- }
- else
- {
- this.context.getHttpSessionAttributeListener().attributeAdded(new HttpSessionBindingEvent(this, name, value));
- }
- }
- }
-
- @Override
- public void setMaxInactiveInterval(final int interval)
- {
- // no validity check conforming to the javadocs
- if ( this.delegate.getMaxInactiveInterval() < interval )
- {
- this.delegate.setMaxInactiveInterval(interval);
- }
- this.maxTimeout = interval;
- try {
- this.delegate.setAttribute(ATTR_MAX_INACTIVE + this.sessionId, interval);
- } catch ( final IllegalStateException iae) {
- // this might throw if delegate is invalid
- }
- }
-
- private static final class SessionBindingValueListenerWrapper implements Serializable
- {
-
- private static final long serialVersionUID = 4009563108883768425L;
-
- private final HttpSessionBindingListener listener;
-
- public SessionBindingValueListenerWrapper(final HttpSessionBindingListener listener)
- {
- this.listener = listener;
- }
-
- public HttpSessionBindingListener getHttpSessionBindingListener()
- {
- return listener;
- }
- }
-
- @Override
- public int hashCode()
- {
- return this.getId().concat(this.sessionId).hashCode();
- }
-
- @Override
- public boolean equals(final Object obj)
- {
- if (this == obj)
- {
- return true;
- }
- if (obj == null || this.getClass() != obj.getClass() )
- {
- return false;
- }
- final HttpSessionWrapper other = (HttpSessionWrapper) obj;
- return other.getId().concat(other.sessionId).equals(this.getId().concat(this.sessionId));
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ListenerHandler.java b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ListenerHandler.java
deleted file mode 100644
index 55d444d4f8..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ListenerHandler.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * 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;
-
-import java.util.EventListener;
-
-import org.apache.felix.http.base.internal.context.ExtServletContext;
-import org.apache.felix.http.base.internal.runtime.ListenerInfo;
-import org.osgi.framework.BundleContext;
-import org.osgi.service.servlet.runtime.dto.DTOConstants;
-
-/**
- * The listener handler handles the initialization and destruction of listener
- * objects.
- */
-public class ListenerHandler implements Comparable<ListenerHandler>
-{
- private final long contextServiceId;
-
- private final ListenerInfo listenerInfo;
-
- private final ExtServletContext context;
-
- private final BundleContext bundleContext;
-
- private volatile EventListener listener;
-
- protected volatile int useCount;
-
- public ListenerHandler(final long contextServiceId,
- final ExtServletContext context,
- final ListenerInfo listenerInfo,
- final BundleContext bundleContext)
- {
- this.contextServiceId = contextServiceId;
- this.context = context;
- this.listenerInfo = listenerInfo;
- this.bundleContext = bundleContext;
- }
-
- @Override
- public int compareTo(final ListenerHandler other)
- {
- return this.listenerInfo.compareTo(other.listenerInfo);
- }
-
- public ExtServletContext getContext()
- {
- return this.context;
- }
-
- public long getContextServiceId()
- {
- return this.contextServiceId;
- }
-
- public EventListener getListener()
- {
- return listener;
- }
-
- public ListenerInfo getListenerInfo()
- {
- return this.listenerInfo;
- }
-
- public boolean destroy()
- {
- final EventListener l = this.listener;
- if ( l != null )
- {
- this.useCount--;
- if ( this.useCount == 0 )
- {
- this.listener = null;
-
- this.getListenerInfo().ungetService(this.bundleContext, l);
-
- return true;
- }
- }
- return false;
- }
-
- public boolean dispose()
- {
- // fully destroy the listener
- this.useCount = 1;
- return this.destroy();
- }
-
- /**
- * Initialize the object
- * @return {code -1} on success, a failure reason according to {@link DTOConstants} otherwise.
- */
- public int init()
- {
- if ( this.useCount > 0 )
- {
- this.useCount++;
- return -1;
- }
-
- this.listener = getListenerInfo().getService(this.bundleContext);
-
- final int reason;
- if (this.listener == null)
- {
- reason = DTOConstants.FAILURE_REASON_SERVICE_NOT_GETTABLE;
- }
- else
- {
- this.useCount++;
- reason = -1;
- }
-
- return reason;
- }
-
- @Override
- public int hashCode()
- {
- return 31 + listenerInfo.hashCode();
- }
-
- @Override
- public boolean equals(final Object obj)
- {
- if (this == obj)
- {
- return true;
- }
- if (obj == null || getClass() != obj.getClass() )
- {
- return false;
- }
- final ListenerHandler other = (ListenerHandler) obj;
- return listenerInfo.equals(other.listenerInfo);
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/PreprocessorHandler.java b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/PreprocessorHandler.java
deleted file mode 100644
index ae30fdadaf..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/PreprocessorHandler.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * 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;
-
-import java.io.IOException;
-
-import org.apache.felix.http.base.internal.logger.SystemLogger;
-import org.apache.felix.http.base.internal.runtime.PreprocessorInfo;
-import org.jetbrains.annotations.NotNull;
-import org.osgi.framework.BundleContext;
-import org.osgi.service.servlet.runtime.dto.DTOConstants;
-import org.osgi.service.servlet.whiteboard.Preprocessor;
-
-import jakarta.servlet.FilterChain;
-import jakarta.servlet.ServletContext;
-import jakarta.servlet.ServletException;
-import jakarta.servlet.ServletRequest;
-import jakarta.servlet.ServletResponse;
-
-/**
- * The preprocessor handler handles the initialization and destruction of preprocessor
- * objects.
- */
-public class PreprocessorHandler implements Comparable<PreprocessorHandler>
-{
- private final PreprocessorInfo info;
-
- private final ServletContext context;
-
- private final BundleContext bundleContext;
-
- private volatile Preprocessor preprocessor;
-
- public PreprocessorHandler(final BundleContext bundleContext,
- final ServletContext context,
- final PreprocessorInfo info)
- {
- this.bundleContext = bundleContext;
- this.context = context;
- this.info = info;
- }
-
- @Override
- public int compareTo(final PreprocessorHandler other)
- {
- return this.info.compareTo(other.info);
- }
-
- public ServletContext getContext()
- {
- return this.context;
- }
-
- public PreprocessorInfo getPreprocessorInfo()
- {
- return this.info;
- }
-
- public int init()
- {
- this.preprocessor = this.getPreprocessorInfo().getService(this.bundleContext);
-
- if (this.preprocessor == null)
- {
- return DTOConstants.FAILURE_REASON_SERVICE_NOT_GETTABLE;
- }
-
- try
- {
- this.preprocessor.init(new FilterConfigImpl(this.preprocessor.getClass().getName(),
- getContext(),
- getPreprocessorInfo().getInitParameters()));
- }
- catch (final Exception e)
- {
- SystemLogger.LOGGER.error(SystemLogger.formatMessage(this.getPreprocessorInfo().getServiceReference(),
- "Error during calling init() on preprocessor ".concat(this.info.getClassName(this.preprocessor))), e);
-
- this.getPreprocessorInfo().ungetService(this.bundleContext, this.preprocessor);
- this.preprocessor = null;
-
- return DTOConstants.FAILURE_REASON_EXCEPTION_ON_INIT;
- }
-
- return -1;
- }
-
- public boolean destroy()
- {
- if (this.preprocessor == null)
- {
- return false;
- }
-
- try
- {
- preprocessor.destroy();
- }
- catch ( final Exception ignore )
- {
- // we ignore this
- SystemLogger.LOGGER.error(SystemLogger.formatMessage(this.getPreprocessorInfo().getServiceReference(),
- "Error during calling destroy() on preprocessor ".concat(this.info.getClassName(this.preprocessor))), ignore);
- }
- this.getPreprocessorInfo().ungetService(this.bundleContext, this.preprocessor);
- this.preprocessor = null;
-
- return true;
- }
-
- public void handle(@NotNull final ServletRequest req,
- @NotNull final ServletResponse res,
- @NotNull final FilterChain chain) throws ServletException, IOException
- {
- final Preprocessor local = this.preprocessor;
- if ( local != null )
- {
- local.doFilter(req, res, chain);
- }
- else
- {
- throw new ServletException("Preprocessor has been unregistered");
- }
- }
-
- public boolean dispose()
- {
- // fully destroy the preprocessor
- return this.destroy();
- }
-
- @Override
- public int hashCode()
- {
- return 31 + info.hashCode();
- }
-
- @Override
- public boolean equals(final Object obj)
- {
- if (this == obj)
- {
- return true;
- }
- if (obj == null || getClass() != obj.getClass() )
- {
- return false;
- }
- final PreprocessorHandler other = (PreprocessorHandler) obj;
- return info.equals(other.info);
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletConfigImpl.java b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletConfigImpl.java
deleted file mode 100644
index dc283fa388..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletConfigImpl.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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;
-
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.Map;
-
-import jakarta.servlet.ServletConfig;
-import jakarta.servlet.ServletContext;
-
-/**
- * Implementation of the servlet configuration
- */
-public final class ServletConfigImpl implements ServletConfig
-{
- private final String name;
- private final ServletContext context;
- private final Map<String, String> initParams;
-
- public ServletConfigImpl(final String name,
- final ServletContext context,
- final Map<String, String> initParams)
- {
- this.name = name;
- this.context = context;
- this.initParams = initParams;
- }
-
- @Override
- public String getServletName()
- {
- return this.name;
- }
-
- @Override
- public ServletContext getServletContext()
- {
- return this.context;
- }
-
- @Override
- public String getInitParameter(final String name)
- {
- return this.initParams.get(name);
- }
-
- @Override
- public Enumeration<String> getInitParameterNames()
- {
- return Collections.enumeration(this.initParams.keySet());
- }
-}
\ No newline at end of file
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandler.java b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandler.java
deleted file mode 100644
index c60e742a9a..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandler.java
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * 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;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.apache.felix.http.base.internal.context.ExtServletContext;
-import org.apache.felix.http.base.internal.dispatch.MultipartConfig;
-import org.apache.felix.http.base.internal.logger.SystemLogger;
-import org.apache.felix.http.base.internal.runtime.ServletInfo;
-import org.osgi.framework.Bundle;
-import org.osgi.service.servlet.runtime.dto.DTOConstants;
-
-import jakarta.servlet.Servlet;
-import jakarta.servlet.ServletException;
-import jakarta.servlet.ServletRequest;
-import jakarta.servlet.ServletResponse;
-
-/**
- * The servlet handler handles the initialization and destruction of
- * a servlet.
- */
-public abstract class ServletHandler implements Comparable<ServletHandler>
-{
- private static final String TEMP_DIR = System.getProperty("java.io.tmpdir");
-
- private static final String JAVA_SERVLET_TEMP_DIR_PROP = "jakarta.servlet.content.tempdir";
-
- private final long contextServiceId;
-
- private final ServletInfo servletInfo;
-
- private final ExtServletContext context;
-
- private volatile Servlet servlet;
-
- protected volatile int useCount;
-
- private final MultipartConfig mpConfig;
-
- public ServletHandler(final long contextServiceId,
- final ExtServletContext context,
- final ServletInfo servletInfo)
- {
- this.contextServiceId = contextServiceId;
- this.context = context;
- this.servletInfo = servletInfo;
- final MultipartConfig origConfig = servletInfo.getMultipartConfig();
- if ( origConfig != null )
- {
- String location = origConfig.multipartLocation;
- if ( location != null && location.trim().length() == 0 ) {
- location = null;
- }
- if ( location == null ) {
- final Object obj = context == null ? null : context.getAttribute(JAVA_SERVLET_TEMP_DIR_PROP);
- if ( obj != null ) {
- if ( obj instanceof File ) {
- location = ((File)obj).getAbsolutePath();
- } else {
- location = obj.toString();
- }
- }
- }
- if ( location == null ) {
- location = TEMP_DIR;
- }
- this.mpConfig = new MultipartConfig(origConfig.multipartThreshold,
- location,
- origConfig.multipartMaxFileSize,
- origConfig.multipartMaxRequestSize,
- origConfig.multipartMaxFileCount);
- }
- else
- {
- this.mpConfig = null;
- }
- }
-
- @Override
- public int compareTo(final ServletHandler other)
- {
- return this.servletInfo.compareTo(other.servletInfo);
- }
-
- public long getContextServiceId()
- {
- return this.contextServiceId;
- }
-
- public ExtServletContext getContext()
- {
- return this.context;
- }
-
- public Servlet getServlet()
- {
- return servlet;
- }
-
- protected void setServlet(final Servlet s)
- {
- this.servlet = s;
- }
-
- public void handle(final ServletRequest req, final ServletResponse res)
- throws ServletException, IOException
- {
- final Servlet local = this.servlet;
- if ( local != null )
- {
- local.service(req, res);
- }
- else
- {
- throw new ServletException("Servlet has been unregistered");
- }
- }
-
- public ServletInfo getServletInfo()
- {
- return this.servletInfo;
- }
-
- public String getName()
- {
- String name = this.servletInfo.getName();
- if (name == null )
- {
- final Servlet local = this.servlet;
- if ( local != null )
- {
- name = local.getClass().getName();
- }
- }
- return name;
- }
-
- /**
- * Initialize the object
- * @return {code -1} on success, a failure reason according to {@link DTOConstants} otherwise.
- */
- public int init()
- {
- if ( this.useCount > 0 )
- {
- this.useCount++;
- return -1;
- }
-
- if (this.servlet == null)
- {
- return DTOConstants.FAILURE_REASON_SERVICE_NOT_GETTABLE;
- }
-
- try
- {
- servlet.init(new ServletConfigImpl(getName(), getContext(), getServletInfo().getInitParameters()));
- }
- catch (final Exception e)
- {
- SystemLogger.LOGGER.error(SystemLogger.formatMessage(this.getServletInfo().getServiceReference(),
- "Error during calling init() on servlet ".concat(this.servletInfo.getClassName(this.servlet))),
- e);
- return DTOConstants.FAILURE_REASON_EXCEPTION_ON_INIT;
- }
- this.useCount++;
- return -1;
- }
-
-
- public boolean destroy()
- {
- if (this.servlet == null)
- {
- return false;
- }
-
- this.useCount--;
- if ( this.useCount == 0 )
- {
- try
- {
- servlet.destroy();
- }
- catch ( final Exception ignore )
- {
- // we ignore this
- SystemLogger.LOGGER.error(SystemLogger.formatMessage(this.getServletInfo().getServiceReference(),
- "Error during calling destroy() on servlet ".concat(this.servletInfo.getClassName(this.servlet))), ignore);
- }
-
- servlet = null;
- return true;
- }
- return false;
- }
-
- public boolean dispose()
- {
- // fully destroy the servlet
- this.useCount = 1;
- return this.destroy();
- }
-
- @Override
- public int hashCode()
- {
- return 31 + servletInfo.hashCode();
- }
-
- @Override
- public boolean equals(final Object obj)
- {
- if (this == obj)
- {
- return true;
- }
- if (obj == null || getClass() != obj.getClass() )
- {
- return false;
- }
- final ServletHandler other = (ServletHandler) obj;
- return servletInfo.equals(other.servletInfo);
- }
-
- public MultipartConfig getMultipartConfig()
- {
- return mpConfig;
- }
-
- public Bundle getMultipartSecurityContext()
- {
- return null;
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/WhiteboardServletHandler.java b/http/base/src/main/java/org/apache/felix/http/base/internal/handler/WhiteboardServletHandler.java
deleted file mode 100644
index c27fe79fd6..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/handler/WhiteboardServletHandler.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * 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;
-
-import java.io.FilePermission;
-
-import org.apache.felix.http.base.internal.context.ExtServletContext;
-import org.apache.felix.http.base.internal.runtime.ServletInfo;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.service.servlet.runtime.dto.DTOConstants;
-
-import jakarta.servlet.Servlet;
-
-/**
- * Servlet handler for servlets registered through the http whiteboard.
- */
-public final class WhiteboardServletHandler extends ServletHandler
-{
- private final BundleContext bundleContext;
-
- private final int multipartErrorCode;
-
- private final Bundle multipartSecurityContext;
-
- public WhiteboardServletHandler(final long contextServiceId,
- final ExtServletContext context,
- final ServletInfo servletInfo,
- final BundleContext contextBundleContext,
- final Bundle registeringBundle,
- final Bundle httpWhiteboardBundle)
- {
- super(contextServiceId, context, servletInfo);
- this.bundleContext = contextBundleContext;
- int errorCode = -1;
- // if multipart upload is enabled and a security manager is active
- // we need to check permissions
- if ( this.getMultipartConfig() != null && System.getSecurityManager() != null )
- {
- final FilePermission writePerm = new FilePermission(this.getMultipartConfig().multipartLocation, "read,write,delete");
- if ( servletInfo.getMultipartConfig().multipartLocation == null )
- {
- // Default location, whiteboard need writePerm, using bundle read perm
- multipartSecurityContext = httpWhiteboardBundle;
- if ( !httpWhiteboardBundle.hasPermission(writePerm))
- {
- errorCode = DTOConstants.FAILURE_REASON_WHITEBOARD_WRITE_TO_DEFAULT_DENIED;
- }
- else
- {
- final FilePermission readPerm = new FilePermission(this.getMultipartConfig().multipartLocation, "read");
- if ( !registeringBundle.hasPermission(readPerm) )
- {
- errorCode = DTOConstants.FAILURE_REASON_SERVLET_READ_FROM_DEFAULT_DENIED;
- }
- }
- }
- else
- {
- multipartSecurityContext = registeringBundle;
- // Provided location, whiteboard and using bundle need write perm
- if ( !registeringBundle.hasPermission(writePerm) )
- {
- errorCode = DTOConstants.FAILURE_REASON_SERVLET_WRITE_TO_LOCATION_DENIED;
- }
- if ( !httpWhiteboardBundle.hasPermission(writePerm) )
- {
- errorCode = DTOConstants.FAILURE_REASON_WHITEBOARD_WRITE_TO_LOCATION_DENIED;
- }
- }
- }
- else
- {
- multipartSecurityContext = null;
- }
- multipartErrorCode = errorCode;
- }
-
- public WhiteboardServletHandler(final long contextServiceId,
- final ExtServletContext context,
- final ServletInfo servletInfo,
- final BundleContext contextBundleContext,
- final Servlet servlet)
- {
- super(contextServiceId, context, servletInfo);
- this.bundleContext = contextBundleContext;
- multipartSecurityContext = null;
- multipartErrorCode = -1;
-
- if (servletInfo.isResource()) {
- this.setServlet(servlet);
- }
- }
-
- @Override
- public int init()
- {
- if (this.getServletInfo().isResource())
- {
- return super.init();
- }
- if ( this.multipartErrorCode != -1 )
- {
- return this.multipartErrorCode;
- }
- if ( this.useCount > 0 )
- {
- this.useCount++;
- return -1;
- }
-
- this.setServlet(this.getServletInfo().getService(this.bundleContext));
-
- final int reason = super.init();
- if ( reason != -1 )
- {
- this.getServletInfo().ungetService(this.bundleContext, this.getServlet());
- this.setServlet(null);
- }
- return reason;
- }
-
- @Override
- public boolean destroy()
- {
- final Servlet s = this.getServlet();
- if ( s != null )
- {
- if ( super.destroy() )
- {
- this.getServletInfo().ungetService(this.bundleContext, this.getServlet());
-
- return true;
- }
- }
- return false;
- }
-
- @Override
- public Bundle getMultipartSecurityContext()
- {
- return multipartSecurityContext;
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/logger/SystemLogger.java b/http/base/src/main/java/org/apache/felix/http/base/internal/logger/SystemLogger.java
deleted file mode 100644
index a8b2baeb15..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/logger/SystemLogger.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * 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.logger;
-
-import java.lang.reflect.Array;
-
-import org.osgi.framework.Bundle;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public final class SystemLogger {
-
- public static final Logger LOGGER = LoggerFactory.getLogger("org.apache.felix.http");
-
- public static String formatMessage(final ServiceReference<?> ref, final String message) {
- if ( ref == null ) {
- return message;
- }
- final Bundle bundle = ref.getBundle();
- final StringBuilder ib = new StringBuilder();
- ib.append("[ServiceReference ");
- ib.append(String.valueOf(ref.getProperty(Constants.SERVICE_ID)));
- ib.append(" from bundle ");
- if ( bundle == null ) {
- ib.append("<uninstalled>");
- } else {
- ib.append(bundle.getBundleId());
- if ( bundle.getSymbolicName() != null ) {
- ib.append(" : ");
- ib.append(bundle.getSymbolicName());
- ib.append(":");
- ib.append(bundle.getVersion());
- }
- }
- ib.append(" ref=");
- ib.append(ref);
- ib.append(" properties={");
- boolean first = true;
- for(final String name : ref.getPropertyKeys()) {
- if ( first ) {
- first = false;
- } else {
- ib.append(", ");
- }
- final Object val = ref.getProperty(name);
- ib.append(name);
- ib.append("=");
- if ( val.getClass().isArray() ) {
- boolean fa = true;
- ib.append('[');
- for(int i=0;i<Array.getLength(val);i++) {
- if ( fa ) {
- fa = false;
- } else {
- ib.append(", ");
- }
- ib.append(Array.get(val, i));
- }
- ib.append(']');
- } else {
- ib.append(val);
- }
- }
- ib.append("}] ");
- ib.append(message);
-
- return ib.toString();
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ErrorPageRegistry.java b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ErrorPageRegistry.java
deleted file mode 100644
index 9deee6bda2..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ErrorPageRegistry.java
+++ /dev/null
@@ -1,609 +0,0 @@
-/*
- * 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.registry;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.regex.Pattern;
-
-import org.jetbrains.annotations.Nullable;
-import org.jetbrains.annotations.NotNull;
-
-import org.apache.felix.http.base.internal.handler.ServletHandler;
-import org.apache.felix.http.base.internal.runtime.ServletInfo;
-import org.apache.felix.http.base.internal.runtime.dto.BuilderConstants;
-import org.apache.felix.http.base.internal.runtime.dto.ErrorPageDTOBuilder;
-import org.osgi.service.servlet.runtime.dto.DTOConstants;
-import org.osgi.service.servlet.runtime.dto.ErrorPageDTO;
-import org.osgi.service.servlet.runtime.dto.FailedErrorPageDTO;
-import org.osgi.service.servlet.runtime.dto.ServletContextDTO;
-
-/**
- * The error page registry keeps tracks of the active/inactive servlets handling
- * error pages (error code and/or exception).
- * This registry is per servlet context.
- */
-public final class ErrorPageRegistry
-{
- private static final String CLIENT_ERROR = "4xx";
- private static final String SERVER_ERROR = "5xx";
- private static final Pattern ERROR_CODE_PATTERN = Pattern.compile("\\d{3}");
-
- private static final List<Long> CLIENT_ERROR_CODES = hundredOf(400);
- private static final List<Long> SERVER_ERROR_CODES = hundredOf(500);
-
- private final Map<String, List<ServletHandler>> errorMapping = new ConcurrentHashMap<String, List<ServletHandler>>();
-
- private volatile List<ErrorRegistrationStatus> status = Collections.emptyList();
-
- public static final class ErrorRegistration {
- public final long[] errorCodes;
- public final String[] exceptions;
-
- public ErrorRegistration(final long[] errorCodes, final String[] exceptions)
- {
- this.errorCodes = errorCodes;
- this.exceptions = exceptions;
- }
- }
-
- static final class ErrorRegistrationStatus implements Comparable<ErrorRegistrationStatus> {
-
- private final ServletHandler handler;
- public final Map<Integer, ErrorRegistration> reasonMapping = new HashMap<Integer, ErrorRegistration>();
-
- public final boolean usesClientErrorCodes;
- public final boolean usesServerErrorCodes;
-
- public ErrorRegistrationStatus(final ServletHandler handler)
- {
- this.handler = handler;
- this.usesClientErrorCodes = hasErrorCode(handler, CLIENT_ERROR);
- this.usesServerErrorCodes = hasErrorCode(handler, SERVER_ERROR);
- }
-
- public ServletHandler getHandler()
- {
- return this.handler;
- }
-
- @Override
- public int compareTo(final ErrorRegistrationStatus o)
- {
- return this.handler.compareTo(o.getHandler());
- }
- }
-
- private static boolean hasErrorCode(final ServletHandler handler, final String key)
- {
- for(final String val : handler.getServletInfo().getErrorPage())
- {
- if ( key.equals(val) )
- {
- return true;
- }
- }
- return false;
- }
-
- private static List<Long> hundredOf(final int start)
- {
- List<Long> result = new ArrayList<Long>();
- for (long i = start; i < start + 100; i++)
- {
- result.add(i);
- }
- return Collections.unmodifiableList(result);
- }
-
- private static long[] toLongArray(final Set<Long> set)
- {
- long[] codes = BuilderConstants.EMPTY_LONG_ARRAY;
- if ( !set.isEmpty() )
- {
- codes = new long[set.size()];
- int index = 0;
- for(final Long code : set)
- {
- codes[index++] = code;
- }
- }
- return codes;
- }
-
- private static Set<Long> toLongSet(final long[] codes)
- {
- final Set<Long> set = new TreeSet<Long>();
- for(final long c : codes)
- {
- set.add(c);
- }
- return set;
- }
-
- private static String[] toStringArray(final Set<String> set)
- {
- String[] array = BuilderConstants.EMPTY_STRING_ARRAY;
- if ( !set.isEmpty() )
- {
- array = set.toArray(new String[set.size()]);
- }
- return array;
- }
-
- private static Set<String> toStringSet(final String[] array)
- {
- final Set<String> set = new TreeSet<String>();
- for(final String s : array)
- {
- set.add(s);
- }
- return set;
- }
-
- private static String parseErrorCodes(final Set<Long> codes, final String string)
- {
- if (CLIENT_ERROR.equalsIgnoreCase(string))
- {
- codes.addAll(CLIENT_ERROR_CODES);
- }
- else if (SERVER_ERROR.equalsIgnoreCase(string))
- {
- codes.addAll(SERVER_ERROR_CODES);
- }
- else if (ERROR_CODE_PATTERN.matcher(string).matches())
- {
- codes.add(Long.parseLong(string));
- }
- else
- {
- return string;
- }
- return null;
- }
-
- /**
- * Parse the registration properties of the servlet for error handling
- * @param info The servlet info
- * @return An error registration object if the servlet handles errors
- */
- public static @Nullable ErrorRegistration getErrorRegistration(@NotNull final ServletInfo info)
- {
- if ( info.getErrorPage() != null )
- {
- final Set<Long> errorCodes = new TreeSet<Long>();
- final Set<String> exceptions = new TreeSet<String>();
-
- for(final String val : info.getErrorPage())
- {
- final String exception = parseErrorCodes(errorCodes, val);
- if ( exception != null )
- {
- exceptions.add(exception);
- }
- }
- final long[] codes = toLongArray(errorCodes);
- final String[] exceptionsArray = toStringArray(exceptions);
-
- return new ErrorRegistration(codes, exceptionsArray);
- }
- return null;
- }
-
- /**
- * Add the servlet for error handling
- * @param handler The servlet handler.
- */
- public synchronized void addServlet(@NotNull final ServletHandler handler)
- {
- final ErrorRegistration reg = getErrorRegistration(handler.getServletInfo());
- if ( reg != null )
- {
- final ErrorRegistrationStatus status = new ErrorRegistrationStatus(handler);
- for(final long code : reg.errorCodes)
- {
- addErrorHandling(handler, status, code, null);
- }
- for(final String exception : reg.exceptions)
- {
- addErrorHandling(handler, status, 0, exception);
- }
- final List<ErrorRegistrationStatus> newList = new ArrayList<ErrorPageRegistry.ErrorRegistrationStatus>(this.status);
- newList.add(status);
- Collections.sort(newList);
- this.status = newList;
- }
- }
-
- /**
- * Remove the servlet from error handling
- * @param info The servlet info.
- */
- public synchronized void removeServlet(@NotNull final ServletInfo info, final boolean destroy)
- {
- final ErrorRegistration reg = getErrorRegistration(info);
- if ( reg != null )
- {
- final List<ErrorRegistrationStatus> newList = new ArrayList<ErrorPageRegistry.ErrorRegistrationStatus>(this.status);
- final Iterator<ErrorRegistrationStatus> i = newList.iterator();
- while ( i.hasNext() )
- {
- final ErrorRegistrationStatus status = i.next();
- if ( status.handler.getServletInfo().equals(info) )
- {
- i.remove();
- break;
- }
- }
- this.status = newList;
-
- for(final long code : reg.errorCodes)
- {
- removeErrorHandling(info, code, null);
- }
- for(final String exception : reg.exceptions)
- {
- removeErrorHandling(info, 0, exception);
- }
- }
- }
-
- public synchronized void cleanup()
- {
- this.errorMapping.clear();
- this.status = Collections.emptyList();
- }
-
- private void addErrorHandling(final ServletHandler handler, final ErrorRegistrationStatus status, final long code, final String exception)
- {
- final String key = (exception != null ? exception : String.valueOf(code));
-
- final List<ServletHandler> newList;
- final List<ServletHandler> list = errorMapping.get(key);
- if ( list == null )
- {
- newList = Collections.singletonList(handler);
- }
- else
- {
- newList = new ArrayList<ServletHandler>(list);
- newList.add(handler);
- Collections.sort(newList);
- }
- if ( newList.get(0) == handler )
- {
- // try to activate (and deactivate old handler)
- final int result = handler.init();
- addReason(status, code, exception, result);
- if ( result == -1 )
- {
- if ( list != null )
- {
- final ServletHandler old = list.get(0);
- old.destroy();
- errorMapping.put(key, newList);
- ErrorRegistrationStatus oldStatus = null;
- final Iterator<ErrorRegistrationStatus> i = this.status.iterator();
- while ( oldStatus == null && i.hasNext() )
- {
- final ErrorRegistrationStatus current = i.next();
- if ( current.handler.getServletInfo().equals(old.getServletInfo()) )
- {
- oldStatus = current;
- }
- }
- if ( oldStatus != null )
- {
- removeReason(oldStatus, code, exception, -1);
- boolean addReason = true;
- if ( exception == null )
- {
- if ( code >= 400 && code < 500 && oldStatus.usesClientErrorCodes && !status.usesClientErrorCodes )
- {
- addReason = false;
- }
- else if ( code >= 500 && code < 600 && oldStatus.usesServerErrorCodes && !status.usesServerErrorCodes )
- {
- addReason = false;
- }
- }
- if ( addReason )
- {
- addReason(oldStatus, code, exception, DTOConstants.FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE);
- }
- }
- }
- else
- {
- errorMapping.put(key, newList);
- }
- }
- }
- else
- {
- // failure
- boolean addReason = true;
- if ( exception == null )
- {
- if ( code >= 400 && code < 500 && status.usesClientErrorCodes && !hasErrorCode(newList.get(0), CLIENT_ERROR) )
- {
- addReason = false;
- }
- else if ( code >= 500 && code < 600 && status.usesServerErrorCodes && !hasErrorCode(newList.get(0), SERVER_ERROR) )
- {
- addReason = false;
- }
- }
- if ( addReason )
- {
- addReason(status, code, exception, DTOConstants.FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE);
- }
- errorMapping.put(key, newList);
- }
- }
-
- /**
- * Make an entry in the status object (which are used to create the DTOs)
- * @param status The status object
- * @param code Either the code
- * @param exception or the exception
- * @param reason The code for the failure reason or {@code -1} for success.
- */
- private void addReason(final ErrorRegistrationStatus status,
- final long code,
- final String exception,
- final int reason)
- {
- ErrorRegistration reg = status.reasonMapping.get(reason);
- if ( reg == null )
- {
- if ( exception != null )
- {
- reg = new ErrorRegistration(BuilderConstants.EMPTY_LONG_ARRAY, new String[] {exception});
- }
- else
- {
- reg = new ErrorRegistration(new long[] {code}, BuilderConstants.EMPTY_STRING_ARRAY);
- }
- }
- else
- {
- long[] codes = reg.errorCodes;
- String[] exceptions = reg.exceptions;
- if ( exception != null )
- {
- final Set<String> set = toStringSet(exceptions);
- set.add(exception);
- exceptions = toStringArray(set);
- }
- else
- {
- final Set<Long> set = toLongSet(codes);
- set.add(code);
- codes = toLongArray(set);
- }
-
- reg = new ErrorRegistration(codes, exceptions);
- }
- status.reasonMapping.put(reason, reg);
- }
-
- private void removeReason(final ErrorRegistrationStatus status, final long code, final String exception, final int reason)
- {
- ErrorRegistration reg = status.reasonMapping.get(reason);
- if ( reg != null )
- {
- long[] codes = reg.errorCodes;
- String[] exceptions = reg.exceptions;
- if ( exception != null )
- {
- final Set<String> set = toStringSet(exceptions);
- set.remove(exception);
- exceptions = toStringArray(set);
- }
- else
- {
- final Set<Long> set = toLongSet(codes);
- set.remove(code);
- codes = toLongArray(set);
- }
- if ( codes.length == 0 && exceptions.length == 0 )
- {
- status.reasonMapping.remove(reason);
- }
- else
- {
- status.reasonMapping.put(reason, new ErrorRegistration(codes, exceptions));
- }
- }
- }
-
- private void removeErrorHandling(final ServletInfo info, final long code, final String exception)
- {
- final String key = (exception != null ? exception : String.valueOf(code));
-
- final List<ServletHandler> list = errorMapping.get(key);
- if ( list != null )
- {
- int index = 0;
- final Iterator<ServletHandler> i = list.iterator();
- while ( i.hasNext() )
- {
- final ServletHandler handler = i.next();
- if ( handler.getServletInfo().equals(info) )
- {
- final List<ServletHandler> newList = new ArrayList<ServletHandler>(list);
- newList.remove(handler);
-
- if ( index == 0 )
- {
- handler.destroy();
-
- index++;
- while ( index < list.size() )
- {
- final ServletHandler next = list.get(index);
- ErrorRegistrationStatus nextStatus = null;
- for(final ErrorRegistrationStatus s : this.status)
- {
- if ( s.handler.getServletInfo().equals(next.getServletInfo()) )
- {
- nextStatus = s;
- break;
- }
- }
- this.removeReason(nextStatus, code, exception, DTOConstants.FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE);
- final int reason = next.init();
- this.addReason(nextStatus, code, exception, reason);
- if ( reason == -1 )
- {
- break;
- }
- else
- {
- newList.remove(next);
- }
- }
- }
- if ( newList.isEmpty() )
- {
- errorMapping.remove(key);
- }
- else
- {
- errorMapping.put(key, newList);
- }
-
- break;
- }
- index++;
- }
- }
- }
-
- /**
- * Get the servlet handling the error (error code or exception).
- * If an exception is provided, a handler for the exception is searched first.
- * If no handler is found (or no exception provided) a handler for the error
- * code is searched.
- * @param exception Optional exception
- * @param errorCode Error code
- * @return The servlet handling the error or {@code null}
- */
- public ServletHandler get(final Throwable exception, final int errorCode)
- {
- ServletHandler errorHandler = this.get(exception);
- if (errorHandler != null)
- {
- return errorHandler;
- }
-
- return get(errorCode);
- }
-
- /**
- * Get the servlet handling the error code
- * @param errorCode Error code
- * @return The servlet handling the error or {@code null}
- */
- private ServletHandler get(final long errorCode)
- {
- final List<ServletHandler> list = this.errorMapping.get(String.valueOf(errorCode));
- if ( list != null )
- {
- return list.get(0);
- }
- return null;
- }
-
- /**
- * Get the servlet handling the exception
- * @param exception Error exception
- * @return The servlet handling the error or {@code null}
- */
- private ServletHandler get(final Throwable exception)
- {
- if (exception == null)
- {
- return null;
- }
-
- ServletHandler servletHandler = null;
- Class<?> throwableClass = exception.getClass();
- while ( servletHandler == null && throwableClass != null )
- {
- final List<ServletHandler> list = this.errorMapping.get(throwableClass.getName());
- if ( list != null )
- {
- servletHandler = list.get(0);
- }
- if ( servletHandler == null )
- {
- throwableClass = throwableClass.getSuperclass();
- if ( !Throwable.class.isAssignableFrom(throwableClass) )
- {
- throwableClass = null;
- }
- }
-
- }
- return servletHandler;
- }
-
- /**
- * Get DTOs for error pages.
- * @param dto The servlet context DTO
- * @param failedErrorPageDTOs The failed error page DTOs
- */
- public void getRuntimeInfo(final ServletContextDTO dto,
- final Collection<FailedErrorPageDTO> failedErrorPageDTOs)
- {
- final List<ErrorPageDTO> errorPageDTOs = new ArrayList<ErrorPageDTO>();
- final List<ErrorRegistrationStatus> statusList = this.status;
- for(final ErrorRegistrationStatus status : statusList)
- {
- for(final Map.Entry<Integer, ErrorRegistration> entry : status.reasonMapping.entrySet())
- {
- final ErrorPageDTO state = ErrorPageDTOBuilder.build(status.getHandler(), entry.getKey());
- state.errorCodes = Arrays.copyOf(entry.getValue().errorCodes, entry.getValue().errorCodes.length);
- state.exceptions = Arrays.copyOf(entry.getValue().exceptions, entry.getValue().exceptions.length);
-
- if ( entry.getKey() == -1 )
- {
- errorPageDTOs.add(state);
- }
- else
- {
- failedErrorPageDTOs.add((FailedErrorPageDTO)state);
- }
- }
- }
- if ( !errorPageDTOs.isEmpty() )
- {
- dto.errorPageDTOs = errorPageDTOs.toArray(new ErrorPageDTO[errorPageDTOs.size()]);
- }
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/EventListenerRegistry.java b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/EventListenerRegistry.java
deleted file mode 100644
index b2eea23333..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/EventListenerRegistry.java
+++ /dev/null
@@ -1,474 +0,0 @@
-/*
- * 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.registry;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jetbrains.annotations.Nullable;
-import org.jetbrains.annotations.NotNull;
-import jakarta.servlet.ServletContextAttributeEvent;
-import jakarta.servlet.ServletContextAttributeListener;
-import jakarta.servlet.ServletContextEvent;
-import jakarta.servlet.ServletContextListener;
-import jakarta.servlet.ServletRequestAttributeEvent;
-import jakarta.servlet.ServletRequestAttributeListener;
-import jakarta.servlet.ServletRequestEvent;
-import jakarta.servlet.ServletRequestListener;
-import jakarta.servlet.http.HttpSessionAttributeListener;
-import jakarta.servlet.http.HttpSessionBindingEvent;
-import jakarta.servlet.http.HttpSessionEvent;
-import jakarta.servlet.http.HttpSessionIdListener;
-import jakarta.servlet.http.HttpSessionListener;
-
-import org.apache.felix.http.base.internal.handler.ListenerHandler;
-import org.apache.felix.http.base.internal.logger.SystemLogger;
-import org.apache.felix.http.base.internal.runtime.ListenerInfo;
-import org.osgi.service.servlet.runtime.dto.FailedListenerDTO;
-import org.osgi.service.servlet.runtime.dto.ListenerDTO;
-import org.osgi.service.servlet.runtime.dto.ServletContextDTO;
-
-/**
- * Per context event listener registry.
- */
-public final class EventListenerRegistry implements
- HttpSessionListener,
- HttpSessionAttributeListener,
- HttpSessionIdListener,
- ServletContextAttributeListener,
- ServletRequestListener,
- ServletRequestAttributeListener
-{
- /** Servlet context listeners. */
- private final ListenerMap<ServletContextListener> contextListeners = new ListenerMap<ServletContextListener>();
-
- /** Servlet context attribute listeners. */
- private final ListenerMap<ServletContextAttributeListener> contextAttributeListeners = new ListenerMap<ServletContextAttributeListener>();
-
- /** Session attribute listeners. */
- private final ListenerMap<HttpSessionAttributeListener> sessionAttributeListeners = new ListenerMap<HttpSessionAttributeListener>();
-
- /** Session listeners. */
- private final ListenerMap<HttpSessionListener> sessionListeners = new ListenerMap<HttpSessionListener>();
-
- /** Session id listeners. */
- private final ListenerMap<HttpSessionIdListener> sessionIdListeners = new ListenerMap<HttpSessionIdListener>();
-
- /** Request listeners. */
- private final ListenerMap<ServletRequestListener> requestListeners = new ListenerMap<ServletRequestListener>();
-
- /** Request attribute listeners. */
- private final ListenerMap<ServletRequestAttributeListener> requestAttributeListeners = new ListenerMap<ServletRequestAttributeListener>();
-
- public void cleanup()
- {
- this.contextListeners.cleanup();
- this.contextAttributeListeners.cleanup();
- this.sessionAttributeListeners.cleanup();
- this.sessionListeners.cleanup();
- this.sessionIdListeners.cleanup();
- this.requestListeners.cleanup();
- this.requestAttributeListeners.cleanup();
- }
-
- /**
- * Add listeners
- *
- * @param listener handler
- */
- public void addListeners(@NotNull final ListenerHandler handler)
- {
- final int reason = handler.init();
-
- if ( handler.getListenerInfo().isListenerType(ServletContextListener.class.getName()))
- {
- this.contextListeners.add(handler, reason);
- }
- if ( handler.getListenerInfo().isListenerType(ServletContextAttributeListener.class.getName()))
- {
- this.contextAttributeListeners.add(handler, reason);
- }
- if ( handler.getListenerInfo().isListenerType(HttpSessionListener.class.getName()))
- {
- this.sessionListeners.add(handler, reason);
- }
- if ( handler.getListenerInfo().isListenerType(HttpSessionIdListener.class.getName()))
- {
- this.sessionIdListeners.add(handler, reason);
- }
- if ( handler.getListenerInfo().isListenerType(HttpSessionAttributeListener.class.getName()))
- {
- this.sessionAttributeListeners.add(handler, reason);
- }
- if ( handler.getListenerInfo().isListenerType(ServletRequestListener.class.getName()))
- {
- this.requestListeners.add(handler, reason);
- }
- if ( handler.getListenerInfo().isListenerType(ServletRequestAttributeListener.class.getName()))
- {
- this.requestAttributeListeners.add(handler, reason);
- }
- }
-
- /**
- * Remove listeners
- *
- * @param info
- */
- public void removeListeners(@NotNull final ListenerInfo info)
- {
- // each listener map returns the same handler, we just need it once to destroy
- ListenerHandler handler = null;
- if ( info.isListenerType(ServletContextListener.class.getName()))
- {
- handler = this.contextListeners.remove(info);
- }
- if ( info.isListenerType(ServletContextAttributeListener.class.getName()))
- {
- handler = this.contextAttributeListeners.remove(info);
- }
- if ( info.isListenerType(HttpSessionListener.class.getName()))
- {
- handler = this.sessionListeners.remove(info);
- }
- if ( info.isListenerType(HttpSessionIdListener.class.getName()))
- {
- handler = this.sessionIdListeners.remove(info);
- }
- if ( info.isListenerType(HttpSessionAttributeListener.class.getName()))
- {
- handler = this.sessionAttributeListeners.remove(info);
- }
- if ( info.isListenerType(ServletRequestListener.class.getName()))
- {
- handler = this.requestListeners.remove(info);
- }
- if ( info.isListenerType(ServletRequestAttributeListener.class.getName()))
- {
- handler = this.requestAttributeListeners.remove(info);
- }
- if ( handler != null )
- {
- handler.destroy();
- }
- }
-
- /**
- * Get the listener handler for the listener info
- * @param info The listener info
- * @return The handler or {@code null}.
- */
- public @Nullable ListenerHandler getServletContextListener(@NotNull final ListenerInfo info)
- {
- return this.contextListeners.getListenerHandler(info);
- }
-
- public void contextInitialized() {
- for (final ListenerHandler l : contextListeners.getActiveHandlers())
- {
- final ServletContextListener listener = (ServletContextListener)l.getListener();
- if ( listener != null )
- {
- contextInitialized(l.getListenerInfo(), listener, new ServletContextEvent(l.getContext()));
- }
- }
- }
-
- public void contextDestroyed() {
- for (final ListenerHandler l : contextListeners.getActiveHandlers())
- {
- final ServletContextListener listener = (ServletContextListener) l.getListener();
- if ( listener != null )
- {
- contextDestroyed(l.getListenerInfo(), listener, new ServletContextEvent(l.getContext()));
- }
- }
- }
-
- @Override
- public void attributeReplaced(final HttpSessionBindingEvent event)
- {
- for (final HttpSessionAttributeListener l : sessionAttributeListeners.getActiveListeners())
- {
- try
- {
- l.attributeReplaced(event);
- }
- catch (final Throwable t)
- {
- SystemLogger.LOGGER.error("Exception while calling listener {}", l, t);
- }
- }
- }
-
- @Override
- public void attributeRemoved(final HttpSessionBindingEvent event)
- {
- for (final HttpSessionAttributeListener l : sessionAttributeListeners.getActiveListeners())
- {
- try
- {
- l.attributeRemoved(event);
- }
- catch (final Throwable t)
- {
- SystemLogger.LOGGER.error("Exception while calling listener {}", l, t);
- }
- }
- }
-
- @Override
- public void attributeAdded(final HttpSessionBindingEvent event)
- {
- for (final HttpSessionAttributeListener l : sessionAttributeListeners.getActiveListeners())
- {
- try
- {
- l.attributeAdded(event);
- }
- catch (final Throwable t)
- {
- SystemLogger.LOGGER.error("Exception while calling listener {}", l, t);
- }
- }
- }
-
- @Override
- public void attributeReplaced(final ServletContextAttributeEvent event)
- {
- for (final ServletContextAttributeListener l : contextAttributeListeners.getActiveListeners())
- {
- try
- {
- l.attributeReplaced(event);
- }
- catch (final Throwable t)
- {
- SystemLogger.LOGGER.error("Exception while calling listener {}", l, t);
- }
- }
- }
-
- @Override
- public void attributeRemoved(final ServletContextAttributeEvent event)
- {
- for (final ServletContextAttributeListener l : contextAttributeListeners.getActiveListeners())
- {
- try
- {
- l.attributeRemoved(event);
- }
- catch (final Throwable t)
- {
- SystemLogger.LOGGER.error("Exception while calling listener {}", l, t);
- }
- }
- }
-
- @Override
- public void attributeAdded(final ServletContextAttributeEvent event)
- {
- for (final ServletContextAttributeListener l : contextAttributeListeners.getActiveListeners())
- {
- try
- {
- l.attributeAdded(event);
- }
- catch (final Throwable t)
- {
- SystemLogger.LOGGER.error("Exception while calling listener {}", l, t);
- }
- }
- }
-
- @Override
- public void sessionCreated(final HttpSessionEvent se)
- {
- for (final HttpSessionListener l : sessionListeners.getActiveListeners())
- {
- try
- {
- l.sessionCreated(se);
- }
- catch (final Throwable t)
- {
- SystemLogger.LOGGER.error("Exception while calling listener {}", l, t);
- }
- }
- }
-
- @Override
- public void sessionDestroyed(final HttpSessionEvent se)
- {
- for (final HttpSessionListener l : sessionListeners.getActiveListeners())
- {
- try
- {
- l.sessionDestroyed(se);
- }
- catch (final Throwable t)
- {
- SystemLogger.LOGGER.error("Exception while calling listener {}", l, t);
- }
- }
- }
-
- @Override
- public void requestDestroyed(final ServletRequestEvent sre)
- {
- for (final ServletRequestListener l : requestListeners.getActiveListeners())
- {
- try
- {
- l.requestDestroyed(sre);
- }
- catch (final Throwable t)
- {
- SystemLogger.LOGGER.error("Exception while calling listener {}", l, t);
- }
- }
- }
-
- @Override
- public void requestInitialized(final ServletRequestEvent sre)
- {
- for (final ServletRequestListener l : requestListeners.getActiveListeners())
- {
- try
- {
- l.requestInitialized(sre);
- }
- catch (final Throwable t)
- {
- SystemLogger.LOGGER.error("Exception while calling listener {}", l, t);
- }
- }
- }
-
- @Override
- public void attributeAdded(final ServletRequestAttributeEvent srae)
- {
- for (final ServletRequestAttributeListener l : requestAttributeListeners.getActiveListeners())
- {
- try
- {
- l.attributeAdded(srae);
- }
- catch (final Throwable t)
- {
- SystemLogger.LOGGER.error("Exception while calling listener {}", l, t);
- }
- }
- }
-
- @Override
- public void attributeRemoved(final ServletRequestAttributeEvent srae)
- {
- for (final ServletRequestAttributeListener l : requestAttributeListeners.getActiveListeners())
- {
- try
- {
- l.attributeRemoved(srae);
- }
- catch (final Throwable t)
- {
- SystemLogger.LOGGER.error("Exception while calling listener {}", l, t);
- }
- }
- }
-
- @Override
- public void attributeReplaced(final ServletRequestAttributeEvent srae)
- {
- for (final ServletRequestAttributeListener l : requestAttributeListeners.getActiveListeners())
- {
- try
- {
- l.attributeReplaced(srae);
- }
- catch (final Throwable t)
- {
- SystemLogger.LOGGER.error("Exception while calling listener {}", l, t);
- }
- }
- }
-
- /**
- * @see jakarta.servlet.http.HttpSessionIdListener#sessionIdChanged(jakarta.servlet.http.HttpSessionEvent, java.lang.String)
- */
- @Override
- public void sessionIdChanged(@NotNull final HttpSessionEvent event, @NotNull final String oldSessionId) {
- for (final HttpSessionIdListener l : sessionIdListeners.getActiveListeners())
- {
- try
- {
- l.sessionIdChanged(event, oldSessionId);
- }
- catch (final Throwable t)
- {
- SystemLogger.LOGGER.error("Exception while calling listener {}", l, t);
- }
- }
- }
-
- public void getRuntimeInfo(final ServletContextDTO dto, final List<FailedListenerDTO> failedListenerDTOs)
- {
- final List<ListenerDTO> listenerDTOs = new ArrayList<ListenerDTO>();
- this.contextListeners.getRuntimeInfo(listenerDTOs, failedListenerDTOs);
- this.contextAttributeListeners.getRuntimeInfo(listenerDTOs, failedListenerDTOs);
- this.requestListeners.getRuntimeInfo(listenerDTOs, failedListenerDTOs);
- this.requestAttributeListeners.getRuntimeInfo(listenerDTOs, failedListenerDTOs);
- this.sessionListeners.getRuntimeInfo(listenerDTOs, failedListenerDTOs);
- this.sessionAttributeListeners.getRuntimeInfo(listenerDTOs, failedListenerDTOs);
- this.sessionIdListeners.getRuntimeInfo(listenerDTOs, failedListenerDTOs);
-
- if ( listenerDTOs.size() > 0 )
- {
- dto.listenerDTOs = listenerDTOs.toArray(new ListenerDTO[listenerDTOs.size()]);
- }
- }
-
- public static void contextInitialized(
- @NotNull final ListenerInfo info,
- @NotNull final ServletContextListener listener,
- @NotNull final ServletContextEvent event)
- {
- try
- {
- listener.contextInitialized(event);
- }
- catch (final Throwable t)
- {
- SystemLogger.LOGGER.error(SystemLogger.formatMessage(info.getServiceReference(), "Exception while calling servlet context listener."), t);
- }
- }
-
- public static void contextDestroyed(
- @NotNull final ListenerInfo info,
- @NotNull final ServletContextListener listener,
- @NotNull final ServletContextEvent event)
- {
- try
- {
- listener.contextDestroyed(event);
- }
- catch (final Throwable t)
- {
- SystemLogger.LOGGER.error(SystemLogger.formatMessage(info.getServiceReference(), "Exception while calling servlet context listener."), t);
- }
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/FilterRegistry.java b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/FilterRegistry.java
deleted file mode 100644
index 014f3e9ec7..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/FilterRegistry.java
+++ /dev/null
@@ -1,268 +0,0 @@
-/*
- * 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.registry;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-import org.jetbrains.annotations.Nullable;
-import org.jetbrains.annotations.NotNull;
-import jakarta.servlet.DispatcherType;
-
-import org.apache.felix.http.base.internal.handler.FilterHandler;
-import org.apache.felix.http.base.internal.handler.ServletHandler;
-import org.apache.felix.http.base.internal.runtime.FilterInfo;
-import org.apache.felix.http.base.internal.runtime.dto.FilterDTOBuilder;
-import org.osgi.service.servlet.runtime.dto.FailedFilterDTO;
-import org.osgi.service.servlet.runtime.dto.FilterDTO;
-import org.osgi.service.servlet.runtime.dto.ServletContextDTO;
-
-/**
- * The filter registry keeps track of all filter mappings for a single servlet context.
- *
- */
-public final class FilterRegistry
-{
- /** List of all filter registrations. These are sorted by the status objects. */
- private volatile List<FilterRegistrationStatus> filters = Collections.emptyList();
-
- /**
- * The status object keeps track of the registration status of a filter and holds
- * the resolvers to match against a uri.
- * The status objects are sorted by result first, followed by ranking. The active
- * filters ( result == -1) are first, followed by the inactive ones. This sorting
- * allows to only traverse over the active ones and also avoids any sorting
- * as the filters are processed in the correct order already.
- */
- private static final class FilterRegistrationStatus implements Comparable<FilterRegistrationStatus>
- {
- private final int result;
- private final FilterHandler handler;
- private final PathResolver[] resolvers;
-
- public FilterRegistrationStatus(@NotNull final FilterHandler handler, @Nullable final PathResolver[] resolvers, final int result)
- {
- this.handler = handler;
- this.resolvers = resolvers;
- this.result = result;
- }
-
- public int getResult()
- {
- return this.result;
- }
-
- public @NotNull FilterHandler getHandler()
- {
- return this.handler;
- }
-
- public @Nullable PathResolver[] getResolvers()
- {
- return this.resolvers;
- }
-
- @Override
- public int compareTo(final FilterRegistrationStatus o) {
- int result = this.result - o.result;
- if ( result == 0 )
- {
- result = this.handler.compareTo(o.handler);
- }
- return result;
- }
- }
-
- /**
- * Add a filter.
- * @param handler The handler for the filter
- */
- public synchronized void addFilter(@NotNull final FilterHandler handler)
- {
- final int result = handler.init();
- PathResolver[] prs = null;
-
- if ( result == -1 )
- {
- final List<PathResolver> resolvers = new ArrayList<PathResolver>();
- if ( handler.getFilterInfo().getPatterns() != null )
- {
- for(final String pattern : handler.getFilterInfo().getPatterns() ) {
- resolvers.add(PathResolverFactory.createPatternMatcher(null, pattern));
- }
- }
- if ( handler.getFilterInfo().getRegexs() != null )
- {
- for(final String regex : handler.getFilterInfo().getRegexs() ) {
- resolvers.add(PathResolverFactory.createRegexMatcher(regex));
- }
- }
- Collections.sort(resolvers);
-
- prs = resolvers.toArray(new PathResolver[resolvers.size()]);
- }
-
- final FilterRegistrationStatus status = new FilterRegistrationStatus(handler, prs, result);
-
- final List<FilterRegistrationStatus> newList = new ArrayList<FilterRegistry.FilterRegistrationStatus>(this.filters);
- newList.add(status);
- Collections.sort(newList);
-
- this.filters = newList;
- }
-
- /**
- * Remove a filter
- * @param filterInfo The filter info
- * @param destroy boolean flag indicating whether to call destroy on the filter.
- */
- public synchronized void removeFilter(@NotNull final FilterInfo filterInfo, final boolean destroy)
- {
- FilterRegistrationStatus found = null;
- final List<FilterRegistrationStatus> newList = new ArrayList<FilterRegistry.FilterRegistrationStatus>(this.filters);
- final Iterator<FilterRegistrationStatus> i = newList.iterator();
- while ( i.hasNext() )
- {
- final FilterRegistrationStatus status = i.next();
- if ( status.getHandler().getFilterInfo().equals(filterInfo) )
- {
- found = status;
- i.remove();
- break;
- }
- }
- if ( found != null )
- {
- this.filters = newList;
-
- if ( found.getResult() == -1 && destroy )
- {
- found.getHandler().dispose();
- }
- }
- }
-
- public synchronized void cleanup()
- {
- this.filters = Collections.emptyList();
- }
-
- /**
- * Get all filters handling the request.
- * Filters are applied to the url and/or the servlet
- * @param handler Optional servlet handler
- * @param dispatcherType The dispatcher type
- * @param requestURI The request uri
- * @return The array of filter handlers, might be empty.
- */
- public @NotNull FilterHandler[] getFilterHandlers(@Nullable final ServletHandler handler,
- @NotNull final DispatcherType dispatcherType,
- @NotNull final String requestURI)
- {
- final List<FilterHandler> result = new ArrayList<FilterHandler>();
- final List<FilterRegistrationStatus> allFilters = this.filters;
-
- for(final FilterRegistrationStatus status : allFilters)
- {
- // as soon as we encounter a failing filter, we can stop
- if ( status.getResult() != -1 )
- {
- break;
- }
- if (referencesDispatcherType(status.getHandler(), dispatcherType) )
- {
- boolean added = false;
- for(final PathResolver resolver : status.getResolvers())
- {
- if ( resolver.resolve(requestURI) != null )
- {
- result.add(status.getHandler());
- added = true;
- break;
- }
- }
- // check for servlet name if it's not a resource
- final String servletName = (handler != null && !handler.getServletInfo().isResource()) ? handler.getName() : null;
- if ( !added && servletName != null && status.getHandler().getFilterInfo().getServletNames() != null )
- {
- for(final String name : status.getHandler().getFilterInfo().getServletNames())
- {
- if ( servletName.equals(name) )
- {
- result.add(status.getHandler());
- added = true;
- break;
- }
- }
- }
-
- }
- }
-
- return result.toArray(new FilterHandler[result.size()]);
- }
-
- /**
- * Check if the filter is registered for the required dispatcher type
- * @param handler The filter handler
- * @param dispatcherType The requested dispatcher type
- * @return {@code true} if the filter can be applied.
- */
- private boolean referencesDispatcherType(final FilterHandler handler, final DispatcherType dispatcherType)
- {
- for(final DispatcherType dt : handler.getFilterInfo().getDispatcher())
- {
- if ( dt == dispatcherType )
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Get the runtime information about filters
- * @param servletContextDTO The servlet context DTO
- * @param failedFilterDTOs The collection holding the failed filters.
- */
- public void getRuntimeInfo(final ServletContextDTO servletContextDTO,
- final Collection<FailedFilterDTO> failedFilterDTOs)
- {
- final List<FilterDTO> filterDTOs = new ArrayList<FilterDTO>();
-
- final List<FilterRegistrationStatus> allFilters = this.filters;
- for(final FilterRegistrationStatus status : allFilters)
- {
- if ( status.getResult() != -1 )
- {
- failedFilterDTOs.add((FailedFilterDTO)FilterDTOBuilder.build(status.getHandler(), status.getResult()));
- }
- else
- {
- filterDTOs.add(FilterDTOBuilder.build(status.getHandler(), status.getResult()));
- }
- }
-
- if ( !filterDTOs.isEmpty() )
- {
- servletContextDTO.filterDTOs = filterDTOs.toArray(new FilterDTO[filterDTOs.size()]);
- }
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/HandlerRegistry.java b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/HandlerRegistry.java
deleted file mode 100644
index 5380bbe9a8..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/HandlerRegistry.java
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * Licensed to the Apaanche 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.registry;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.felix.http.base.internal.HttpConfig;
-import org.apache.felix.http.base.internal.handler.FilterHandler;
-import org.apache.felix.http.base.internal.handler.ServletHandler;
-import org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo;
-import org.apache.felix.http.base.internal.runtime.dto.FailedDTOHolder;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-import org.osgi.service.servlet.runtime.dto.ServletContextDTO;
-
-import jakarta.servlet.DispatcherType;
-
-/**
- * Registry for all services.
- *
- * The registry is organized per servlet context and is dispatching to one
- * of the {@link PerContextHandlerRegistry} registries.
- */
-public final class HandlerRegistry
-{
- private static FilterHandler[] EMPTY_FILTER_HANDLER = new FilterHandler[0];
-
- /** Current list of context registrations. */
- private volatile List<PerContextHandlerRegistry> registrations = Collections.emptyList();
-
- private final HttpConfig config;
-
- public HandlerRegistry(final HttpConfig config)
- {
- this.config = config;
- }
-
- public HttpConfig getConfig()
- {
- return this.config;
- }
-
- /**
- * Reset to initial state
- */
- public void reset()
- {
- this.registrations.clear();
- }
-
- /**
- * Shutdown
- */
- public void shutdown()
- {
- final List<PerContextHandlerRegistry> list;
-
- synchronized ( this )
- {
- list = new ArrayList<>(this.registrations);
- this.registrations = Collections.emptyList();
-
- }
-
- for(final PerContextHandlerRegistry r : list)
- {
- r.removeAll();
- }
- }
-
- /**
- * Remove a context registration.
- * @param info The servlet context helper info
- */
- public void remove(@NotNull ServletContextHelperInfo info)
- {
- synchronized ( this )
- {
- final List<PerContextHandlerRegistry> updatedList = new ArrayList<>(this.registrations);
- final Iterator<PerContextHandlerRegistry> i = updatedList.iterator();
- while ( i.hasNext() )
- {
- final PerContextHandlerRegistry reg = i.next();
- if ( reg.getContextServiceId() == info.getServiceId() )
- {
- i.remove();
- this.registrations = updatedList;
- break;
- }
- }
- }
- }
-
-
- /**
- * Add a new context registration.
- */
- public void add(@NotNull PerContextHandlerRegistry registry)
- {
- synchronized ( this )
- {
- final List<PerContextHandlerRegistry> updatedList = new ArrayList<>(this.registrations);
- updatedList.add(registry);
- Collections.sort(updatedList);
-
- this.registrations = updatedList;
- }
- }
-
- public PerContextHandlerRegistry getRegistry(final long key)
- {
- final List<PerContextHandlerRegistry> list = this.registrations;
- for(final PerContextHandlerRegistry r : list)
- {
- if ( key == r.getContextServiceId())
- {
- return r;
- }
- }
- return null;
- }
-
- public @Nullable ServletResolution getErrorHandler(@NotNull final String requestURI,
- final Long serviceId,
- final int code,
- final Throwable exception)
- {
- final PerContextHandlerRegistry reg;
- if ( serviceId == null )
- {
- // if the context is unknown, we use the first matching one!
- PerContextHandlerRegistry found = null;
- final List<PerContextHandlerRegistry> regs = this.registrations;
- for(final PerContextHandlerRegistry r : regs)
- {
- final String path = r.isMatching(requestURI);
- if ( path != null )
- {
- found = r;
- break;
- }
- }
- reg = found;
- }
- else
- {
- reg = this.getRegistry(serviceId);
- }
- if ( reg != null )
- {
- final ServletHandler handler = reg.getErrorHandler(code, exception);
- if ( handler != null )
- {
- final ServletResolution res = new ServletResolution();
- res.handler = handler;
- res.handlerRegistry = reg;
-
- return res;
- }
- }
- return null;
- }
-
- public FilterHandler[] getFilters(@NotNull final ServletResolution pr,
- @NotNull final DispatcherType dispatcherType,
- @NotNull String requestURI)
- {
- if ( pr != null && pr.handlerRegistry != null )
- {
- return pr.handlerRegistry.getFilterHandlers(pr.handler, dispatcherType, requestURI);
- }
- return EMPTY_FILTER_HANDLER;
- }
-
- public PathResolution resolveServlet(@NotNull final String requestURI)
- {
- final List<PerContextHandlerRegistry> regs = this.registrations;
- for(final PerContextHandlerRegistry r : regs)
- {
- final String path = r.isMatching(requestURI);
- if ( path != null )
- {
- final PathResolution ps = r.resolve(path);
- if ( ps != null )
- {
- // remove context path from request URI and add registry object
- ps.requestURI = path;
- ps.handlerRegistry = r;
- return ps;
- }
- }
- }
-
- return null;
- }
-
- /**
- * Get the servlet handler for a servlet by name
- * @param contextId The context id
- * @param name The servlet name
- * @return The servlet handler or {@code null}
- */
- public ServletResolution resolveServletByName(final long contextId, @NotNull final String name)
- {
- final PerContextHandlerRegistry reg = this.getRegistry(contextId);
- if ( reg != null )
- {
- final ServletHandler handler = reg.resolveServletByName(name);
- if ( handler != null )
- {
- final ServletResolution resolution = new ServletResolution();
- resolution.handler = handler;
- resolution.handlerRegistry = reg;
-
- return resolution;
- }
- }
- return null;
- }
-
- public boolean getRuntimeInfo(@NotNull final ServletContextDTO dto,
- @NotNull final FailedDTOHolder failedDTOHolder)
- {
- final PerContextHandlerRegistry reg = this.getRegistry(dto.serviceId);
- if ( reg != null )
- {
- reg.getRuntime(dto, failedDTOHolder);
- return true;
- }
- return false;
- }
-
- public PerContextHandlerRegistry getBestMatchingRegistry(String requestURI)
- {
- // if the context is unknown, we use the first matching one!
- PerContextHandlerRegistry found = null;
- final List<PerContextHandlerRegistry> regs = this.registrations;
- for(final PerContextHandlerRegistry r : regs)
- {
- final String path = r.isMatching(requestURI);
- if ( path != null )
- {
- found = r;
- break;
- }
- }
- return found;
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ListenerMap.java b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ListenerMap.java
deleted file mode 100644
index c62325a87d..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ListenerMap.java
+++ /dev/null
@@ -1,292 +0,0 @@
-/*
- * 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.registry;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.EventListener;
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-
-import org.jetbrains.annotations.NotNull;
-
-import org.apache.felix.http.base.internal.handler.ListenerHandler;
-import org.apache.felix.http.base.internal.runtime.ListenerInfo;
-import org.apache.felix.http.base.internal.runtime.dto.ListenerDTOBuilder;
-import org.osgi.service.servlet.runtime.dto.FailedListenerDTO;
-import org.osgi.service.servlet.runtime.dto.ListenerDTO;
-
-public class ListenerMap<T extends EventListener> {
-
- private volatile List<ListenerRegistrationStatus<T>> handlers = Collections.emptyList();
-
- /**
- * The status object keeps track of the registration status of a listener
- * The status objects are sorted by result first, followed by ranking. The active
- * listeners ( result == -1) are first, followed by the inactive ones. This sorting
- * allows to only traverse over the active ones and also avoids any sorting
- * as the listeners are processed in the correct order already.
- */
- private static final class ListenerRegistrationStatus<T> implements Comparable<ListenerRegistrationStatus<T>>
- {
- private final int result;
- private final ListenerHandler handler;
-
- public ListenerRegistrationStatus(@NotNull final ListenerHandler handler, final int result)
- {
- this.handler = handler;
- this.result = result;
- }
-
- public int getResult()
- {
- return this.result;
- }
-
- public @NotNull ListenerHandler getHandler()
- {
- return this.handler;
- }
-
- @Override
- public int compareTo(final ListenerRegistrationStatus<T> o)
- {
- int result = this.result - o.result;
- if ( result == 0 )
- {
- result = this.handler.compareTo(o.handler);
- }
- return result;
- }
- }
-
- public synchronized void cleanup()
- {
- this.handlers = Collections.emptyList();
- }
-
- public synchronized void add(final ListenerHandler handler, final int reason)
- {
- final ListenerRegistrationStatus<T> status = new ListenerRegistrationStatus<T>(handler, reason);
-
- final List<ListenerRegistrationStatus<T>> newList = new ArrayList<ListenerMap.ListenerRegistrationStatus<T>>(this.handlers);
- newList.add(status);
- Collections.sort(newList);
- this.handlers = newList;
- }
-
- public synchronized ListenerHandler remove(final ListenerInfo info)
- {
- final List<ListenerRegistrationStatus<T>> newList = new ArrayList<ListenerMap.ListenerRegistrationStatus<T>>(this.handlers);
- final Iterator<ListenerRegistrationStatus<T>> i = newList.iterator();
- while ( i.hasNext() )
- {
- final ListenerRegistrationStatus<T> status = i.next();
- if ( status.getHandler().getListenerInfo().equals(info) )
- {
- i.remove();
- this.handlers = newList;
-
- return status.getResult() == -1 ? status.getHandler() : null;
- }
- }
- return null;
- }
-
- public ListenerHandler getListenerHandler(@NotNull final ListenerInfo info)
- {
- final List<ListenerRegistrationStatus<T>> list = this.handlers;
- for(final ListenerRegistrationStatus<T> status : list)
- {
- if ( status.getHandler().getListenerInfo().equals(info) )
- {
- return status.getHandler();
- }
- }
- return null;
- }
-
- public Iterable<ListenerHandler> getActiveHandlers()
- {
- final List<ListenerRegistrationStatus<T>> list = this.handlers;
- final Iterator<ListenerRegistrationStatus<T>> iter = list.iterator();
- final Iterator<ListenerHandler> newIter = new Iterator<ListenerHandler>()
- {
-
- private ListenerHandler next;
-
- {
- peek();
- }
-
- private void peek()
- {
- next = null;
- if ( iter.hasNext() )
- {
- final ListenerRegistrationStatus<T> status = iter.next();
- if ( status.getResult() == -1 )
- {
- next = status.getHandler();
- }
- }
- }
-
- @Override
- public boolean hasNext()
- {
- return this.next != null;
- }
-
- @Override
- public ListenerHandler next()
- {
- if ( this.next == null )
- {
- throw new NoSuchElementException();
- }
- final ListenerHandler result = this.next;
- peek();
- return result;
- }
-
- @Override
- public void remove()
- {
- throw new UnsupportedOperationException();
- }
- };
- return new Iterable<ListenerHandler>()
- {
-
- @Override
- public Iterator<ListenerHandler> iterator()
- {
- return newIter;
- }
- };
- }
-
- public Iterable<T> getActiveListeners()
- {
- final Iterator<ListenerHandler> iter = this.getActiveHandlers().iterator();
- final Iterator<T> newIter = new Iterator<T>()
- {
-
- private T next;
-
- {
- peek();
- }
-
- @SuppressWarnings("unchecked")
- private void peek()
- {
- next = null;
- while ( next == null && iter.hasNext() )
- {
- final ListenerHandler handler = iter.next();
- next = (T)handler.getListener();
- }
- }
-
- @Override
- public boolean hasNext()
- {
- return this.next != null;
- }
-
- @Override
- public T next()
- {
- if ( this.next == null )
- {
- throw new NoSuchElementException();
- }
- final T result = this.next;
- peek();
- return result;
- }
-
- @Override
- public void remove()
- {
- throw new UnsupportedOperationException();
- }
- };
- return new Iterable<T>()
- {
-
- @Override
- public Iterator<T> iterator()
- {
- return newIter;
- }
- };
- }
-
- public void getRuntimeInfo(final List<ListenerDTO> listenerDTOs, final List<FailedListenerDTO> failedListenerDTOs)
- {
- final int length = listenerDTOs.size();
- final int failedLength = failedListenerDTOs.size();
- final List<ListenerRegistrationStatus<T>> list = this.handlers;
- for (final ListenerRegistrationStatus<T> status : list)
- {
- // search for DTO with same service id and failureCode
- if ( status.getResult() == -1 )
- {
- int index = 0;
- boolean found = false;
- final Iterator<ListenerDTO> i = listenerDTOs.iterator();
- while ( !found && index < length )
- {
- final ListenerDTO dto = i.next();
- if ( dto.serviceId == status.getHandler().getListenerInfo().getServiceId() )
- {
- found = true;
- }
- index++;
- }
- if ( !found )
- {
- listenerDTOs.add(ListenerDTOBuilder.build(status.getHandler(), status.getResult()));
- }
- }
- else
- {
- int index = 0;
- boolean found = false;
- final Iterator<FailedListenerDTO> i = failedListenerDTOs.iterator();
- while ( !found && index < failedLength )
- {
- final FailedListenerDTO dto = i.next();
- if ( dto.serviceId == status.getHandler().getListenerInfo().getServiceId()
- && dto.failureReason == status.getResult() )
- {
- found = true;
- }
- index++;
- }
- if ( !found )
- {
- failedListenerDTOs.add((FailedListenerDTO)ListenerDTOBuilder.build(status.getHandler(), status.getResult()));
- }
- }
- }
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/PathResolution.java b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/PathResolution.java
deleted file mode 100644
index 945be6368f..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/PathResolution.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.registry;
-
-import jakarta.servlet.http.MappingMatch;
-
-/**
- * Resolution of a servlet based on the path
- */
-public class PathResolution extends ServletResolution {
-
- public String servletPath;
-
- public String pathInfo;
-
- public String requestURI;
-
- public String[] patterns;
-
- public String matchedPattern;
-
- public MappingMatch match;
-
- public String matchValue;
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/PathResolver.java b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/PathResolver.java
deleted file mode 100644
index 389de1ddd1..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/PathResolver.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.registry;
-
-import org.apache.felix.http.base.internal.handler.ServletHandler;
-
-
-public interface PathResolver extends Comparable<PathResolver> {
-
- PathResolution resolve(String uri);
-
- ServletHandler getServletHandler();
-
- int getRanking();
-
- int getOrdering();
-
- String getPattern();
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/PathResolverFactory.java b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/PathResolverFactory.java
deleted file mode 100644
index e4f1796113..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/PathResolverFactory.java
+++ /dev/null
@@ -1,413 +0,0 @@
-/*
- * 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.registry;
-
-import java.util.regex.Pattern;
-
-import org.apache.felix.http.base.internal.HttpConfig;
-import org.apache.felix.http.base.internal.handler.ServletHandler;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import jakarta.servlet.http.MappingMatch;
-
-/**
- * The path resolver factory creates a path resolver for a pattern.
- * The servlet spec supports different patterns
- * - path mapping, a pattern starting with / and ending with /*
- * - extension mapping, a pattern starting with *.
- * - default mapping, the pattern /
- * - root mapping, the pattern is the empty string
- * - exact match
- *
- * Exact match is tried first, followed by longest match and finally
- * extension match.
- */
-public abstract class PathResolverFactory {
-
- public static @NotNull PathResolver createPatternMatcher(@Nullable final ServletHandler handler, @NotNull final String pattern)
- {
- if ( pattern.length() == 0 )
- {
- return new RootMatcher(handler);
- }
- else if ( pattern.equals("/") )
- {
- return new DefaultMatcher(handler);
- }
- else if ( pattern.startsWith("*.") )
- {
- return new ExtensionMatcher(handler, pattern);
- }
- else if ( pattern.endsWith("/*") )
- {
- return new PathMatcher(handler, pattern);
- }
- /**
- * TODO: clarify regarding pattern matcher created dependent on whether service ID of handler used (previously HttpServiceFactory.HTTP_SERVICE_CONTEXT_SERVICE_ID)
- **/
- else if ( handler != null && handler.getContextServiceId() == HttpConfig.DEFAULT_CONTEXT_SERVICE_ID )
- {
- return new ExactAndPathMatcher(handler, pattern);
- }
- return new ExactMatcher(handler, pattern);
- }
-
- public static @NotNull PathResolver createRegexMatcher(@NotNull final String regex)
- {
- return new RegexMatcher(regex);
- }
-
- public static abstract class AbstractMatcher implements PathResolver
- {
- private final int ranking;
-
- private final String pattern;
-
- private final ServletHandler handler;
-
- public AbstractMatcher(final ServletHandler handler, final String pattern, final int ranking)
- {
- this.handler = handler;
- this.ranking = ranking;
- this.pattern = pattern;
- }
-
- @Override
- public int compareTo(final PathResolver o)
- {
- int result = o.getRanking() - this.ranking;
- if ( result == 0 )
- {
- result = o.getOrdering() - this.getOrdering();
- }
- return result;
- }
-
- @Override
- public ServletHandler getServletHandler()
- {
- return this.handler;
- }
-
- @Override
- public int getRanking()
- {
- return this.ranking;
- }
-
- @Override
- public int getOrdering()
- {
- return 0;
- }
-
- @Override
- public String getPattern()
- {
- return this.pattern;
- }
-
- @Override
- public int hashCode()
- {
- return pattern.hashCode();
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (this == obj)
- {
- return true;
- }
- if (obj == null || getClass() != obj.getClass())
- {
- return false;
- }
- final AbstractMatcher other = (AbstractMatcher) obj;
- return this.pattern.equals(other.pattern);
- }
- }
-
- public static final class RootMatcher extends AbstractMatcher
- {
- public RootMatcher(final ServletHandler handler)
- {
- super(handler, "", 2);
- }
-
- @Override
- public PathResolution resolve(final String uri) {
- if ( uri.length() == 0 || uri.equals("/") )
- {
- final PathResolution pr = new PathResolution();
- pr.pathInfo = "/";
- pr.servletPath = "";
- pr.requestURI = uri;
- pr.handler = this.getServletHandler();
-
- pr.matchedPattern = this.getPattern();
- pr.match = MappingMatch.CONTEXT_ROOT;
- pr.matchValue = this.getPattern();
-
- return pr;
- }
- return null;
- }
- }
-
- public static final class DefaultMatcher extends AbstractMatcher
- {
- public DefaultMatcher(final ServletHandler handler)
- {
- super(handler, "/", 1);
- }
-
- @Override
- public PathResolution resolve(final String uri) {
- final PathResolution pr = new PathResolution();
- pr.pathInfo = null;
- pr.servletPath = uri;
- pr.requestURI = uri;
- pr.handler = this.getServletHandler();
-
- pr.matchedPattern = this.getPattern();
- pr.match = MappingMatch.DEFAULT;
- pr.matchValue = "";
-
- return pr;
- }
- }
-
- public static final class ExactAndPathMatcher extends AbstractMatcher
- {
- private final String path;
-
- private final String prefix;
-
- public ExactAndPathMatcher(final ServletHandler handler, final String pattern)
- {
- super(handler, pattern, 5);
- this.path = pattern;
- this.prefix = pattern.concat("/");
- }
-
- @Override
- public PathResolution resolve(final String uri) {
- if ( uri.equals(this.path) )
- {
- final PathResolution pr = new PathResolution();
- pr.pathInfo = null;
- pr.servletPath = uri;
- pr.requestURI = uri;
- pr.handler = this.getServletHandler();
-
- pr.matchedPattern = this.getPattern();
- pr.match = MappingMatch.EXACT;
- final int pos = uri.lastIndexOf("/");
- pr.matchValue = uri.substring(pos + 1, uri.length());
-
- return pr;
- }
- else if ( uri.startsWith(prefix) )
- {
- final PathResolution pr = new PathResolution();
- pr.servletPath = this.prefix.substring(0, this.prefix.length() - 1);
- pr.pathInfo = uri.substring(pr.servletPath.length());
- pr.requestURI = uri;
- pr.handler = this.getServletHandler();
-
- pr.matchedPattern = this.getPattern();
- pr.match = MappingMatch.PATH;
- final int pos = uri.lastIndexOf("/");
- pr.matchValue = uri.substring(pos + 1, uri.length());
-
- return pr;
- }
- return null;
- }
-
- @Override
- public int getOrdering()
- {
- return this.path.length();
- }
- }
-
- public static final class ExactMatcher extends AbstractMatcher
- {
- private final String path;
-
- public ExactMatcher(final ServletHandler handler, final String pattern)
- {
- super(handler, pattern, 5);
- this.path = pattern;
- }
-
- @Override
- public PathResolution resolve(final String uri) {
- if ( uri.equals(this.path) )
- {
- final PathResolution pr = new PathResolution();
- pr.servletPath = uri;
- pr.pathInfo = null;
- pr.requestURI = uri;
- pr.handler = this.getServletHandler();
-
- pr.matchedPattern = this.getPattern();
- pr.match = MappingMatch.EXACT;
- final int pos = uri.lastIndexOf("/");
- pr.matchValue = uri.substring(pos + 1, uri.length());
-
- return pr;
- }
- return null;
- }
-
- @Override
- public int getOrdering()
- {
- return this.path.length();
- }
- }
-
- public static final class PathMatcher extends AbstractMatcher
- {
- private final String prefix;
-
- private final String path;
-
- public PathMatcher(final ServletHandler handler, final String pattern)
- {
- super(handler, pattern, 4);
- this.prefix = pattern.substring(0, pattern.length() - 1);
- this.path = pattern.substring(0, pattern.length() - 2);
- }
-
- @Override
- public PathResolution resolve(final String uri) {
- if ( uri.equals(this.path) )
- {
- final PathResolution pr = new PathResolution();
- pr.servletPath = this.path;
- pr.pathInfo = null;
- pr.requestURI = uri;
- pr.handler = this.getServletHandler();
-
- pr.matchedPattern = this.getPattern();
- pr.match = MappingMatch.PATH;
- pr.matchValue = uri.length() > 0 ? uri.substring(1) : "";
-
- return pr;
- }
- if ( uri.startsWith(this.prefix) )
- {
- final PathResolution pr = new PathResolution();
- pr.servletPath = this.prefix.substring(0, this.prefix.length() - 1);
- pr.pathInfo = uri.substring(pr.servletPath.length());
- pr.requestURI = uri;
- pr.handler = this.getServletHandler();
-
- pr.matchedPattern = this.getPattern();
- pr.match = MappingMatch.PATH;
- pr.matchValue = uri.substring(this.prefix.length(), uri.length());
-
- return pr;
- }
- return null;
- }
-
- @Override
- public int getOrdering()
- {
- return this.prefix.length() + 1;
- }
- }
-
- public static final class ExtensionMatcher extends AbstractMatcher
- {
- private final String extension;
-
- public ExtensionMatcher(final ServletHandler handler, final String pattern)
- {
- super(handler, pattern, 3);
- this.extension = pattern.substring(1);
- }
-
- @Override
- public PathResolution resolve(final String uri) {
- if ( uri.endsWith(this.extension) )
- {
- final PathResolution pr = new PathResolution();
- pr.pathInfo = null;
- pr.servletPath = uri;
- pr.requestURI = uri;
- pr.handler = this.getServletHandler();
-
- pr.matchedPattern = this.getPattern();
- pr.match = MappingMatch.EXTENSION;
- final int pos = uri.lastIndexOf("/");
- pr.matchValue = uri.substring(pos + 1, uri.length() - this.extension.length());
-
- return pr;
- }
- return null;
- }
-
- @Override
- public int getOrdering()
- {
- return this.extension.length();
- }
- }
-
- public static final class RegexMatcher extends AbstractMatcher
- {
- private final Pattern pattern;
-
- public RegexMatcher(final String regex)
- {
- super(null, regex, 0);
- this.pattern = Pattern.compile(regex);
- }
-
- @Override
- public @Nullable PathResolution resolve(@NotNull final String uri) {
- if ( pattern.matcher(uri).matches() )
- {
- final PathResolution pr = new PathResolution();
- pr.pathInfo = null;
- pr.servletPath = uri;
- pr.requestURI = uri;
-
- // regex is not supported by servlet spec, we use PATH matching
- pr.matchedPattern = this.getPattern();
- pr.match = MappingMatch.PATH;
- pr.matchValue = uri;
-
- return pr;
- }
- return null;
- }
-
- @Override
- public int getOrdering()
- {
- return this.pattern.toString().length();
- }
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/PerContextHandlerRegistry.java b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/PerContextHandlerRegistry.java
deleted file mode 100644
index d8c37a2232..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/PerContextHandlerRegistry.java
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- * 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.registry;
-
-import jakarta.servlet.DispatcherType;
-
-import org.apache.felix.http.base.internal.HttpConfig;
-import org.apache.felix.http.base.internal.handler.FilterHandler;
-import org.apache.felix.http.base.internal.handler.ListenerHandler;
-import org.apache.felix.http.base.internal.handler.ServletHandler;
-import org.apache.felix.http.base.internal.runtime.FilterInfo;
-import org.apache.felix.http.base.internal.runtime.ListenerInfo;
-import org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo;
-import org.apache.felix.http.base.internal.runtime.ServletInfo;
-import org.apache.felix.http.base.internal.runtime.dto.FailedDTOHolder;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-import org.osgi.service.servlet.runtime.dto.ServletContextDTO;
-
-/**
- * This registry keeps track of all processing components per context:
- * - servlets
- * - filters
- * - error pages
- */
-public final class PerContextHandlerRegistry implements Comparable<PerContextHandlerRegistry>
-{
- /** Service id of the context. */
- private final long serviceId;
-
- /** Ranking of the context. */
- private final int ranking;
-
- /** The context path. */
- private final String path;
-
- /** The context prefix. */
- private final String prefix;
-
- private final ServletRegistry servletRegistry = new ServletRegistry();
-
- private final FilterRegistry filterRegistry = new FilterRegistry();
-
- private final ErrorPageRegistry errorPageRegistry = new ErrorPageRegistry();
-
- private final EventListenerRegistry eventListenerRegistry = new EventListenerRegistry();
-
- private final HttpConfig config;
-
- /**
- * Registry for a servlet context helper (whiteboard support)
- * @param info The servlet context helper info
- */
- public PerContextHandlerRegistry(@NotNull final ServletContextHelperInfo info, @NotNull final HttpConfig config)
- {
- this.config = config;
- this.serviceId = info.getServiceId();
- this.ranking = info.getRanking();
- this.path = info.getPath();
- if ( this.path.equals("/") )
- {
- this.prefix = null;
- }
- else
- {
- this.prefix = this.path + "/";
- }
- }
-
- public long getContextServiceId()
- {
- return this.serviceId;
- }
-
- public HttpConfig getConfig()
- {
- return this.config;
- }
-
- public void removeAll()
- {
- this.errorPageRegistry.cleanup();
- this.eventListenerRegistry.cleanup();
- this.filterRegistry.cleanup();
- this.servletRegistry.cleanup();
- }
-
- @Override
- public int compareTo(@NotNull final PerContextHandlerRegistry other)
- {
- final int result = Integer.valueOf(other.path.length()).compareTo(this.path.length());
- if ( result == 0 ) {
- if (this.ranking == other.ranking)
- {
- // Service id's can be negative. Negative id's follow the reverse natural ordering of integers.
- int reverseOrder = ( this.serviceId <= 0 && other.serviceId <= 0 ) ? -1 : 1;
- return reverseOrder * Long.valueOf(this.serviceId).compareTo(other.serviceId);
- }
-
- return Integer.valueOf(other.ranking).compareTo(this.ranking);
- }
- return result;
- }
-
- public String isMatching(@NotNull final String requestURI)
- {
- if (requestURI.equals(this.path))
- {
- return "";
- }
- if (this.prefix == null)
- {
- return requestURI;
- }
- if (requestURI.startsWith(this.prefix))
- {
- return requestURI.substring(this.prefix.length() - 1);
- }
- return null;
- }
-
- public PathResolution resolve(@NotNull final String relativeRequestURI)
- {
- return this.servletRegistry.resolve(relativeRequestURI);
- }
-
- public ServletHandler resolveServletByName(final String name)
- {
- return this.servletRegistry.resolveByName(name);
- }
-
- /**
- * Get filter handlers for the request uri
- * @param servletHandler The servlet handler (might be null)
- * @param dispatcherType The dispatcher type
- * @param requestURI The request uri
- * @return The array of filter handlers, the array might be empty.
- */
- public @NotNull FilterHandler[] getFilterHandlers(@Nullable final ServletHandler servletHandler,
- @NotNull final DispatcherType dispatcherType,
- @NotNull final String requestURI)
- {
- return this.filterRegistry.getFilterHandlers(servletHandler, dispatcherType, requestURI);
- }
-
- /**
- * Get the servlet handling the error.
- * @param code The error code
- * @param exception The optional exception
- * @return The servlet handler or {@code null}.
- */
- public @Nullable ServletHandler getErrorHandler(final int code, @Nullable final Throwable exception)
- {
- return this.errorPageRegistry.get(exception, code);
- }
-
- public EventListenerRegistry getEventListenerRegistry()
- {
- return this.eventListenerRegistry;
- }
-
- /**
- * Create all DTOs for servlets, filters, resources and error pages
- * @param dto The servlet context DTO
- * @param failedDTOHolder The container for all failed DTOs
- */
- public void getRuntime(final ServletContextDTO dto,
- final FailedDTOHolder failedDTOHolder)
- {
- // collect filters
- this.filterRegistry.getRuntimeInfo(dto, failedDTOHolder.failedFilterDTOs);
-
- // collect error pages
- this.errorPageRegistry.getRuntimeInfo(dto, failedDTOHolder.failedErrorPageDTOs);
-
- // collect servlets and resources
- this.servletRegistry.getRuntimeInfo(dto, failedDTOHolder.failedServletDTOs, failedDTOHolder.failedResourceDTOs);
-
- // collect listeners
- this.eventListenerRegistry.getRuntimeInfo(dto, failedDTOHolder.failedListenerDTOs);
- }
-
- /**
- * Add a servlet
- * @param handler The servlet handler
- */
- public void registerServlet(@NotNull final ServletHandler handler)
- {
- this.servletRegistry.addServlet(handler);
- this.errorPageRegistry.addServlet(handler);
- }
-
- /**
- * Remove a servlet
- * @param servletInfo The servlet info
- * @param destroy Destroy the servlet
- */
- public void unregisterServlet(@NotNull final ServletInfo servletInfo, final boolean destroy)
- {
- this.servletRegistry.removeServlet(servletInfo, destroy);
- this.errorPageRegistry.removeServlet(servletInfo, destroy);
- }
-
- /**
- * Add a filter
- * @param handler The filter handler
- */
- public void registerFilter(@NotNull final FilterHandler handler)
- {
- this.filterRegistry.addFilter(handler);
- }
-
- /**
- * Remove a filter
- * @param info The filter info
- * @param destroy Destroy the filter
- */
- public void unregisterFilter(@NotNull final FilterInfo info, final boolean destroy)
- {
- this.filterRegistry.removeFilter(info, destroy);
- }
-
- /**
- * Register listeners
- * @param listenerHandler
- */
- public void registerListeners(@NotNull final ListenerHandler listenerHandler)
- {
- this.eventListenerRegistry.addListeners(listenerHandler);
- }
-
- /**
- * Unregister listeners
- *
- * @param info The listener info
- */
- public void unregisterListeners(@NotNull final ListenerInfo info)
- {
- this.eventListenerRegistry.removeListeners(info);
- }
-
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java
deleted file mode 100644
index 78ebd0c316..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletRegistry.java
+++ /dev/null
@@ -1,528 +0,0 @@
-/*
- * 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.registry;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.felix.http.base.internal.handler.ServletHandler;
-import org.apache.felix.http.base.internal.runtime.ServletInfo;
-import org.apache.felix.http.base.internal.runtime.dto.BuilderConstants;
-import org.apache.felix.http.base.internal.runtime.dto.ResourceDTOBuilder;
-import org.apache.felix.http.base.internal.runtime.dto.ServletDTOBuilder;
-import org.jetbrains.annotations.NotNull;
-import org.osgi.service.servlet.runtime.dto.DTOConstants;
-import org.osgi.service.servlet.runtime.dto.FailedResourceDTO;
-import org.osgi.service.servlet.runtime.dto.FailedServletDTO;
-import org.osgi.service.servlet.runtime.dto.ResourceDTO;
-import org.osgi.service.servlet.runtime.dto.ServletContextDTO;
-import org.osgi.service.servlet.runtime.dto.ServletDTO;
-
-/**
- * The servlet registry keeps the mappings for all servlets (by using their pattern)
- * for a single servlet context.
- */
-public final class ServletRegistry
-{
- private static final String NAMED_SERVLET_PATTERN = ":::";
-
- private volatile List<PathResolver> activeResolvers = Collections.emptyList();
-
- private final Map<String, List<ServletHandler>> inactiveServletMappings = new HashMap<String, List<ServletHandler>>();
-
- private final Map<String, List<ServletHandler>> servletsByName = new ConcurrentHashMap<String, List<ServletHandler>>();
-
- private static final class RegistrationStatus
- {
- public ServletHandler handler;
- public Map<Integer, String[]> statusToPath = new HashMap<Integer, String[]>();
- }
-
- private volatile Map<ServletInfo, RegistrationStatus> mapping = Collections.emptyMap();
-
- /**
- * Resolve a request uri
- *
- * @param relativeRequestURI The request uri
- * @return A path resolution if a servlet matched, {@code null} otherwise
- */
- public PathResolution resolve(@NotNull final String relativeRequestURI)
- {
- final List<PathResolver> resolvers = this.activeResolvers;
- for(final PathResolver entry : resolvers)
- {
- final PathResolution pr = entry.resolve(relativeRequestURI);
- if ( pr != null )
- {
- pr.patterns = new String[] {entry.getPattern()};
- pr.matchedPattern = entry.getPattern();
- return pr;
- }
- }
- return null;
- }
-
- private PathResolver findResolver(final List<PathResolver> resolvers, final String pattern)
- {
- for(final PathResolver pr : resolvers)
- {
- if ( pr.getPattern().equals(pattern) )
- {
- return pr;
- }
- }
- return null;
- }
-
- /**
- * Add a servlet.
- *
- * @param handler The servlet handler
- */
- public synchronized void addServlet(@NotNull final ServletHandler handler)
- {
- // we have to check for every pattern in the info
- // Can be null in case of error-handling servlets and named servlets
- if ( handler.getServletInfo().getPatterns() != null )
- {
- final Map<ServletInfo, RegistrationStatus> newMap = new TreeMap<ServletInfo, ServletRegistry.RegistrationStatus>(this.mapping);
-
- final List<PathResolver> resolvers = new ArrayList<PathResolver>(this.activeResolvers);
-
- final RegistrationStatus status = new RegistrationStatus();
- status.handler = handler;
-
- boolean isActive = false;
- // used for detecting duplicates
- final Set<String> patterns = new HashSet<String>();
- for(final String pattern : handler.getServletInfo().getPatterns())
- {
- if ( patterns.contains(pattern) )
- {
- continue;
- }
- patterns.add(pattern);
- final PathResolver regHandler = findResolver(resolvers, pattern);
- if ( regHandler != null )
- {
- if ( regHandler.getServletHandler().getServletInfo().compareTo(handler.getServletInfo()) > 0 )
- {
- // replace if no error with new servlet
- if ( this.tryToActivate(resolvers, pattern, handler, status, regHandler) )
- {
- isActive = true;
- final String oldName = regHandler.getServletHandler().getName();
- regHandler.getServletHandler().destroy();
-
- final RegistrationStatus oldStatus = newMap.get(regHandler.getServletHandler().getServletInfo());
- final RegistrationStatus newOldStatus = new RegistrationStatus();
- newOldStatus.handler = oldStatus.handler;
- newOldStatus.statusToPath = new HashMap<Integer, String[]>(oldStatus.statusToPath);
- newMap.put(regHandler.getServletHandler().getServletInfo(), newOldStatus);
- this.addToInactiveList(pattern, regHandler.getServletHandler(), newOldStatus);
-
- if ( regHandler.getServletHandler().getServlet() == null )
- {
- removeFromNameMapping(oldName, regHandler.getServletHandler());
- }
- }
- }
- else
- {
- // add to inactive
- this.addToInactiveList(pattern, handler, status);
- }
- }
- else
- {
- // add to active
- if ( this.tryToActivate(resolvers, pattern, handler, status, null) )
- {
- isActive = true;
- }
- }
- }
- newMap.put(handler.getServletInfo(), status);
- if ( isActive )
- {
- addToNameMapping(handler);
- }
- Collections.sort(resolvers);
- this.activeResolvers = resolvers;
- this.mapping = newMap;
- }
- else if ( !handler.getServletInfo().isResource() && handler.getServletInfo().getName() != null )
- {
- final Map<ServletInfo, RegistrationStatus> newMap = new TreeMap<ServletInfo, ServletRegistry.RegistrationStatus>(this.mapping);
-
- final RegistrationStatus status = new RegistrationStatus();
- status.handler = handler;
-
- // if a servlet has only a name we always try to activate
- // this is not very efficient, but works
- // add to active
- final int result = handler.init();
- if ( result == -1 )
- {
- addToNameMapping(handler);
- }
- addPattern(status, result, NAMED_SERVLET_PATTERN);
-
- newMap.put(handler.getServletInfo(), status);
- this.mapping = newMap;
- }
- }
-
- private void addToNameMapping(final ServletHandler handler)
- {
- if ( !handler.getServletInfo().isResource() )
- {
- final String servletName = handler.getName();
- List<ServletHandler> list = this.servletsByName.get(servletName);
- if ( list == null )
- {
- list = new ArrayList<ServletHandler>();
- list.add(handler);
- }
- else
- {
- list = new ArrayList<ServletHandler>(list);
- list.add(handler);
- Collections.sort(list);
- }
- this.servletsByName.put(servletName, list);
- }
- }
-
- private void removeFromNameMapping(final String servletName, final ServletHandler handler)
- {
- if ( !handler.getServletInfo().isResource() )
- {
- List<ServletHandler> list = this.servletsByName.get(servletName);
- if ( list != null )
- {
- final List<ServletHandler> newList = new ArrayList<ServletHandler>(list);
- final Iterator<ServletHandler> i = newList.iterator();
- while ( i.hasNext() )
- {
- final ServletHandler s = i.next();
- if ( s == handler )
- {
- i.remove();
- break;
- }
- }
- if ( newList.isEmpty() )
- {
- this.servletsByName.remove(servletName);
- }
- else
- {
- this.servletsByName.put(servletName, newList);
- }
- }
- }
- }
-
- /**
- * Remove a servlet
- * @param info The servlet info
- */
- public synchronized void removeServlet(@NotNull final ServletInfo info, final boolean destroy)
- {
- if ( info.getPatterns() != null )
- {
- final List<PathResolver> resolvers = new ArrayList<PathResolver>(this.activeResolvers);
-
- final Map<ServletInfo, RegistrationStatus> newMap = new TreeMap<ServletInfo, ServletRegistry.RegistrationStatus>(this.mapping);
- newMap.remove(info);
-
- ServletHandler cleanupHandler = null;
-
- // used for detecting duplicates
- final Set<String> patterns = new HashSet<String>();
- for(final String pattern : info.getPatterns())
- {
- if ( patterns.contains(pattern) )
- {
- continue;
- }
- patterns.add(pattern);
- final PathResolver regHandler = this.findResolver(resolvers, pattern);
- if ( regHandler != null && regHandler.getServletHandler().getServletInfo().equals(info) )
- {
- cleanupHandler = regHandler.getServletHandler();
- removeFromNameMapping(cleanupHandler.getName(), cleanupHandler);
-
- final List<ServletHandler> inactiveList = this.inactiveServletMappings.get(pattern);
- if ( inactiveList == null )
- {
- resolvers.remove(regHandler);
- }
- else
- {
- boolean done = false;
- while ( !done )
- {
- final ServletHandler h = inactiveList.remove(0);
- boolean activate = h.getServlet() == null;
- final RegistrationStatus oldStatus = newMap.get(h.getServletInfo());
- if ( oldStatus != null ) {
- final RegistrationStatus newOldStatus = new RegistrationStatus();
- newOldStatus.handler = oldStatus.handler;
- newOldStatus.statusToPath = new HashMap<Integer, String[]>(oldStatus.statusToPath);
- removePattern(newOldStatus, DTOConstants.FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE, pattern);
- newMap.put(h.getServletInfo(), newOldStatus);
- done = this.tryToActivate(resolvers, pattern, h, newOldStatus, regHandler);
- if ( done && activate ) {
- this.addToNameMapping(h);
- }
- }
- if ( !done )
- {
- done = inactiveList.isEmpty();
- }
- }
- if ( inactiveList.isEmpty() )
- {
- this.inactiveServletMappings.remove(pattern);
- }
- }
- }
- else
- {
- final List<ServletHandler> inactiveList = this.inactiveServletMappings.get(pattern);
- if ( inactiveList != null )
- {
- final Iterator<ServletHandler> i = inactiveList.iterator();
- while ( i.hasNext() )
- {
- final ServletHandler h = i.next();
- if ( h.getServletInfo().equals(info) )
- {
- i.remove();
- cleanupHandler = h;
- break;
- }
- }
- if ( inactiveList.isEmpty() )
- {
- this.inactiveServletMappings.remove(pattern);
- }
- }
- }
- }
-
- Collections.sort(resolvers);
- this.activeResolvers = resolvers;
- this.mapping = newMap;
-
- if ( cleanupHandler != null )
- {
- cleanupHandler.dispose();
- }
- }
- else if ( !info.isResource() && info.getName() != null )
- {
- final Map<ServletInfo, RegistrationStatus> newMap = new TreeMap<ServletInfo, ServletRegistry.RegistrationStatus>(this.mapping);
- final RegistrationStatus status = newMap.remove(info);
-
- if ( status != null )
- {
- removeFromNameMapping(info.getName(), status.handler);
-
- this.mapping = newMap;
-
- status.handler.dispose();
- }
-
- }
- }
-
- public synchronized void cleanup()
- {
- this.activeResolvers = Collections.emptyList();
- this.inactiveServletMappings.clear();
- this.servletsByName.clear();
- this.mapping = Collections.emptyMap();
- }
-
- private void addToInactiveList(final String pattern, final ServletHandler handler, final RegistrationStatus status)
- {
- List<ServletHandler> inactiveList = this.inactiveServletMappings.get(pattern);
- if ( inactiveList == null )
- {
- inactiveList = new ArrayList<ServletHandler>();
- this.inactiveServletMappings.put(pattern, inactiveList);
- }
- inactiveList.add(handler);
- Collections.sort(inactiveList);
- removePattern(status, -1, pattern);
- addPattern(status, DTOConstants.FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE, pattern);
- }
-
- private boolean tryToActivate(final List<PathResolver> resolvers,
- final String pattern,
- final ServletHandler handler,
- final RegistrationStatus status,
- final PathResolver oldResolver)
- {
- // add to active
- final int result = handler.init();
- if ( result == -1 )
- {
- if ( oldResolver != null )
- {
- resolvers.remove(oldResolver);
- }
- final PathResolver resolver = PathResolverFactory.createPatternMatcher(handler, pattern);
- resolvers.add(resolver);
- }
- // update status
- addPattern(status, result, pattern);
- return result == -1;
- }
-
- private void addPattern(final RegistrationStatus status, final int failureCode, final String pattern)
- {
- String[] paths = status.statusToPath.get(failureCode);
- if ( paths == null )
- {
- status.statusToPath.put(failureCode, new String[] {pattern});
- }
- else
- {
- final String[] newPaths = new String[paths.length + 1];
- System.arraycopy(paths, 0, newPaths, 0, paths.length);
- newPaths[paths.length] = pattern;
- status.statusToPath.put(failureCode, newPaths);
- }
- }
-
- private void removePattern(final RegistrationStatus status, final int failureCode, final String pattern)
- {
- String[] paths = status.statusToPath.get(failureCode);
- if ( paths != null )
- {
- final List<String> array = new ArrayList<String>(Arrays.asList(paths));
- if ( array.remove(pattern) )
- {
- if ( array.isEmpty() )
- {
- status.statusToPath.remove(failureCode);
- }
- else
- {
- status.statusToPath.put(failureCode, array.toArray(new String[array.size()]));
- }
- }
- }
- }
-
- public ServletHandler resolveByName(final @NotNull String name)
- {
- final List<ServletHandler> handlerList = this.servletsByName.get(name);
- if ( handlerList != null )
- {
- return handlerList.get(0);
- }
- return null;
- }
-
- public void getRuntimeInfo(
- final ServletContextDTO servletContextDTO,
- final Collection<FailedServletDTO> allFailedServletDTOs,
- final Collection<FailedResourceDTO> allFailedResourceDTOs)
- {
- final Map<Long, ServletDTO> servletDTOs = new HashMap<Long, ServletDTO>();
- final Map<Long, ResourceDTO> resourceDTOs = new HashMap<Long, ResourceDTO>();
-
- final Map<Long, FailedServletDTO> failedServletDTOs = new HashMap<Long, FailedServletDTO>();
- final Map<Long, FailedResourceDTO> failedResourceDTOs = new HashMap<Long, FailedResourceDTO>();
-
- for(final Map.Entry<ServletInfo, RegistrationStatus> entry : mapping.entrySet())
- {
- final long serviceId = entry.getKey().getServiceId();
- for(final Map.Entry<Integer, String[]> map : entry.getValue().statusToPath.entrySet())
- {
- if ( entry.getKey().isResource() )
- {
- final ResourceDTO state = ResourceDTOBuilder.build(entry.getValue().handler, map.getKey());
- if ( map.getValue().length == 1 && NAMED_SERVLET_PATTERN == map.getValue()[0] )
- {
- state.patterns = BuilderConstants.EMPTY_STRING_ARRAY;
- }
- else
- {
- state.patterns = Arrays.copyOf(map.getValue(), map.getValue().length);
- }
- if ( map.getKey() == -1 )
- {
- resourceDTOs.put(serviceId, state);
- }
- else
- {
- failedResourceDTOs.put(serviceId, (FailedResourceDTO)state);
- }
- }
- else
- {
- final ServletDTO state = ServletDTOBuilder.build(entry.getValue().handler, map.getKey());
- if ( map.getValue().length == 1 && NAMED_SERVLET_PATTERN == map.getValue()[0] )
- {
- state.patterns = BuilderConstants.EMPTY_STRING_ARRAY;
- }
- else
- {
- state.patterns = Arrays.copyOf(map.getValue(), map.getValue().length);
- }
- if ( map.getKey() == -1 )
- {
- servletDTOs.put(serviceId, state);
- }
- else
- {
- failedServletDTOs.put(serviceId, (FailedServletDTO)state);
- }
- }
- }
- }
-
- final Collection<ServletDTO> servletDTOsArray = servletDTOs.values();
- if ( !servletDTOsArray.isEmpty() )
- {
- servletContextDTO.servletDTOs = servletDTOsArray.toArray(new ServletDTO[servletDTOsArray.size()]);
- }
- final Collection<ResourceDTO> resourceDTOsArray = resourceDTOs.values();
- if ( !resourceDTOsArray.isEmpty() )
- {
- servletContextDTO.resourceDTOs = resourceDTOsArray.toArray(new ResourceDTO[resourceDTOsArray.size()]);
- }
- allFailedResourceDTOs.addAll(failedResourceDTOs.values());
- allFailedServletDTOs.addAll(failedServletDTOs.values());
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletResolution.java b/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletResolution.java
deleted file mode 100644
index 5729a8bb9b..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/registry/ServletResolution.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * 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.registry;
-
-import org.apache.felix.http.base.internal.handler.ServletHandler;
-
-public class ServletResolution {
-
- public ServletHandler handler;
-
- public PerContextHandlerRegistry handlerRegistry;
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/AbstractInfo.java b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/AbstractInfo.java
deleted file mode 100644
index cfa29d389b..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/AbstractInfo.java
+++ /dev/null
@@ -1,270 +0,0 @@
-/*
- * 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.runtime;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-
-import org.apache.felix.http.base.internal.util.ServiceUtils;
-import org.jetbrains.annotations.NotNull;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.servlet.whiteboard.HttpWhiteboardConstants;
-
-/**
- * Base class for all info objects.
- * Provides support for ranking and ordering of services.
- */
-public abstract class AbstractInfo<T> implements Comparable<AbstractInfo<T>>
-{
- /** Service ranking. */
- private final int ranking;
-
- /** Service id. */
- private final long serviceId;
-
- /** Service reference. */
- private final ServiceReference<T> serviceReference;
-
- /** Target. */
- private final String target;
-
- public AbstractInfo(final ServiceReference<T> ref)
- {
- this.serviceId = (Long) ref.getProperty(Constants.SERVICE_ID);
- final Object rankingObj = ref.getProperty(Constants.SERVICE_RANKING);
- if (rankingObj instanceof Integer)
- {
- this.ranking = (Integer) rankingObj;
- }
- else
- {
- this.ranking = 0;
- }
- this.serviceReference = ref;
- this.target = getStringProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_TARGET);
- }
-
- public AbstractInfo(final int ranking, final long serviceId)
- {
- this.ranking = ranking;
- this.serviceId = serviceId;
- this.serviceReference = null;
- this.target = null;
- }
-
- public boolean isValid()
- {
- return true;
- }
-
- /**
- * Compare two info objects based on their ranking (aka reverse ServiceReference ordering)
- */
- @Override
- public int compareTo(final AbstractInfo<T> other)
- {
- if (this.ranking == other.ranking)
- {
- if ( this.serviceId == other.serviceId )
- {
- return this.getClass().getName().compareTo(other.getClass().getName());
- }
- // Service id's can be negative. Negative id's follow the reverse natural ordering of integers.
- int reverseOrder = ( this.serviceId >= 0 && other.serviceId >= 0 ) ? 1 : -1;
- return reverseOrder * Long.valueOf(this.serviceId).compareTo(other.serviceId);
- }
-
- int result = Integer.valueOf(other.ranking).compareTo(this.ranking);
- return result;
- }
-
- /**
- * Compare two info objects
- */
- public boolean isSame(final AbstractInfo<T> other) {
- if (this.serviceId != other.serviceId) {
- return false;
- }
- if (this.ranking != other.ranking) {
- return false;
- }
- return Objects.equals(this.target, other.target);
- }
-
- protected boolean isEmpty(final String value)
- {
- return value == null || value.length() == 0;
- }
-
- protected boolean isEmpty(final String[] value)
- {
- return value == null || value.length == 0;
- }
-
- protected String getStringProperty(final ServiceReference<T> ref, final String key)
- {
- final Object value = ref.getProperty(key);
- return (value instanceof String) ? ((String) value).trim() : null;
- }
-
- protected String[] getStringArrayProperty(ServiceReference<T> ref, String key)
- {
- Object value = ref.getProperty(key);
-
- if (value instanceof String)
- {
- return new String[] { ((String) value).trim() };
- }
- else if (value instanceof String[])
- {
- final String[] arr = (String[]) value;
- String[] values = new String[arr.length];
-
- for (int i = 0, j = 0; i < arr.length; i++)
- {
- if (arr[i] != null)
- {
- values[j++] = arr[i].trim();
- }
- }
- return values;
- }
- else if (value instanceof Collection<?>)
- {
- Collection<?> collectionValues = (Collection<?>) value;
- String[] values = new String[collectionValues.size()];
-
- int i = 0;
- for (Object current : collectionValues)
- {
- values[i++] = current != null ? String.valueOf(current).trim() : null;
- }
-
- return values;
- }
-
- return null;
- }
-
- protected boolean getBooleanProperty(ServiceReference<T> ref, String key)
- {
- Object value = ref.getProperty(key);
- if (value instanceof String)
- {
- return Boolean.valueOf((String) value);
- }
- else if (value instanceof Boolean)
- {
- return ((Boolean) value).booleanValue();
- }
- return false;
- }
-
- /**
- * Get the init parameters.
- */
- protected Map<String, String> getInitParams(final ServiceReference<T> ref, final String prefix)
- {
- final Map<String, String> result = new HashMap<String, String>();
- for (final String key : ref.getPropertyKeys())
- {
- if (key.startsWith(prefix))
- {
- final String paramKey = key.substring(prefix.length());
- final String paramValue = getStringProperty(ref, key);
-
- if (paramValue != null)
- {
- result.put(paramKey, paramValue);
- }
- }
- }
- return Collections.unmodifiableMap(result);
- }
-
- public int getRanking()
- {
- return this.ranking;
- }
-
- public long getServiceId()
- {
- return this.serviceId;
- }
-
- public String getTarget()
- {
- return this.target;
- }
-
- public ServiceReference<T> getServiceReference()
- {
- return this.serviceReference;
- }
-
- @Override
- public int hashCode()
- {
- return 31 + (int) (serviceId ^ (serviceId >>> 32));
- }
-
- @Override
- public boolean equals(final Object obj)
- {
- if (this == obj)
- {
- return true;
- }
- if (obj == null || getClass() != obj.getClass())
- {
- return false;
- }
- final AbstractInfo<?> other = (AbstractInfo<?>) obj;
- return serviceId == other.serviceId;
- }
-
- /**
- * Get a service object
- * @param bundleContext context
- * @return The object or {@code null}
- */
- public T getService(final BundleContext bundleContext) {
- return ServiceUtils.safeGetServiceObjects(bundleContext, this.getServiceReference());
- }
-
- /**
- * Unget the service object
- * @param bundleContext The bundle context
- * @param service The service object
- */
- public void ungetService(final BundleContext bundleContext, final T service) {
- ServiceUtils.safeUngetServiceObjects(bundleContext, this.getServiceReference(), service);
- }
-
- /**
- * Get the type represented by this info
- * @return The type
- */
- public abstract @NotNull String getType();
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/DefaultServletContextHelperInfo.java b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/DefaultServletContextHelperInfo.java
deleted file mode 100644
index 756b20db5e..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/DefaultServletContextHelperInfo.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.runtime;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.service.servlet.whiteboard.HttpWhiteboardConstants;
-import org.osgi.service.servlet.context.ServletContextHelper;
-
-/**
- * Info for the default context
- */
-public class DefaultServletContextHelperInfo extends ServletContextHelperInfo {
-
- public DefaultServletContextHelperInfo() {
- super(Integer.MIN_VALUE, Integer.MIN_VALUE, HttpWhiteboardConstants.HTTP_WHITEBOARD_DEFAULT_CONTEXT_NAME, "/", null);
- }
-
- @Override
- public ServletContextHelper getService(final BundleContext bundleContext) {
- return new ServletContextHelper(bundleContext.getBundle()) {
- // nothing to override
- };
-}
-
- @Override
- public void ungetService(final BundleContext bundleContext, final ServletContextHelper service) {
- // nothing to do
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/FilterInfo.java b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/FilterInfo.java
deleted file mode 100644
index 1e6555883c..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/FilterInfo.java
+++ /dev/null
@@ -1,241 +0,0 @@
-/*
- * 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.runtime;
-
-import java.util.Arrays;
-import java.util.Map;
-import java.util.Objects;
-import java.util.regex.Pattern;
-import java.util.regex.PatternSyntaxException;
-
-import org.apache.felix.http.base.internal.util.PatternUtil;
-import org.jetbrains.annotations.NotNull;
-import org.osgi.dto.DTO;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.servlet.runtime.dto.FilterDTO;
-import org.osgi.service.servlet.whiteboard.HttpWhiteboardConstants;
-
-import jakarta.servlet.DispatcherType;
-import jakarta.servlet.Filter;
-
-/**
- * Provides registration information for a {@link Filter}, and is used to programmatically register {@link Filter}s.
- * <p>
- * This class only provides information used at registration time, and as such differs slightly from {@link DTO}s like, {@link FilterDTO}.
- * </p>
- */
-public class FilterInfo extends WhiteboardServiceInfo<Filter>
-{
- /**
- * The name of the filter.
- */
- private final String name;
-
- /**
- * The request mappings for the servlet.
- * <p>
- * The specified patterns are used to determine whether a request is mapped to the servlet filter.<br>
- * Note that these patterns should conform to the Servlet specification.
- * </p>
- */
- private final String[] patterns;
-
- /**
- * The servlet names for the servlet filter.
- * <p>
- * The specified names are used to determine the servlets whose requests are mapped to the servlet filter.
- * </p>
- */
- private final String[] servletNames;
-
- /**
- * The request mappings for the servlet filter.
- * <p>
- * The specified regular expressions are used to determine whether a request is mapped to the servlet filter.<br>
- * These regular expressions are a convenience extension allowing one to specify filters that match paths that are difficult to match with plain Servlet patterns alone.
- * </p>
- */
- private final String[] regexs;
-
- /**
- * Specifies whether the servlet filter supports asynchronous processing.
- */
- private final boolean asyncSupported;
-
- /**
- * The dispatcher associations for the servlet filter.
- * <p>
- * The specified names are used to determine in what occasions the servlet filter is called.
- * See {@link DispatcherType} and Servlet 3.0 specification, section 6.2.5.
- * </p>
- */
- private final DispatcherType[] dispatcher;
-
- /**
- * The filter initialization parameters as provided during registration of the filter.
- */
- private final Map<String, String> initParams;
-
- /**
- * new filter info
- * @param ref filter service reference
- */
- public FilterInfo(final ServiceReference<Filter> ref)
- {
- super(ref);
- this.name = getStringProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_NAME);
- this.asyncSupported = getBooleanProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_ASYNC_SUPPORTED);
- this.servletNames = getStringArrayProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_SERVLET);
- this.patterns = getStringArrayProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_PATTERN);
- this.regexs = getStringArrayProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_REGEX);
- this.initParams = getInitParams(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_INIT_PARAM_PREFIX);
- String[] dispatcherNames = getStringArrayProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_DISPATCHER);
- if (dispatcherNames != null && dispatcherNames.length > 0)
- {
- DispatcherType[] dispatchers = new DispatcherType[dispatcherNames.length];
- for (int i = 0; i < dispatchers.length; i++)
- {
- try
- {
- dispatchers[i] = DispatcherType.valueOf(dispatcherNames[i].toUpperCase());
- }
- catch ( final IllegalArgumentException iae)
- {
- dispatchers = null;
- break;
- }
- }
- this.dispatcher = dispatchers;
- }
- else
- {
- this.dispatcher = new DispatcherType[] {DispatcherType.REQUEST};
- }
- }
-
- @Override
- public boolean isValid()
- {
- boolean valid = super.isValid() && (!isEmpty(this.patterns) || !isEmpty(this.regexs) || !isEmpty(this.servletNames));
- if ( valid )
- {
- if ( this.patterns != null )
- {
- for(final String p : this.patterns)
- {
- if ( !PatternUtil.isValidPattern(p) )
- {
- valid = false;
- break;
- }
- }
- }
- if ( valid && this.regexs != null )
- {
- for(final String p : this.regexs)
- {
- try
- {
- Pattern.compile(p);
- }
- catch ( final PatternSyntaxException pse)
- {
- valid = false;
- break;
- }
- }
- }
- }
- if ( valid )
- {
- if ( this.dispatcher == null || this.dispatcher.length == 0 )
- {
- valid = false;
- }
- }
- return valid;
- }
-
- public String getName()
- {
- return name;
- }
-
- public String[] getPatterns()
- {
- return patterns;
- }
-
- public String[] getServletNames()
- {
- return servletNames;
- }
-
- public String[] getRegexs()
- {
- return regexs;
- }
-
- public boolean isAsyncSupported()
- {
- return asyncSupported;
- }
-
- public DispatcherType[] getDispatcher()
- {
- return dispatcher;
- }
-
- /**
- * Returns an immutable map of the init parameters.
- */
- public Map<String, String> getInitParameters()
- {
- return initParams;
- }
-
- @Override
- public @NotNull String getType() {
- return "Filter";
- }
-
- /**
- * Get the class name of the filter
- * @param filter The filter
- * @return The class name
- */
- public @NotNull String getClassName(@NotNull final Filter filter) {
- return filter.getClass().getName();
- }
-
- @Override
- public boolean isSame(AbstractInfo<Filter> other) {
- if (!super.isSame(other)) {
- return false;
- }
- final FilterInfo o = (FilterInfo) other;
- return Objects.equals(this.name, o.name)
- && Arrays.equals(this.patterns, o.patterns)
- && Arrays.equals(this.servletNames, o.servletNames)
- && Arrays.equals(this.regexs, o.regexs)
- && this.asyncSupported == o.asyncSupported
- && Arrays.equals(this.dispatcher, o.dispatcher)
- && Objects.equals(this.initParams, o.initParams);
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ListenerInfo.java b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ListenerInfo.java
deleted file mode 100644
index eb34ec62a4..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ListenerInfo.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * 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.runtime;
-
-import java.util.EventListener;
-import java.util.HashSet;
-import java.util.Objects;
-import java.util.Set;
-
-import org.jetbrains.annotations.NotNull;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.servlet.whiteboard.HttpWhiteboardConstants;
-
-import jakarta.servlet.ServletContextAttributeListener;
-import jakarta.servlet.ServletContextListener;
-import jakarta.servlet.ServletRequestAttributeListener;
-import jakarta.servlet.ServletRequestListener;
-import jakarta.servlet.http.HttpSessionAttributeListener;
-import jakarta.servlet.http.HttpSessionIdListener;
-import jakarta.servlet.http.HttpSessionListener;
-
-/**
- * Info object for registered listeners.
- */
-public class ListenerInfo extends WhiteboardServiceInfo<EventListener>
-{
- private static final Set<String> ALLOWED_INTERFACES;
- static {
- ALLOWED_INTERFACES = new HashSet<String>();
- ALLOWED_INTERFACES.add(HttpSessionAttributeListener.class.getName());
- ALLOWED_INTERFACES.add(HttpSessionIdListener.class.getName());
- ALLOWED_INTERFACES.add(HttpSessionListener.class.getName());
- ALLOWED_INTERFACES.add(ServletContextAttributeListener.class.getName());
- ALLOWED_INTERFACES.add(ServletContextListener.class.getName());
- ALLOWED_INTERFACES.add(ServletRequestAttributeListener.class.getName());
- ALLOWED_INTERFACES.add(ServletRequestListener.class.getName());
- }
-
- /** Is the listener enabled (per properties) */
- private final boolean enabled;
-
- /** The service types */
- private final Set<String> types;
-
- /** The service types as reported through DTOs */
- private final String[] dtoTypes;
-
- /**
- * Constructor
- * @param ref The service reference
- */
- public ListenerInfo(final ServiceReference<EventListener> ref)
- {
- this(ref, getTypes(ref), null);
- }
-
- /**
- * Constructor
- * @param ref The service reference
- * @param dtoTypes Optional dto types
- * @param types The listener types
- */
- public ListenerInfo(final ServiceReference<EventListener> ref, final Set<String> types, final String[] dtos)
- {
- super(ref);
- this.enabled = this.getBooleanProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER);
- this.types = types;
- this.dtoTypes = dtos == null ? types.toArray(new String[types.size()]) : dtos;
- }
-
- private static Set<String> getTypes(final ServiceReference<EventListener> ref) {
- final String[] objectClass = (String[])ref.getProperty(Constants.OBJECTCLASS);
- final Set<String> names = new HashSet<String>();
- for(final String name : objectClass)
- {
- if ( ALLOWED_INTERFACES.contains(name) )
- {
- names.add(name);
- }
- }
- return names;
- }
-
- @Override
- public boolean isValid()
- {
- return super.isValid() && this.enabled;
- }
-
- /**
- * The types as reported through the DTOs
- * @return Array of types
- */
- public @NotNull String[] getDTOListenerTypes()
- {
- return this.dtoTypes;
- }
-
- /**
- * Is this listener of the required type?
- * @param className The listener type
- * @return {@code true} If the listener should be registered as that type
- */
- public boolean isListenerType(@NotNull final String className)
- {
- for(final String t : this.types)
- {
- if ( t.equals(className) )
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Get the registered listener types
- * @return The set of types
- */
- public @NotNull Set<String> getListenerTypes() {
- return this.types;
- }
-
- @Override
- public @NotNull String getType() {
- return "Listener";
- }
-
- @Override
- public boolean isSame(AbstractInfo<EventListener> other) {
- if (!super.isSame(other)) {
- return false;
- }
- final ListenerInfo o = (ListenerInfo) other;
- if (!Objects.equals(this.types, o.types)) {
- return false;
- }
- return this.enabled == o.enabled;
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/PreprocessorInfo.java b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/PreprocessorInfo.java
deleted file mode 100644
index 6af840d938..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/PreprocessorInfo.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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.runtime;
-
-import java.util.Map;
-import java.util.Objects;
-
-import org.jetbrains.annotations.NotNull;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.servlet.whiteboard.HttpWhiteboardConstants;
-import org.osgi.service.servlet.whiteboard.Preprocessor;
-
-/**
- * Provides registration information for a {@link Preprocessor}.
- * <p>
- * This class only provides information used at registration time, and as such differs
- * slightly from the corresponding DTO
- * </p>
- */
-public class PreprocessorInfo extends WhiteboardServiceInfo<Preprocessor>
-{
- /**
- * The preprocessor initialization parameters as provided during registration of the preprocessor.
- */
- private final Map<String, String> initParams;
-
- public PreprocessorInfo(final ServiceReference<Preprocessor> ref)
- {
- super(ref);
- this.initParams = getInitParams(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_PREPROCESSOR_INIT_PARAM_PREFIX);
- }
-
- /**
- * Returns an immutable map of the init parameters.
- */
- public Map<String, String> getInitParameters()
- {
- return initParams;
- }
-
-
- @Override
- public @NotNull String getType() {
- return "Preprocessor";
- }
-
- /**
- * Get the class name of the preprocessor
- * @param preprocessor The preprocesor
- * @return The class name
- */
- public @NotNull String getClassName(@NotNull final Preprocessor preprocessor) {
- return preprocessor.getClass().getName();
- }
-
-
- @Override
- public boolean isSame(AbstractInfo<Preprocessor> other) {
- if (!super.isSame(other)) {
- return false;
- }
- final PreprocessorInfo o = (PreprocessorInfo) other;
- return Objects.equals(this.initParams, o.initParams);
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ResourceInfo.java b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ResourceInfo.java
deleted file mode 100644
index ebabdf0e74..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ResourceInfo.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * 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.runtime;
-
-import java.util.Arrays;
-import java.util.Objects;
-
-import org.apache.felix.http.base.internal.util.PatternUtil;
-import org.jetbrains.annotations.NotNull;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.servlet.whiteboard.HttpWhiteboardConstants;
-
-/**
- * Info object for a resource registration
- */
-public final class ResourceInfo extends WhiteboardServiceInfo<Object>
-{
- /**
- * The request mappings for the resource.
- */
- private final String[] patterns;
-
- /**
- * The error pages and/or codes.
- */
- private final String prefix;
-
- private final ServletInfo servletInfo;
-
- private static final class ResourceServletInfo extends ServletInfo {
-
- public ResourceServletInfo(ResourceInfo resource) {
- super(resource);
- }
- }
-
- public ResourceInfo(final ServiceReference<Object> ref)
- {
- super(ref);
- this.patterns = getStringArrayProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_RESOURCE_PATTERN);
- this.prefix = getStringProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_RESOURCE_PREFIX);
- this.servletInfo = new ResourceServletInfo(this);
- }
-
- @Override
- public boolean isValid()
- {
- boolean valid = super.isValid() && !isEmpty(this.patterns) && !isEmpty(this.prefix);
- if ( valid ) {
- for(final String p : patterns)
- {
- if ( !PatternUtil.isValidPattern(p) )
- {
- valid = false;
- break;
- }
- }
- }
- return valid;
- }
-
- public String getPrefix()
- {
- return this.prefix;
- }
-
- public String[] getPatterns()
- {
- return patterns;
- }
-
- public ServletInfo getServletInfo()
- {
- return this.servletInfo;
- }
-
- @Override
- public @NotNull String getType() {
- return "Resource";
- }
-
- @Override
- public boolean isSame(AbstractInfo<Object> other) {
- if (!super.isSame(other)) {
- return false;
- }
- final ResourceInfo o = (ResourceInfo) other;
- return Arrays.equals(this.patterns, o.patterns)
- && Objects.equals(this.prefix, o.prefix);
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletContextHelperInfo.java b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletContextHelperInfo.java
deleted file mode 100644
index ffda03d5cf..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletContextHelperInfo.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * 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.runtime;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-
-import org.apache.felix.http.base.internal.util.PatternUtil;
-import org.jetbrains.annotations.NotNull;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.servlet.context.ServletContextHelper;
-import org.osgi.service.servlet.whiteboard.HttpWhiteboardConstants;
-
-/**
- * Provides registration information for a {@link ServletContextHelper}
- */
-public class ServletContextHelperInfo extends AbstractInfo<ServletContextHelper>
-{
-
- private final String name;
-
- private final String path;
-
- /**
- * The filter initialization parameters as provided during registration of the filter.
- */
- private final Map<String, String> initParams;
-
- public ServletContextHelperInfo(final ServiceReference<ServletContextHelper> ref)
- {
- super(ref);
- this.name = this.getStringProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME);
- this.path = this.getStringProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH);
- this.initParams = getInitParams(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_INIT_PARAM_PREFIX);
- }
-
- public ServletContextHelperInfo(final int serviceRanking,
- final long serviceId,
- final String name,
- final String path,
- final Map<String, String> initParams)
- {
- super(serviceRanking, serviceId);
- this.name = name;
- this.path = path;
- this.initParams = initParams == null ? Collections.<String, String>emptyMap(): Collections.unmodifiableMap(initParams);
- }
-
- private boolean isValidPath()
- {
- if (!this.isEmpty(path))
- {
- if (path.equals("/"))
- {
- return true;
- }
- if (path.startsWith("/") && !path.endsWith("/"))
- {
- return true;
- }
- }
- return false;
- }
-
- @Override
- public boolean isValid()
- {
- return super.isValid()
- && PatternUtil.isValidSymbolicName(this.name)
- && isValidPath();
- }
-
- public String getName()
- {
- return this.name;
- }
-
- public String getPath()
- {
- return this.path;
- }
-
- /**
- * Returns an unmodifiable map of the parameters.
- * @return
- */
- public Map<String, String> getInitParameters()
- {
- return initParams;
- }
-
- @Override
- public @NotNull String getType() {
- return "ServletContextHelper";
- }
-
- /**
- * Get the registered service type
- * @return The type
- */
- public @NotNull String getServiceType() {
- return ServletContextHelper.class.getName();
- }
-
- public boolean match(final WhiteboardServiceInfo<?> info) {
- if ( this.getServiceReference() != null ) {
- return info.getContextSelectionFilter().match(this.getServiceReference());
- }
- final Map<String, String> props = new HashMap<>();
- props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME, this.getName());
- props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH, this.getPath());
- if ( HttpWhiteboardConstants.HTTP_WHITEBOARD_DEFAULT_CONTEXT_NAME.equals(this.getName()) ) {
- props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME, this.getName());
- }
- return info.getContextSelectionFilter().matches(props);
- }
-
- @Override
- public boolean isSame(AbstractInfo<ServletContextHelper> other) {
- if (!super.isSame(other)) {
- return false;
- }
- final ServletContextHelperInfo o = (ServletContextHelperInfo) other;
- return Objects.equals(this.name, o.name)
- && Objects.equals(this.path, o.path)
- && Objects.equals(this.initParams, o.initParams);
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletInfo.java b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletInfo.java
deleted file mode 100644
index e4e42213fe..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/ServletInfo.java
+++ /dev/null
@@ -1,289 +0,0 @@
-/*
- * 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.runtime;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Map;
-import java.util.Objects;
-
-import org.apache.felix.http.base.internal.dispatch.MultipartConfig;
-import org.apache.felix.http.base.internal.util.PatternUtil;
-import org.jetbrains.annotations.NotNull;
-import org.osgi.dto.DTO;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.servlet.runtime.dto.ServletDTO;
-import org.osgi.service.servlet.whiteboard.HttpWhiteboardConstants;
-
-import jakarta.servlet.Servlet;
-
-/**
- * Provides registration information for a {@link Servlet}, and is used to programmatically register {@link Servlet}s.
- * <p>
- * This class only provides information used at registration time, and as such differs slightly from {@link DTO}s like, {@link ServletDTO}.
- * </p>
- */
-public class ServletInfo extends WhiteboardServiceInfo<Servlet>
-{
- /**
- * The name of the servlet.
- */
- private final String name;
-
- /**
- * The request mappings for the servlet.
- * <p>
- * The specified patterns are used to determine whether a request is mapped to the servlet.
- * </p>
- */
- private final String[] patterns;
-
- /**
- * The error pages and/or codes.
- */
- private final String[] errorPage;
-
- /**
- * Specifies whether the servlet supports asynchronous processing.
- */
- private final boolean asyncSupported;
-
- /**
- * Specifies whether the info represents a resource.
- */
- private final boolean isResource;
-
- /**
- * Specifies the multipart config for this servlet
- * or {@code null} if not enabled.
- */
- private final MultipartConfig multipartConfig;
-
-
- /**
- * The servlet initialization parameters as provided during registration of the servlet.
- */
- private final Map<String, String> initParams;
-
- private final String prefix;
-
- public ServletInfo(final ServiceReference<Servlet> ref)
- {
- super(ref);
- this.name = getStringProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_NAME);
- this.errorPage = getStringArrayProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ERROR_PAGE);
- this.patterns = getStringArrayProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN);
- this.asyncSupported = getBooleanProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ASYNC_SUPPORTED);
- if ( getBooleanProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_MULTIPART_ENABLED) )
- {
- MultipartConfig cfg = null;
- try
- {
- cfg = new MultipartConfig(getIntProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_MULTIPART_FILESIZETHRESHOLD),
- getStringProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_MULTIPART_LOCATION),
- getLongProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_MULTIPART_MAXFILESIZE),
- getLongProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_MULTIPART_MAXREQUESTSIZE),
- getLongProperty(ref, "osgi.http.whiteboard.servlet.multipart.maxFileCount"));
- }
- catch (final IllegalArgumentException iae)
- {
- cfg = MultipartConfig.INVALID_CONFIG;
- }
- this.multipartConfig = cfg;
- }
- else
- {
- this.multipartConfig = null;
- }
- this.initParams = getInitParams(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_INIT_PARAM_PREFIX);
- this.isResource = false;
- this.prefix = null;
- }
-
- @SuppressWarnings("unchecked")
- public ServletInfo(final ResourceInfo resource)
- {
- super(getRef(resource.getServiceReference()));
- this.name = null;
- this.patterns = resource.getPatterns();
- this.errorPage = null;
- this.asyncSupported = false;
- this.multipartConfig = null;
- this.initParams = Collections.emptyMap();
- this.isResource = true;
- this.prefix = resource.getPrefix();
- }
-
- private Integer getIntProperty(final ServiceReference<Servlet> ref, final String key)
- {
- final Object value = ref.getProperty(key);
- if (value instanceof String)
- {
- return Integer.valueOf((String) value);
- }
- else if (value instanceof Number)
- {
- return ((Number) value).intValue();
- }
- else if ( value != null )
- {
- throw new IllegalArgumentException();
- }
- return null;
- }
-
- private long getLongProperty(final ServiceReference<Servlet> ref, final String key)
- {
- final Object value = ref.getProperty(key);
- if (value instanceof String)
- {
- return Long.valueOf((String) value);
- }
- else if (value instanceof Number)
- {
- return ((Number) value).longValue();
- }
- else if ( value != null )
- {
- throw new IllegalArgumentException();
- }
- return -1;
- }
-
- @SuppressWarnings("rawtypes")
- private static ServiceReference getRef(ServiceReference ref)
- {
- return ref;
- }
-
- /**
- * Constructor for Http Service
- */
- public ServletInfo(final String name,
- final String pattern,
- final Map<String, String> initParams)
- {
- super(Integer.MAX_VALUE);
- this.name = name;
- this.patterns = new String[] {pattern};
- this.initParams = Collections.unmodifiableMap(initParams);
- this.asyncSupported = true;
- this.multipartConfig = MultipartConfig.DEFAULT_CONFIG;
- this.errorPage = null;
- this.isResource = false;
- this.prefix = null;
- }
-
- @Override
- public boolean isValid()
- {
- boolean valid = super.isValid()
- && !(isEmpty(this.patterns) && isEmpty(this.errorPage) && isEmpty(this.name))
- && this.multipartConfig != MultipartConfig.INVALID_CONFIG;
- if ( valid )
- {
- if ( this.patterns != null )
- {
- for(final String p : this.patterns)
- {
- if ( !PatternUtil.isValidPattern(p) )
- {
- valid = false;
- break;
- }
- }
- }
- }
- return valid;
- }
-
- public String getName()
- {
- return name;
- }
-
- public String[] getPatterns()
- {
- return patterns;
- }
-
- public String[] getErrorPage()
- {
- return errorPage;
- }
-
- public boolean isAsyncSupported()
- {
- return asyncSupported;
- }
-
- /**
- * Returns an unmodifiable map of the init parameters.
- * @return
- */
- public Map<String, String> getInitParameters()
- {
- return initParams;
- }
-
- public boolean isResource()
- {
- return isResource;
- }
-
- public String getPrefix()
- {
- return prefix;
- }
-
- public MultipartConfig getMultipartConfig()
- {
- return multipartConfig;
- }
-
- @Override
- public @NotNull String getType() {
- return "Servlet";
- }
-
- /**
- * Get the class name of the servlet
- * @param servlet The servlet
- * @return The class name
- */
- public @NotNull String getClassName(@NotNull final Servlet servlet) {
- return servlet.getClass().getName();
- }
-
- @Override
- public boolean isSame(AbstractInfo<Servlet> other) {
- if (!super.isSame(other)) {
- return false;
- }
- final ServletInfo o = (ServletInfo) other;
- return Objects.equals(this.name, o.name)
- && Arrays.equals(this.patterns, o.patterns)
- && Arrays.equals(this.errorPage, o.errorPage)
- && this.asyncSupported == o.asyncSupported
- && this.isResource == o.isResource
- && Objects.equals(this.multipartConfig, o.multipartConfig)
- && Objects.equals(this.prefix, o.prefix)
- && Objects.equals(this.initParams, o.initParams);
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/WhiteboardServiceInfo.java b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/WhiteboardServiceInfo.java
deleted file mode 100644
index 2da0ac6318..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/WhiteboardServiceInfo.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * 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.runtime;
-
-import java.util.Objects;
-
-import org.apache.felix.http.base.internal.util.InternalIdFactory;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Filter;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.servlet.whiteboard.HttpWhiteboardConstants;
-
-/**
- * Base class for all info objects.
- * Provides support for ranking and ordering of services.
- */
-public abstract class WhiteboardServiceInfo<T> extends AbstractInfo<T>
-{
- /** The context selection. */
- private final String contextSelection;
-
- private final Filter filter;
-
- public WhiteboardServiceInfo(final ServiceReference<T> ref)
- {
- super(ref);
- String sel = getStringProperty(ref, HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT);
- if ( isEmpty(sel) )
- {
- this.contextSelection = "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "="
- + HttpWhiteboardConstants.HTTP_WHITEBOARD_DEFAULT_CONTEXT_NAME + ")";
- }
- else
- {
- this.contextSelection = sel;
- }
- Filter f = null;
- try
- {
- final Bundle bundle = ref.getBundle();
- if ( bundle != null )
- {
- final BundleContext ctx = bundle.getBundleContext();
- if ( ctx != null )
- {
- f = ctx.createFilter(this.contextSelection);
- }
- }
- }
- catch ( final InvalidSyntaxException ise)
- {
- // ignore
- f = null;
- }
- this.filter = f;
- }
-
- public WhiteboardServiceInfo(final int ranking)
- {
- this(ranking, InternalIdFactory.INSTANCE.next());
-
- }
-
- public WhiteboardServiceInfo(final int ranking, final long serviceId)
- {
- super(ranking, serviceId);
- this.contextSelection = null;
- this.filter = null;
- }
-
- @Override
- public boolean isValid()
- {
- return super.isValid() && (this.filter != null || this.getServiceReference() == null);
- }
-
- public String getContextSelection()
- {
- return this.contextSelection;
- }
-
- public Filter getContextSelectionFilter()
- {
- return this.filter;
- }
-
-
- @Override
- public boolean isSame(AbstractInfo<T> other) {
- if (!super.isSame(other)) {
- return false;
- }
- final WhiteboardServiceInfo<T> o = (WhiteboardServiceInfo<T>) other;
- return Objects.equals(this.contextSelection, o.contextSelection);
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/BaseServletDTOBuilder.java b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/BaseServletDTOBuilder.java
deleted file mode 100644
index 3b3e791832..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/BaseServletDTOBuilder.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.runtime.dto;
-
-import org.apache.felix.http.base.internal.handler.ServletHandler;
-import org.apache.felix.http.base.internal.runtime.ServletInfo;
-import org.osgi.service.servlet.runtime.dto.BaseServletDTO;
-
-abstract class BaseServletDTOBuilder
-{
- /**
- * Build a servlet DTO from a servlet info
- * @param info The servlet info
- * @return A servlet DTO
- */
- public static void fill(final BaseServletDTO dto, final ServletHandler handler)
- {
- dto.name = handler.getName();
- if ( handler.getServlet() != null )
- {
- dto.servletInfo = handler.getServlet().getServletInfo();
- }
- dto.servletContextId = handler.getContextServiceId();
- }
-
- /**
- * Build a servlet DTO from a servlet info
- * @param info The servlet info
- * @return A servlet DTO
- */
- public static void fill(final BaseServletDTO dto, final ServletInfo info)
- {
- dto.asyncSupported = info.isAsyncSupported();
- dto.initParams = info.getInitParameters();
- dto.name = info.getName();
- dto.serviceId = info.getServiceId();
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/BuilderConstants.java b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/BuilderConstants.java
deleted file mode 100644
index f6ff2267dd..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/BuilderConstants.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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.runtime.dto;
-
-import static java.util.Arrays.copyOf;
-
-import org.osgi.service.servlet.runtime.dto.ErrorPageDTO;
-import org.osgi.service.servlet.runtime.dto.FailedErrorPageDTO;
-import org.osgi.service.servlet.runtime.dto.FailedFilterDTO;
-import org.osgi.service.servlet.runtime.dto.FailedListenerDTO;
-import org.osgi.service.servlet.runtime.dto.FailedResourceDTO;
-import org.osgi.service.servlet.runtime.dto.FailedServletContextDTO;
-import org.osgi.service.servlet.runtime.dto.FailedServletDTO;
-import org.osgi.service.servlet.runtime.dto.FilterDTO;
-import org.osgi.service.servlet.runtime.dto.ListenerDTO;
-import org.osgi.service.servlet.runtime.dto.ResourceDTO;
-import org.osgi.service.servlet.runtime.dto.ServletContextDTO;
-import org.osgi.service.servlet.runtime.dto.ServletDTO;
-
-public abstract class BuilderConstants
-{
-
- public static final String[] EMPTY_STRING_ARRAY = new String[0];
- public static final long[] EMPTY_LONG_ARRAY = new long[0];
-
- public static final ServletContextDTO[] CONTEXT_DTO_ARRAY = new ServletContextDTO[0];
-
- public static final ServletDTO[] SERVLET_DTO_ARRAY = new ServletDTO[0];
- public static final ResourceDTO[] RESOURCE_DTO_ARRAY = new ResourceDTO[0];
- public static final FilterDTO[] EMPTY_FILTER_DTO_ARRAY = new FilterDTO[0];
- public static final ErrorPageDTO[] ERROR_PAGE_DTO_ARRAY = new ErrorPageDTO[0];
- public static final ListenerDTO[] LISTENER_DTO_ARRAY = new ListenerDTO[0];
-
- public static final FailedServletContextDTO[] CONTEXT_FAILURE_DTO_ARRAY = new FailedServletContextDTO[0];
-
- public static final FailedServletDTO[] SERVLET_FAILURE_DTO_ARRAY = new FailedServletDTO[0];
- public static final FailedFilterDTO[] FILTER_FAILURE_DTO_ARRAY = new FailedFilterDTO[0];
- public static final FailedResourceDTO[] RESOURCE_FAILURE_DTO_ARRAY = new FailedResourceDTO[0];
- public static final FailedErrorPageDTO[] ERROR_PAGE_FAILURE_DTO_ARRAY = new FailedErrorPageDTO[0];
- public static final FailedListenerDTO[] LISTENER_FAILURE_DTO_ARRAY = new FailedListenerDTO[0];
-
- public static <V> V[] copyWithDefault(V[] array, V[] defaultArray)
- {
- return array == null ? defaultArray : copyOf(array, array.length);
- }
-
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ErrorPageDTOBuilder.java b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ErrorPageDTOBuilder.java
deleted file mode 100644
index af4169a6bc..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ErrorPageDTOBuilder.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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.runtime.dto;
-
-import org.apache.felix.http.base.internal.handler.ServletHandler;
-import org.apache.felix.http.base.internal.runtime.ServletInfo;
-import org.osgi.service.servlet.runtime.dto.ErrorPageDTO;
-import org.osgi.service.servlet.runtime.dto.FailedErrorPageDTO;
-
-public final class ErrorPageDTOBuilder extends BaseServletDTOBuilder
-{
- /**
- * Build a servlet DTO from a servlet handler
- * @param handler The servlet handler
- * @param reason If reason is -1, a servlet DTO is created, otherwise a failed servlet DTO is returned
- * @return A servlet DTO
- */
- public static ErrorPageDTO build(final ServletHandler handler, final int reason)
- {
- final ErrorPageDTO dto = build(handler.getServletInfo(), reason != -1);
-
- BaseServletDTOBuilder.fill(dto, handler);
-
- if ( reason != -1 )
- {
- ((FailedErrorPageDTO)dto).failureReason = reason;
- }
-
- return dto;
- }
-
- /**
- * Build a servlet DTO from a servlet info
- * @param info The servlet info
- * @return A servlet DTO
- */
- public static ErrorPageDTO build(final ServletInfo info, final boolean failed)
- {
- final ErrorPageDTO dto = (failed ? new FailedErrorPageDTO() : new ErrorPageDTO());
-
- BaseServletDTOBuilder.fill(dto, info);
-
- dto.errorCodes = BuilderConstants.EMPTY_LONG_ARRAY;
- dto.exceptions = BuilderConstants.EMPTY_STRING_ARRAY;
-
- return dto;
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailedDTOHolder.java b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailedDTOHolder.java
deleted file mode 100644
index edf91414e1..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FailedDTOHolder.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * 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.runtime.dto;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.felix.http.base.internal.logger.SystemLogger;
-import org.apache.felix.http.base.internal.registry.ErrorPageRegistry;
-import org.apache.felix.http.base.internal.runtime.AbstractInfo;
-import org.apache.felix.http.base.internal.runtime.FilterInfo;
-import org.apache.felix.http.base.internal.runtime.ListenerInfo;
-import org.apache.felix.http.base.internal.runtime.PreprocessorInfo;
-import org.apache.felix.http.base.internal.runtime.ResourceInfo;
-import org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo;
-import org.apache.felix.http.base.internal.runtime.ServletInfo;
-import org.osgi.service.servlet.runtime.dto.FailedErrorPageDTO;
-import org.osgi.service.servlet.runtime.dto.FailedFilterDTO;
-import org.osgi.service.servlet.runtime.dto.FailedListenerDTO;
-import org.osgi.service.servlet.runtime.dto.FailedPreprocessorDTO;
-import org.osgi.service.servlet.runtime.dto.FailedResourceDTO;
-import org.osgi.service.servlet.runtime.dto.FailedServletContextDTO;
-import org.osgi.service.servlet.runtime.dto.FailedServletDTO;
-
-public final class FailedDTOHolder
-{
-
- public final List<FailedFilterDTO> failedFilterDTOs = new ArrayList<FailedFilterDTO>();
-
- public final List<FailedListenerDTO> failedListenerDTOs = new ArrayList<FailedListenerDTO>();
-
- public final List<FailedServletDTO> failedServletDTOs = new ArrayList<FailedServletDTO>();
-
- public final List<FailedResourceDTO> failedResourceDTOs = new ArrayList<FailedResourceDTO>();
-
- public final List<FailedErrorPageDTO> failedErrorPageDTOs = new ArrayList<FailedErrorPageDTO>();
-
- public final List<FailedServletContextDTO> failedServletContextDTOs = new ArrayList<FailedServletContextDTO>();
-
- public final List<FailedPreprocessorDTO> failedPreprocessorDTOs = new ArrayList<FailedPreprocessorDTO>();
-
- public void add(final AbstractInfo<?> info, final long contextId, final int failureCode)
- {
- if (info instanceof ServletContextHelperInfo)
- {
- final FailedServletContextDTO dto = (FailedServletContextDTO)ServletContextDTOBuilder.build((ServletContextHelperInfo)info, null, failureCode);
- this.failedServletContextDTOs.add(dto);
- }
- else if (info instanceof ServletInfo )
- {
- boolean isError = false;
- if ( ((ServletInfo) info).getErrorPage() != null)
- {
- isError = true;
- final FailedErrorPageDTO dto = (FailedErrorPageDTO)ErrorPageDTOBuilder.build((ServletInfo)info, true);
- dto.failureReason = failureCode;
- final ErrorPageRegistry.ErrorRegistration reg = ErrorPageRegistry.getErrorRegistration((ServletInfo)info);
- dto.errorCodes = reg.errorCodes;
- dto.exceptions = reg.exceptions;
- dto.servletContextId = contextId;
- this.failedErrorPageDTOs.add(dto);
- }
-
- if ( ((ServletInfo) info).getPatterns() != null || ((ServletInfo)info).getName() != null || !isError )
- {
- final FailedServletDTO dto = (FailedServletDTO)ServletDTOBuilder.build((ServletInfo) info, failureCode);
- if ( ((ServletInfo) info).getPatterns() != null )
- {
- dto.patterns = ((ServletInfo) info).getPatterns();
- }
- else
- {
- dto.patterns = BuilderConstants.EMPTY_STRING_ARRAY;
- }
- dto.name = ((ServletInfo)info).getName();
- dto.servletContextId = contextId;
- this.failedServletDTOs.add(dto);
- }
- }
- else if (info instanceof FilterInfo)
- {
- final FailedFilterDTO dto = (FailedFilterDTO)FilterDTOBuilder.build((FilterInfo) info, failureCode);
- dto.failureReason = failureCode;
-
- dto.servletContextId = contextId;
- this.failedFilterDTOs.add(dto);
- }
- else if (info instanceof ResourceInfo)
- {
- final FailedResourceDTO dto = (FailedResourceDTO)ResourceDTOBuilder.build((ResourceInfo) info, true);
- dto.failureReason = failureCode;
- dto.servletContextId = contextId;
- this.failedResourceDTOs.add(dto);
- }
- else if (info instanceof ListenerInfo)
- {
- final FailedListenerDTO dto = (FailedListenerDTO)ListenerDTOBuilder.build((ListenerInfo)info, failureCode);
- dto.servletContextId = contextId;
- this.failedListenerDTOs.add(dto);
- }
- else if ( info instanceof PreprocessorInfo )
- {
- final FailedPreprocessorDTO dto = (FailedPreprocessorDTO)PreprocessorDTOBuilder.build((PreprocessorInfo) info, failureCode);
- this.failedPreprocessorDTOs.add(dto);
- }
- else
- {
- SystemLogger.LOGGER.error("Unsupported info type: {}", info.getClass());
- }
- }
-}
-
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FilterDTOBuilder.java b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FilterDTOBuilder.java
deleted file mode 100644
index 528dcefcd4..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/FilterDTOBuilder.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * 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.runtime.dto;
-
-import org.jetbrains.annotations.NotNull;
-import jakarta.servlet.DispatcherType;
-
-import org.apache.felix.http.base.internal.handler.FilterHandler;
-import org.apache.felix.http.base.internal.runtime.FilterInfo;
-import org.osgi.service.servlet.runtime.dto.FailedFilterDTO;
-import org.osgi.service.servlet.runtime.dto.FilterDTO;
-
-public final class FilterDTOBuilder
-{
- /**
- * Build an array of filter DTOs from a filter handler array
- * @param handlers The filter handler array
- * @return The filter DTO array
- */
- public static @NotNull FilterDTO[] build(@NotNull final FilterHandler[] handlers)
- {
- if ( handlers.length == 0 )
- {
- return BuilderConstants.EMPTY_FILTER_DTO_ARRAY;
- }
- final FilterDTO[] array = new FilterDTO[handlers.length];
- for(int i=0; i<handlers.length; i++)
- {
- array[i] = build(handlers[i], -1);
- }
-
- return array;
- }
-
- /**
- * Build a filter DTO from a filter handler
- * @param handler The filter handler
- * @return A filter DTO
- */
- public static @NotNull FilterDTO build(@NotNull final FilterHandler handler, final int reason)
- {
- final FilterDTO filterDTO = build(handler.getFilterInfo(), reason);
-
- filterDTO.name = handler.getName();
- filterDTO.servletContextId = handler.getContextServiceId();
-
- return filterDTO;
- }
-
- /**
- * Build a filter DTO from a filter info
- * @param info The filter info
- * @return A filter DTO
- */
- public static @NotNull FilterDTO build(@NotNull final FilterInfo info, final int reason)
- {
- final FilterDTO filterDTO = (reason != -1 ? new FailedFilterDTO() : new FilterDTO());
-
- filterDTO.asyncSupported = info.isAsyncSupported();
- filterDTO.dispatcher = getNames(info.getDispatcher());
- filterDTO.initParams = info.getInitParameters();
- filterDTO.name = info.getName();
- filterDTO.patterns = BuilderConstants.copyWithDefault(info.getPatterns(), BuilderConstants.EMPTY_STRING_ARRAY);
- filterDTO.regexs = BuilderConstants.copyWithDefault(info.getRegexs(), BuilderConstants.EMPTY_STRING_ARRAY);
- filterDTO.serviceId = info.getServiceId();
- filterDTO.servletNames = BuilderConstants.copyWithDefault(info.getServletNames(), BuilderConstants.EMPTY_STRING_ARRAY);
-
- if ( reason != -1 )
- {
- ((FailedFilterDTO)filterDTO).failureReason = reason;
- }
-
- return filterDTO;
- }
-
- private static @NotNull String[] getNames(@NotNull final DispatcherType[] dispatcher)
- {
- final String[] names = new String[dispatcher.length];
- for (int i = 0; i < dispatcher.length; i++)
- {
- names[i] = dispatcher[i].name();
- }
- return names;
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ListenerDTOBuilder.java b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ListenerDTOBuilder.java
deleted file mode 100644
index 2ecfd91e4d..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ListenerDTOBuilder.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.runtime.dto;
-
-import java.util.Arrays;
-
-import org.apache.felix.http.base.internal.handler.ListenerHandler;
-import org.apache.felix.http.base.internal.runtime.ListenerInfo;
-import org.osgi.service.servlet.runtime.dto.FailedListenerDTO;
-import org.osgi.service.servlet.runtime.dto.ListenerDTO;
-
-public final class ListenerDTOBuilder
-{
- public static ListenerDTO build(final ListenerInfo info, final int reason)
- {
- final ListenerDTO dto = (reason == -1 ? new ListenerDTO() : new FailedListenerDTO());
-
- dto.serviceId = info.getServiceId();
- dto.types = Arrays.copyOf(info.getDTOListenerTypes(), info.getDTOListenerTypes().length);
-
- if ( reason != -1 )
- {
- ((FailedListenerDTO)dto).failureReason = reason;
- }
-
- return dto;
- }
-
- public static ListenerDTO build(final ListenerHandler handler, final int reason)
- {
- final ListenerDTO dto = build(handler.getListenerInfo(), reason);
- dto.servletContextId = handler.getContextServiceId();
- return dto;
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/PreprocessorDTOBuilder.java b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/PreprocessorDTOBuilder.java
deleted file mode 100644
index 2964719a9c..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/PreprocessorDTOBuilder.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.runtime.dto;
-
-import org.jetbrains.annotations.NotNull;
-
-import org.apache.felix.http.base.internal.runtime.PreprocessorInfo;
-import org.osgi.service.servlet.runtime.dto.FailedPreprocessorDTO;
-import org.osgi.service.servlet.runtime.dto.PreprocessorDTO;
-
-public final class PreprocessorDTOBuilder
-{
-
- /**
- * Build a preprocessor DTO from a filter info
- * @param info The preprocessor info
- * @return A preprocessor DTO
- */
- public static @NotNull PreprocessorDTO build(@NotNull final PreprocessorInfo info, final int reason)
- {
- final PreprocessorDTO dto = (reason != -1 ? new FailedPreprocessorDTO() : new PreprocessorDTO());
-
- dto.initParams = info.getInitParameters();
- dto.serviceId = info.getServiceId();
-
- if ( reason != -1 )
- {
- ((FailedPreprocessorDTO)dto).failureReason = reason;
- }
-
- return dto;
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RegistryRuntime.java b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RegistryRuntime.java
deleted file mode 100644
index 9b1b96a342..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RegistryRuntime.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.runtime.dto;
-
-import java.util.Collection;
-
-import org.osgi.service.servlet.runtime.dto.PreprocessorDTO;
-import org.osgi.service.servlet.runtime.dto.ServletContextDTO;
-
-public final class RegistryRuntime
-{
- private final Collection<ServletContextDTO> contextDTOs;
- private final FailedDTOHolder failedDTOHolder;
- private final Collection<PreprocessorDTO> preprocessorDTOs;
-
- public RegistryRuntime(final FailedDTOHolder failedDTOHolder,
- final Collection<ServletContextDTO> contextDTOs,
- final Collection<PreprocessorDTO> preprocessorDTOs)
- {
- this.failedDTOHolder = failedDTOHolder;
- this.contextDTOs = contextDTOs;
- this.preprocessorDTOs = preprocessorDTOs;
- }
-
- public FailedDTOHolder getFailedDTOHolder()
- {
- return this.failedDTOHolder;
- }
-
- public Collection<ServletContextDTO> getServletContextDTOs()
- {
- return this.contextDTOs;
- }
-
- public Collection<PreprocessorDTO> getPreprocessorDTOs()
- {
- return this.preprocessorDTOs;
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RequestInfoDTOBuilder.java b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RequestInfoDTOBuilder.java
deleted file mode 100644
index b3d85eb4a5..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/RequestInfoDTOBuilder.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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.runtime.dto;
-
-import jakarta.servlet.DispatcherType;
-
-import org.apache.felix.http.base.internal.handler.FilterHandler;
-import org.apache.felix.http.base.internal.registry.HandlerRegistry;
-import org.apache.felix.http.base.internal.registry.PathResolution;
-import org.osgi.service.servlet.runtime.dto.FilterDTO;
-import org.osgi.service.servlet.runtime.dto.RequestInfoDTO;
-
-public final class RequestInfoDTOBuilder
-{
- private static final FilterDTO[] FILTER_DTO_ARRAY = new FilterDTO[0];
-
- private final HandlerRegistry registry;
- private final String path;
-
- public RequestInfoDTOBuilder(final HandlerRegistry registry, final String path)
- {
- this.registry = registry;
- this.path = path;
- }
-
- public RequestInfoDTO build()
- {
- final RequestInfoDTO requestInfoDTO = new RequestInfoDTO();
- requestInfoDTO.path = path;
-
- final PathResolution pr = registry.resolveServlet(path);
- if ( pr == null )
- {
- // no servlet found, return empty DTO
- requestInfoDTO.filterDTOs = FILTER_DTO_ARRAY;
- return requestInfoDTO;
- }
- requestInfoDTO.servletContextId = pr.handler.getContextServiceId();
- if (pr.handler.getServletInfo().isResource())
- {
- requestInfoDTO.resourceDTO = ResourceDTOBuilder.build(pr.handler, -1);
- requestInfoDTO.resourceDTO.patterns = pr.patterns;
- }
- else
- {
- requestInfoDTO.servletDTO = ServletDTOBuilder.build(pr.handler, -1);
- requestInfoDTO.servletDTO.patterns = pr.patterns;
- }
-
- final FilterHandler[] filterHandlers = registry.getFilters(pr, DispatcherType.REQUEST, path);
- requestInfoDTO.filterDTOs = FilterDTOBuilder.build(filterHandlers);
-
- return requestInfoDTO;
- }
-}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ResourceDTOBuilder.java b/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ResourceDTOBuilder.java
deleted file mode 100644
index 579f3baf05..0000000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/runtime/dto/ResourceDTOBuilder.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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.runtime.dto;
-
-import org.apache.felix.http.base.internal.handler.ServletHandler;
-import org.apache.felix.http.base.internal.runtime.ResourceInfo;
-import org.apache.felix.http.base.internal.runtime.ServletInfo;
-import org.osgi.service.servlet.runtime.dto.FailedResourceDTO;
-import org.osgi.service.servlet.runtime.dto.ResourceDTO;
-
-public final class ResourceDTOBuilder
-{
- /**
- * Build a servlet DTO from a servlet handler
- * @param handler The servlet handler
- * @param reason If reason is -1, a servlet DTO is created, otherwise a failed servlet DTO is returned
- * @return A servlet DTO
- */
- public static ResourceDTO build(final ServletHandler handler, final int reason)
- {
- final ResourceDTO dto = build(handler.getServletInfo(), reason != -1);
-
- dto.servletContextId = handler.getContextServiceId();
-
- if ( reason != -1 )
- {
- ((FailedResourceDTO)dto).failureReason = reason;
- }
-
- return dto;
- }
-
- /**
- * Build a servlet DTO from a servlet info
- * @param info The servlet info
- * @return A servlet DTO
- */
- public static ResourceDTO build(final ServletInfo info, final boolean failed)
- {
- final ResourceDTO dto = (failed ? new FailedResourceDTO() : new ResourceDTO());
-
- dto.patterns = BuilderConstants.EMPTY_STRING_ARRAY;
- dto.prefix = info.getPrefix();
- dto.serviceId = info.getServiceId();
-
- return dto;
- }
-
- /**
- * Build a servlet DTO from a servlet info
- * @param info The servlet info
- * @return A servlet DTO
- */
... 8816 lines suppressed ...