使用 Spring RESTTemplate 时停止 URITemplate 扩展
我正在使用 Spring RestTemplate 来调用 Apache Solr 索引。我手动形成请求字符串,并且不提供任何有意的 {variable_name} 模板扩展变量。查询的一部分是术语 {!lucene q.op=OR}。不幸的是,这由 URITemplate 引擎作为restTemplate.getForObject 调用的一部分进行处理。
理想情况下我想停止这个处理。是否可以转义 { } 字符以使 URITemplate 不处理它们?我尝试过对字符进行编码,但 RestTemplate 假定为非编码字符串,因此它们被编码两次并导致后端出现 400: Bad Request。
示例网址:
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我找到了一种解决方法,可以使用模板来扩展一个包含有问题的
{!lucene q.op=OR}
变量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
来完成它不适合的事情。您提供的示例 URL 不是 REST 样式的 URL,它只是大量查询参数,使用您在 REST 方案中找不到的编码字符,因此很难进行不需要的替换。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.使用接受 URI 的重载方法怎么样?
How about using the overloaded method that accepts a URI?