backoffbelief / odata4j

Automatically exported from code.google.com/p/odata4j
0 stars 0 forks source link

ODataConsumer failed to parse XML Metadata #25

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
1) What steps will reproduce the problem?

I tried to execute the following source code with the below mentioned Azure 
Datamarket dataset: 

boolean dump = true;
ODataConsumer.DUMP_REQUEST_BODY = dump;
ODataConsumer.DUMP_REQUEST_HEADERS = dump;
ODataConsumer.DUMP_RESPONSE_BODY = dump;
ODataConsumer.DUMP_RESPONSE_HEADERS = dump;

ODataConsumer odc = 
ODataConsumers.dallas("https://api.datamarket.azure.com/Data.ashx/EEA/GreenHouse
Gas/", "xyz", "xyz"); // xyz are my credentials

EdmDataServices eds = odc.getMetadata();
Iterable<EdmEntityType> i = eds.getEntityTypes();
for (;i.iterator().hasNext();) 
{
 System.out.println(i.iterator().next().name);
 System.out.println(i.iterator().next().namespace);
}

2) What is the expected output? What do you see instead?
Expected:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<edmx:Edmx Version="1.0" 
xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" 
xmlns:dr="http://schemas.microsoft.com/dallas/2010/04">
  <edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="1.0">
    <Schema Namespace="EEA.GreenHouseGas" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://schemas.microsoft.com/ado/2007/05/edm">
      <EntityType Name="UNFCCC">
        <Key>
          <PropertyRef Name="ID" />
        </Key>
        <Property Name="ID" Type="Edm.Decimal" Nullable="false" dr:Queryable="true" dr:Returned="true" />
        <Property Name="Country_code" Type="Edm.String" Nullable="true" dr:Queryable="true" dr:Returned="true" />
        <Property Name="Country" Type="Edm.String" Nullable="true" dr:Queryable="true" dr:Returned="true" />
        <Property Name="Pollutant_name" Type="Edm.String" Nullable="true" dr:Queryable="true" dr:Returned="true" />
        <Property Name="Format_name" Type="Edm.String" Nullable="true" dr:Queryable="true" dr:Returned="true" />
        <Property Name="Sector_code" Type="Edm.String" Nullable="true" dr:Queryable="true" dr:Returned="true" />
        <Property Name="Parent_sector_code" Type="Edm.String" Nullable="true" dr:Queryable="true" dr:Returned="true" />
        <Property Name="Sector_name" Type="Edm.String" Nullable="true" dr:Queryable="true" dr:Returned="true" />
        <Property Name="Year" Type="Edm.String" Nullable="true" dr:Queryable="true" dr:Returned="true" />
        <Property Name="emissions" Type="Edm.Decimal" Nullable="true" dr:Queryable="false" dr:Returned="true" />
        <Property Name="Unit" Type="Edm.String" Nullable="true" dr:Queryable="true" dr:Returned="true" />
        <Property Name="Notation" Type="Edm.String" Nullable="true" dr:Queryable="false" dr:Returned="true" />
      </EntityType>
      <EntityContainer Name="EEAGreenHouseGasContainer" m:IsDefaultEntityContainer="true">
        <EntitySet Name="UNFCCC" EntityType="EEA.GreenHouseGas.UNFCCC" />
      </EntityContainer>
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>

Instead result: XML data starts with "?".

GET https://api.datamarket.azure.com/Data.ashx/EEA/GreenHouseGas/$metadata
Status: 200
X-AspNet-Version: 4.0.30319
DataServiceVersion: 1.0;
Transfer-Encoding: chunked
Date: Fri, 28 Jan 2011 14:35:36 GMT
Content-Type: application/xml;charset=utf-8
Server: Microsoft-IIS/7.0
X-Powered-By: ASP.NET
Cache-Control: no-cache
?<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<edmx:Edmx Version="1.0" 
xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" 
xmlns:dr="http://schemas.microsoft.com/dallas/2010/04">
  <edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="1.0">
    <Schema Namespace="EEA.GreenHouseGas" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://schemas.microsoft.com/ado/2007/05/edm">
      <EntityType Name="UNFCCC">
        <Key>
          <PropertyRef Name="ID" />
        </Key>
        <Property Name="ID" Type="Edm.Decimal" Nullable="false" dr:Queryable="true" dr:Returned="true" />
        <Property Name="Country_code" Type="Edm.String" Nullable="true" dr:Queryable="true" dr:Returned="true" />
        <Property Name="Country" Type="Edm.String" Nullable="true" dr:Queryable="true" dr:Returned="true" />
        <Property Name="Pollutant_name" Type="Edm.String" Nullable="true" dr:Queryable="true" dr:Returned="true" />
        <Property Name="Format_name" Type="Edm.String" Nullable="true" dr:Queryable="true" dr:Returned="true" />
        <Property Name="Sector_code" Type="Edm.String" Nullable="true" dr:Queryable="true" dr:Returned="true" />
        <Property Name="Parent_sector_code" Type="Edm.String" Nullable="true" dr:Queryable="true" dr:Returned="true" />
        <Property Name="Sector_name" Type="Edm.String" Nullable="true" dr:Queryable="true" dr:Returned="true" />
        <Property Name="Year" Type="Edm.String" Nullable="true" dr:Queryable="true" dr:Returned="true" />
        <Property Name="emissions" Type="Edm.Decimal" Nullable="true" dr:Queryable="false" dr:Returned="true" />
        <Property Name="Unit" Type="Edm.String" Nullable="true" dr:Queryable="true" dr:Returned="true" />
        <Property Name="Notation" Type="Edm.String" Nullable="true" dr:Queryable="false" dr:Returned="true" />
      </EntityType>
      <EntityContainer Name="EEAGreenHouseGasContainer" m:IsDefaultEntityContainer="true">
        <EntitySet Name="UNFCCC" EntityType="EEA.GreenHouseGas.UNFCCC" />
      </EntityContainer>
    </Schema>
  </edmx:DataServices>
</edmx:Edmx>
java.lang.RuntimeException: javax.xml.stream.XMLStreamException: ParseError at 
[row,col]:[1,1]
Message: Content is not allowed in prolog.
    at org.odata4j.stax2.staximpl.StaxXMLFactoryProvider2$StaxXMLEventReader2.nextEvent(StaxXMLFactoryProvider2.java:103)
    at org.odata4j.format.xml.EdmxFormatParser.parseMetadata(EdmxFormatParser.java:37)
    at org.odata4j.consumer.ODataClient.getMetadata(ODataClient.java:50)
    at org.odata4j.consumer.ODataConsumer.getMetadata(ODataConsumer.java:159)
    at com.fluidops.iwb.provider.AzureDataMarketProvider.gather(AzureDataMarketProvider.java:127)
    at com.fluidops.iwb.provider.AzureDataMarketProvider.main(AzureDataMarketProvider.java:96)
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1]
Message: Content is not allowed in prolog.
    at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(Unknown Source)
    at com.sun.xml.internal.stream.XMLEventReaderImpl.nextEvent(Unknown Source)
    at org.odata4j.stax2.staximpl.StaxXMLFactoryProvider2$StaxXMLEventReader2.nextEvent(StaxXMLFactoryProvider2.java:101)
    ... 5 more

If I query the metadata of this dataset in my browser, everything works fine 
and there is no "?". E

What version of the product are you using? On what operating system?
0.3

If further information is required, please contact me. Thanks for any efforts!

Original issue reported on code.google.com by dirk.c.aumueller on 28 Jan 2011 at 3:01

GoogleCodeExporter commented 9 years ago
This looks like an encoding issue.  Can you see if this is resolved in trunk?  
I seem to recall putting a more lenient parser in a while ago...

Original comment by john.spurlock on 28 Jan 2011 at 4:26

GoogleCodeExporter commented 9 years ago
Indeed, using the svn checkout with the trunk version, everything works fine. 
Thanks for your help!

Original comment by dirk.c.aumueller on 31 Jan 2011 at 8:30

GoogleCodeExporter commented 9 years ago
Glad to hear it.  Marking as fixed in 0.4.

Original comment by john.spurlock on 31 Jan 2011 at 11:59