Thanks for the reply. For the record I confirmed this error happens on
xercesImpl-2.12.2.jar.

While I too am somewhat amazed this cast ever worked, it did actually work
for 10 years starting on this Rampart commit below.

"
commit b73690eefaad9027bb9633a20e29a218a1021cc9 (HEAD -> master)
Author: Amila Jayasekara <ami...@apache.org>
Date:   Thu Mar 8 08:11:32 2012 +0000

   Refactored SAML2TokenIssuer and cleaned up code. Created a test
framework to write unit tests for trust scenarios. Fixed documentation
errors. Reduced code duplication. Added more tests.
"

I see that OMNode at runtime ends up being an Axiom class
DOOMNSAwareElementImpl
that "extends CoreElementImpl" , which implements "org.w3c.dom.Element" -
that to me explains why it compiles.

So, this is a runtime issue on code that worked fine for a long time.

Before I figure out how to rewrite the code in question as I'm not really
sure, I thought I'd ask why this happened all of sudden on the Xerces side
as I have no clue on the Axiom side.


On Wed, Sep 27, 2023 at 9:03 AM Rick Brown <tamr...@swbell.net> wrote:

> Ill throe this in, but i might be out in left field (or iut in da weeds)
> But this is a difference between axiom and DOM
> When working with JAXB and axis2 we had to be very specific as to which
> "space" we were in
> Axiom or DOM
>
> you cant just cast between them
>
> Rick Brown
>
> On Wednesday, September 27, 2023 at 01:30:53 PM CDT, robertlazarski <
> robertlazar...@gmail.com> wrote:
>
>
> I'm the VP of the Apache Axis project and on the PMC of the Apache Axiom
> project, and I am trying to upgrade the Axis sub project Apache Rampart
> project - last released in 2017 - to modern dependencies.
>
> My environment is JDK 17 on Linux with a compiler target of JDK 11.
>
> I mention all this because I have a Rampart unit test that I am trying to
> fix. The code compiles fine, git history shows this code has no recent
> changes in the area and just always worked.
>
> However, there is now a ClassCastException running a unit test when
> casting as shown.
>
> import org.apache.axiom.om.OMElement;
> import org.apache.axiom.om.OMNode;
> import org.w3c.dom.Element;
>
> // defined as <wst:RequestedSecurityToken>
> OMElement requestedSecurityTokenElement = ...
> // OpenSAML assertion defined as <saml> with org.w3c.dom.Element
> Element assertionElement = assertion.getDOM();
> // Boom!
> requestedSecurityTokenElement.addChild((OMNode)assertionElement);
>
> Error:
>
> java.lang.ClassCastException: class org.apache.xerces.dom.ElementNSImpl
> cannot be cast to class org.apache.axiom.om.OMNode
> (org.apache.xerces.dom.ElementNSImpl and org.apache.axiom.om.OMNode are in
> unnamed module of loader 'app')
>        at
> org.apache.rahas.impl.SAML2TokenIssuer.createRequestSecurityTokenResponse(SAML2TokenIssuer.java:242)
>
> The code is here.
>
>
> https://github.com/apache/axis-axis2-java-rampart/blob/master/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAML2TokenIssuer.java#L242
>
> I tried asking the most prolific Axiom developer for help in the issue
> below a few weeks ago but got no response.
>
> https://issues.apache.org/jira/browse/RAMPART-449
>
> I am asking here because I am stuck and need some type of guidance.
>

Reply via email to