You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2020/12/05 16:25:34 UTC
[cxf] branch 3.3.x-fixes updated: [CXF-8361] Added support for
jakarta NS in AnnotationHandlerChainBuilder (#718)
This is an automated email from the ASF dual-hosted git repository.
reta pushed a commit to branch 3.3.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/3.3.x-fixes by this push:
new 122f14b [CXF-8361] Added support for jakarta NS in AnnotationHandlerChainBuilder (#718)
122f14b is described below
commit 122f14b2896395261be2711556aa976055eb98a3
Author: Richard Opálka <op...@gmail.com>
AuthorDate: Sat Dec 5 17:25:21 2020 +0100
[CXF-8361] Added support for jakarta NS in AnnotationHandlerChainBuilder (#718)
* [CXF-8361] Added support for jakarta NS in AnnotationHandlerChainBuilder
* [CXF-8361] Adding simple test case
---
.../handler/AnnotationHandlerChainBuilder.java | 46 ++++++++++++----
.../apache/cxf/jaxws/handler/Messages.properties | 1 +
.../JakartaAnnotationHandlerChainBuilderTest.java | 61 ++++++++++++++++++++++
...=> JavaxAnnotationHandlerChainBuilderTest.java} | 6 +--
.../apache/cxf/jaxws/handler/jakarta-handlers.xml | 19 +++++++
.../handler/{handlers.xml => javax-handlers.xml} | 18 +++----
6 files changed, 129 insertions(+), 22 deletions(-)
diff --git a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/AnnotationHandlerChainBuilder.java b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/AnnotationHandlerChainBuilder.java
index 5919e96..3a72c06 100644
--- a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/AnnotationHandlerChainBuilder.java
+++ b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/AnnotationHandlerChainBuilder.java
@@ -55,6 +55,10 @@ import org.apache.cxf.staxutils.StaxUtils;
@SuppressWarnings("rawtypes")
public class AnnotationHandlerChainBuilder extends HandlerChainBuilder {
+ private static final String HANDLER_CHAINS_E = "handler-chains";
+ private static final String HANDLER_CHAIN_E = "handler-chain";
+ private static final String JAKARTAEE_NS = "https://jakarta.ee/xml/ns/jakartaee";
+ private static final String JAVAEE_NS = "http://java.sun.com/xml/ns/javaee";
private static final Logger LOG = LogUtils.getL7dLogger(AnnotationHandlerChainBuilder.class);
private static final ResourceBundle BUNDLE = LOG.getResourceBundle();
private static JAXBContext context;
@@ -97,16 +101,30 @@ public class AnnotationHandlerChainBuilder extends HandlerChainBuilder {
Document doc = StaxUtils.read(handlerFileURL.openStream());
Element el = doc.getDocumentElement();
- if (!"http://java.sun.com/xml/ns/javaee".equals(el.getNamespaceURI())
- || !"handler-chains".equals(el.getLocalName())) {
-
+ boolean isJavaEENamespace = JAVAEE_NS.equals(el.getNamespaceURI());
+ boolean isJakartaEENamespace = JAKARTAEE_NS.equals(el.getNamespaceURI());
+ if (!isJavaEENamespace && !isJakartaEENamespace) {
+ throw new WebServiceException(
+ BundleUtils.getFormattedString(BUNDLE,
+ "NOT_VALID_NAMESPACE",
+ el.getNamespaceURI()));
+ }
+ if (isJavaEENamespace && !HANDLER_CHAINS_E.equals(el.getLocalName())) {
+ String xml = StaxUtils.toString(el);
+ throw new WebServiceException(
+ BundleUtils.getFormattedString(BUNDLE,
+ "NOT_VALID_ROOT_ELEMENT",
+ JAVAEE_NS.equals(el.getNamespaceURI()),
+ HANDLER_CHAINS_E.equals(el.getLocalName()),
+ xml, handlerFileURL));
+ }
+ if (isJakartaEENamespace && !HANDLER_CHAINS_E.equals(el.getLocalName())) {
String xml = StaxUtils.toString(el);
throw new WebServiceException(
BundleUtils.getFormattedString(BUNDLE,
"NOT_VALID_ROOT_ELEMENT",
- "http://java.sun.com/xml/ns/javaee"
- .equals(el.getNamespaceURI()),
- "handler-chains".equals(el.getLocalName()),
+ JAKARTAEE_NS.equals(el.getNamespaceURI()),
+ HANDLER_CHAINS_E.equals(el.getLocalName()),
xml, handlerFileURL));
}
chain = new ArrayList<>();
@@ -114,9 +132,15 @@ public class AnnotationHandlerChainBuilder extends HandlerChainBuilder {
while (node != null) {
if (node instanceof Element) {
el = (Element)node;
- if (!"http://java.sun.com/xml/ns/javaee".equals(el.getNamespaceURI())
- || !"handler-chain".equals(el.getLocalName())) {
-
+ isJavaEENamespace = JAVAEE_NS.equals(el.getNamespaceURI());
+ isJakartaEENamespace = JAKARTAEE_NS.equals(el.getNamespaceURI());
+ if (!isJavaEENamespace && !isJakartaEENamespace) {
+ throw new WebServiceException(
+ BundleUtils.getFormattedString(BUNDLE,
+ "NOT_VALID_NAMESPACE",
+ el.getNamespaceURI()));
+ }
+ if (!HANDLER_CHAIN_E.equals(el.getLocalName())) {
String xml = StaxUtils.toString(el);
throw new WebServiceException(
BundleUtils.getFormattedString(BUNDLE,
@@ -161,7 +185,9 @@ public class AnnotationHandlerChainBuilder extends HandlerChainBuilder {
node = node.getNextSibling();
if (cur instanceof Element) {
el = (Element)cur;
- if (!"http://java.sun.com/xml/ns/javaee".equals(el.getNamespaceURI())) {
+ boolean isJavaEENamespace = JAVAEE_NS.equals(el.getNamespaceURI());
+ boolean isJakartaEENamespace = JAKARTAEE_NS.equals(el.getNamespaceURI());
+ if (!isJavaEENamespace && !isJakartaEENamespace) {
String xml = StaxUtils.toString(el);
throw new WebServiceException(
BundleUtils.getFormattedString(BUNDLE,
diff --git a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/Messages.properties b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/Messages.properties
index 9b3eb5c..f4a2727 100644
--- a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/Messages.properties
+++ b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/Messages.properties
@@ -27,6 +27,7 @@ CHAIN_NOT_SPECIFIED_EXC = Chain not specified
SEI_LOAD_FAILURE_EXC = Failed to load service endpoint interface.
NOT_A_QNAME_PATTER = Pattern {0} is not a qname pattern in xml {1}
NOT_VALID_ELEMENT_IN_HANDLER = Element {0} is not allowed in handler chain
+NOT_VALID_NAMESPACE = Namespace {0} is not supported
NOT_VALID_ROOT_ELEMENT = {0} {1} Element {2} is not a valid root element in file {3}
HANDLER_RAISED_RUNTIME_EXCEPTION = Handler execution raised a runtime exception.
NO_INIT_METHOD_ON_HANDLER=Handler of type {0} has no init method but has been configured with init-params.
diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/JakartaAnnotationHandlerChainBuilderTest.java b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/JakartaAnnotationHandlerChainBuilderTest.java
new file mode 100644
index 0000000..f167343
--- /dev/null
+++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/JakartaAnnotationHandlerChainBuilderTest.java
@@ -0,0 +1,61 @@
+/**
+ * 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.cxf.jaxws.handler;
+
+import java.util.List;
+
+import javax.jws.HandlerChain;
+import javax.jws.WebService;
+import javax.xml.ws.handler.Handler;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+
+public class JakartaAnnotationHandlerChainBuilderTest {
+
+ @Before
+ public void setUp() {
+ }
+
+ @Test
+ public void testFindJakartaEmptyHandlerChainAnnotation() {
+ HandlerTestImpl handlerTestImpl = new HandlerTestImpl();
+ AnnotationHandlerChainBuilder chainBuilder = new AnnotationHandlerChainBuilder();
+ @SuppressWarnings("rawtypes")
+ List<Handler> handlers = chainBuilder
+ .buildHandlerChainFromClass(handlerTestImpl.getClass(),
+ null,
+ null,
+ null);
+ assertNotNull(handlers);
+ assertEquals(0, handlers.size());
+ }
+
+ @WebService()
+ @HandlerChain(file = "./jakarta-handlers.xml", name = "TestHandlerChain")
+ public class HandlerTestImpl {
+
+ }
+
+}
diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/AnnotationHandlerChainBuilderTest.java b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/JavaxAnnotationHandlerChainBuilderTest.java
similarity index 97%
rename from rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/AnnotationHandlerChainBuilderTest.java
rename to rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/JavaxAnnotationHandlerChainBuilderTest.java
index 99b32a5..deaf3eb 100644
--- a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/AnnotationHandlerChainBuilderTest.java
+++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/JavaxAnnotationHandlerChainBuilderTest.java
@@ -36,7 +36,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-public class AnnotationHandlerChainBuilderTest {
+public class JavaxAnnotationHandlerChainBuilderTest {
@Before
public void setUp() {
@@ -137,9 +137,9 @@ public class AnnotationHandlerChainBuilderTest {
}
@WebService()
- @HandlerChain(file = "./handlers.xml", name = "TestHandlerChain")
+ @HandlerChain(file = "./javax-handlers.xml", name = "TestHandlerChain")
public class HandlerTestImpl {
}
-}
\ No newline at end of file
+}
diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/jakarta-handlers.xml b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/jakarta-handlers.xml
new file mode 100644
index 0000000..a31f8fe
--- /dev/null
+++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/jakarta-handlers.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+ -->
+<handler-chains xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:cfg="http://cxf.apache.org/configuration/cfg" xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee">
+ <handler-chain />
+</handler-chains>
diff --git a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/handlers.xml b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/javax-handlers.xml
similarity index 78%
rename from rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/handlers.xml
rename to rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/javax-handlers.xml
index 4c8f02e..6327e06 100644
--- a/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/handlers.xml
+++ b/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/handler/javax-handlers.xml
@@ -19,7 +19,7 @@
<handler>
<handler-name>lh3</handler-name>
<handler-class>
- org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilderTest$TestProtocolHandler
+ org.apache.cxf.jaxws.handler.JavaxAnnotationHandlerChainBuilderTest$TestProtocolHandler
</handler-class>
<init-param>
<param-name>token</param-name>
@@ -31,7 +31,7 @@
<handler>
<handler-name>lh1</handler-name>
<handler-class>
- org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilderTest$TestLogicalHandler
+ org.apache.cxf.jaxws.handler.JavaxAnnotationHandlerChainBuilderTest$TestLogicalHandler
</handler-class>
<init-param>
<param-name>token</param-name>
@@ -41,7 +41,7 @@
<handler>
<handler-name>lh2</handler-name>
<handler-class>
- org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilderTest$TestLogicalHandler
+ org.apache.cxf.jaxws.handler.JavaxAnnotationHandlerChainBuilderTest$TestLogicalHandler
</handler-class>
<init-param>
<param-name>token</param-name>
@@ -56,13 +56,13 @@
<handler>
<handler-name>Handler1</handler-name>
<handler-class>
- org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilderTest$TestLogicalHandler
+ org.apache.cxf.jaxws.handler.JavaxAnnotationHandlerChainBuilderTest$TestLogicalHandler
</handler-class>
</handler>
<handler>
<handler-name>Handler2</handler-name>
<handler-class>
- org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilderTest$TestLogicalHandler
+ org.apache.cxf.jaxws.handler.JavaxAnnotationHandlerChainBuilderTest$TestLogicalHandler
</handler-class>
</handler>
</handler-chain>
@@ -73,13 +73,13 @@
<handler>
<handler-name>Handler1</handler-name>
<handler-class>
- org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilderTest$TestLogicalHandler
+ org.apache.cxf.jaxws.handler.JavaxAnnotationHandlerChainBuilderTest$TestLogicalHandler
</handler-class>
</handler>
<handler>
<handler-name>Handler2</handler-name>
<handler-class>
- org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilderTest$TestLogicalHandler
+ org.apache.cxf.jaxws.handler.JavaxAnnotationHandlerChainBuilderTest$TestLogicalHandler
</handler-class>
</handler>
</handler-chain>
@@ -96,13 +96,13 @@
<handler>
<handler-name>Handler7</handler-name>
<handler-class>
- org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilderTest$TestLogicalHandler
+ org.apache.cxf.jaxws.handler.JavaxAnnotationHandlerChainBuilderTest$TestLogicalHandler
</handler-class>
</handler>
<handler>
<handler-name>Handler8</handler-name>
<handler-class>
- org.apache.cxf.jaxws.handler.AnnotationHandlerChainBuilderTest$TestProtocolHandler
+ org.apache.cxf.jaxws.handler.JavaxAnnotationHandlerChainBuilderTest$TestProtocolHandler
</handler-class>
</handler>
</handler-chain>