我需要你的帮助:拜托,拜托。我有一个 Xades 签名的 XML 文档,我收到了一个 byteArray :所以我将我的 byteArray 转换为一个字符串。之后,我尝试解组,以便获得映射的 Java 对象。
结果是我得到了一个“MyJavaObj”实例,其中包含除 Xades-Signature 之外的所有信息。我的签名在 Java 对象中为空,而所有其他信息都映射良好。以下是我的java方法。请帮我获取 MyJavaObj 实例中的对象签名。
<school>
<documentVersion>2.10</documentVersion>
<teacher>
.....
</teacher>
<student>
<name></name>
<age></age>
....
</student>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="xmldsig-2b72d2f4-4794-4a8b-8cbf-4c74d33629a7">
<ds:SignedInfo>
........
</ds:SignedInfo>
.......
</ds:Signature>
</school>
这是转换的方法
public static MyJavaObj unmarshallBinary(final byte[] pByteStr) {
try {
final String xmlFlow = new String(pByteStr, "UTF-8");
final StringBuffer xmlStr = new StringBuffer(xmlFlow);
// Unmarshalling with JAXB
final JAXBContext jaxbContext = JAXBContext.newInstance("generated.package");
// marshaller
final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
// Unmarshalling
final JAXBElement<MyJavaObj> root = unmarshaller.unmarshal(
new StreamSource(new StringReader(xmlStr.toString())), MyJavaObj.class);
return root.getValue();
} catch (final Throwable excep) {
excep.printStacktrace();
}
}
MyJavaObj 结果 = unmarshallBinary(..a ByteArray..);
result.getDocumentVersion() :返回 2.10;
result.getStudent() :返回学生;
result.getSignature() :返回 NULL;
MyJavaObj.java 文件有很好的注释
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "My_Java_Obj", namespace = "urn:my_java_obj",
propOrder = {"documentVersion", "teacher", "student","signature"})
public class MyJavaObj {
@XmlElement(name = "documentVersion", required = true)
protected String documentVersion;
@XmlElement(name = "teacher", required = true)
protected Teacher teacher;
@XmlElement(name = "student", required = true)
protected Student student;
@XmlElement(name = "Signature")
protected Signature signature;
@XmlAttribute(name = "Id", required = true)
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
@XmlID
@XmlSchemaType(name = "ID")
protected String id;
.....
getters and setters
}
谢谢你的帮助。