You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by ro...@apache.org on 2026/02/14 19:27:13 UTC

(axis-axis2-java-core) branch master updated (90764ed878 -> a003d3c467)

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

robertlazarski pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/axis-axis2-java-core.git


    from 90764ed878 Document custom HTTP response status codes in http-transport guide
     new f5227f9034 Fix AXIS2-6053: Add diagnostic hints for unresolved attribute ref= in schema validation
     new 0e7464a23b Add integration test for AXIS2-6053 diagnostic hint through invoke() flow
     new a003d3c467 Clarify AXIS2-6053 diagnostic hint to indicate it is one possible cause

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 modules/schema-validation/pom.xml                  |  10 ++
 .../validation/SchemaFactoryErrorHandler.java      |   2 +-
 .../axis2/validation/SchemaValidationHandler.java  |  19 ++-
 .../validation/SchemaValidationHandlerTest.java    | 134 +++++++++++++++++++++
 4 files changed, 162 insertions(+), 3 deletions(-)
 create mode 100644 modules/schema-validation/src/test/java/org/apache/axis2/validation/SchemaValidationHandlerTest.java


(axis-axis2-java-core) 01/03: Fix AXIS2-6053: Add diagnostic hints for unresolved attribute ref= in schema validation

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

robertlazarski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/axis-axis2-java-core.git

commit f5227f90345404cd889957f403ec2badf079f9c1
Author: Robert Lazarski <ro...@gmail.com>
AuthorDate: Sat Feb 14 09:04:00 2026 -1000

    Fix AXIS2-6053: Add diagnostic hints for unresolved attribute ref= in schema validation
    
    When a schema uses xs:attribute ref= to reference an attribute from an
    external namespace (e.g., xmime:contentType) and the referenced schema
    cannot be resolved, the validator produces a cryptic cvc-complex-type.3.2.2
    error. This change detects that error code and appends an actionable hint
    explaining the likely cause and remediation.
    
    Also improves SchemaFactoryErrorHandler to log warnings with full exception
    context, making unresolvable import warnings visible for diagnosis.
    
    Co-Authored-By: Claude Opus 4.6 <no...@anthropic.com>
---
 modules/schema-validation/pom.xml                  | 10 +++++
 .../validation/SchemaFactoryErrorHandler.java      |  2 +-
 .../axis2/validation/SchemaValidationHandler.java  | 18 +++++++-
 .../validation/SchemaValidationHandlerTest.java    | 51 ++++++++++++++++++++++
 4 files changed, 78 insertions(+), 3 deletions(-)

diff --git a/modules/schema-validation/pom.xml b/modules/schema-validation/pom.xml
index e2d8695426..c8308645dd 100644
--- a/modules/schema-validation/pom.xml
+++ b/modules/schema-validation/pom.xml
@@ -49,6 +49,16 @@
             <artifactId>axis2-kernel</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/modules/schema-validation/src/main/java/org/apache/axis2/validation/SchemaFactoryErrorHandler.java b/modules/schema-validation/src/main/java/org/apache/axis2/validation/SchemaFactoryErrorHandler.java
index b4605f5243..0c451c3c0c 100644
--- a/modules/schema-validation/src/main/java/org/apache/axis2/validation/SchemaFactoryErrorHandler.java
+++ b/modules/schema-validation/src/main/java/org/apache/axis2/validation/SchemaFactoryErrorHandler.java
@@ -29,7 +29,7 @@ final class SchemaFactoryErrorHandler implements ErrorHandler {
 
     @Override
     public void warning(SAXParseException exception) throws SAXException {
-        log.warn(exception.getMessage());
+        log.warn("Schema compilation warning: " + exception.getMessage(), exception);
     }
 
     @Override
diff --git a/modules/schema-validation/src/main/java/org/apache/axis2/validation/SchemaValidationHandler.java b/modules/schema-validation/src/main/java/org/apache/axis2/validation/SchemaValidationHandler.java
index 11619820d4..89add55110 100644
--- a/modules/schema-validation/src/main/java/org/apache/axis2/validation/SchemaValidationHandler.java
+++ b/modules/schema-validation/src/main/java/org/apache/axis2/validation/SchemaValidationHandler.java
@@ -71,15 +71,29 @@ public class SchemaValidationHandler extends AbstractHandler {
         try {
             schema = schemaFactory.newSchema(schemaSources.toArray(new Source[schemaSources.size()]));
         } catch (SAXException ex) {
-            throw new AxisFault("Failed to compile schemas", ex);
+            throw new AxisFault("Failed to compile schemas: " + ex.getMessage()
+                    + appendRefHint(ex), ex);
         }
         try {
             schema.newValidator().validate(msgContext.getEnvelope().getBody().getFirstElement().getSAXSource(true));
         } catch (SAXException ex) {
-            throw new AxisFault("Failed to validate message: " + ex.getMessage(), ex);
+            throw new AxisFault("Failed to validate message: " + ex.getMessage()
+                    + appendRefHint(ex), ex);
         } catch (OMException | IOException ex) {
             throw new AxisFault("Failed to validate message", ex);
         }
         return InvocationResponse.CONTINUE;
     }
+
+    static String appendRefHint(SAXException ex) {
+        String msg = ex.getMessage();
+        if (msg != null && msg.contains("cvc-complex-type.3.2.2")) {
+            return ". This may be caused by a schema using xs:attribute ref= to reference"
+                    + " an attribute from an external namespace (e.g., xmime:contentType)"
+                    + " whose schema was not imported or could not be resolved."
+                    + " Consider defining the attribute inline instead of using ref=,"
+                    + " or ensure the referenced schema is accessible.";
+        }
+        return "";
+    }
 }
diff --git a/modules/schema-validation/src/test/java/org/apache/axis2/validation/SchemaValidationHandlerTest.java b/modules/schema-validation/src/test/java/org/apache/axis2/validation/SchemaValidationHandlerTest.java
new file mode 100644
index 0000000000..7cdbadc4b9
--- /dev/null
+++ b/modules/schema-validation/src/test/java/org/apache/axis2/validation/SchemaValidationHandlerTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.axis2.validation;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.jupiter.api.Test;
+import org.xml.sax.SAXException;
+
+public class SchemaValidationHandlerTest {
+
+    @Test
+    public void testAppendRefHintForCvcComplexType322() {
+        SAXException ex = new SAXException(
+                "cvc-complex-type.3.2.2: Attribute 'contentType' is not allowed to appear in element 'foo'");
+        String hint = SchemaValidationHandler.appendRefHint(ex);
+        assertThat(hint).contains("xs:attribute ref=");
+        assertThat(hint).contains("xmime:contentType");
+        assertThat(hint).contains("not imported or could not be resolved");
+    }
+
+    @Test
+    public void testAppendRefHintReturnsEmptyForOtherErrors() {
+        SAXException ex = new SAXException("cvc-type.3.1.3: some other validation error");
+        String hint = SchemaValidationHandler.appendRefHint(ex);
+        assertThat(hint).isEmpty();
+    }
+
+    @Test
+    public void testAppendRefHintHandlesNullMessage() {
+        SAXException ex = new SAXException((String) null);
+        String hint = SchemaValidationHandler.appendRefHint(ex);
+        assertThat(hint).isEmpty();
+    }
+}


(axis-axis2-java-core) 02/03: Add integration test for AXIS2-6053 diagnostic hint through invoke() flow

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

robertlazarski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/axis-axis2-java-core.git

commit 0e7464a23bba7c60ede6493730c1052873106a25
Author: Robert Lazarski <ro...@gmail.com>
AuthorDate: Sat Feb 14 09:11:06 2026 -1000

    Add integration test for AXIS2-6053 diagnostic hint through invoke() flow
    
    Exercises the full SchemaValidationHandler.invoke() path with a SOAP
    message containing an undeclared xmime:contentType attribute, triggering
    a cvc-complex-type.3.2.2 validation error, and verifies the resulting
    AxisFault includes the diagnostic hint about unresolved ref= attributes.
    
    Co-Authored-By: Claude Opus 4.6 <no...@anthropic.com>
---
 .../validation/SchemaValidationHandlerTest.java    | 83 ++++++++++++++++++++++
 1 file changed, 83 insertions(+)

diff --git a/modules/schema-validation/src/test/java/org/apache/axis2/validation/SchemaValidationHandlerTest.java b/modules/schema-validation/src/test/java/org/apache/axis2/validation/SchemaValidationHandlerTest.java
index 7cdbadc4b9..66314005fa 100644
--- a/modules/schema-validation/src/test/java/org/apache/axis2/validation/SchemaValidationHandlerTest.java
+++ b/modules/schema-validation/src/test/java/org/apache/axis2/validation/SchemaValidationHandlerTest.java
@@ -19,7 +19,26 @@
 package org.apache.axis2.validation;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
+import java.io.ByteArrayInputStream;
+import java.nio.charset.StandardCharsets;
+
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.soap.SOAPBody;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
 import org.junit.jupiter.api.Test;
 import org.xml.sax.SAXException;
 
@@ -48,4 +67,68 @@ public class SchemaValidationHandlerTest {
         String hint = SchemaValidationHandler.appendRefHint(ex);
         assertThat(hint).isEmpty();
     }
+
+    /**
+     * Integration test: invoke the handler with a SOAP message containing an
+     * attribute not declared in the schema, triggering cvc-complex-type.3.2.2,
+     * and verify the AxisFault message includes the diagnostic ref= hint.
+     */
+    @Test
+    public void testInvokeProducesRefHintForUnexpectedAttribute() throws Exception {
+        // Schema that defines <note> with child elements only — no attributes allowed
+        String xsd =
+                "<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'"
+                + " targetNamespace='http://example.com/test'"
+                + " xmlns:tns='http://example.com/test'"
+                + " elementFormDefault='qualified'>"
+                + "  <xs:element name='note'>"
+                + "    <xs:complexType>"
+                + "      <xs:sequence>"
+                + "        <xs:element name='to' type='xs:string'/>"
+                + "      </xs:sequence>"
+                + "    </xs:complexType>"
+                + "  </xs:element>"
+                + "</xs:schema>";
+
+        XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+        XmlSchema schema = schemaCol.read(new StreamSource(
+                new ByteArrayInputStream(xsd.getBytes(StandardCharsets.UTF_8))));
+
+        // AxisService with the schema
+        AxisService service = new AxisService("TestService");
+        service.addSchema(schema);
+
+        // MessageContext
+        ConfigurationContext configCtx = new ConfigurationContext(new AxisConfiguration());
+        MessageContext msgCtx = configCtx.createMessageContext();
+        msgCtx.setAxisService(service);
+
+        // SOAP envelope whose body element has an attribute the schema doesn't allow
+        SOAPFactory sf = OMAbstractFactory.getSOAP11Factory();
+        SOAPEnvelope envelope = sf.createSOAPEnvelope();
+        SOAPBody body = sf.createSOAPBody(envelope);
+
+        OMNamespace tns = sf.createOMNamespace("http://example.com/test", "tns");
+        OMElement note = sf.createOMElement("note", tns);
+
+        // Add the required child so the only error is the unexpected attribute
+        OMElement to = sf.createOMElement("to", tns);
+        to.setText("Alice");
+        note.addChild(to);
+
+        // Add an attribute that the schema does not declare — triggers cvc-complex-type.3.2.2
+        OMNamespace xmimeNs = sf.createOMNamespace("http://www.w3.org/2005/05/xmlmime", "xmime");
+        note.addAttribute("contentType", "text/xml", xmimeNs);
+
+        body.addChild(note);
+        msgCtx.setEnvelope(envelope);
+
+        // Invoke the handler and assert the AxisFault contains the hint
+        SchemaValidationHandler handler = new SchemaValidationHandler();
+        assertThatThrownBy(() -> handler.invoke(msgCtx))
+                .isInstanceOf(AxisFault.class)
+                .hasMessageContaining("cvc-complex-type.3.2.2")
+                .hasMessageContaining("xs:attribute ref=")
+                .hasMessageContaining("not imported or could not be resolved");
+    }
 }


(axis-axis2-java-core) 03/03: Clarify AXIS2-6053 diagnostic hint to indicate it is one possible cause

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

robertlazarski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/axis-axis2-java-core.git

commit a003d3c467d5ab98b7e157530f2977526e566569
Author: Robert Lazarski <ro...@gmail.com>
AuthorDate: Sat Feb 14 09:20:22 2026 -1000

    Clarify AXIS2-6053 diagnostic hint to indicate it is one possible cause
    
    Reword the hint to say "if this attribute is expected to be valid, one
    common cause is..." rather than "This may be caused by...", making it
    clear the hint is advisory and only relevant when the attribute should
    have been allowed by the schema.
    
    Co-Authored-By: Claude Opus 4.6 <no...@anthropic.com>
---
 .../java/org/apache/axis2/validation/SchemaValidationHandler.java  | 7 ++++---
 .../org/apache/axis2/validation/SchemaValidationHandlerTest.java   | 6 +++---
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/modules/schema-validation/src/main/java/org/apache/axis2/validation/SchemaValidationHandler.java b/modules/schema-validation/src/main/java/org/apache/axis2/validation/SchemaValidationHandler.java
index 89add55110..b1383f9fbc 100644
--- a/modules/schema-validation/src/main/java/org/apache/axis2/validation/SchemaValidationHandler.java
+++ b/modules/schema-validation/src/main/java/org/apache/axis2/validation/SchemaValidationHandler.java
@@ -88,11 +88,12 @@ public class SchemaValidationHandler extends AbstractHandler {
     static String appendRefHint(SAXException ex) {
         String msg = ex.getMessage();
         if (msg != null && msg.contains("cvc-complex-type.3.2.2")) {
-            return ". This may be caused by a schema using xs:attribute ref= to reference"
+            return ". Note: if this attribute is expected to be valid,"
+                    + " one common cause is a schema using xs:attribute ref= to reference"
                     + " an attribute from an external namespace (e.g., xmime:contentType)"
                     + " whose schema was not imported or could not be resolved."
-                    + " Consider defining the attribute inline instead of using ref=,"
-                    + " or ensure the referenced schema is accessible.";
+                    + " In that case, ensure the referenced schema is accessible"
+                    + " or define the attribute inline instead of using ref=.";
         }
         return "";
     }
diff --git a/modules/schema-validation/src/test/java/org/apache/axis2/validation/SchemaValidationHandlerTest.java b/modules/schema-validation/src/test/java/org/apache/axis2/validation/SchemaValidationHandlerTest.java
index 66314005fa..f7e320cea2 100644
--- a/modules/schema-validation/src/test/java/org/apache/axis2/validation/SchemaValidationHandlerTest.java
+++ b/modules/schema-validation/src/test/java/org/apache/axis2/validation/SchemaValidationHandlerTest.java
@@ -49,8 +49,8 @@ public class SchemaValidationHandlerTest {
         SAXException ex = new SAXException(
                 "cvc-complex-type.3.2.2: Attribute 'contentType' is not allowed to appear in element 'foo'");
         String hint = SchemaValidationHandler.appendRefHint(ex);
+        assertThat(hint).contains("if this attribute is expected to be valid");
         assertThat(hint).contains("xs:attribute ref=");
-        assertThat(hint).contains("xmime:contentType");
         assertThat(hint).contains("not imported or could not be resolved");
     }
 
@@ -128,7 +128,7 @@ public class SchemaValidationHandlerTest {
         assertThatThrownBy(() -> handler.invoke(msgCtx))
                 .isInstanceOf(AxisFault.class)
                 .hasMessageContaining("cvc-complex-type.3.2.2")
-                .hasMessageContaining("xs:attribute ref=")
-                .hasMessageContaining("not imported or could not be resolved");
+                .hasMessageContaining("if this attribute is expected to be valid")
+                .hasMessageContaining("xs:attribute ref=");
     }
 }