命名空间和 xpath [英] namespace and xpath

查看:30
本文介绍了命名空间和 xpath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

图书馆 xades4j .代码如下:

 静态 {尝试 {DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();dbf.setNamespaceAware(true);db = dbf.newDocumentBuilder();} catch (ParserConfigurationException ex) {//... ...}}文档文档 = db.getNewDocument();DataObjectDesc obj1 = new DataObjectReference("file:///E:/​​doctosign/forxpath/ori_message.xml").withCommitmentType(getCommitmentType()).withTransform(new CanonicalXMLWithoutComments()).withTransform(XPath2Filter.intersect(getxPath())).withDataObjectTimeStamp();XadesSigner xadesSigner = (XadesSigner) 新 XadesTSigningProfile(keyProvider).withTimeStampTokenProvider(TestTimeStampTokenProvider.class).withAlgorithmsProviderEx(ExclusiveC14nForTimeStampsAlgorithmsProvider.class).newSigner();xadesSigner.sign(new SignedDataObjects(obj1), doc);

如果在 XML 文档中没有定义任何命名空间并且 getxPath() 返回路径喜欢

<块引用>

"/文档/组件",

签名生成和验证都运行良好.

然后,我将命名空间添加到 xml 文件中:

<块引用>

<文档 xmlns="ff:kk">

并将getxPath()的返回值改为

<块引用>

"/ff:kk:文档/ff:kk:组件"

签名生成时抛出异常

<块引用>

前缀必须解析为命名空间:ff:kk

似乎我必须在签名生成期间向代码中添加类似 xpath.setNamespaceContext(javax.xml.namespace.NamespaceContext) 的内容.

但是我在哪里可以做到.

谢谢

异常堆栈如下

xades4j.production.PropertyDataGenerationException:IndividualDataObjectsTimeStamp 的属性数据生成失败:无法创建时间戳输入在 xades4j.production.DataGenBaseTimeStamp.generatePropertyData(DataGenBaseTimeStamp.java:71)在 xades4j.production.PropertiesDataObjectsGeneratorImpl.doGenPropsData(PropertiesDataObjectsGeneratorImpl.java:86)在 xades4j.production.PropertiesDataObjectsGeneratorImpl.genPropsData(PropertiesDataObjectsGeneratorImpl.java:72)在 xades4j.production.PropertiesDataObjectsGeneratorImpl.generateSignedPropertiesData(PropertiesDataObjectsGeneratorImpl.java:55)在 xades4j.production.SignerBES.sign(SignerBES.java:220)在 xades4j.production.SignerBES.sign(SignerBES.java:122)在 jp.okayamauniv.medinformatics.xmlsign.xades.XAdES_TEnvelopedXPathSignerImpl.sign(XAdES_TEnvelopedXPathSignerImpl.java:59)在 jp.okayamauniv.medinformatics.xmlsign.xades.XAdESSigner.generateSignature(XAdESSigner.java:83)在 jp.okayamauniv.medinformatics.xmlsign.xades.IXAdES_BESXPathSignWorkFlow.sign(IXAdES_BESXPathSignWorkFlow.java:37)在 jp.okayamauniv.medinformatics.xmlsign.xades.IXAdESSignWorkFlow.signWorkflow(IXAdESSignWorkFlow.java:71)在 xsignui.partinpp2.MainWindowPart$9.widgetSelected(MainWindowPart.java:723)在 org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)在 org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)在 org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)在 org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4169)在 org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)在 org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1021)在 org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)在 org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:915)在 org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)在 org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java:150)在 org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)在 org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)在 org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)在 org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)在 org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)在 sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)在 sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)在 java.lang.reflect.Method.invoke(Unknown Source)在 org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)在 org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)在 org.eclipse.equinox.launcher.Main.run(Main.java:1438)在 org.eclipse.equinox.launcher.Main.main(Main.java:1414)引起:xades4j.utils.CannotAddDataToDigestInputException:前缀必须解析为命名空间:ff:kk在 xades4j.utils.TimeStampDigestInputImpl.addReference(TimeStampDigestInputImpl.java:68)在 xades4j.production.DataGenIndivDataObjsTimeStamp.addPropSpecificTimeStampInput(DataGenIndivDataObjsTimeStamp.java:64)在 xades4j.production.DataGenIndivDataObjsTimeStamp.addPropSpecificTimeStampInput(DataGenIndivDataObjsTimeStamp.java:41)在 xades4j.production.DataGenBaseTimeStamp.generatePropertyData(DataGenBaseTimeStamp.java:58)... 33 更多引起:org.apache.xml.security.signature.XMLSignatureException:前缀必须解析为命名空间:ff:kk原始异常是 org.apache.xml.security.transforms.TransformationException: Prefix must resolve to a namespace: ff:kk原始异常是 org.apache.xpath.domapi.XPathStylesheetDOM3Exception: Prefix must resolve to a namespace: ff:kk在 org.apache.xml.security.signature.Reference.getContentsAfterTransformation(Reference.java:464)在 org.apache.xml.security.signature.Reference.getContentsAfterTransformation(Reference.java:480)在 xades4j.utils.TimeStampDigestInputImpl.addReference(TimeStampDigestInputImpl.java:63)... 36 更多引起:org.apache.xml.security.transforms.TransformationException:前缀必须解析为命名空间:ff:kk原始异常是 org.apache.xpath.domapi.XPathStylesheetDOM3Exception: Prefix must resolve to a namespace: ff:kk在 org.apache.xml.security.transforms.implementations.TransformXPath2Filter.enginePerformTransform(TransformXPath2Filter.java:138)在 org.apache.xml.security.transforms.Transform.performTransform(Transform.java:304)在 org.apache.xml.security.transforms.Transforms.performTransforms(Transforms.java:277)在 org.apache.xml.security.signature.Reference.getContentsAfterTransformation(Reference.java:448)... 38 更多引起:org.apache.xpath.domapi.XPathStylesheetDOM3Exception:前缀必须解析为命名空间:ff:kk在 org.apache.xpath.compiler.XPathParser.errorForDOM3(XPathParser.java:655)在 org.apache.xpath.compiler.Lexer.mapNSTokens(Lexer.java:647)在 org.apache.xpath.compiler.Lexer.tokenize(Lexer.java:365)在 org.apache.xpath.compiler.Lexer.tokenize(Lexer.java:98)在 org.apache.xpath.compiler.XPathParser.initXPath(XPathParser.java:112)在 org.apache.xpath.XPath.(XPath.java:178)在 org.apache.xml.security.utils.XalanXPathAPI.createXPath(XalanXPathAPI.java:159)在 org.apache.xml.security.utils.XalanXPathAPI.eval(XalanXPathAPI.java:134)在 org.apache.xml.security.utils.XalanXPathAPI.selectNodeList(XalanXPathAPI.java:82)在 org.apache.xml.security.transforms.implementations.TransformXPath2Filter.enginePerformTransform(TransformXPath2Filter.java:117)……还有 41 个jp.okayamauniv.medinformatics.xmlsign.xades.ErrorInGenerateSignatureException:IndividualDataObjectsTimeStamp 的属性数据生成失败:无法创建时间戳输入在 jp.okayamauniv.medinformatics.xmlsign.xades.XAdES_TEnvelopedXPathSignerImpl.sign(XAdES_TEnvelopedXPathSignerImpl.java:69)在 jp.okayamauniv.medinformatics.xmlsign.xades.XAdESSigner.generateSignature(XAdESSigner.java:83)在 jp.okayamauniv.medinformatics.xmlsign.xades.IXAdES_BESXPathSignWorkFlow.sign(IXAdES_BESXPathSignWorkFlow.java:37)在 jp.okayamauniv.medinformatics.xmlsign.xades.IXAdESSignWorkFlow.signWorkflow(IXAdESSignWorkFlow.java:71)在 xsignui.partinpp2.MainWindowPart$9.widgetSelected(MainWindowPart.java:723)在 org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)在 org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)在 org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)在 org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4169)在 org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)在 org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1021)在 org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)在 org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:915)在 org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)在 org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java:150)在 org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)在 org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)在 org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)在 org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)在 org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)在 sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)在 sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)在 java.lang.reflect.Method.invoke(Unknown Source)在 org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)在 org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)在 org.eclipse.equinox.launcher.Main.run(Main.java:1438)在 org.eclipse.equinox.launcher.Main.main(Main.java:1414)引起:xades4j.production.PropertyDataGenerationException:IndividualDataObjectsTimeStamp 的属性数据生成失败:无法创建时间戳输入在 xades4j.production.DataGenBaseTimeStamp.generatePropertyData(DataGenBaseTimeStamp.java:71)在 xades4j.production.PropertiesDataObjectsGeneratorImpl.doGenPropsData(PropertiesDataObjectsGeneratorImpl.java:86)在 xades4j.production.PropertiesDataObjectsGeneratorImpl.genPropsData(PropertiesDataObjectsGeneratorImpl.java:72)在 xades4j.production.PropertiesDataObjectsGeneratorImpl.generateSignedPropertiesData(PropertiesDataObjectsGeneratorImpl.java:55)在 xades4j.production.SignerBES.sign(SignerBES.java:220)在 xades4j.production.SignerBES.sign(SignerBES.java:122)在 jp.okayamauniv.medinformatics.xmlsign.xades.XAdES_TEnvelopedXPathSignerImpl.sign(XAdES_TEnvelopedXPathSignerImpl.java:59)……还有 27 个引起:xades4j.utils.CannotAddDataToDigestInputException:前缀必须解析为命名空间:ff:kk在 xades4j.utils.TimeStampDigestInputImpl.addReference(TimeStampDigestInputImpl.java:68)在 xades4j.production.DataGenIndivDataObjsTimeStamp.addPropSpecificTimeStampInput(DataGenIndivDataObjsTimeStamp.java:64)在 xades4j.production.DataGenIndivDataObjsTimeStamp.addPropSpecificTimeStampInput(DataGenIndivDataObjsTimeStamp.java:41)在 xades4j.production.DataGenBaseTimeStamp.generatePropertyData(DataGenBaseTimeStamp.java:58)... 33 更多引起:org.apache.xml.security.signature.XMLSignatureException:前缀必须解析为命名空间:ff:kk原始异常是 org.apache.xml.security.transforms.TransformationException: Prefix must resolve to a namespace: ff:kk原始异常是 org.apache.xpath.domapi.XPathStylesheetDOM3Exception: Prefix must resolve to a namespace: ff:kk在 org.apache.xml.security.signature.Reference.getContentsAfterTransformation(Reference.java:464)在 org.apache.xml.security.signature.Reference.getContentsAfterTransformation(Reference.java:480)在 xades4j.utils.TimeStampDigestInputImpl.addReference(TimeStampDigestInputImpl.java:63)... 36 更多引起:org.apache.xml.security.transforms.TransformationException:前缀必须解析为命名空间:ff:kk原始异常是 org.apache.xpath.domapi.XPathStylesheetDOM3Exception: Prefix must resolve to a namespace: ff:kk在 org.apache.xml.security.transforms.implementations.TransformXPath2Filter.enginePerformTransform(TransformXPath2Filter.java:138)在 org.apache.xml.security.transforms.Transform.performTransform(Transform.java:304)在 org.apache.xml.security.transforms.Transforms.performTransforms(Transforms.java:277)在 org.apache.xml.security.signature.Reference.getContentsAfterTransformation(Reference.java:448)... 38 更多引起:org.apache.xpath.domapi.XPathStylesheetDOM3Exception:前缀必须解析为命名空间:ff:kk在 org.apache.xpath.compiler.XPathParser.errorForDOM3(XPathParser.java:655)在 org.apache.xpath.compiler.Lexer.mapNSTokens(Lexer.java:647)在 org.apache.xpath.compiler.Lexer.tokenize(Lexer.java:365)在 org.apache.xpath.compiler.Lexer.tokenize(Lexer.java:98)在 org.apache.xpath.compiler.XPathParser.initXPath(XPathParser.java:112)在 org.apache.xpath.XPath.(XPath.java:178)在 org.apache.xml.security.utils.XalanXPathAPI.createXPath(XalanXPathAPI.java:159)在 org.apache.xml.security.utils.XalanXPathAPI.eval(XalanXPathAPI.java:134)在 org.apache.xml.security.utils.XalanXPathAPI.selectNodeList(XalanXPathAPI.java:82)在 org.apache.xml.security.transforms.implementations.TransformXPath2Filter.enginePerformTransform(TransformXPath2Filter.java:117)……还有 41 个

解决方案

在命名空间声明中,您声明该元素的默认命名空间是ff:kk",而不是前缀.在 xpath 表达式中,您将其用作未定义的前缀.

您可能希望在顶部元素上使用 xmlns:prefix="namespace" 之类的东西,然后在 xpath 上使用 /prefix:Document/prefix:component 之类的东西.

Libarary xades4j . code as following:

  static {
            try {
                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                dbf.setNamespaceAware(true);
                db = dbf.newDocumentBuilder();
            } catch (ParserConfigurationException ex) {
                 // ... ... 
            }
        }


Document doc = db.getNewDocument();          
DataObjectDesc obj1 = new DataObjectReference(
"file:///E:/doctosign/forxpath/ori_message.xml")
.withCommitmentType(getCommitmentType())
.withTransform(new     CanonicalXMLWithoutComments()) 
.withTransform(XPath2Filter.intersect(getxPath())) 
.withDataObjectTimeStamp( );

XadesSigner xadesSigner = (XadesSigner) new XadesTSigningProfile(keyProvider)
.withTimeStampTokenProvider(TestTimeStampTokenProvider.class)    
.withAlgorithmsProviderEx(ExclusiveC14nForTimeStampsAlgorithmsProvider.class)
.newSigner();

xadesSigner.sign(new SignedDataObjects(obj1),  doc);

if there is not any namespace defined in XML document and the getxPath() return path likes

"/Document/component" ,

the both the signature generation and verification work well .

and then , I add the namespace into the xml file :

<Document xmlns="ff:kk">

and change the return value of getxPath() to

"/ff:kk:Document/ff:kk:component"

Exceptions are threw out when signature generation

Prefix must resolve to a namespace: ff:kk

it seems that i have to add something like xpath.setNamespaceContext(javax.xml.namespace.NamespaceContext) into the code during signature generation.

but where can I do it .

thanks

exception stack as below

xades4j.production.PropertyDataGenerationException: Property data generation failed for IndividualDataObjectsTimeStamp: cannot create time stamp input
    at xades4j.production.DataGenBaseTimeStamp.generatePropertyData(DataGenBaseTimeStamp.java:71)
    at xades4j.production.PropertiesDataObjectsGeneratorImpl.doGenPropsData(PropertiesDataObjectsGeneratorImpl.java:86)
    at xades4j.production.PropertiesDataObjectsGeneratorImpl.genPropsData(PropertiesDataObjectsGeneratorImpl.java:72)
    at xades4j.production.PropertiesDataObjectsGeneratorImpl.generateSignedPropertiesData(PropertiesDataObjectsGeneratorImpl.java:55)
    at xades4j.production.SignerBES.sign(SignerBES.java:220)
    at xades4j.production.SignerBES.sign(SignerBES.java:122)
    at jp.okayamauniv.medinformatics.xmlsign.xades.XAdES_TEnvelopedXPathSignerImpl.sign(XAdES_TEnvelopedXPathSignerImpl.java:59)
    at jp.okayamauniv.medinformatics.xmlsign.xades.XAdESSigner.generateSignature(XAdESSigner.java:83)
    at jp.okayamauniv.medinformatics.xmlsign.xades.IXAdES_BESXPathSignWorkFlow.sign(IXAdES_BESXPathSignWorkFlow.java:37)
    at jp.okayamauniv.medinformatics.xmlsign.xades.IXAdESSignWorkFlow.signWorkflow(IXAdESSignWorkFlow.java:71)
    at xsignui.partinpp2.MainWindowPart$9.widgetSelected(MainWindowPart.java:723)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4169)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1021)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:915)
    at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
    at org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java:150)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Caused by: xades4j.utils.CannotAddDataToDigestInputException: Prefix must resolve to a namespace:  ff:kk
    at xades4j.utils.TimeStampDigestInputImpl.addReference(TimeStampDigestInputImpl.java:68)
    at xades4j.production.DataGenIndivDataObjsTimeStamp.addPropSpecificTimeStampInput(DataGenIndivDataObjsTimeStamp.java:64)
    at xades4j.production.DataGenIndivDataObjsTimeStamp.addPropSpecificTimeStampInput(DataGenIndivDataObjsTimeStamp.java:41)
    at xades4j.production.DataGenBaseTimeStamp.generatePropertyData(DataGenBaseTimeStamp.java:58)
    ... 33 more
Caused by: org.apache.xml.security.signature.XMLSignatureException: Prefix must resolve to a namespace:  ff:kk
Original Exception was org.apache.xml.security.transforms.TransformationException: Prefix must resolve to a namespace:  ff:kk
Original Exception was org.apache.xpath.domapi.XPathStylesheetDOM3Exception: Prefix must resolve to a namespace:  ff:kk
    at org.apache.xml.security.signature.Reference.getContentsAfterTransformation(Reference.java:464)
    at org.apache.xml.security.signature.Reference.getContentsAfterTransformation(Reference.java:480)
    at xades4j.utils.TimeStampDigestInputImpl.addReference(TimeStampDigestInputImpl.java:63)
    ... 36 more
Caused by: org.apache.xml.security.transforms.TransformationException: Prefix must resolve to a namespace:  ff:kk
Original Exception was org.apache.xpath.domapi.XPathStylesheetDOM3Exception: Prefix must resolve to a namespace:  ff:kk
    at org.apache.xml.security.transforms.implementations.TransformXPath2Filter.enginePerformTransform(TransformXPath2Filter.java:138)
    at org.apache.xml.security.transforms.Transform.performTransform(Transform.java:304)
    at org.apache.xml.security.transforms.Transforms.performTransforms(Transforms.java:277)
    at org.apache.xml.security.signature.Reference.getContentsAfterTransformation(Reference.java:448)
    ... 38 more
Caused by: org.apache.xpath.domapi.XPathStylesheetDOM3Exception: Prefix must resolve to a namespace:  ff:kk
    at org.apache.xpath.compiler.XPathParser.errorForDOM3(XPathParser.java:655)
    at org.apache.xpath.compiler.Lexer.mapNSTokens(Lexer.java:647)
    at org.apache.xpath.compiler.Lexer.tokenize(Lexer.java:365)
    at org.apache.xpath.compiler.Lexer.tokenize(Lexer.java:98)
    at org.apache.xpath.compiler.XPathParser.initXPath(XPathParser.java:112)
    at org.apache.xpath.XPath.<init>(XPath.java:178)
    at org.apache.xml.security.utils.XalanXPathAPI.createXPath(XalanXPathAPI.java:159)
    at org.apache.xml.security.utils.XalanXPathAPI.eval(XalanXPathAPI.java:134)
    at org.apache.xml.security.utils.XalanXPathAPI.selectNodeList(XalanXPathAPI.java:82)
    at org.apache.xml.security.transforms.implementations.TransformXPath2Filter.enginePerformTransform(TransformXPath2Filter.java:117)
    ... 41 more
jp.okayamauniv.medinformatics.xmlsign.xades.ErrorInGenerateSignatureException: Property data generation failed for IndividualDataObjectsTimeStamp: cannot create time stamp input
    at jp.okayamauniv.medinformatics.xmlsign.xades.XAdES_TEnvelopedXPathSignerImpl.sign(XAdES_TEnvelopedXPathSignerImpl.java:69)
    at jp.okayamauniv.medinformatics.xmlsign.xades.XAdESSigner.generateSignature(XAdESSigner.java:83)
    at jp.okayamauniv.medinformatics.xmlsign.xades.IXAdES_BESXPathSignWorkFlow.sign(IXAdES_BESXPathSignWorkFlow.java:37)
    at jp.okayamauniv.medinformatics.xmlsign.xades.IXAdESSignWorkFlow.signWorkflow(IXAdESSignWorkFlow.java:71)
    at xsignui.partinpp2.MainWindowPart$9.widgetSelected(MainWindowPart.java:723)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4169)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1021)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:915)
    at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
    at org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java:150)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Caused by: xades4j.production.PropertyDataGenerationException: Property data generation failed for IndividualDataObjectsTimeStamp: cannot create time stamp input
    at xades4j.production.DataGenBaseTimeStamp.generatePropertyData(DataGenBaseTimeStamp.java:71)
    at xades4j.production.PropertiesDataObjectsGeneratorImpl.doGenPropsData(PropertiesDataObjectsGeneratorImpl.java:86)
    at xades4j.production.PropertiesDataObjectsGeneratorImpl.genPropsData(PropertiesDataObjectsGeneratorImpl.java:72)
    at xades4j.production.PropertiesDataObjectsGeneratorImpl.generateSignedPropertiesData(PropertiesDataObjectsGeneratorImpl.java:55)
    at xades4j.production.SignerBES.sign(SignerBES.java:220)
    at xades4j.production.SignerBES.sign(SignerBES.java:122)
    at jp.okayamauniv.medinformatics.xmlsign.xades.XAdES_TEnvelopedXPathSignerImpl.sign(XAdES_TEnvelopedXPathSignerImpl.java:59)
    ... 27 more
Caused by: xades4j.utils.CannotAddDataToDigestInputException: Prefix must resolve to a namespace:  ff:kk
    at xades4j.utils.TimeStampDigestInputImpl.addReference(TimeStampDigestInputImpl.java:68)
    at xades4j.production.DataGenIndivDataObjsTimeStamp.addPropSpecificTimeStampInput(DataGenIndivDataObjsTimeStamp.java:64)
    at xades4j.production.DataGenIndivDataObjsTimeStamp.addPropSpecificTimeStampInput(DataGenIndivDataObjsTimeStamp.java:41)
    at xades4j.production.DataGenBaseTimeStamp.generatePropertyData(DataGenBaseTimeStamp.java:58)
    ... 33 more
Caused by: org.apache.xml.security.signature.XMLSignatureException: Prefix must resolve to a namespace:  ff:kk
Original Exception was org.apache.xml.security.transforms.TransformationException: Prefix must resolve to a namespace:  ff:kk
Original Exception was org.apache.xpath.domapi.XPathStylesheetDOM3Exception: Prefix must resolve to a namespace:  ff:kk
    at org.apache.xml.security.signature.Reference.getContentsAfterTransformation(Reference.java:464)
    at org.apache.xml.security.signature.Reference.getContentsAfterTransformation(Reference.java:480)
    at xades4j.utils.TimeStampDigestInputImpl.addReference(TimeStampDigestInputImpl.java:63)
    ... 36 more
Caused by: org.apache.xml.security.transforms.TransformationException: Prefix must resolve to a namespace:  ff:kk
Original Exception was org.apache.xpath.domapi.XPathStylesheetDOM3Exception: Prefix must resolve to a namespace:  ff:kk
    at org.apache.xml.security.transforms.implementations.TransformXPath2Filter.enginePerformTransform(TransformXPath2Filter.java:138)
    at org.apache.xml.security.transforms.Transform.performTransform(Transform.java:304)
    at org.apache.xml.security.transforms.Transforms.performTransforms(Transforms.java:277)
    at org.apache.xml.security.signature.Reference.getContentsAfterTransformation(Reference.java:448)
    ... 38 more
Caused by: org.apache.xpath.domapi.XPathStylesheetDOM3Exception: Prefix must resolve to a namespace:  ff:kk
    at org.apache.xpath.compiler.XPathParser.errorForDOM3(XPathParser.java:655)
    at org.apache.xpath.compiler.Lexer.mapNSTokens(Lexer.java:647)
    at org.apache.xpath.compiler.Lexer.tokenize(Lexer.java:365)
    at org.apache.xpath.compiler.Lexer.tokenize(Lexer.java:98)
    at org.apache.xpath.compiler.XPathParser.initXPath(XPathParser.java:112)
    at org.apache.xpath.XPath.<init>(XPath.java:178)
    at org.apache.xml.security.utils.XalanXPathAPI.createXPath(XalanXPathAPI.java:159)
    at org.apache.xml.security.utils.XalanXPathAPI.eval(XalanXPathAPI.java:134)
    at org.apache.xml.security.utils.XalanXPathAPI.selectNodeList(XalanXPathAPI.java:82)
    at org.apache.xml.security.transforms.implementations.TransformXPath2Filter.enginePerformTransform(TransformXPath2Filter.java:117)
    ... 41 more

解决方案

On the namespace declaration you're stating that de default namespace for that element is "ff:kk", not the prefix. On the xpath expression you're using it as a prefix, which is not defined.

You probably want something like xmlns:prefix="namespace" on the top element and then /prefix:Document/prefix:component on the xpath.

这篇关于命名空间和 xpath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆