Closed rafaelferrari closed 3 years ago
Hi @rafaelferrari, thanks for reaching out!
I see that you are using a version of the SDK that is very outdated. The latest version is 3.39.0
and we generally highly recommend to update it! You can check our Release Notes and also our guide & tutorial to move from 2.X to 3.X (it's pretty straight forward, don't worry).
To the actual issue: In the payload I see you used a placeholder for the data in question: "Content":"base64encodeddatahere"
.
Could you please clarify, if the actual payload has quotes around the value? So do you have:
"Content": "1234"
or"Content": 1234
Also, could you please add the what the service responds with?
In general it would be great to have a working example with Postman. Because as SDK team we can't really help with the semantics of individual services. For that it's best to reach out to the service owners.
But we should first verify that the SDK sends out the data correctly. And that's easiest to prove with a working request we can compare to.
Hi @MatKuhr, thanks for the quick reply =) I'll break down the answers in the requested topics.
The project is actually live with this version using a lot of sdk services so there is some risk to upgrade it because of retesting all integrations, but we are currently studying this possibility and actual effort needed to do so.
The quotes are present in the Content
field for the JSON as well, so that would be option 1 - "Content": "1234"
. I've attached below the actual files used for this test.
Note: I've renamed the extension for second one to txt and updated the BO fields to match my previous example
- ErASdMfW4AE30hg.jpg - original file
- ErASdMfW4AE30hg.txt - file retrieved from S/4 after upload Also, I can tell that the string on the
Content
field for the second file is actually the first file encoded in base64 format.
I can't tell unless I try to debug it (which tbh is a little tricky because we don't have access to a s/4 environment unless it's the client's), but no exceptions are thrown by the service class and our REST APIs return with no errors. As I can see the files through the other APIs, I'm assuming the upload operation itself is successful...
We are currently working with another colleague who is able to call the S/4 APIs directly from Postman and hopefully we might be able to obtain a working example in the next couple of days.
Hi @MatKuhr, a few updates from our side.
We have migrated the cloud-sdk libraries to v3.39.0
in a separate branch, but the exact same error was noticed.
The following collection contains a request in which we were able to successfully upload an attachment. In it we are connecting directly to the service's API on the host. The body type in Postman is set as "binary" and the tested txt is also in the zip file.
Our colleague who’s working with the S/4 services wants to know which of the two services is the SDK calling for this operation - CV_ATTACHMENT ODATA
or API_CV_ATTACHMENT ODATA
- just so we are testing the right ones.
Do you have that info? We assume it’s the one in the EDMX file (API_CV_ATTACHMENT_ODATA
in our case).
Also, can you tell if there is a SDK how-to guide that we could use for reference?
Summary from our call:
Edm.Binary
Potential workaround:
Edm.Binary
to Edm.String
and re-generateFuture steps:
If the service requires a special payload (e.g. sending the context as plain text only, not the full entity as JSON), you can achieve this with the low-level API of the SDK:
request = new ODataRequestCreate(AttachmentsService.DEFAULT_SERVICE_PATH, attachmentContent.getEntityCollection(), "<your-payload-goes-here>", ODataProtocol.V2);
httpClient = HttpClientAccessor.getHttpClient(destination);
result = request.execute(httpClient);
// optional, in case you want to evaluate the result with some convenience
// EDIT: this is actually package private, my bad
// response = ModificationResponse.of(result, attachmentContent, destination);
Thanks @MatKuhr !
In case we want to evaluate the request result, I believe the static method ModificationResponse.of(...);
is package protected, so not sure if we can access.
Is there any alternative?
The idea would be to get the specific error message coming from S/4HANA and do something with it.
Thanks!
For error handling please catch the ODataException
thrown by execute
. You can find out more on the documentation: https://sap.github.io/cloud-sdk/docs/java/features/odata/use-typed-odata-v2-client-in-sap-cloud-sdk-for-java#error-handling
Hi @MatKuhr ,
We also have issues with the Download API_CV_ATTACHMENT_ODATA service.
As far as I understood the SDK only supports the fetchAsStream()
after you call the Entity GET (i.e. /AttachmentContentSet
), right?
Problem is: we get an exception from S/4HANA whenever we call GET /AttachmentContentSet
without the /$value
tag. Not only via SDK, but also directly in S/4HANA with any http client tool.
In our case, we need to call the GOS services, since we retrieve document keys via /GetAllOriginals
.
AttachmentContentSet
Get Entity only supports DMS keys, which are nonsense for our use case. So if we call it, it does not cache, but rather throws the exception.
For now, we are exploring the same approach we did for the Upload operation (as you suggested), but we wanted to make sure there is a way to achieve this fully with SDK.
Thank you! Fernando
Okay, interesting. There might be a more convenient workaround:
AttachmentContent
object via constructor or builderattachToService(AttachmentService.DEFAULT_SERVICE_PATH, destination)
on itfetchAsStream()
I haven't tested this but I think it should let you perform the fetchAsStream()
without retrieving the entity first.
Otherwise the low-level API should also work. However, in that case you probably have to evaluate the HTTP response entity manually.
Hey @ffg91,
Let us know if the solution worked for you and we can close this issue?
Hey @MatKuhr
FYI, In my initial tests with your latest suggestion I got an XML parsing error.
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[18,5]
Message: The element type "link" must be terminated by the matching end-tag "</link>".
I'd like to investigate a little further to check whether the suggestion actually works before getting back to you - it could be a valuable workaround available.
For now we are doing the same approach as we did for the Upload - using the low-level API. It works fine! 😄
Many thanks for all the great support! 🏆
Hi @artemkovalyov I believe we could close this issue. Thank you!
@ffg91 wrote:
In case we want to evaluate the request result, I believe the static method ModificationResponse.of(...); is package protected, so not sure if we can access.
Is there any alternative?
I'm happy to inform you that we have been working on exposing these static factory methods in our current sprint - the changes have been merged just a few seconds ago 🥳
That means that you can leverage our (previously package-private) factory methods to conveniently convert responses of our low-level API into more elaborate, typed variants starting with the release of version 3.50.0
of the SAP Cloud SDK.
While I cannot make any promises on the actual release date, I'm currently expecting these changes to be publicly available at the end of July/beginning of August (roughly two weeks from now).
Best regards, Johannes
Issue Description
Hi colleagues,
Our team is working with the attachments APIs (especifically, the
DefaultAPICVATTACHMENTSRVService
service) and we found an error with the files that were uploaded using the SDK. The operation runs fine and the document is uploaded to S/4 with the correct linked object key/type and metadata (file name, mime type); however, the actual data for the document is not valid.Through a binary comparison between the original file and the one retrieved from S/4, I've noticed that data for the uploaded file is actually readable in a text editor and it contains a JSON representation of the actual file. E.g.:
Here is how our code looks like when creating the command (using the generated builders, we also tried to use the setter methods but we got the same result):
This
attachmentContent
variable is then provided when we call thecreateAttachmentContent()
method onDefaultAPICVATTACHMENTSRVService
, but somewhere along the way it seems like the content is being replaced with the JSON containing both the data and the metadata.The command's
run()
method looks like this:We are currently unable to perform this operation via API (e.g. Postman) but we're working on that. Currently we don't have a working example of how the body and headers should look like in the API request, so if you could share some example request with us we'd appreciate it.
Right now we are unsure if this is caused by something we are missing from our code or if there is a bug in this service somewhere. Could you please assist us with this issue?
Impact / Priority
Affected development phase: Development
Impact: Blocked
Timeline: Go-Live is in 6 weeks.
Error Message
Maven Dependency Tree
Project Details
Checklist