SergeZ
SergeZ

Reputation: 408

Turn CURL in Spring RestTemplate

I'm a little bit confused...

I tried to rewrite the following curl command: http://:/solr/test2_shard1_replica1/update?commit=true -H "Content-Type: text/xml" --data-binary '111alphadevx'

using StringFramework RestTemplate class and method postForObject(url, request, response_class), but had no luck. I mean, it seems, that request goes normally, but there is absolutely no effect in SolrCloud...

Here is the code:

MultiValueMap<String, Object> requestMap = new LinkedMultiValueMap<>();
requestMap.add("Content-Type", "text/xml");
requestMap.add("data-binary", dataToSend);

String sentData =      restTemplate.postForObject("http://<solr_server>:<solr_port>/solr/test1_shard1_replica1/update?commit=true",     requestMap, String.class);

is there a mistake ?

Very appreciate any suggestions

Upvotes: 1

Views: 5388

Answers (1)

SergeZ
SergeZ

Reputation: 408

I got it

The following is the right way to do this:

HttpHeaders headers = new HttpHeaders();
headers.setContentType(org.springframework.http.MediaType.TEXT_XML);
HttpEntity<String> entity = new HttpEntity<>(dataToSend, headers);
ResponseEntity<String> sentData = restTemplate.exchange(((shardAddress == null ? ("http://" +     this.address + ":" + this.port + "/solr") : (this.shardAddress))) + "/test1_shard1_replica1/update?commit=true", HttpMethod.POST, entity, String.class);

Upvotes: 1

Related Questions