Re: [Simple-support] Does not understand this ElementException
Brought to you by:
niallg
|
From: Thomas <tho...@gm...> - 2012-09-20 07:38:26
|
Hello,
First, thank you for your reply.
In the previous mail, I extracted the piece of XML code where the line 43 is. Here is with line numbers:
...other datas...
42: <vt:SignedDataObject Id="signeddata1">
43: <vt:Encapsulated>true</vt:Encapsulated>
44: <vt:MimeType>application/pdf</vt:MimeType>
45: <vt:Name>signeddata-1.pdf</vt:Name>
46: <vt:Size>131323</vt:Size>
47: <vt:DigestAlgAndValue>
48: <ds:DigestMethod Algorithm="1.3.14.3.2.26"></ds:DigestMethod>
49: <ds:DigestValue>KuWqL3YVcSMZeHRov5nE90PZSeY=</ds:DigestValue>
50: </vt:DigestAlgAndValue>
51: </vt:SignedDataObject>
...other datas...
As you can see, the Id attribute is set.
And here is the Java class which modelize the DigestAlgAndValueType XML type:
public class DigestAlgAndValueType {
@Element(name = "DigestMethod", required = true)
protected DigestMethodType digestMethod;
@Element(name = "DigestValue", required = true)
protected String encodedDigestValue;
protected byte[] digestValue;
@Commit
public void commit() {
digestValue = Base64.decode(encodedDigestValue);
encodedDigestValue = null;
}
@Persist
public void prepare() {
encodedDigestValue = new String(Base64.encode(digestValue));
}
@Complete
public void release() {
encodedDigestValue = null;
}
... getters and setters...
}
I don't understand about the DigestAlgAndValueType because it is already used in the XML and the mapping works. Here is the piece of XML file which work and which use DigestAlgAndValueType:
16: <vt:BeforeVerification>
17: <vt:Size>131323</vt:Size>
18: <vt:DigestAlgAndValue>
19: <ds:DigestMethod Algorithm="2.16.840.1.101.3.4.2.1"></ds:DigestMethod>
20: <ds:DigestValue>E8re2OFo7sUq0C78R6ueaC8M56xQjvy97OFU9sgaw1U=</ds:DigestValue>
21: </vt:DigestAlgAndValue>
22: </vt:BeforeVerification>
On Sep 20, 2012, at 1:02 AM, Niall Gallagher - Yieldbroker wrote:
> Hi,
>
> From this I can tell one of your XML elements named "SignedDataObject" does not have an "id" attribute. Look in your XML file at line 43, I think you will see there is no "Id" element, set the @Attribute(name="Id", required=false) this should fix it. Also, without seeing the class DigestAlgAndValueType I cannot tell if it has an @Element matching "DigestMethod", though Ill bet there is no such element. A good option for you might be.
>
> Persister.read(MyClass.class, mySourceStream, false) // false means ignore elements and attributes not matched by your annotations
>
> Niall
>
> -----Original Message-----
> From: Thomas [mailto:tho...@gm...]
> Sent: Wednesday, 19 September 2012 11:05 PM
> To: sim...@li...
> Subject: [Simple-support] Does not understand this ElementException
>
> Hello,
>
> I have a little problem with Simple. First, here is a part of my XSD file:
>
> <xs:complexType name="SignedDataObjectType">
> <xs:sequence>
> <xs:element name="Encapsulated" type="xs:boolean"/>
> <xs:element name="MimeType" type="xs:string"/>
> <xs:element name="Name" type="xs:string" minOccurs="0"/>
> <xs:element name="Description" type="xs:string" minOccurs="0"/>
> <xs:element name="Size" type="xs:long" minOccurs="0"/>
> <xs:element name="DigestAlgAndValue" type="xad:DigestAlgAndValueType" minOccurs="0"/>
> <xs:element name="Revisions" type="vt:RevisionsType" minOccurs="0"/>
> <xs:element name="Errors" type="vt:ErrorsType" minOccurs="0"/>
> </xs:sequence>
> <xs:attribute name="Id" type="xs:ID" use="required"/>
> </xs:complexType>
>
> Then, here is my targetted Java class:
>
> public class SignedDataObjectType {
>
> @Attribute(name = "Id")
> protected String id;
>
> @Element(name = "Encapsulated")
> protected boolean encapsulated;
>
> @Element(name = "MimeType")
> public String mimeType;
>
> @Element(name = "Name", required = false)
> protected String name;
>
> @Element(name = "Description", required = false)
> protected String description;
>
> @Element(name = "Size", required = false)
> protected Long size;
>
> @Element(name = "DigestAlgAndValue", required = false)
> protected DigestAlgAndValueType digestAlgAndValue;
>
> @Element(name = "Revisions", required = false)
> protected RevisionsType revisions;
>
> @Element(name = "Errors", required = false)
> protected ErrorsType errors;
>
> ... setters and getters here...
>
> And to finish, a the part of my XML file:
> ... other datas here...
> <vt:SignedDataObject Id="signeddata-1">
> <vt:Encapsulated>true</vt:Encapsulated>
> <vt:MimeType>application/pdf</vt:MimeType>
> <vt:Name>signeddata-1.pdf</vt:Name>
> <vt:Size>131323</vt:Size>
> <vt:DigestAlgAndValue>
> <ds:DigestMethod Algorithm="1.3.14.3.2.26"></ds:DigestMethod>
> <ds:DigestValue>KuWqL3YVcSMZeHRov5nE90PZSeY=</ds:DigestValue>
> </vt:DigestAlgAndValue>
> </vt:SignedDataObject>
> ... other datas here...
>
> And I have this exception:
>
> org.simpleframework.xml.core.ValueRequiredException: Unable to satisfy @org.simpleframework.xml.Attribute(empty=, name=Id, required=true) on field 'id' protected java.lang.String com.lexpersona.lp7verifybox.entities.SignedDataObjectType.id for class com.lexpersona.lp7verifybox.entities.SignedDataObjectType at line 43 at org.simpleframework.xml.core.Composite.validate(Composite.java:644)
> at org.simpleframework.xml.core.Composite.readAttributes(Composite.java:416)
> ...blah blah blah...
>
> As you can see, the datas exists. So, I tried to use the required false (which is very bad because my class attributes are mandatory) in the annotation but I have another exception with the DigestAlgAndValue tag:
>
> org.simpleframework.xml.core.ElementException: Element 'DigestMethod' does not have a match in class com.lexpersona.lp7verifybox.entities.SignedDataObjectType at line 48 at org.simpleframework.xml.core.Composite.readElement(Composite.java:527)
> ... blah blah blah...
>
> I do not understand why Simple is against me at this level :s And you can note the I already use the DigestAlgAndValue element before and that works... I realy do not understand why Exception are thrown in this level :(
>
> Have you any ideas? Do I need to send you more informations?
>
> Thomas
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Simple-support mailing list
> Sim...@li...
> https://lists.sourceforge.net/lists/listinfo/simple-support
|