Hi, I am having trouble setting requestBody for POST calls when using crisp API. As mentioned in the official document, ExchangeHintBuilder can be used to specify the methodName, requestHeader and requestBody.(https://documentation.bloomreach.com/library/concepts/crisp-api/getting-started.html)
I have to make a call where the content-type is application/x-www-form-urlencoded. I have tried setting this requestHeader but unfortunately this does not work for me.
The same call in POSTMAN works fine when I set the content-type. POSTMAN also appends some temporary request headers like Accept-Encoding, Content-length, UserAgent, Host etc…
Can someone help me understand where am I going wrong?
I have attached the snippet responsible for this below:
Resource resource = resourceServiceBroker.resolve(“catalog”,path,
ExchangeHintBuilder.create()
.methodName(“POST”)
.requestHeader(“Accept-Encoding”,“gzip”,“deflate”)
.requestHeader(“Content-Type”,“application/x-www-form-urlencoded”)
.requestHeader(“Content-Length”,“24”)
.requestHeader(“Host”,“cat.host.org”)
.requestBody(“bib=004046593|Equipment0”)
.build());
Do I need to append every request header before making the call or are there some headers which will be taken care of by CRISP like content-length? Is there some property that needs to be set when making POST calls that I have missed?
Hi,
Can you try with bib%3D004046593%7CEquipment0
instead of the unencoded body data?
Also, try after removing Accept-Encoding
and Content-Length
request headers.
CRISP uses Spring Framework RestTemplate
which uses Apache HttpComponents HttpClient. I guess that it should be okay without Content-Length
in request or HttpClient would set it automatically.
Hey, I tried with the URLencoded string as well.
Resource resource = resourceServiceBroker.resolve(“catalog”,path,
ExchangeHintBuilder.create()
.methodName(“POST”)
.requestHeader(“Content-Type”,“application/x-www-form-urlencoded”)
.requestBody(“bib%3D004046593%7CEquipment0”)
.build());
This did not work for me
Sorry, I mean this: .requestBody("bib=004046593%7CEquipment0")
.
If this doesn’t work either, could you somehow monitor the http request payload between crisp call and postman call?
Also, you can see debug logs in HttpClient level by setting these even if it’s really verbose:
<Logger name="org.apache.http" level="debug" />
<Logger name="org.apache.http.wire" level="debug" />
Sorry for the late reply.
Resource resource = resourceServiceBroker.resolve("catalog",path,
ExchangeHintBuilder.create()
.methodName("POST")
.requestHeader("Content-Type","application/x-www-form-urlencoded")
.requestBody("bib=004046593%7CEquipment0")
.build());
The logs from console:
[INFO] [talledLocalContainer] 13.11.2019 12:11:36 DEBUG http-nio-8080-exec-9 [Wire.wire:73] http-outgoing-4 >> “GET /cgi-bin/laptops HTTP/1.1[\r][\n]”
[INFO] [talledLocalContainer] 13.11.2019 12:11:36 DEBUG http-nio-8080-exec-9 [Wire.wire:73] http-outgoing-4 >> “Accept: text/plain, application/json, application/*+json, /[\r][\n]”
[INFO] [talledLocalContainer] 13.11.2019 12:11:36 DEBUG http-nio-8080-exec-9 [Wire.wire:73] http-outgoing-4 >> “Host: cat.host.org[\r][\n]”
[INFO] [talledLocalContainer] 13.11.2019 12:11:36 DEBUG http-nio-8080-exec-9 [Wire.wire:73] http-outgoing-4 >> “Connection: Keep-Alive[\r][\n]”
[INFO] [talledLocalContainer] 13.11.2019 12:11:36 DEBUG http-nio-8080-exec-9 [Wire.wire:73] http-outgoing-4 >> “User-Agent: Apache-HttpClient/4.5.6 (Java/1.8.0_222)[\r][\n]”
[INFO] [talledLocalContainer] 13.11.2019 12:11:36 DEBUG http-nio-8080-exec-9 [Wire.wire:73] http-outgoing-4 >> “Accept-Encoding: gzip,deflate[\r][\n]”
[INFO] [talledLocalContainer] 13.11.2019 12:11:36 DEBUG http-nio-8080-exec-9 [Wire.wire:73] http-outgoing-4 >> “[\r][\n]”
[INFO] [talledLocalContainer] 13.11.2019 12:11:36 DEBUG http-nio-8080-exec-9 [Wire.wire:73] http-outgoing-4 << “HTTP/1.1 200 OK[\r][\n]”
[INFO] [talledLocalContainer] 13.11.2019 12:11:36 DEBUG http-nio-8080-exec-9 [Wire.wire:73] http-outgoing-4 << “Date: Wed, 13 Nov 2019 17:11:37 GMT[\r][\n]”
[INFO] [talledLocalContainer] 13.11.2019 12:11:36 DEBUG http-nio-8080-exec-9 [Wire.wire:73] http-outgoing-4 << “Server: Apache[\r][\n]”
[INFO] [talledLocalContainer] 13.11.2019 12:11:36 DEBUG http-nio-8080-exec-9 [Wire.wire:73] http-outgoing-4 << “Pragma: no-cache[\r][\n]”
[INFO] [talledLocalContainer] 13.11.2019 12:11:36 DEBUG http-nio-8080-exec-9 [Wire.wire:73] http-outgoing-4 << “Expires: Fri, 01 Jan 2000 00:00:00 GMT[\r][\n]”
[INFO] [talledLocalContainer] 13.11.2019 12:11:36 DEBUG http-nio-8080-exec-9 [Wire.wire:73] http-outgoing-4 << “Cache-Control: No-Cache, No-Store[\r][\n]”
[INFO] [talledLocalContainer] 13.11.2019 12:11:36 DEBUG http-nio-8080-exec-9 [Wire.wire:73] http-outgoing-4 << “Keep-Alive: timeout=15, max=100[\r][\n]”
[INFO] [talledLocalContainer] 13.11.2019 12:11:37 DEBUG http-nio-8080-exec-9 [Wire.wire:73] http-outgoing-4 << “Connection: Keep-Alive[\r][\n]”
[INFO] [talledLocalContainer] 13.11.2019 12:11:37 DEBUG http-nio-8080-exec-9 [Wire.wire:73] http-outgoing-4 << “Transfer-Encoding: chunked[\r][\n]”
[INFO] [talledLocalContainer] 13.11.2019 12:11:37 DEBUG http-nio-8080-exec-9 [Wire.wire:73] http-outgoing-4 << “Content-Type: text/html; charset=ISO-8859-1[\r][\n]”
[INFO] [talledLocalContainer] 13.11.2019 12:11:37 DEBUG http-nio-8080-exec-9 [Wire.wire:73] http-outgoing-4 << “[\r][\n]”
[INFO] [talledLocalContainer] 13.11.2019 12:11:37 DEBUG http-nio-8080-exec-9 [LoggingManagedHttpClientConnection.onResponseReceived:122] http-outgoing-4 << HTTP/1.1 200 OK
[INFO] [talledLocalContainer] 13.11.2019 12:11:37 DEBUG http-nio-8080-exec-9 [LoggingManagedHttpClientConnection.onResponseReceived:125] http-outgoing-4 << Date: Wed, 13 Nov 2019 17:11:37 GMT
[INFO] [talledLocalContainer] 13.11.2019 12:11:37 DEBUG http-nio-8080-exec-9 [LoggingManagedHttpClientConnection.onResponseReceived:125] http-outgoing-4 << Server: Apache
[INFO] [talledLocalContainer] 13.11.2019 12:11:37 DEBUG http-nio-8080-exec-9 [LoggingManagedHttpClientConnection.onResponseReceived:125] http-outgoing-4 << Pragma: no-cache
[INFO] [talledLocalContainer] 13.11.2019 12:11:37 DEBUG http-nio-8080-exec-9 [LoggingManagedHttpClientConnection.onResponseReceived:125] http-outgoing-4 << Expires: Fri, 01 Jan 2000 00:00:00 GMT
[INFO] [talledLocalContainer] 13.11.2019 12:11:37 DEBUG http-nio-8080-exec-9 [LoggingManagedHttpClientConnection.onResponseReceived:125] http-outgoing-4 << Cache-Control: No-Cache, No-Store
[INFO] [talledLocalContainer] 13.11.2019 12:11:37 DEBUG http-nio-8080-exec-9 [LoggingManagedHttpClientConnection.onResponseReceived:125] http-outgoing-4 << Keep-Alive: timeout=15, max=100
[INFO] [talledLocalContainer] 13.11.2019 12:11:37 DEBUG http-nio-8080-exec-9 [LoggingManagedHttpClientConnection.onResponseReceived:125] http-outgoing-4 << Connection: Keep-Alive
[INFO] [talledLocalContainer] 13.11.2019 12:11:37 DEBUG http-nio-8080-exec-9 [LoggingManagedHttpClientConnection.onResponseReceived:125] http-outgoing-4 << Transfer-Encoding: chunked
[INFO] [talledLocalContainer] 13.11.2019 12:11:37 DEBUG http-nio-8080-exec-9 [LoggingManagedHttpClientConnection.onResponseReceived:125] http-outgoing-4 << Content-Type: text/html; charset=ISO-8859-1
[INFO] [talledLocalContainer] 13.11.2019 12:11:37 DEBUG http-nio-8080-exec-9 [MainClientExec.execute:285] Connection can be kept alive for 15000 MILLISECONDS
[INFO] [talledLocalContainer] 13.11.2019 12:11:37 DEBUG http-nio-8080-exec-9 [Wire.wire:73] http-outgoing-4 << “fd1[\r][\n]”
[INFO] [talledLocalContainer] 13.11.2019 12:11:37 DEBUG http-nio-8080-exec-9 [Wire.wire:73] http-outgoing-4 << “[\n]”
[INFO] [talledLocalContainer] 13.11.2019 12:11:37 DEBUG http-nio-8080-exec-9 [Wire.wire:73] http-outgoing-4 << “[\n]”
[INFO] [talledLocalContainer] 13.11.2019 12:11:37 DEBUG http-nio-8080-exec-9 [Wire.wire:73] http-outgoing-4 << “[\n]”
[INFO] [talledLocalContainer] 13.11.2019 12:11:37 DEBUG http-nio-8080-exec-9 [Wire.wire:73] http-outgoing-4 << “[\n]”
.
.
.[Response]
.
.
[INFO] [talledLocalContainer] 13.11.2019 12:12:03 DEBUG http-nio-8080-exec-9 [PoolingHttpClientConnectionManager.releaseConnection:341] Connection [id: 4][route: {s}->https://cat.host.org:443] can be kept alive for 15.0 seconds
[INFO] [talledLocalContainer] 13.11.2019 12:12:03 DEBUG http-nio-8080-exec-9 [LoggingManagedHttpClientConnection.setSocketTimeout:88] http-outgoing-4: set socket timeout to 0
[INFO] [talledLocalContainer] 13.11.2019 12:12:03 DEBUG http-nio-8080-exec-9 [PoolingHttpClientConnectionManager.releaseConnection:348] Connection released: [id: 4][route: {s}->https://cat.host.org:443][total kept alive: 3; route allocated: 1 of 200; total allocated: 3 of 600]
Looks like CRISP makes a GET call rather than a POST call.
HTTP Code from Postman:
POST /cgi-bin/laptops HTTP/1.1
Host: cat.org.umd
Content-Type: application/x-www-form-urlencoded
User-Agent: PostmanRuntime/7.19.0
Accept: /
Cache-Control: no-cache
Postman-Token: 7c33158f-4340-422b-adf3-79889ffd00b5,7a28acb5-de76-4efb-8843-1fcf0b897d38
Accept-Encoding: gzip, deflate
Content-Length: 24
Connection: keep-alive
cache-control: no-cache
bib=004046593|Equipment0
I am stuck with this from quite some time, any help is really appreciated.
If you need more direct or speedy support than this community provides I suggest you make contact with Bloomreach or one of our partners. If you are working on an enterprise project you likely already have some level of support. This community can only offer limited support and only so far as the members are able and willing.
That’s weird. What are the version(s)?
If possible, you can put a debugger at org.onehippo.cms7.crisp.core.resource.jackson.SimpleJacksonRestTemplateResourceResolver#resolve(String, Map<String, Object>, ExchangeHint)
method where the ExchangeHint#methodName()
is read and invocation with either POST
or GET
is made.
Regards,
Woonsan
Thanks so much for that comment. I had created my own resolver and was not handling the POST call within the resolver because of which it was always making a GET call.
Thanks for the update, Pankul!