CSRF token not properly handled when calling a function - sap-cloud-sdk

We're using SAP Cloud SDK 3.32.0 with SpringBoot.
We've generated a typed OData service based on the EDMX metadata file generated by the service and use the generated client in our code. All logs entries showing our issue are below (cleaned them up a bit to show the important parts only)
The situation is the following:
We send a myservice.createEntity(MyEntity).exectureRequest(myDestination) with the generated client. Since this is a modifying/creating call, the client first requests a CSRF token. This works fine as shown in the logs below (first HEAD and POST calls)
Next we call a function with myservice.myFunction(p1, p2, p3).executeRequest(myDestination). This is a function exposed by the same OData service, so the service path is the same. Since this function is a POST, the client will again try to fetch a CSRF token. However, this results in a HTTP 403 Forbidden status code. We do not get the CSRF token (see second HEAD request in the logs below).
The function call is still executed, but with an empty X-CSRF-Token http header (second POST request in logs).
Although we seem to receive a response from the OData service, the client finallly times out (Read time out) and we are unable to process the result of the function call.
Debugging/clicking through the code of the CloudSDK, I discovered that the generated "FluentHelperFunction" class has it's own logic for retrieving the CSRF token (e.g. it uses "Fetch" in the HEAD requests), where as the FluentHelperCreate class uses the DefaultCsrfRetriever class (which uses lower case "fetch" for the HEAD call).
So my questions are:
Why does the HEAD call for CSRF fail when done by a function call (i.e. myservice.myFunction())
Why does the FluentHelperFunction class have it's own logic for getting a CSRF token?
What can I do to make this work properly. Or is this a bug in the SDK?
Logs:
=== HEAD before create entity - Returns CSRF token OK -
2020-11-19T08:54:57.02+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 >> \"HEAD http://dev-gateway-cd:443/sap/opu/odata/sap/ZCU_PE_CONCEPT_SRV HTTP/1.1[\\r][\\n]\"" }
2020-11-19T08:54:57.02+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 >> \"x-csrf-token: fetch[\\r][\\n]\"" }
2020-11-19T08:54:57.02+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 >> \"Accept: application/json[\\r][\\n]\"" }
2020-11-19T08:54:57.02+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 >> \"Content-Type: application/json[\\r][\\n]\"" }
2020-11-19T08:54:57.02+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 >> \"Proxy-Authorization: Bearer eyJh...." }
2020-11-19T08:54:57.02+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 >> \"SAP-Connectivity-Authentication: Bearer eyJh...." }
2020-11-19T08:54:57.02+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 >> \"X-Requested-With: X-Requested-With[\\r][\\n]\"" }
2020-11-19T08:54:57.02+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 >> \"sap-language: en[\\r][\\n]\"" }
2020-11-19T08:54:57.02+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 >> \"Host: dev-gateway-cd:443[\\r][\\n]\"" }
2020-11-19T08:54:57.02+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 >> \"Proxy-Connection: Keep-Alive[\\r][\\n]\"" }
2020-11-19T08:54:57.02+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 >> \"User-Agent: Apache-HttpClient/4.5.12 (Java/11.0.8)[\\r][\\n]\"" }
2020-11-19T08:54:57.02+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 >> \"Accept-Encoding: gzip,deflate[\\r][\\n]\"" }
2020-11-19T08:54:57.02+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 >> \"[\\r][\\n]\"" }
2020-11-19T08:54:57.10+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 << \"HTTP/1.1 200 OK[\\r][\\n]\"" }
2020-11-19T08:54:57.10+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 << \"content-type: text/html[\\r][\\n]\"" }
2020-11-19T08:54:57.10+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 << \"content-length: 0[\\r][\\n]\"" }
2020-11-19T08:54:57.10+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 << \"x-csrf-token: 38IQnzDSn6aZeqmFczbqQA==[\\r][\\n]\"" }
2020-11-19T08:54:57.10+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 << \"sap-processing-info: microhub=,crp=,st=,MedCacheHub=,codeployed=,softstate=-[\\r][\\n]\"" }
2020-11-19T08:54:57.10+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 << \"sap-perf-fesrec: 28128.000000[\\r][\\n]\"" }
2020-11-19T08:54:57.10+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 << \"set-cookie: sap-usercontext=sap-language=en&sap-client=550; path=/[\\r][\\n]\"" }
2020-11-19T08:54:57.10+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 << \"set-cookie: MYSAPSSO2=AjQxMDMBABhBAEwAMgAyADIANwA2ACAAIAAgACAAIAACAAY1ADUAMAADABBEAEcAVwAgACAAIAAgACAABAAYMgAwADIAMAAxADEAMQA5ADAANwA1ADQABQAEAAAACAYAAlgACQACRQD%2fASswggEnBgkqhkiG9w0BBwKgggEYMIIBFAIBATELMAkGBSsOAwIaBQAwCwYJKoZIhvcNAQcBMYH0MIHxAgEBMEcwOjEVMBMGA1UEChMMU0FQIFNlY3VyaXR5MSEwHwYDVQQDExhTZWN1cmUgTG9naW4gVXNlciBTdWIgQ0ECCQQz%21dD%2f97ncUTAJBgUrDgMCGgUAoF0wGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMjAxMTE5MDc1NDU3WjAjBgkqhkiG9w0BCQQxFgQU4PBXYuos4C1Bm%21YztJ4J8CdsGQ4wCQYHKoZIzjgEAwQuMCwCFCavVSRTFJsKNa3srFhnEbOByT8GAhRHSbed50wUDAOB4AYClz%2ftvf3pYg%3d%3d; path=/; domain=dev-gateway-cd; HttpOnly[\\r][\\n]\"" }
2020-11-19T08:54:57.10+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 << \"set-cookie: SAP_SESSIONID_DGW_550=4BFhS5Wq30GRv2nbzjuNh4RHkVUqPBHrpSgCOIUjX_g%3d; path=/; HttpOnly[\\r][\\n]\"" }
2020-11-19T08:54:57.10+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 << \"[\\r][\\n]\"" }
=== POST Create entity - Uses CSRF token from previous HEAD request -
2020-11-19T08:54:57.11+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 >> \"POST http://dev-gateway-cd:443/sap/opu/odata/sap/ZCU_PE_CONCEPT_SRV/HeaderSet HTTP/1.1[\\r][\\n]\"" }
2020-11-19T08:54:57.11+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 >> \"Accept: application/json[\\r][\\n]\"" }
2020-11-19T08:54:57.11+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 >> \"x-csrf-token: 38IQnzDSn6aZeqmFczbqQA==[\\r][\\n]\"" }
2020-11-19T08:54:57.11+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 >> \"Content-Type: application/json[\\r][\\n]\"" }
2020-11-19T08:54:57.11+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 >> \"Proxy-Authorization: Bearer eyJh...." }
2020-11-19T08:54:57.11+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 >> \"SAP-Connectivity-Authentication: Bearer eyJh...." }
2020-11-19T08:54:57.11+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 >> \"X-Requested-With: X-Requested-With[\\r][\\n]\"" }
2020-11-19T08:54:57.11+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 >> \"sap-language: en[\\r][\\n]\"" }
2020-11-19T08:54:57.11+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 >> \"Content-Length: 1223[\\r][\\n]\"" }
2020-11-19T08:54:57.11+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 >> \"Host: dev-gateway-cd:443[\\r][\\n]\"" }
2020-11-19T08:54:57.11+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 >> \"Proxy-Connection: Keep-Alive[\\r][\\n]\"" }
2020-11-19T08:54:57.11+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 >> \"User-Agent: Apache-HttpClient/4.5.12 (Java/11.0.8)[\\r][\\n]\"" }
2020-11-19T08:54:57.11+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 >> \"Cookie: MYSAPSSO2=AjQxMDMBABhBAEwAMgAyADIANwA2ACAAIAAgACAAIAACAAY1ADUAMAADABBEAEcAVwAgACAAIAAgACAABAAYMgAwADIAMAAxADEAMQA5ADAANwA1ADQABQAEAAAACAYAAlgACQACRQD%2fASswggEnBgkqhkiG9w0BBwKgggEYMIIBFAIBATELMAkGBSsOAwIaBQAwCwYJKoZIhvcNAQcBMYH0MIHxAgEBMEcwOjEVMBMGA1UEChMMU0FQIFNlY3VyaXR5MSEwHwYDVQQDExhTZWN1cmUgTG9naW4gVXNlciBTdWIgQ0ECCQQz%21dD%2f97ncUTAJBgUrDgMCGgUAoF0wGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMjAxMTE5MDc1NDU3WjAjBgkqhkiG9w0BCQQxFgQU4PBXYuos4C1Bm%21YztJ4J8CdsGQ4wCQYHKoZIzjgEAwQuMCwCFCavVSRTFJsKNa3srFhnEbOByT8GAhRHSbed50wUDAOB4AYClz%2ftvf3pYg%3d%3d; SAP_SESSIONID_DGW_550=4BFhS5Wq30GRv2nbzjuNh4RHkVUqPBHrpSgCOIUjX_g%3d; sap-usercontext=sap-language=en&sap-client=550[\\r][\\n]\"" }
2020-11-19T08:54:57.11+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 >> \"Accept-Encoding: gzip,deflate[\\r][\\n]\"" }
2020-11-19T08:54:57.11+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 >> \"[\\r][\\n]\"" }
2020-11-19T08:54:57.11+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 >> \"{\"DesNum\":\"290272\",\"PeItemSet\":[{\"InternPeId\":3,\"Taaklijst\":\"4316\",\"DesGuid\":\"02656ec2-ef0e-1edb-87b8-8a32b6cf28c7\",\"LevelCounter\":1,\"DesNum\":\"290272\",\"Supcunr\":2,\"Parcunr\":2,\"PeId\":\"43004631\",\"ProductID\":\"114010\",\"PeLevel\":3,\"PeTxt\":\"Aansluiting E AC4a tm 3x160A\",\"PeType\":\"1\",\"Uitvoeringsfactor\":\"1\",\"Eenheid\":\"ST\",\"SoortWerk\":\"00\"},{\"InternPeId\":2,\"Taaklijst\":\"2766\",\"DesGuid\":\"02656ec2-ef0e-1edb-87b8-8a32b6cf28c7\",\"LevelCounter\":1,\"DesNum\":\"290272\",\"Supcunr\":1,\"Parcunr\":2,\"PeId\":\"43003082\",\"ProductID\":\"114010\",\"PeLevel\":2,\"PeTxt\":\"E MAKEN AC4A AANSLUITING\",\"PeType\":\"V\",\"Uitvoeringsfactor\":\"1\",\"OptOmp\":false,\"SoortWerk\":\"05\",\"SoortWerkOmschrijving\":\"Uitbreiding\"},{\"InternPeId\":4,\"Taaklijst\":\"6317\",\"DesGuid\":\"02656ec2-ef0e-1edb-87b8-8a32b6cf28c7\",\"LevelCounter\":2,\"DesNum\":\"290272\",\"Supcunr\":1,\"Parcunr\":4,\"PeId\":\"43006902\",\"PeLevel\":2,\"PeTxt\":\"E Combi SION Baas Flevo\",\"PeType\":\"1\",\"Uitvoeringsfactor\":\"0\",\"Eenheid\":\"ST\",\"OptOmp\":false},{\"InternPeId\":5,\"Taaklijst\":\"4977\",\"DesGuid\":\"02656ec2-ef0e-1edb-87b8-8a32b6cf28c7\",\"LevelCounter\":3,\"DesNum\":\"290272\",\"Supcunr\":1,\"Parcunr\":5,\"PeId\":\"43005291\",\"PeLevel\":2,\"PeTxt\":\"ALG. PE-UREN - R\\u0026N\",\"PeType\":\"1\",\"Uitvoeringsfactor\":\"0\",\"Eenheid\":\"ST\",\"OptOmp\":false}]}\"" }
2020-11-19T08:54:57.65+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 << \"HTTP/1.1 201 Created[\\r][\\n]\"" }
2020-11-19T08:54:57.65+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 << \"content-type: application/json; charset=utf-8[\\r][\\n]\"" }
2020-11-19T08:54:57.65+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 << \"content-length: 739[\\r][\\n]\"" }
2020-11-19T08:54:57.65+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 << \"dataserviceversion: 2.0[\\r][\\n]\"" }
2020-11-19T08:54:57.65+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 << \"sap-processing-info: microhub=,crp=,st=,MedCacheHub=SHM,codeployed=,softstate=[\\r][\\n]\"" }
2020-11-19T08:54:57.65+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 << \"sap-perf-fesrec: 523322.000000[\\r][\\n]\"" }
2020-11-19T08:54:57.65+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 << \"content-encoding: gzip[\\r][\\n]\"" }
2020-11-19T08:54:57.65+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 << \"location: http://dev-gateway-cd:443/sap/opu/odata/sap/ZCU_PE_CONCEPT_SRV/HeaderSet('290272')[\\r][\\n]\"" }
2020-11-19T08:54:57.65+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-15 << \"[\\r][\\n]\"" }
=== HEAD before function call (FinalizeConcept) - Return 403 Forbidden response and no CSRF token -
2020-11-19T08:54:57.69+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 >> \"HEAD http://dev-gateway-cd:443/opu/odata/sap/ZCU_PE_CONCEPT_SRV HTTP/1.1[\\r][\\n]\"" }
2020-11-19T08:54:57.69+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 >> \"x-csrf-token: Fetch[\\r][\\n]\"" }
2020-11-19T08:54:57.69+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 >> \"Proxy-Authorization: Bearer eyJh...." }
2020-11-19T08:54:57.69+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 >> \"SAP-Connectivity-Authentication: Bearer eyJh...." }
2020-11-19T08:54:57.69+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 >> \"X-Requested-With: X-Requested-With[\\r][\\n]\"" }
2020-11-19T08:54:57.69+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 >> \"sap-language: en[\\r][\\n]\"" }
2020-11-19T08:54:57.69+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 >> \"Host: dev-gateway-cd:443[\\r][\\n]\"" }
2020-11-19T08:54:57.69+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 >> \"Proxy-Connection: Keep-Alive[\\r][\\n]\"" }
2020-11-19T08:54:57.69+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 >> \"User-Agent: Apache-HttpClient/4.5.12 (Java/11.0.8)[\\r][\\n]\"" }
2020-11-19T08:54:57.69+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 >> \"Accept-Encoding: gzip,deflate[\\r][\\n]\"" }
2020-11-19T08:54:57.69+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 >> \"[\\r][\\n]\"" }
2020-11-19T08:54:57.70+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 << \"HTTP/1.1 403 Forbidden[\\r][\\n]\"" }
2020-11-19T08:54:57.70+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 << \"content-type: text/plain; charset=utf-8[\\r][\\n]\"" }
2020-11-19T08:54:57.70+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 << \"content-length: 188[\\r][\\n]\"" }
2020-11-19T08:54:57.70+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 << \"[\\r][\\n]\"" }
2020-11-19T08:54:57.70+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 << \"Access denied to resource /opu/odata/sap/ZCU_PE_CONCEPT_SRV on system dev-gateway-cd:443. In case this was a valid request, ensure to expose the resource correctly in your cloud connector.\"" }
=== POST call function (FinalizeConcept) - Still executes request without CSRF token -
2020-11-19T08:54:57.70+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 >> \"POST http://dev-gateway-cd:443/sap/opu/odata/sap/ZCU_PE_CONCEPT_SRV/FinalizeConcept?contractPositie='00001'&contract='4600001985'&desNum='290272'&$format=json HTTP/1.1[\\r][\\n]\"" }
2020-11-19T08:54:57.70+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 >> \"x-csrf-token: [\\r][\\n]\"" }
2020-11-19T08:54:57.70+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 >> \"Proxy-Authorization: Bearer eyJh...." }
2020-11-19T08:54:57.70+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 >> \"SAP-Connectivity-Authentication: Bearer eyJh...." }
2020-11-19T08:54:57.70+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 >> \"X-Requested-With: X-Requested-With[\\r][\\n]\"" }
2020-11-19T08:54:57.70+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 >> \"sap-language: en[\\r][\\n]\"" }
2020-11-19T08:54:57.70+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 >> \"Host: dev-gateway-cd:443[\\r][\\n]\"" }
2020-11-19T08:54:57.70+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 >> \"Proxy-Connection: Keep-Alive[\\r][\\n]\"" }
2020-11-19T08:54:57.70+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 >> \"User-Agent: Apache-HttpClient/4.5.12 (Java/11.0.8)[\\r][\\n]\"" }
2020-11-19T08:54:57.70+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 >> \"Accept-Encoding: gzip,deflate[\\r][\\n]\"" }
2020-11-19T08:54:57.70+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 >> \"[\\r][\\n]\"" }
2020-11-19T08:55:13.56+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 << \"HTTP/1.1 200 OK[\\r][\\n]\"" }
2020-11-19T08:55:13.56+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 << \"content-type: application/json; charset=utf-8[\\r][\\n]\"" }
2020-11-19T08:55:13.56+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 << \"content-length: 856[\\r][\\n]\"" }
2020-11-19T08:55:13.56+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 << \"dataserviceversion: 2.0[\\r][\\n]\"" }
2020-11-19T08:55:13.56+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 << \"cache-control: no-cache, no-store[\\r][\\n]\"" }
2020-11-19T08:55:13.56+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 << \"pragma: no-cache[\\r][\\n]\"" }
2020-11-19T08:55:13.56+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 << \"sap-processing-info: microhub=,crp=,st=,MedCacheHub=SHM,codeployed=,softstate=[\\r][\\n]\"" }
2020-11-19T08:55:13.56+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 << \"sap-perf-fesrec: 15758403.000000[\\r][\\n]\"" }
2020-11-19T08:55:13.56+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 << \"set-cookie: sap-usercontext=sap-language=en&sap-client=550; path=/[\\r][\\n]\"" }
2020-11-19T08:55:13.56+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 << \"set-cookie: MYSAPSSO2=AjQxMDMBABhBAEwAMgAyADIANwA2ACAAIAAgACAAIAACAAY1ADUAMAADABBEAEcAVwAgACAAIAAgACAABAAYMgAwADIAMAAxADEAMQA5ADAANwA1ADQABQAEAAAACAYAAlgACQACRQD%2fASswggEnBgkqhkiG9w0BBwKgggEYMIIBFAIBATELMAkGBSsOAwIaBQAwCwYJKoZIhvcNAQcBMYH0MIHxAgEBMEcwOjEVMBMGA1UEChMMU0FQIFNlY3VyaXR5MSEwHwYDVQQDExhTZWN1cmUgTG9naW4gVXNlciBTdWIgQ0ECCQQz%21dD%2f97ncUTAJBgUrDgMCGgUAoF0wGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMjAxMTE5MDc1NDU3WjAjBgkqhkiG9w0BCQQxFgQU4PBXYuos4C1Bm%21YztJ4J8CdsGQ4wCQYHKoZIzjgEAwQuMCwCFAqryT5UyRSqtelnADn%214ExvPaHGAhQFUmkaZVG1UL%21iM4Wz3sb%21triClQ%3d%3d; path=/; domain=dev-gateway-cd; HttpOnly[\\r][\\n]\"" }
2020-11-19T08:55:13.56+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 << \"set-cookie: SAP_SESSIONID_DGW_550=ufIRFLfZoVbkIXV-6RengoRHkVwqPBHrpSgCOIUjX_g%3d; path=/; HttpOnly[\\r][\\n]\"" }
2020-11-19T08:55:13.56+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 << \"[\\r][\\n]\"" }
=== We do seem to receive a response
2020-11-19T08:55:13.56+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 << \"{\"d\":{\"__metadata\":{\"id\":\"https://vhanddgwci.hec.alliander.local:44300/sap/opu/odata/sap/ZCU_PE_CONCEPT_SRV/HeaderSet('290272')\",\"uri\":\"https://vhanddgwci.hec.alliander.local:44300/sap/opu/odata/sap/ZCU_PE_CONCEPT_SRV/HeaderSet('290272')\",\"type\":\"ZCU_PE_CONCEPT_SRV.Header\"},\"Contract\":\"4600001985\",\"DesGuid\":\"02656ec2-ef0e-1edb-87b8-8a32b6cf28c7\",\"PsReference\":\"\",\"ContractPositie\":\"00001\",\"DesNum\":\"290272\",\"DesType\":\"D\",\"Ktext\":\"PMD - 20201103 Artemisweg 55 Lelystad\",\"OhOrganisatie\":\"2300\",\"OhPlanningsgroep\":\"MCR\",\"Werkplek\":\"IPRH\",\"OhPrestatie\":\"R&N\",\"BasisStart\":\"\\/Date(1596153600000)\\/\",\"BasisEinde\":\"\\/Date(1597363200000)\\/\",\"PeOrder\":\"4108510\",\"Bouwmaatregel\":\"223942\",\"Wbs\":\"IPR-21007813-0001\",\"PeItemSet\":{\"__deferred\":{\"uri\":\"https://vhanddgwci.hec.alliander.local:44300/sap/opu/odata/sap/ZCU_PE_CONCEPT_SRV/HeaderSet('290272')/PeItemSet\"}}}}\"" }
2020-11-19T08:55:13.56+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.impl.conn.DefaultHttpResponseParser","level":"DEBUG","msg":"Garbage in response: Access denied to resource /opu/odata/sap/ZCU_PE_CONCEPT_SRV on system dev-gateway-cd:443. In case this was a valid request, ensure to expose the resource correctly in your cloud connector.HTTP/1.1 200 OK" }
2020-11-19T08:55:13.56+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.impl.conn.DefaultHttpResponseParser","level":"DEBUG","msg":"Garbage in response: content-type: application/json; charset=utf-8" }
2020-11-19T08:55:13.56+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.impl.conn.DefaultHttpResponseParser","level":"DEBUG","msg":"Garbage in response: content-length: 856" }
2020-11-19T08:55:13.56+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.impl.conn.DefaultHttpResponseParser","level":"DEBUG","msg":"Garbage in response: dataserviceversion: 2.0" }
2020-11-19T08:55:13.56+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.impl.conn.DefaultHttpResponseParser","level":"DEBUG","msg":"Garbage in response: cache-control: no-cache, no-store" }
2020-11-19T08:55:13.56+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.impl.conn.DefaultHttpResponseParser","level":"DEBUG","msg":"Garbage in response: pragma: no-cache" }
2020-11-19T08:55:13.56+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.impl.conn.DefaultHttpResponseParser","level":"DEBUG","msg":"Garbage in response: sap-processing-info: microhub=,crp=,st=,MedCacheHub=SHM,codeployed=,softstate=" }
2020-11-19T08:55:13.56+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.impl.conn.DefaultHttpResponseParser","level":"DEBUG","msg":"Garbage in response: sap-perf-fesrec: 15758403.000000" }
2020-11-19T08:55:13.56+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.impl.conn.DefaultHttpResponseParser","level":"DEBUG","msg":"Garbage in response: set-cookie: sap-usercontext=sap-language=en&sap-client=550; path=/" }
2020-11-19T08:55:13.56+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.impl.conn.DefaultHttpResponseParser","level":"DEBUG","msg":"Garbage in response: set-cookie: MYSAPSSO2=AjQxMDMBABhBAEwAMgAyADIANwA2ACAAIAAgACAAIAACAAY1ADUAMAADABBEAEcAVwAgACAAIAAgACAABAAYMgAwADIAMAAxADEAMQA5ADAANwA1ADQABQAEAAAACAYAAlgACQACRQD%2fASswggEnBgkqhkiG9w0BBwKgggEYMIIBFAIBATELMAkGBSsOAwIaBQAwCwYJKoZIhvcNAQcBMYH0MIHxAgEBMEcwOjEVMBMGA1UEChMMU0FQIFNlY3VyaXR5MSEwHwYDVQQDExhTZWN1cmUgTG9naW4gVXNlciBTdWIgQ0ECCQQz%21dD%2f97ncUTAJBgUrDgMCGgUAoF0wGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMjAxMTE5MDc1NDU3WjAjBgkqhkiG9w0BCQQxFgQU4PBXYuos4C1Bm%21YztJ4J8CdsGQ4wCQYHKoZIzjgEAwQuMCwCFAqryT5UyRSqtelnADn%214ExvPaHGAhQFUmkaZVG1UL%21iM4Wz3sb%21triClQ%3d%3d; path=/; domain=dev-gateway-cd; HttpOnly" }
2020-11-19T08:55:13.56+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.impl.conn.DefaultHttpResponseParser","level":"DEBUG","msg":"Garbage in response: set-cookie: SAP_SESSIONID_DGW_550=ufIRFLfZoVbkIXV-6RengoRHkVwqPBHrpSgCOIUjX_g%3d; path=/; HttpOnly" }
2020-11-19T08:55:13.56+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.impl.conn.DefaultHttpResponseParser","level":"DEBUG","msg":"Garbage in response: " }
=== Finally a "Read timeout"
2020-11-19T08:57:13.66+0100 [APP/PROC/WEB/0] OUT { "logger":"o.a.h.wire","level":"DEBUG","msg":"http-outgoing-16 << \"[read] I/O error: Read timed out\"" }
Thanks,
Danny

This is indeed a shortcoming in the SDK. In previous versions all create/update/delete/function requests would fail if CSRF token retrieval failed. This was improved for most of the code. But as of today (SDK version 3.33.0) functions still have this behaviour.
If you really need a workaround today the following should work for queries that use POST:
String servicePath = "/sap/opu/odata/sap/ZCU_PE_CONCEPT_SRV";
String functionCall = "CreateEntity?EntityKey='key'";
ODataRequestAction action = new ODataRequestAction(servicePath, functionCall, "", ODataProtocol.V2);
ODataRequestResultGeneric result = action.execute(HttpClientAccessor.getHttpClient(destination));
// in case there is a return value expected:
ResultFoo foo = result.as(ResultFoo.class);
This is not pretty since you have to hard-code most of the values. And it will also try to fetch a CSRF token. But crucially it will execute the request also with the token. You can prevent the SDK from fetching a CSRF token by setting a dummy value into the header: action.addHeader(DefaultCsrfTokenRetriever.X_CSRF_TOKEN_HEADER_KEY, "dummy")

Just noticing that the HEAD request for the function import call goes against a relative path which is unexpected: http://host:port/opu/odata/sap/ZCU_PE_CONCEPT_SRV
Normally OData APIs reside under the relative path /sap/opu/odata/sap/here-comes-the-api. You seem to miss the initial part sap in your relative path.
Can it be that you mistyped the path in your destination configuration?

We finally ended up implementing the workaround by creating the following method, based on the example workaround:
private Header callFinalizeFunction(final ExternalId peConceptId, final ExternalId contractId, final String contractPosition, HttpDestination destination) {
final String servicePath = ZCUPECONCEPTSRVService.DEFAULT_SERVICE_PATH;
Map<String, String> params = Map.of(
"desNum", peConceptId.getValue(),
"contract", contractId.getValue(),
"contractPositie", contractPosition);
String actionCall = "FinalizeConcept";
ODataRequestAction action = new ODataRequestAction(servicePath, actionCall, "", ODataProtocol.V2);
params.forEach((k,v) -> action.addQueryParameter(k, String.format("'%s'", v)));
return action
.execute(HttpClientAccessor.getHttpClient(destination))
.as(Header.class);
}

SAP Cloud SDK 3.34.1 available since yesterday ships an improved function import call invocation so that a failing CSRF token retrieval no longer breaks the function import call, but continues issuing the request and thereafter processing the function import result.
This is mainly useful in case the server does not support or requires CSRF tokens for any reason.

Related

Axios does not return XML error message from S3 when uploading asset over the size limit

Axios does not return XML error message from S3 when uploading asset over the size limit.
Environment
Axios Version : 0.24.0
Node.js Version: v14.17.4
OS: Mac OS 12.3
S3 is returning this XML error message when I try to uplaod an asset over teh size limit
UPLOAD FAILED. Status Code: 400. Error message:
<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>EntityTooLarge</Code><Message>Your proposed upload exceeds the maximum allowed size</Message><ProposedSize>52432788</ProposedSize><MaxSizeAllowed>52428800</MaxSizeAllowed><RequestId>N8RFYCS0K10GB4FF</RequestId><HostId>2OaG69rf19DMxItXx8J//rscZuSbxU8hJ/93du/a1zaFwAZa6jN2v1xCDebW4MRMgW3Kfuw0n10=</HostId></Error>
But Axios:
does not return it, just returns a generic error message: Request failed with status code 400"
and also breaks when trying to parse it.
This is the code I am running for the upload to S3:
let dataForm = new FormData();
dataForm.append('key', functionParams.uploadData.fields.key);
dataForm.append('bucket', functionParams.uploadData.fields.bucket);
dataForm.append('X-Amz-Algorithm', functionParams.uploadData.fields['X-Amz-Algorithm']);
dataForm.append('X-Amz-Credential', functionParams.uploadData.fields['X-Amz-Credential']);
dataForm.append('X-Amz-Date', functionParams.uploadData.fields['X-Amz-Date']);
dataForm.append('Policy', functionParams.uploadData.fields.Policy);
dataForm.append('X-Amz-Signature', functionParams.uploadData.fields['X-Amz-Signature']);
dataForm.append('file', fs.createReadStream(functionParams.assetFullPath),
{ knownLength: fs.statSync(functionParams.assetFullPath).size }
);
const uploadServiceURL = uploadData.url;
var config = {
method: 'POST',
url: uploadServiceURL,
headers: {
...dataForm.getHeaders(),
'content-length': dataForm.getLengthSync()
},
data: dataForm,
maxContentLength: Infinity,
maxBodyLength: Infinity,
transitional: {
forcedJSONParsing: false,
silentJSONParsing: false,
clarifyTimeoutError: true
}
};
axios(config)
.then(answer => {
resolve(answer);
})
.catch((error) => {
console.log(`Error:`)
console.log(error.toJSON())
reject(error)
})
This is the error I get from Axios:
{
"message": "Request failed with status code 400",
"name": "Error",
"stack": "Error: Request failed with status code 400\n at createError (/Users/vlad/modules/node_modules/axios/lib/core/createError.js:16:15)\n at settle (/Users/vlad/modules/axios/lib/core/settle.js:17:12)\n at IncomingMessage.handleStreamEnd (/Users/vlad/modules/node_modules/axios/lib/adapters/http.js:322:11)\n at IncomingMessage.emit (events.js:412:35)\n at endReadableNT (internal/streams/readable.js:1317:12)\n at processTicksAndRejections (internal/process/task_queues.js:82:21)",
"config": {
"transitional": {
"silentJSONParsing": false,
"forcedJSONParsing": false,
"clarifyTimeoutError": true
},
"transformRequest": [
null
],
"transformResponse": [
null
],
"timeout": 0,
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN",
"maxContentLength": null,
"maxBodyLength": null,
"headers": {
"Accept": "application/json, text/plain, */*",
"Content-Type": "multipart/form-data; boundary=--------------------------913873697821807580301477",
"content-length": 114310407,
"User-Agent": "axios/0.26.0"
},
"method": "post",
"url": "https://s3.us-east-1.amazonaws.com/public-assets.bluescape.com",
"data": {
"_overheadLength": 938,
"_valueLength": 114309413,
"_valuesToMeasure": [],
"writable": false,
"readable": true,
"dataSize": 0,
"maxDataSize": 2097152,
"pauseStreams": true,
"_released": true,
"_streams": [],
"_currentStream": null,
"_insideLoop": false,
"_pendingNext": false,
"_boundary": "--------------------------913873697821807580301477",
"_events": {},
"_eventsCount": 1
},
"axios-retry": {
"retryCount": 0,
"lastRequestTime": 1648080399442
}
},
"status": 400
}
Any idea how can I get back the XML from S3 describing the issue?
I want to present it as the cause of the error.
I have tried using “transformResponse“ to transform the response from remote server, but I cannot make it work and accept a new error message:
var config = {
method: 'POST',
url: uploadServiceURL,
headers: {
...dataForm.getHeaders(),
'content-length': dataForm.getLengthSync()
},
data: dataForm,
maxContentLength: Infinity,
maxBodyLength: Infinity,
transformResponse: [(response, headers) => {
var resp = response;
// Note: A successful upload to S3 will return an empty response, status code 204
if (response) {
console.log(` ---> response for ${functionParams.assetFullPath} : ${JSON.stringify(response, null, ' ')} `)
var resp;
try {
// Detect an error when parsing the answer: XML or something else
resp = JSON.parse(response)
console.log(`==> answer parsed:`)
console.log(JSON.stringify(resp, null, ' '))
} catch (error) {
console.log(` ===> ERROR parsing response for ${functionParams.assetFullPath}: ${JSON.stringify(error, null, ' ')}`)
// Trying to construct an XML response
resp = {
"test message": "manually created error message"
}
}
}
console.log(`----> Response to send back: ${JSON.stringify(resp, null, ' ')}`)
return resp;
}, ...axios.defaults.transformRequest],
transitional: {
forcedJSONParsing: false,
silentJSONParsing: false,
clarifyTimeoutError: true
}
};
Axios cannot automatically parse XML. You can get the response as a string if you use the text response type.
config = {...config, responseType: 'text'}
Then, the response will be included in answer.data as a string. Of course, if you need to do anything smarter than just printing the response, you'll still need to parse it by using the DOMParser, for example.

Home Assistant - Request failed Error code 400

I made this function to make it possible to send announcements to my google home mini but im getting error code 400 (Bad Request) nonstop. I tried using multiple approaches to this.
In Home-Assistant, i have setup my Google Home and can play media through it but whenever i try it with the "google_say" API of Home-Assistant it doesn't work.
I also tried calling the Home-Assistant API over my Phone using an App called "API Client" but i got the same response.
function ttsGoogleHome(text) {
var ttsUrl = "http://127.0.0.1:8123/api/services/tts/google_say?api_password=<MY_PASSWORD>"
var varToken = "<MY_TOKEN>"
var postData = {"entity_id": "media_player.david", "message": `${text}`};
let axiosConfig = {
headers: {
'authorization': `Bearer ${varToken}`,
'Content-Type': 'application/json',
"Access-Control-Allow-Origin": "*",
}
};
axios.post(ttsUrl, postData, axiosConfig)
.then((res) => {
console.log("RESPONSE RECEIVED: ", JSON.stringify(res));
})
.catch((err) => {
console.log("AXIOS ERROR: ", JSON.stringify(err));
})
}
This is the response i get in the server:
{
"message": "Request failed with status code 400",
"name": "Error",
"stack": "Error: Request failed with status code 400\n
at createError (/home/pi/nodejs/node_modules/axios/lib/core/createError.js:16:15)\n
at settle (/home/pi/nodejs/node_modules/axios/lib/core/settle.js:17:12)\n
at IncomingMessage.handleStreamEnd (/home/pi/nodejs/node_modules/axios/lib/adapters/http.js:260:11)\n
at IncomingMessage.emit (events.js:388:22)\n
at endReadableNT (internal/streams/readable.js:1336:12)\n
at processTicksAndRejections (internal/process/task_queues.js:82:21)",
"config": {
"url": "http://127.0.0.1:8123/api/services/tts/google_say?api_password=<MY_PASSWORD>",
"method": "post",
"data": "{\"entity_id\":\"media_player.david\",\"message\":\"Erste Stunde Fach Deutsch Lehrer Schemmer Raum Schemmer\"}",
"headers": {
"Accept": "application/json, text/plain, */*",
"Content-Type": "application/json;charset=UTF-8",
"authorization": "Bearer <MY_TOKEN>",
"Access-Control-Allow-Origin": "*",
"User-Agent": "axios/0.21.1",
"Content-Length": 103
},
"transformRequest": [
null
],
"transformResponse": [
null
],
"timeout": 0,
"xsrfCookieName": "XSRF-TOKEN",
"xsrfHeaderName": "X-XSRF-TOKEN",
"maxContentLength": -1,
"maxBodyLength": -1
}
}
I found my error.
I used the wrong api link
here is the correct way to call it.
function ttsGoogleHome(text) {
var ttsUrl = "http://127.0.0.1:8123/api/services/tts/google_translate_say?api_password=APIPASSWORD"
var varToken = "TOKEN"
var postData = `{"entity_id": "media_player.david", "message": "${text}", "language": "de"}`;
let axiosConfig = {
data: null,
headers: {
'authorization': `Bearer ${varToken}`,
'Content-Type': 'application/json',
"Access-Control-Allow-Origin": "*",
}
};
axios.post(ttsUrl, postData, axiosConfig)
.then((res) => {
console.clear();
console.info("RESPONSE RECEIVED: ", JSON.stringify(res));
})
.catch((err) => {
console.clear();
console.error("AXIOS ERROR: ", JSON.stringify(err));
})
}
also here is my configuration.yaml:
# Configure a default steup of Home Assistant (frontend, api, etc)
# Text to speech
tts:
- platform: google_translate
- language: "de"
- service_name: google_say
-base_url: http://192.168.0.176:8123
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
homeassistant:
auth_providers:
- type: legacy_api_password
api_password: !secret http_password

Amazon Sp-Api createFeedDocument, No Responding (Node.js) / And InvalidInput-contentType Error

I am trying to call the createFeedDocument operation to sp-api. But I never get a response.
Here is my signedRequest:
{
path: '/feeds/2020-09-04/documents',
method: 'POST',
host: 'sellingpartnerapi-fe.amazon.com',
region: 'us-west-2',
service: 'execute-api',
headers: {
'User-Agent': 'MyAmazonApp/1.0 (Language=JavaScript;)',
'x-amz-access-token': 'Atzasd61as689d1a1f89a189198ea1f891ad89d1e891f89ae189f189165',
Accept: 'application/json',
'Accept-Charset': 'utf-8',
Host: 'sellingpartnerapi-fe.amazon.com',
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
'Content-Length': 58,
'X-Amz-Security-Token': 'Fwa***********************************************',
'X-Amz-Date': '20210404T230040Z',
Authorization: 'AWS4-HMAC-SHA256 Credential=ASIASEECTM3DHQOSTQ4M/20210404/us-west-2/execute-api/aws4_request, SignedHeaders=accept;accept-charset;content-length;content-type;host;x-amz-access-token;x-amz-date;x-amz-security-token, Signature=f***********************************************e'
},
body: '{"contentType":"text/tab-separated-values; charset=UTF-8"}'
}
And if I tried to call this operation without body it gives the error shown below:
{
"statusCode": 400,
"res": {
"errors": [
{
"code": "InvalidInput",
"message": "One or more required parameters missing",
"details": "contentType;"
}
]
}
}
Your Content-Type header should be application/json

How to resolve error in external HTTP request from Node.js app

I'm trying to add an external HTTP request to a Node.js/Express app. When I add this request, I get an error 'ECONNREFUSED 127.0.0.1:80 '. I get this regardless of whether it is the Post request or a simple Get request to Google for instance. I am behind a corporate proxy that is configured and works with NPM.
For the client side:
$.ajax({
url: '/postRequest',
contentType: 'application/json',
type: 'POST',
dataType: 'json',
data: settings,
success: function (data) {
console.log(data);
}, error: function () {
console.log(data);
}
});
On the server side:
const axios = require('axios');
app.post('/postRequest', function (req, res) {
axios.get('https://google.com')
.then(response => {
res.send(response);
console.log('Successful response: ', response);
})
.catch(err => {
console.log('Unsuccessful response: ', err);
});
});
Here is the full error message:
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] toJSON: [Function] }
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] isAxiosError: true,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] response: undefined,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] _currentUrl: 'http:https://google.com/' },
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] parser: null },
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] _redirectable: [Circular],
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] _ended: false,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] path: 'https://google.com/',
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] method: 'GET',
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] timeout: undefined,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] socketPath: undefined,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] agent: [Object],
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] _onPendingData: null,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] _headerNames: [Object],
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] _headers: [Object],
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] _header: 'GET https://google.com/ HTTP/1.1\r\nAccept: application/json, text/plain, */*\r\nUser-Agent: axios/0.19.0\r\nhost: google.com\r\nConnection: close\r\n\r\n',
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] connection: [Object],
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] socket: [Object],
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] _headerSent: true,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] finished: true,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] _trailer: '',
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] _hasBody: true,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] _contentLength: 0,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] _removedHeader: {},
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] sendDate: false,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] useChunkedEncodingByDefault: false,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] shouldKeepAlive: false,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] chunkedEncoding: false,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] upgrading: false,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] _last: true,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] writable: true,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] outputSize: 0,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] outputCallbacks: [],
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] outputEncodings: [],
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] output: [],
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] _maxListeners: undefined,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] _eventsCount: 6,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] _events: [Object],
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] domain: null,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] ClientRequest {
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] _currentRequest:
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] _onNativeResponse: [Function],
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] _requestBodyBuffers: [],
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] _requestBodyLength: 0,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] _redirects: [],
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] _redirectCount: 0,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] pathname: 'https://google.com/' },
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] nativeProtocols: [Object],
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] host: null,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] port: null,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] hostname: null,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] auth: undefined,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] agent: undefined,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] headers: [Object],
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] maxBodyLength: 10485760,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] maxRedirects: 21,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] { protocol: 'http:',
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] _options:
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] _maxListeners: undefined,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] _eventsCount: 2,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] error: [Function: handleRequestError] },
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] { response: [Function: handleResponse],
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] _events:
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] domain: null,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] writable: true,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] corkedRequestsFree: [Object] },
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] bufferedRequestCount: 0,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] errorEmitted: false,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] prefinished: false,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] pendingcb: 0,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] lastBufferedRequest: null,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] bufferedRequest: null,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] writelen: 0,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] writecb: null,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] onwrite: [Function],
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] bufferProcessing: false,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] sync: true,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] corked: 0,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] writing: false,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] length: 0,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] defaultEncoding: 'utf8',
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] decodeStrings: true,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] finished: false,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] ended: false,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] ending: false,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] needDrain: false,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] highWaterMark: 16384,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] objectMode: false,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] WritableState {
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] _writableState:
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] Writable {
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] request:
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] data: undefined },
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] validateStatus: [Function: validateStatus],
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] maxContentLength: -1,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] xsrfHeaderName: 'X-XSRF-TOKEN',
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] xsrfCookieName: 'XSRF-TOKEN',
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] adapter: [Function: httpAdapter],
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] timeout: 0,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] transformResponse: [ [Function: transformResponse] ],
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] transformRequest: [ [Function: transformRequest] ],
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] host: 'google.com' },
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] 'User-Agent': 'axios/0.19.0',
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] { Accept: 'application/json, text/plain, */*',
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] headers:
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] method: 'get',
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] { url: 'https://google.com',
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] config:
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] port: 80,
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] address: '127.0.0.1',
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] syscall: 'connect',
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] errno: 'ECONNREFUSED',
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] code: 'ECONNREFUSED',
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1099:14)
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] at exports._exceptionWithHostPort (util.js:1043:20)
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] at Object.exports._errnoException (util.js:1020:11)
2019-07-15T14:54:41.298-05:00 [APP/PROC/WEB/0] [OUT] Unsuccessful response: { Error: connect ECONNREFUSED 127.0.0.1:80
"Locally you could also have an issue with a firewall blocking binds to addresses other than localhost. "
This ended up being the issue. Not a local firewall issue, but something a little more complicated in our firewall setup that was blocking the request.

What causes the ESOCKETTIMEDOUT or ECONNREFUSED error under load with Docker/Node?

Our Node API running on docker gets the ESOCKETTIMEDOUT or ECONNREFUSED error under load. This happens when we call the .NET API from node API.
{ [-]
_anonFuncCount: 3
_body: {"events":[{"serviceCategoryCode":{"codeValue":"core"},"eventNameCode":{"codeValue":"clock.punch","shortName":"Clock Punch"},"data":{"eventContext":{"associateOID":"","workAssignmentId":""},"transform":{"clockEntry":{"deviceDateTime":"2017-12-10T18:21:46-04:00","entryDateTime":"2017-12-10T18:21:46-04:00","actionCode":{"codeValue":"clockout","shortName":"clockout"},"laborAllocations":[]}}}}]}
_cacheURL: /api/offlinePunch
_clen: 424
_consuming: true
_contentType: application/json
_currentHandler: handler-2
_currentRoute: postapiofflinepunch100
_dtraceId: 5276
_dumped: false
_events: { [+]
}
_eventsCount: 4
_matchedVersion: 1.0.0
_negotiator: { [+]
}
_parsedBody: true
_readBody: true
_readableState: { [+]
}
_time: 1512958462607
_timerMap: { [+]
}
_url: { [+]
}
_version: \x7e1
body: { [+]
}
client: ~socket
complete: true
connection: ~socket
context: ~params
domain: null
headers: { [+]
}
httpVersion: 1.1
httpVersionMajor: 1
httpVersionMinor: 1
log: ~socket~_httpMessage~log
method: POST
params: { [+]
}
query: { [+]
}
rawBody: {"events":[{"serviceCategoryCode":{"codeValue":"core"},"eventNameCode":{"codeValue":"clock.punch","shortName":"Clock Punch"},"data":{"eventContext":{"associateOID":"","workAssignmentId":""},"transform":{"clockEntry":{"deviceDateTime":"2017-12-10T18:21:46-04:00","entryDateTime":"2017-12-10T18:21:46-04:00","actionCode":{"codeValue":"clockout","shortName":"clockout"},"laborAllocations":[]}}}}]}
rawHeaders: [ [+]
]
rawTrailers: [ [+]
]
readable: false
route: { [+]
}
serverName: time-clocking-api
socket: { [+]
}
statusCode: null
statusMessage: null
timers: [ [+]
]
trailers: { [+]
}
upgrade: false
url: /api/offlinePunch
uuid: f008be5d-ee11-4e1e-8ae4-afa47dc5e587
}
This is most likely due to the same issue here. Also,here is an excellent explanation of what is going on in node. You may have to set the UV_THREADPOOL_SIZE in your Docker Container.

Resources