我想使用Spring集成调用Apache Solr。Solr提供rest式的搜索功能,例如:我想调用:http://localhost:8983/solr/#/ccy/query?q=id:*&wt=json
,这将返回一个json字符串。
所以计划是提供一个ReferenceData控制器,它调用一个服务,而这个服务又通过spring集成调用Solr。但我需要响应是同步的。
我查看了提供的Spring集成示例代码,并遇到了rest-http示例。但它要越过我的头顶。那么我该怎么做呢?任何代码示例都会很有用。
谢谢通用汽车
其余的示例集中在服务器端;在客户端,您需要像…
这样的东西。<int:gateway id="toRest" default-request-channel="foo" service-interface="ToRest" />
<int:channel id="foo" />
<int-http:outbound-gateway id="out" request-channel="foo"
http-method="GET"
url="http://localhost:8983/solr/ccy/query?q=id:{currency}&wt=json">
<int-http:uri-variable name="currency" expression="headers['currency']"/>
</int-http:outbound-gateway>
与ToRest
是一个Java接口的方法类似String toRest(String in)
;将ToRest实例注入到控制器中,然后发送一个空字符串"。
但是,我认为URL中间的#
会给您带来麻烦。
增加了uri-variable
-表达式可以是任何SpEL表达式,例如payload.currency
(在消息负载上调用getCurrency()
);headers['currency']
;或@someBean.determineCurrency(payload)
;等等等等。
您的网关可以填充报头…
String result(@Payload String payload, @Header("currency") String currency);
当然,由于您只执行GET操作,因此您可以简单地在有效负载中设置货币并使用expression="payload"
。
关于散列标签,请查看:http://en.wikipedia.org/wiki/Fragment_identifier
片段标识符的功能不同于URI的其余部分:也就是说,它的处理完全是客户端,没有web服务器的参与