我通过 Spring Integration 调用外部 HTTP URL,但我的 URL 完全硬编码在 spring 上下文文件中。
我想:
- 从我的程序传递查询参数(即 a=1&b=2&c=3)
- 从我的程序传递 URL 本身(i.e http://host/port/xyz
)
我的 Spring Integration Context 文件当前如下所示:
<int:gateway id="requestGateway"
service-interface="com.bingo.RequestGateway"
default-request-channel="requestChannel"/>
<int:channel id="requestChannel"/>
<int-http:outbound-gateway request-channel="requestChannel"
url="http//host:port/xyz?a=1&b=2&c=3"
http-method="GET"
expected-response-type="java.lang.String"/>
调用它的java代码是:
public static void main(String args[])
{
ApplicationContext context = new ClassPathXmlApplicationContext(
"spring-integr.xml");
RequestGateway requestGateway = context.getBean("requestGateway",
RequestGateway.class);
String reply = requestGateway.sendMyRequest("");
System.out.println("Replied with: " + reply);
}
还:
public interface RequestGateway {
public String sendMyRequest(String request);
}
如何通过我的http://host:port/xyz
程序传递 URL(),尤其是参数(a=1&b=2&c=3)?