2012-12-14 4 views
0

천칭 자리 xades4j. 다음과 같이 코드 :네임 스페이스 및 xpath

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); 

XML 문서와 getxPath() 반환 경로에 정의 된 네임 스페이스가없는 경우는

"/ 문서/구성 요소"

둘 다 좋아 서명 생성 및 검증이 잘 작동합니다.

후, 나는 xml 파일에 네임 스페이스를 추가합니다

<Document xmlns="ff:kk"> 

에 getxPath()의 반환 값을 변경 "/ FF : KK : 문서/ff : kk : 구성 요소 "

서명 생성시 예외가 발생합니다.

접두사는 네임 스페이스에 해결해야합니다 : FF : 내가 서명 생성시 코드로 xpath.setNamespaceContext (javax.xml.namespace.NamespaceContext) 같은 것을 추가해야 할 것 같다

KK.

는하지만 난 그것을 어디에서 할 수 있습니다. 아닌 접두사 : 해당 요소에 대한 그 드의 기본 네임 스페이스를 명시하고있는 네임 스페이스 선언에

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 

답변

3

아래로

감사

예외 스택은 "주식 FF"입니다. xpath 표현식에서 접두어로 사용하고 있습니다. 접두어는 정의되지 않았습니다.

아마도 최상위 요소에 xmlns:prefix="namespace"과 같은 것이 있고 xpath에는 /prefix:Document/prefix:component이 필요합니다.

+0

lgoncalves .thanks. [xmlns : prefix = "namespace"]를 최상위 구성 요소에 추가하지만 여전히 experted로 작동하지 않습니다. 나는 [xpath와 네임 스페이스에 대한] 문서를 찾아서 여기로 돌아갈 것이다. –