Spring integration HTTP出站网关-传递URI参数
我需要通过Spring集成的HTTP出站网关调用RESTAPI。如何用有效负载中的值替换path变量。有效负载只有一个字符串值。下面的代码片段正在发送占位符。感谢您的帮助Spring integration HTTP出站网关-传递URI参数,spring-integration,Spring Integration,我需要通过Spring集成的HTTP出站网关调用RESTAPI。如何用有效负载中的值替换path变量。有效负载只有一个字符串值。下面的代码片段正在发送占位符。感谢您的帮助 @Bean public MessageHandler httpGateway(@Value("http://localhost:8080/api/test-resource/v1/{parameter1}/codes") URI uri) { HttpRequestExecutingMessageHandler
@Bean
public MessageHandler httpGateway(@Value("http://localhost:8080/api/test-resource/v1/{parameter1}/codes") URI uri) {
HttpRequestExecutingMessageHandler httpHandler = new HttpRequestExecutingMessageHandler(uri);
httpHandler.setExpectedResponseType(Map.class);
httpHandler.setHttpMethod(HttpMethod.GET);
Map<String, Expression> uriVariableExp = new HashMap();
SpelExpressionParser parser = new SpelExpressionParser();
uriVariableExp.put("parameter1", parser.parseExpression("payload.Message"));
httpHandler.setUriVariableExpressions(uriVariableExp);
return httpHandler;
}
@Bean
public MessageHandler httpGateway(@Value(“http://localhost:8080/api/test-资源/v1/{parameter1}/codes“)URI){
HttpRequestExecutingMessageHandler httpHandler=新的HttpRequestExecutingMessageHandler(uri);
setExpectedResponseType(Map.class);
setHttpMethod(HttpMethod.GET);
Map uriVariableExp=新HashMap();
SpelExpressionParser=新建SpelExpressionParser();
uriVariableExp.put(“参数1”,parser.parseExpression(“payload.Message”);
setUriVariableExpressions(uriVariableExp);
返回httpHandler;
}
首先让我们看看@Value
是什么
* Annotation at the field or method/constructor parameter level
* that indicates a default value expression for the affected argument.
*
* <p>Typically used for expression-driven dependency injection. Also supported
* for dynamic resolution of handler method parameters, e.g. in Spring MVC.
*
* <p>A common use case is to assign default field values using
* "#{systemProperties.myProp}" style expressions.
虽然在这种情况下没关系
你的代码看起来不错,除非我们不知道你的负载是什么。
这个payload.Message
表达式看起来很奇怪。从大高度看,它可能意味着类似于MyClass.getMessage()
,但它不能调用getter,因为您使用了大写的属性名。如果你真的有这样一个getter,那么就像payload.message
那样使用它。否则,请详细说明。一些日志、StackTrace、有关有效负载的信息等。。。现在还不清楚问题出在哪里。首先让我们看看@Value
是什么
* Annotation at the field or method/constructor parameter level
* that indicates a default value expression for the affected argument.
*
* <p>Typically used for expression-driven dependency injection. Also supported
* for dynamic resolution of handler method parameters, e.g. in Spring MVC.
*
* <p>A common use case is to assign default field values using
* "#{systemProperties.myProp}" style expressions.
虽然在这种情况下没关系
你的代码看起来不错,除非我们不知道你的负载是什么。
这个payload.Message
表达式看起来很奇怪。从大高度看,它可能意味着类似于MyClass.getMessage()
,但它不能调用getter,因为您使用了大写的属性名。如果你真的有这样一个getter,那么就像payload.message
那样使用它。否则,请详细说明。一些日志、StackTrace、有关有效负载的信息等。。。现在还不清楚是什么问题。谢谢你,阿泰姆。它现在运转良好。我已经将url移动到application.properties并更新了下面的表达式uriVariableExp.put(“参数1”,parser.parseExpression(“负载”);谢谢你,阿泰姆。它现在运转良好。我已经将url移动到application.properties并更新了下面的表达式uriVariableExp.put(“参数1”,parser.parseExpression(“负载”);