From 213a8c06832affbc6e70f18a974adda8015bc86a Mon Sep 17 00:00:00 2001 From: ramya vasanth Date: Thu, 8 Feb 2018 15:03:15 +0530 Subject: [PATCH] [OLINGO-1232]Metadata parsing goes into an infinite loop when there is a collection of Records inside Annotation groups --- .../edm/xml/annotation/ClientCsdlRecord.java | 4 +- .../olingo/client/core/MetadataTest.java | 18 + .../caps.products.CatalogService_default.xml | 1086 +++++++++++++++++ 3 files changed, 1107 insertions(+), 1 deletion(-) create mode 100644 lib/client-core/src/test/resources/org/apache/olingo/client/core/caps.products.CatalogService_default.xml diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/ClientCsdlRecord.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/ClientCsdlRecord.java index a2a1b07d2..57215d5ea 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/ClientCsdlRecord.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/xml/annotation/ClientCsdlRecord.java @@ -46,8 +46,10 @@ class ClientCsdlRecord extends CsdlRecord implements Serializable { if ("Type".equals(jp.getCurrentName())) { record.setType(jp.nextTextValue()); } else if ("Annotation".equals(jp.getCurrentName())) { + jp.nextToken(); record.getAnnotations().add(jp.readValueAs(ClientCsdlAnnotation.class)); - } else { + } else if ("PropertyValue".equals(jp.getCurrentName())) { + jp.nextToken(); record.getPropertyValues().add(jp.readValueAs(ClientCsdlPropertyValue.class)); } } diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/MetadataTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/MetadataTest.java index 1288b08b2..23ef55ffc 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/MetadataTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/MetadataTest.java @@ -63,10 +63,12 @@ import org.apache.olingo.commons.api.edm.provider.CsdlTerm; import org.apache.olingo.commons.api.edm.provider.annotation.CsdlApply; import org.apache.olingo.commons.api.edm.provider.annotation.CsdlCollection; import org.apache.olingo.commons.api.edm.provider.annotation.CsdlConstantExpression; +import org.apache.olingo.commons.api.edm.provider.annotation.CsdlExpression; //CHECKSTYLE:OFF import org.apache.olingo.commons.api.edm.provider.annotation.CsdlLogicalOrComparisonExpression.LogicalOrComparisonExpressionType; //CHECKSTYLE:ON import org.apache.olingo.commons.api.edm.provider.annotation.CsdlPath; +import org.apache.olingo.commons.api.edm.provider.annotation.CsdlRecord; import org.apache.olingo.commons.api.edm.provider.annotation.CsdlUrlRef; import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.core.edm.primitivetype.EdmDecimal; @@ -481,4 +483,20 @@ public class MetadataTest extends AbstractTest { assertNull(providerLicensePractices.getRelatedBindingTarget("Provider")); assertNull(providerLicenses.getRelatedBindingTarget("ProviderLicense")); } + + @Test + public void issueOLINGO1232() { + XMLMetadata xmlMetadata = client.getDeserializer(ContentType.APPLICATION_XML). + toMetadata(getClass().getResourceAsStream("caps.products.CatalogService_default.xml")); + assertNotNull(xmlMetadata); + assertEquals(94, xmlMetadata.getSchema(0).getAnnotationGroups().size()); + List expressions = xmlMetadata.getSchema(0).getAnnotationGroups().get(0). + getAnnotation("UI.LineItem").getExpression().asDynamic().asCollection().getItems(); + assertEquals(6, expressions.size()); + CsdlRecord record = (CsdlRecord) expressions.get(0); + assertEquals("UI.DataField", record.getType()); + assertEquals(1, record.getAnnotations().size()); + assertEquals("Value", record.getPropertyValues().get(0).getProperty()); + assertEquals("image", record.getPropertyValues().get(0).getValue().asDynamic().asPath().getValue()); + } } diff --git a/lib/client-core/src/test/resources/org/apache/olingo/client/core/caps.products.CatalogService_default.xml b/lib/client-core/src/test/resources/org/apache/olingo/client/core/caps.products.CatalogService_default.xml new file mode 100644 index 000000000..cd3d197b7 --- /dev/null +++ b/lib/client-core/src/test/resources/org/apache/olingo/client/core/caps.products.CatalogService_default.xml @@ -0,0 +1,1086 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ID + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + priceRange_code + stock/availability_code + category_ID + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file