This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 97ce4d9558 Refactor to support TCK tests adding custom transformations
97ce4d9558 is described below

commit 97ce4d9558a6faa9224d91ddd899136248ccffb4
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Jul 24 17:41:57 2025 +0100

    Refactor to support TCK tests adding custom transformations
    
    The client filtering of extensions has a bug. Once that is fixed, some
    TCK tests will fail because they expect they client to request a number
    of TCK specific extensions. To support that, the TCK client needs to be
    able to define those extensions. This refactoring will allow that to
    happen. The bug will be fixed in a subsequent commit.
---
 .../apache/tomcat/websocket/PerMessageDeflate.java |  7 ++++++
 .../tomcat/websocket/TransformationBuilder.java    | 26 ++++++++++++++++++++++
 .../tomcat/websocket/TransformationFactory.java    | 20 +++++++++++++++--
 3 files changed, 51 insertions(+), 2 deletions(-)

diff --git a/java/org/apache/tomcat/websocket/PerMessageDeflate.java 
b/java/org/apache/tomcat/websocket/PerMessageDeflate.java
index 2b05a7219f..08c1146cc3 100644
--- a/java/org/apache/tomcat/websocket/PerMessageDeflate.java
+++ b/java/org/apache/tomcat/websocket/PerMessageDeflate.java
@@ -44,6 +44,13 @@ public class PerMessageDeflate implements Transformation {
 
     public static final String NAME = "permessage-deflate";
 
+    public static final TransformationBuilder BUILDER = new 
TransformationBuilder() {
+        @Override
+        public Transformation build(List<List<Parameter>> preferences, boolean 
isServer) {
+            return PerMessageDeflate.build(preferences, isServer);
+        }
+    };
+
     private final boolean serverContextTakeover;
     private final int serverMaxWindowBits;
     private final boolean clientContextTakeover;
diff --git a/java/org/apache/tomcat/websocket/TransformationBuilder.java 
b/java/org/apache/tomcat/websocket/TransformationBuilder.java
new file mode 100644
index 0000000000..3b6f21a859
--- /dev/null
+++ b/java/org/apache/tomcat/websocket/TransformationBuilder.java
@@ -0,0 +1,26 @@
+/*
+ * 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.tomcat.websocket;
+
+import java.util.List;
+
+import jakarta.websocket.Extension;
+
+public interface TransformationBuilder {
+
+    Transformation build(List<List<Extension.Parameter>> preferences, boolean 
isServer);
+}
diff --git a/java/org/apache/tomcat/websocket/TransformationFactory.java 
b/java/org/apache/tomcat/websocket/TransformationFactory.java
index 549b7111a6..6d706541eb 100644
--- a/java/org/apache/tomcat/websocket/TransformationFactory.java
+++ b/java/org/apache/tomcat/websocket/TransformationFactory.java
@@ -16,7 +16,9 @@
  */
 package org.apache.tomcat.websocket;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import javax.websocket.Extension;
 
@@ -28,17 +30,26 @@ public class TransformationFactory {
 
     private static final TransformationFactory factory = new 
TransformationFactory();
 
+    private Map<String,TransformationBuilder> builders = new HashMap<>();
+
+
     private TransformationFactory() {
         // Hide default constructor
+
+        // Configure the built-in transformations
+        builders.put(PerMessageDeflate.NAME, PerMessageDeflate.BUILDER);
     }
 
+
     public static TransformationFactory getInstance() {
         return factory;
     }
 
+
     public Transformation create(String name, List<List<Extension.Parameter>> 
preferences, boolean isServer) {
-        if (PerMessageDeflate.NAME.equals(name)) {
-            return PerMessageDeflate.build(preferences, isServer);
+        TransformationBuilder builder = builders.get(name);
+        if (builder != null) {
+            return builder.build(preferences, isServer);
         }
         if (Constants.ALLOW_UNSUPPORTED_EXTENSIONS) {
             return null;
@@ -46,4 +57,9 @@ public class TransformationFactory {
             throw new 
IllegalArgumentException(sm.getString("transformerFactory.unsupportedExtension",
 name));
         }
     }
+
+
+    public void registerExtension(String name, TransformationBuilder builder) {
+        builders.put(name, builder);
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to