You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Je...@gxs.com on 2006/05/02 18:58:45 UTC

NullPointerException when calling Document.importNode(Node importedNode,boolean deep)

I'm hoping someone can give me some insight to an issue that is
currently stalling a development project. In summary, I need to insert a
pre-existing XML document fragment in to another XML document. I have
tried to do this insertion by first using the importNode() operation on
the org.w3c.dom.Document interface followed by an appendChild()
operation from the org.w3c.dom.Node interface on the new owner document.
When I attempt these operations I receive a NullPointException that is
being generated by an underlying Xerces implementation. The code below
generates the Exception:

 

 

            public void insertNode(SOAPMessage message, Context context)

            {

                        // This is the Node that needs to be inserted in
the new "Owner" document. The content of the node can be seen below

Node wsseNode =
(Node)sessionContext.getSessionAttribute(ISessionContext.WSSE_NODE_KEY);

                        

                        // This Node is present and this print statement
never executes

                        if (wsseNode == null)

 
System.out.println(ErrorFormatter.formatLogMessage(this.getClass(),"wsse
:Security Node IS NULL",ErrorFormatter.ERROR));

                        else

                        {

                                    Node importedNode = null;

 

                                    // soapMessage is not null and the
following code block always executes

                                    

if (message != null)

                                    {

                                                Element header =
message.getHeader();

                                                if (header == null)

                                                            header =
message.addHeader();

 

                                                Document doc =
message.getDocument();

                                                try

                                                {

                                                            // this call
generates the NullPointException. The wsseNode is not null and its
presence has been verified by multiple means

                                                            // the
method never proceeds beyond this point.

 

ImportedNode = doc.importNode(wsseNode,true);

                                                }

                                                catch (DOMException de)

 
{System.out.println(ErrorFormatter.formatErrorMessage(this.getClass(),de
));}

 

 
header.appendChild(importedNode);

                                    }

                                 else

 
System.out.println(ErrorFormatter.formatLogMessage(this.getClass(),"SOAP
Message IS NULL",ErrorFormatter.ERROR));

                        }

            }

 

 

 

 

 

This is the resulting stack trace:

 

Exception in thread "main" java.lang.NullPointerException 

        at org.apache.xerces.dom.CoreDocumentImpl.importNode(Unknown
Source)

        at org.apache.xerces.dom.CoreDocumentImpl.importNode(Unknown
Source)

        at org.apache.xerces.dom.CoreDocumentImpl.importNode(Unknown
Source)

        at
com.gxs.common.webservice.security.SAMLSerializationInterceptor.intercep
t(SAMLSerializationInterceptor.java:61)

        at electric.soap.util.SOAPInterceptors.callInterceptors(Unknown
Source)

        at
electric.soap.references.interceptor.InterceptorSOAPReference.handle(Unk
nown Source)

        at electric.soap.java.reference.JavaToSOAP.handle(Unknown
Source)

        at electric.soap.java.reference.JavaToSOAP.invoke(Unknown
Source)

        at electric.soap.java.reference.JavaToSOAP.invoke(Unknown
Source)

        at electric.proxy.handler.Proxy.invoke(Unknown Source)

        at $Proxy0.testProcess(Unknown Source)

        at
com.gxs.saml.test.SAMLTestClient.<init>(SAMLTestClient.java:54)

        at com.gxs.saml.test.SAMLTestClient.main(SAMLTestClient.java:66)

 

 

 

 

The XML Node that I'm trying to insert is:

 

<wsse:Security
xmlns:wsse='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wsse
curity-secext-1.0.xsd'>

                <saml:Assertion
AssertionID='id-5a344e56a77d5f8b88fba7adf1a5e9578edf3cec'
IssueInstant='2006-04-05T19:40:00.869Z'
Issuer='http://www.forumsys.com/sentry' MajorVersion='1'
MinorVersion='1' xmlns:saml='urn:oasis:names:tc:SAML:1.0:assertion'>

                                <saml:Conditions
NotBefore='2006-04-05T19:40:00.869Z'
NotOnOrAfter='2006-04-05T19:41:00.869Z'></saml:Conditions>

                                <saml:AuthenticationStatement
AuthenticationInstant='2006-04-05T19:40:00.869Z'
AuthenticationMethod='urn:oasis:names:tc:SAML:1.0:am:password'>

                                                <saml:Subject>

 
<saml:NameIdentifier
Format='urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName'>
1.2.840.113549.1.9.1=#16167062656e656e736f6e40666f72756d7379732e636f6d,C
N=Pasha Benenson,C=US</saml:NameIdentifier>

 
<saml:SubjectConfirmation>

 
<saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:sender-vouches</
saml:ConfirmationMethod>

 
</saml:SubjectConfirmation>

                                                </saml:Subject>

                                                <saml:SubjectLocality
IPAddress='10.160.37.108'></saml:SubjectLocality>

                                </saml:AuthenticationStatement>

                                <saml:AttributeStatement>

                                                <saml:Subject>

 
<saml:NameIdentifier
Format='urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName'>1.2.8
40.113549.1.9.1=#16167062656e656e736f6e40666f72756d7379732e636f6d,CN=Pas
ha Benenson,C=US</saml:NameIdentifier>

 
<saml:SubjectConfirmation>

 
<saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:sender-vouches</
saml:ConfirmationMethod>

 
</saml:SubjectConfirmation>

                                                </saml:Subject>

                                                <saml:Attribute
AttributeName='IM_UserID'
AttributeNamespace='http://www.forumsys.com/sentry'>

 
<saml:AttributeValue>GCP4444449999</saml:AttributeValue>

                                                </saml:Attribute>

                                                <saml:Attribute
AttributeName='IM_FirstName'
AttributeNamespace='http://www.forumsys.com/sentry'>

 
<saml:AttributeValue>Donald</saml:AttributeValue>

                                                </saml:Attribute>

                                                <saml:Attribute
AttributeName='IM_MiddleInitials'
AttributeNamespace='http://www.forumsys.com/sentry'>

 
<saml:AttributeValue>M</saml:AttributeValue>

                                                </saml:Attribute>

                                                <saml:Attribute
AttributeName='IM_LastName'
AttributeNamespace='http://www.forumsys.com/sentry'>

 
<saml:AttributeValue>Duck</saml:AttributeValue>

                                                </saml:Attribute>

                                                <saml:Attribute
AttributeName='IM_BUID'
AttributeNamespace='http://www.forumsys.com/sentry'>

 
<saml:AttributeValue>GC7777888888</saml:AttributeValue></saml:Attribute>

                                                <saml:Attribute
AttributeName='IM_PreferredLanguage'
AttributeNamespace='http://www.forumsys.com/sentry'>

 
<saml:AttributeValue>en</saml:AttributeValue>

                                                </saml:Attribute>

                                                <saml:Attribute
AttributeName='IM_TimeZone'
AttributeNamespace='http://www.forumsys.com/sentry'>

 
<saml:AttributeValue>America/Los Angelos</saml:AttributeValue>

                                                </saml:Attribute>

                                                <saml:Attribute
AttributeName='IM_UserEmail'
AttributeNamespace='http://www.forumsys.com/sentry'>

 
<saml:AttributeValue>donald.duck@disney.com</saml:AttributeValue>

                                                </saml:Attribute>

                                                <saml:Attribute
AttributeName='IM_Country'
AttributeNamespace='http://www.forumsys.com/sentry'>

 
<saml:AttributeValue>US</saml:AttributeValue>

                                                </saml:Attribute>

                                                <saml:Attribute
AttributeName='IM_CommunityID'
AttributeNamespace='http://www.forumsys.com/sentry'>

 
<saml:AttributeValue>GCM65405</saml:AttributeValue>

                                                </saml:Attribute>

                                </saml:AttributeStatement>

                                <saml:AuthorizationDecisionStatement
Decision='Permit' Resource='WebService_Authorization'>

                                                <saml:Subject>

 
<saml:NameIdentifier
Format='urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName'>1.2.8
40.113549.1.9.1=#16167062656e656e736f6e40666f72756d7379732e636f6d,CN=Pas
ha Benenson,C=US</saml:NameIdentifier>

 
<saml:SubjectConfirmation>

 
<saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:sender-vouches</
saml:ConfirmationMethod>

 
</saml:SubjectConfirmation>

                                                </saml:Subject>

                                                <saml:Action
Namespace='urn:oasis:names:tc:SAML:1.0:action:rwedc-negation'>Execute</s
aml:Action>

                                </saml:AuthorizationDecisionStatement>

                </saml:Assertion>

 </wsse:Security>

 

 

 

Are there limitations to the complexity of the Node that you can import?
I tried the import operation with a simple parent/single child xml
document and the import() operation worked successfully.

Am I using the importNode() operation in an inappropriate way?

If so, what are my alternatives for inserting an xml fragment from one
document to another?

If not, what changes do I need to make to accomplish this activity?

 

I am using the xml-apis.jar and xercesImpl.jar files from the 2.7
release of Xalan. 

 

Thanks in advance for any help!

 

Jeff 


Re: NullPointerException when calling Document.importNode(Node importedNode,boolean deep)

Posted by Joseph Kesselman <ke...@us.ibm.com>.
You might want to try running this under a debugger to see what field is
actually coming up as null. I'd be inclined to suspect that the node you're
importing from is damaged and/or otherwise isn't properly implementing the
DOM APIs, hence is returning null at a time when null isn't expected.

If not, then we may have a bug in the importNode implementation. But
determining exactly what's failing is the first step in determining whether
the problem is in the source DOM or sink DOM.

______________________________________
"... Three things are most perilous: Connectors that corrode,
  Unproven algorithms, and self-modifying code! ..."
  -- "Threes" Rev 1.1 - Duane Elms / Leslie Fish
(http://www.ovff.org/pegasus/songs/threes-rev-11.html)


---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org