This is an automated email from the ASF dual-hosted git repository.
jbonofre pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karaf.git
The following commit(s) were added to refs/heads/main by this push:
new d08d2390c feat(#562): Re-add OsgiServletRegisterer to camel-servlet
module (#685)
d08d2390c is described below
commit d08d2390c1ebea85514d3e0ecc2aec0cc8a642dd
Author: JB Onofré <[email protected]>
AuthorDate: Fri Mar 13 09:07:10 2026 +0100
feat(#562): Re-add OsgiServletRegisterer to camel-servlet module (#685)
* feat(#562): Re-add OsgiServletRegisterer to camel-servlet module
Restore the OsgiServletRegisterer class that was removed during the Camel
4.x
refactoring. Updated to use javax.servlet.Servlet interface to match the
OSGi
CMPN 7 HttpService API and the 2-arg StringHelper.notEmpty() form for Camel
4.x
compatibility.
* fix(#562): Mark io.quarkus.arc import as optional in camel-servlet
The upstream camel-servlet JAR references io.quarkus.arc which the BND
analyzer adds as a mandatory OSGi import. Since Quarkus Arc is not
available in Karaf, this causes feature resolution failure.
* fix(#562): Mark javax.servlet and org.osgi.service.http imports as
optional in camel-servlet
These packages are provided by pax-web at runtime but are not available
during karaf-maven-plugin feature verification, causing CI failure.
---
components/camel-servlet/pom.xml | 20 ++++
.../servlet/osgi/OsgiServletRegisterer.java | 109 +++++++++++++++++++++
2 files changed, 129 insertions(+)
diff --git a/components/camel-servlet/pom.xml b/components/camel-servlet/pom.xml
index cc30c3965..4488752cc 100644
--- a/components/camel-servlet/pom.xml
+++ b/components/camel-servlet/pom.xml
@@ -37,6 +37,9 @@
org.apache.camel*;version=${camel-version}
</camel.osgi.export>
<camel.osgi.import>
+ io.quarkus.arc;resolution:=optional,
+ javax.servlet*;resolution:=optional,
+ org.osgi.service.http*;resolution:=optional,
*
</camel.osgi.import>
</properties>
@@ -53,6 +56,23 @@
</exclusion>
</exclusions>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-util</artifactId>
+ <version>${camel-version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <version>4.0.1</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>osgi.cmpn</artifactId>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
<build>
diff --git
a/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/osgi/OsgiServletRegisterer.java
b/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/osgi/OsgiServletRegisterer.java
new file mode 100644
index 000000000..6dbf0b767
--- /dev/null
+++
b/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/osgi/OsgiServletRegisterer.java
@@ -0,0 +1,109 @@
+/*
+ * 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.camel.component.servlet.osgi;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import javax.servlet.Servlet;
+
+import org.apache.camel.util.StringHelper;
+import org.osgi.service.http.HttpContext;
+import org.osgi.service.http.HttpService;
+
+/**
+ * Register the given (CamelHttpTransport) Servlet with the OSGI
+ * <a
href="http://www.osgi.org/javadoc/r4v42/org/osgi/service/http/HttpService.html">
+ * HttpService</a>
+ */
+public class OsgiServletRegisterer {
+
+ /**
+ * The alias is the name in the URI namespace of the Http Service at which
the registration will be mapped.
+ * An alias must begin with slash ('/') and must not end with slash ('/'),
with the exception that an alias
+ * of the form "/" is used to denote the root alias.
+ */
+ private String alias;
+
+ /**
+ * The servlet name.
+ */
+ private String servletName = "CamelServlet";
+
+ /**
+ * Servlet to be registered.
+ */
+ private Servlet servlet;
+
+ /**
+ * HttpService to register with. Get this with osgi:reference in the
blueprint file.
+ */
+ private HttpService httpService;
+
+ private HttpContext httpContext;
+
+ private boolean alreadyRegistered;
+
+ // The servlet will default have to match on uri prefix as some endpoints
may do so
+ private volatile boolean matchOnUriPrefix = true;
+
+ public void setHttpService(HttpService httpService) {
+ this.httpService = httpService;
+ }
+
+ public void setAlias(String alias) {
+ this.alias = alias;
+ }
+
+ public void setServletName(String servletName) {
+ this.servletName = servletName;
+ }
+
+ public void setServlet(Servlet servlet) {
+ this.servlet = servlet;
+ }
+
+ public void setHttpContext(HttpContext httpContext) {
+ this.httpContext = httpContext;
+ }
+
+ public void setMatchOnUriPrefix(boolean matchOnUriPrefix) {
+ this.matchOnUriPrefix = matchOnUriPrefix;
+ }
+
+ public void register() throws Exception {
+ StringHelper.notEmpty(alias, "alias");
+ StringHelper.notEmpty(servletName, "servletName");
+
+ HttpContext actualHttpContext = (httpContext == null)
+ ? httpService.createDefaultHttpContext()
+ : httpContext;
+ final Dictionary<String, String> initParams = new Hashtable<>();
+ initParams.put("matchOnUriPrefix", matchOnUriPrefix ? "true" :
"false");
+ initParams.put("servlet-name", servletName);
+ httpService.registerServlet(alias, servlet, initParams,
actualHttpContext);
+ alreadyRegistered = true;
+ }
+
+ public void unregister() {
+ if (alreadyRegistered) {
+ httpService.unregister(alias);
+ alreadyRegistered = false;
+ }
+ }
+
+}