nialloc
nialloc

Reputation: 1193

Stop URITemplate expansion when using Spring RESTTemplate

I am using the Spring RestTemplate to make calls to a Apache Solr index. I form a request string manually and don't supply any intentional {variable_name} template expansion variables. Part of the query is the term {!lucene q.op=OR}. Unfortunately this gets processed by the URITemplate engine as part of a restTemplate.getForObject call.

Ideally i would like to stop this processing. Is there away of escaping the { } characters so that URITemplate doesn't process them? I have tried encoding the characters but RestTemplate assumes a non-encoded string so they are encoded twice and cause a 400: Bad Request on the backend.

Sample URL:

http://localhost/solr/select?q={!lucene q.op=OR}se_genbanklocus:* se_gb_create:* se_gb_update:* se_clone_name:* se_sample_tissue:*&facet=true&facet.limit=3&facet.mincount=1&facet.field=se_sample_tissue&facet.field=se_sample_tissue_name&facet.field=se_sample_tissue_code&facet.field=se_sample_tissue_class&facet.field=se_nuc_acid_type&facet.field=ssam_sample_georegion&start=0&rows=10

Upvotes: 0

Views: 3782

Answers (3)

Rossen Stoyanchev
Rossen Stoyanchev

Reputation: 5018

How about using the overloaded method that accepts a URI?

Upvotes: 1

skaffman
skaffman

Reputation: 403591

The problem here is that you're using RestTemplate for something it's not designed for. The sample URL you gave is not a REST-style URL, it's just a mass of query parameters, using encoded characters that you're not going to find in a REST scheme, hence the difficulty with unwanted substitutions.

Upvotes: 1

nialloc
nialloc

Reputation: 1193

I've found a work around in which i can use the template to expand one variable which contains the offending {!lucene q.op=OR}

restTemplate.getForObject(solrServer+"select?{query}" , String.class, requestString );

Upvotes: 2

Related Questions