moh-hassan/odata2poco

Gzip encoded content

Closed this issue · 5 comments

When testing the dotnet o2pgen against a SAP S/4 OData endpoint I discovered an issue with the fact that the SAP metadata is returned from the metadata endpoint with Content-Encoding set to gzip.

This results in the following error

Information: Start processing url: https://sandbox.api.sap.com/s4hanacloud/sap/opu/odata/sap/API_SALES_ORDER_SRV
Error: Error in executing o2pgen
Error: '▼', hexadecimal value 0x1F, is an invalid character. Line 1, position 1.
Information: Error details with Stack trace are written to the file: 'c:\Temp\error.txt'
Information: Application Exit code: 2

The contents of the error.txt file are as follows:

'�', hexadecimal value 0x1F, is an invalid character. Line 1, position 1.
Exception Details:
 System.Xml.XmlException: '�', hexadecimal value 0x1F, is an invalid character. Line 1, position 1.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args)
   at System.Xml.XmlTextReaderImpl.ThrowInvalidChar(Char[] data, Int32 length, Int32 invCharPos)
   at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
   at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.XmlReader.MoveToContent()
   at OData2Poco.Helper.GetMetadataVersion(String metadataString) in C:\projects\odata2poco\OData2PocoLib\Helper.cs:line 68
   at OData2Poco.MetaDataReader.LoadMetaDataHttpAsync(OdataConnectionString odataConnString) in C:\projects\odata2poco\OData2PocoLib\MetaDataReader.cs:line 14
   at OData2Poco.MetaDataReader.LoadMetadataAsync(OdataConnectionString odataConnString) in C:\projects\odata2poco\OData2PocoLib\MetaDataReader.cs:line 66
   at OData2Poco.PocoFactory.GenerateModel(OdataConnectionString connectionString, PocoSetting setting) in C:\projects\odata2poco\OData2PocoLib\PocoFactory.cs:line 35
   at OData2Poco.Api.O2P.GenerateModel(OdataConnectionString odataConnString) in C:\projects\odata2poco\OData2PocoLib\Api\O2P.cs:line 35
   at OData2Poco.Api.O2P.GenerateCsAsync(OdataConnectionString odataConnString) in C:\projects\odata2poco\OData2PocoLib\Api\O2P.cs:line 71
   at OData2Poco.Api.O2P.GenerateAsync(OdataConnectionString odataConnString) in C:\projects\odata2poco\OData2PocoLib\Api\O2P.cs:line 52
   at OData2Poco.CommandLine.CsCommand.GenerateCodeCommandAsync() in C:\projects\odata2poco\OData2Poco.Cli\CsCommand.cs:line 146
   at OData2Poco.CommandLine.CsCommand.Execute() in C:\projects\odata2poco\OData2Poco.Cli\CsCommand.cs:line 43
   at OData2Poco.CommandLine.ArgumentParser.RunCommandAsync(Options options) in C:\projects\odata2poco\OData2Poco.Cli\ArgumentParser.cs:line 47
   at OData2Poco.CommandLine.ArgumentParser.<>c__DisplayClass15_0.<<RunOptionsAsync>b__0>d.MoveNext() in C:\projects\odata2poco\OData2Poco.Cli\ArgumentParser.cs:line 29
--- End of stack trace from previous location ---
   at OData2Poco.CommandLine.ArgumentParser.RunOptionsAsync(String[] args, Func`2 func) in C:\projects\odata2poco\OData2Poco.Cli\ArgumentParser.cs:line 26
   at OData2Poco.CommandLine.ArgumentParser.RunOptionsAsync(String[] args) in C:\projects\odata2poco\OData2Poco.Cli\ArgumentParser.cs:line 43
   at OData2Poco.CommandLine.StartUp.RunOptionsAsync(String[] args) in C:\projects\odata2poco\OData2Poco.Cli\StartUp.cs:line 117
   at OData2Poco.CommandLine.StartUp.Run(String[] args) in C:\projects\odata2poco\OData2Poco.Cli\StartUp.cs:line 78

I have created a PR #47 with a simple fix to allow the http response message content to be automatically decompressed and read as a string.

Thanks @DerekGn for you PR. I will add this feature in the next release.

It is supposed that SAP server may send xml document de-compressed by sending a request header: accept-encoding:identity
Can you try o2pgen v6 by sending a header request by passing the next parameter :

-H accept-encoding=identity

Kindly, Let me if you get xml document or still zip.

Should have mentioned that I had tested the use of the accept-encoding:identity. Unfortunately the SAP API does not honor the header.

Thanks for test.
So, your PR will resolve such cases.

PR is merged

The new version 6.1.0 including PR is available for download