使用 Spring RESTTemplate 时停止 URITemplate 扩展

发布于 2024-09-12 21:26:53 字数 875 浏览 3 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

毅然前行 2024-09-19 21:26:53

我找到了一种解决方法,可以使用模板来扩展一个包含有问题的 {!lucene q.op=OR} 变量

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

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 );
温柔女人霸气范 2024-09-19 21:26:53

这里的问题是您使用 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.

ヅ她的身影、若隐若现 2024-09-19 21:26:53

使用接受 URI 的重载方法怎么样?

How about using the overloaded method that accepts a URI?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文