Re: Runtime ClassCastException on class org.apache.xerces.dom.ElementNSImpl

Rick Brown <[email protected]> Wed, 27 Sep 2023 19:02:46 +0000 (UTC)
Newsgroups gmane.text.xml.xerces-j.user
Message-ID <[email protected]>
------=_Part_3629522_859893043.1695841366338
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

 Ill throe this in, but i might be out in left field (or iut in da weeds)Bu=
t this is a difference between axiom and DOMWhen working with JAXB and axis=
2 we had to be very specific as to which "space" we were inAxiom or DOM
you cant just cast between them
Rick Brown
    On Wednesday, September 27, 2023 at 01:30:53 PM CDT, robertlazarski <ro=
[email protected]> wrote: =20
=20
 I'm the VP of the Apache Axis project and on the PMC of the Apache Axiom p=
roject, and I am trying to upgrade the Axis sub project Apache Rampart proj=
ect - last released in 2017 - to modern dependencies.=20

My environment is JDK 17 on Linux with a compiler target of JDK 11.=C2=A0=
=C2=A0
I mention all this because I have a Rampart unit test that I am trying to f=
ix. The code compiles fine, git history shows this code has no recent chang=
es in the area and just always worked.=C2=A0
However, there is now a ClassCastException running a unit test when casting=
 as shown.=C2=A0
import org.apache.axiom.om.OMElement;import org.apache.axiom.om.OMNode;
import org.w3c.dom.Element;
// defined as <wst:RequestedSecurityToken>OMElement requestedSecurityTokenE=
lement =3D ...// OpenSAML assertion defined as <saml> with org.w3c.dom.Elem=
ent Element assertionElement =3D assertion.getDOM();
// Boom!=20
requestedSecurityTokenElement.addChild((OMNode)assertionElement);

Error:=20

java.lang.ClassCastException: class org.apache.xerces.dom.ElementNSImpl can=
not be cast to class org.apache.axiom.om.OMNode (org.apache.xerces.dom.Elem=
entNSImpl and org.apache.axiom.om.OMNode are in unnamed module of loader 'a=
pp')=20
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0at org.apache.rahas.impl.SAML2Tok=
enIssuer.createRequestSecurityTokenResponse(SAML2TokenIssuer.java:242)

The code is here.=20

https://github.com/apache/axis-axis2-java-rampart/blob/master/modules/rampa=
rt-trust/src/main/java/org/apache/rahas/impl/SAML2TokenIssuer.java#L242=20


I tried asking the most prolific Axiom developer for help in the issue belo=
w a few weeks ago but got no response.=20


https://issues.apache.org/jira/browse/RAMPART-449

I am asking here because I am stuck and need some type of guidance.=20

 =20
------=_Part_3629522_859893043.1695841366338
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<html><head></head><body><div class=3D"ydp81f5c5e9yahoo-style-wrap" style=
=3D"font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:16px=
;"><div></div>
        <div>Ill throe this in, but i might be out in left field (or iut in=
 da weeds)</div><div>But this is a difference between axiom and DOM</div><d=
iv>When working with JAXB and axis2 we had to be very specific as to which =
"space" we were in</div><div>Axiom or DOM</div><div><br></div><div>you cant=
 just cast between them</div><div><br></div><div>Rick Brown</div><div><br><=
/div>
       =20
        <div id=3D"ydp81f5c5e9yahoo_quoted_6628126962" class=3D"ydp81f5c5e9=
yahoo_quoted">
            <div style=3D"font-family:'Helvetica Neue', Helvetica, Arial, s=
ans-serif;font-size:13px;color:#26282a;">
               =20
                <div>
                    On Wednesday, September 27, 2023 at 01:30:53 PM CDT, ro=
bertlazarski &lt;[email protected]&gt; wrote:
                </div>
                <div><br></div>
                <div><br></div>
                <div><div id=3D"ydp81f5c5e9yiv8636611883"><div dir=3D"ltr">=
<div>I'm the VP of the Apache Axis project and on the PMC of the Apache Axi=
om project, and I am trying to upgrade the Axis sub project Apache Rampart =
project - last released in 2017 - to modern dependencies. <br></div><div><b=
r></div><div>My environment is JDK 17 on Linux with a compiler target of JD=
K 11.&nbsp;</div><div>&nbsp;<br></div><div>I mention all this because I hav=
e 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 w=
orked.&nbsp;</div><div><br></div><div>However, there is now a ClassCastExce=
ption running a unit test when casting as shown.&nbsp;</div><div><br></div>=
<div><span style=3D"font-family:monospace;"><span style=3D"color:rgb(95,215=
,255);background-color:rgb(255,255,255);">import</span><span style=3D"color=
:rgb(0,0,0);background-color:rgb(255,255,255);"> org.apache.axiom.om.OMElem=
ent;</span></span></div><div><div><span style=3D"font-family:monospace;"><s=
pan style=3D"color:rgb(0,0,0);background-color:rgb(255,255,255);"></span></=
span></div><div><span style=3D"font-family:monospace;"><span style=3D"color=
:rgb(95,215,255);background-color:rgb(255,255,255);">import</span><span sty=
le=3D"color:rgb(0,0,0);background-color:rgb(255,255,255);"> org.apache.axio=
m.om.OMNode;</span><br></span></div></div><div><span style=3D"font-family:m=
onospace;"><span style=3D"color:rgb(95,215,255);background-color:rgb(255,25=
5,255);">import</span><span style=3D"color:rgb(0,0,0);background-color:rgb(=
255,255,255);"> org.w3c.dom.Element;</span></span></div><div><span style=3D=
"font-family:monospace;"><span style=3D"color:rgb(0,0,0);background-color:r=
gb(255,255,255);"><br></span></span></div><div>// <font color=3D"#000000">d=
efined as &lt;wst:RequestedSecurityT</font>oken&gt;</div><div><span style=
=3D"font-family:monospace;"><span style=3D"color:rgb(0,0,0);background-colo=
r:rgb(255,255,255);">OMElement requestedSecurityTokenElement =3D </span>...=
</span></div><div>// OpenSAML assertion defined as &lt;saml&gt; <font color=
=3D"#000000">with org.w3c.dom.Element</font> </div><div><span style=3D"font=
-family:monospace;"><span style=3D"color:rgb(0,0,0);background-color:rgb(25=
5,255,255);">Element assertionElement =3D assertion.getDOM();</span><br></s=
pan></div><div>// Boom! <br></div><div><span style=3D"font-family:monospace=
;"><span style=3D"color:rgb(0,0,0);background-color:rgb(255,255,255);">requ=
estedSecurityTokenElement.addChild((OMNode)assertionElement);</span><br></s=
pan></div><div><span style=3D"font-family:monospace;"><br></span></div><div=
><span style=3D"font-family:monospace;">Error: <br></span></div><div><p><fo=
nt color=3D"#000000">java.lang.ClassCast</font><font color=3D"#000000">Exce=
</font><font color=3D"#000000">ption: class org.apache.xerces.dom.ElementNS=
Impl can</font>not
 be cast to class org.apache.axiom.om.OMNode=20
(org.apache.xerces.dom.ElementNSImpl and org.apache.axiom.om.OMNode are=20
in unnamed module of loader 'app') <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;at org.apache.rahas.impl.SAML2Tok=
enIssuer.createRequestSecurityTokenResponse(SAML2TokenIssuer.java:242)</p>


<p>The code is here. </p>

<p><a href=3D"https://github.com/apache/axis-axis2-java-rampart/blob/master=
/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAML2TokenIssuer=
.java#L242" class=3D"ydp81f5c5e9yiv8636611883external-link" rel=3D"nofollow=
" target=3D"_blank">https://github.com/apache/axis-axis2-java-rampart/blob/=
master/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAML2Token=
Issuer.java#L242</a> <br></p><p>I tried asking the most prolific Axiom deve=
loper for help in the issue below a few weeks ago but got no response. <br>=
</p><p><a href=3D"https://issues.apache.org/jira/browse/RAMPART-449" rel=3D=
"nofollow" target=3D"_blank">https://issues.apache.org/jira/browse/RAMPART-=
449</a></p><p>I am asking here because I am stuck and need some type of gui=
dance. <br></p></div></div>
</div></div>
            </div>
        </div></div></body></html>
------=_Part_3629522_859893043.1695841366338--