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(),"SOAPMessage
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.intercept(SAMLSerializationInterceptor.java:61)
at electric.soap.util.SOAPInterceptors.callInterceptors(Unknown Source)
at electric.soap.references.interceptor.InterceptorSOAPReference.handle(Unknown
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-wssecurity-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,CN=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.840.113549.1.9.1=#16167062656e656e736f6e40666f72756d7379732e636f6d,CN=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: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 <at> 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.840.113549.1.9.1=#16167062656e656e736f6e40666f72756d7379732e636f6d,CN=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:Action Namespace='urn:oasis:names:tc:SAML:1.0:action:rwedc-negation'>Execute</saml: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