Java 在http请求连接器中传递动态查询参数和路径参数
我希望将查询参数和路径参数列表传递给http请求mule连接器。此连接器的输入是一个pojo列表,其中包含查询和路径参数的值 http请求连接器如下所示:Java 在http请求连接器中传递动态查询参数和路径参数,java,spring,mule,mule-studio,mule-component,Java,Spring,Mule,Mule Studio,Mule Component,我希望将查询参数和路径参数列表传递给http请求mule连接器。此连接器的输入是一个pojo列表,其中包含查询和路径参数的值 http请求连接器如下所示: <http:request config-ref="HTTP_Request_Configuration" path="/rates/api/v1/rates/{in}.csv" method="GET" doc:name="End_HTTP request"> <http:request-builder> &
<http:request config-ref="HTTP_Request_Configuration" path="/rates/api/v1/rates/{in}.csv" method="GET" doc:name="End_HTTP request">
<http:request-builder>
<http:query-param paramName="api_key"
value="abcde" />
<http:query-param paramName="quote" value={target_currency} />
<http:query-param paramName="date" value={date} />
<http:query-param paramName="fields" value="averages" />
<http:uri-param paramName="in" value={source_currency} />
</http:request-builder>
如果http请求连接器的输入是数据类的对象,那么如何设置查询和路径参数
有人能帮我举个例子吗
多谢各位
Sumved我认为您需要在流中添加一个数据对象(流变量)。然后可以在请求生成器中使用变量,如
{flowVars.variable.someproperty}
首先必须将对象数据(即有效负载)中的值分配给所需的变量(targetCurrency、date、sourceCurrency),然后必须将变量的值分配给查询参数和路径参数。这里有一个例子:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:jms="http://www.mulesoft.org/schema/mule/jms"
xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
xmlns:file="http://www.mulesoft.org/schema/mule/file"
xmlns:ftp="http://www.mulesoft.org/schema/mule/ftp"
xmlns:db="http://www.mulesoft.org/schema/mule/db"
xmlns:mule-xml="http://www.mulesoft.org/schema/mule/xml"
xmlns:jersey="http://www.mulesoft.org/schema/mule/jersey"
xmlns:json="http://www.mulesoft.org/schema/mule/json"
xmlns:ws="http://www.mulesoft.org/schema/mule/ws"
xmlns:smtps="http://www.mulesoft.org/schema/mule/smtps"
xmlns:email="http://www.mulesoft.org/schema/mule/email"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd
http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ftp http://www.mulesoft.org/schema/mule/ftp/current/mule-ftp.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/jersey http://www.mulesoft.org/schema/mule/jersey/current/mule-jersey.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/ws http://www.mulesoft.org/schema/mule/ws/current/mule-ws.xsd
http://www.mulesoft.org/schema/mule/smtps http://www.mulesoft.org/schema/mule/smtps/current/mule-smtps.xsd
http://www.mulesoft.org/schema/mule/email http://www.mulesoft.org/schema/mule/email/current/mule-email.xsd
">
<http:listener-config name="HTTP_Listener_Configuration" host="localhost" port="8081" doc:name="HTTP Listener Configuration">
<http:worker-threading-profile maxThreadsActive="64" />
</http:listener-config>
<http:request-config name="HTTP_Request_Configuration" host="localhost" port="8081"/>
<flow name="testingFlowService">
<http:listener config-ref="HTTP_Listener_Configuration" path="/service/{waitTime}/*" doc:name="HTTP"/>
<logger message="Query Params: #[message.inboundProperties.'http.query.params']" level="INFO" doc:name="Log Failure"/>
<logger message="Uri Params: #[message.inboundProperties.'http.uri.params']" level="INFO" doc:name="Log Failure"/>
</flow>
<flow name="testingFlowClient">
<http:listener config-ref="HTTP_Listener_Configuration" path="/client/*" doc:name="HTTP"/>
<logger message="Before Transformation" level="INFO" />
<json:json-to-object-transformer returnClass="com.testing.domain.GeneralRequest" />
<set-variable variableName="processTypeJob" value="#[payload.processTypeJob]"/>
<set-variable variableName="waitTime" value="#[payload.waitTime]"/>
<logger message="After Transformation" level="INFO" />
<json:object-to-json-transformer/>
<http:request config-ref="HTTP_Request_Configuration" path="/service/{waitTime}" method="POST"
responseTimeout="50000000">
<http:request-builder>
<http:query-param paramName="api_key"
value="abcde" />
<http:query-param paramName="processTypeJob" value="#[processTypeJob]" />
<http:query-param paramName="fields" value="averages" />
<http:uri-param paramName="waitTime" value="#[waitTime]" />
</http:request-builder>
</http:request>
</flow>
</mule>
这是我正在使用的类:
package com.testing.domain;
import java.util.List;
public class GeneralRequest {
private String processTypeJob;
private String waitTime;
private List<String> processIds;
private String processTypeGroup;
private List<JobConfiguration> jobConfigurations;
public String getProcessTypeJob() {
return processTypeJob;
}
public void setProcessTypeJob(String processTypeJob) {
this.processTypeJob = processTypeJob;
}
public List<String> getProcessIds() {
return processIds;
}
public void setProcessIds(List<String> processIds) {
this.processIds = processIds;
}
public String getProcessTypeGroup() {
return processTypeGroup;
}
public void setProcessTypeGroup(String processTypeGroup) {
this.processTypeGroup = processTypeGroup;
}
public List<JobConfiguration> getJobConfigurations() {
return jobConfigurations;
}
public void setJobConfigurations(List<JobConfiguration> jobConfigurations) {
this.jobConfigurations = jobConfigurations;
}
public String getWaitTime() {
return waitTime;
}
public void setWaitTime(String waitTime) {
this.waitTime = waitTime;
}
}
package com.testing.domain;
导入java.util.List;
公共类一般请求{
私有字符串processTypeJob;
私有字符串等待时间;
私有列表进程ID;
私有字符串处理类型组;
私有列表作业配置;
公共字符串getProcessTypeJob(){
返回加工类型作业;
}
public void setProcessTypeJob(字符串processTypeJob){
this.processTypeJob=processTypeJob;
}
公共列表getProcessId(){
返回进程ID;
}
public void setProcessId(列出ProcessId){
this.processIds=processIds;
}
公共字符串getProcessTypeGroup(){
返回进程类型组;
}
public void setProcessTypeGroup(字符串processTypeGroup){
this.processTypeGroup=processTypeGroup;
}
公共列表GetJobConfiguration(){
返回作业配置;
}
public void setJobConfigurations(列出jobConfigurations){
this.jobConfigurations=jobConfigurations;
}
公共字符串getWaitTime(){
返回等待时间;
}
公共void setWaitTime(字符串waitTime){
this.waitTime=waitTime;
}
}
有关更多信息,请参见下一个链接:
在“http:request”之前,流的有效负载是多少?是数据列表还是仅是数据类的实例?。因为在问题的第一部分你谈论一个列表,在最后一部分你谈论一个对象。
package com.testing.domain;
import java.util.List;
public class GeneralRequest {
private String processTypeJob;
private String waitTime;
private List<String> processIds;
private String processTypeGroup;
private List<JobConfiguration> jobConfigurations;
public String getProcessTypeJob() {
return processTypeJob;
}
public void setProcessTypeJob(String processTypeJob) {
this.processTypeJob = processTypeJob;
}
public List<String> getProcessIds() {
return processIds;
}
public void setProcessIds(List<String> processIds) {
this.processIds = processIds;
}
public String getProcessTypeGroup() {
return processTypeGroup;
}
public void setProcessTypeGroup(String processTypeGroup) {
this.processTypeGroup = processTypeGroup;
}
public List<JobConfiguration> getJobConfigurations() {
return jobConfigurations;
}
public void setJobConfigurations(List<JobConfiguration> jobConfigurations) {
this.jobConfigurations = jobConfigurations;
}
public String getWaitTime() {
return waitTime;
}
public void setWaitTime(String waitTime) {
this.waitTime = waitTime;
}
}