我正在尝试使用 Mule SDK 实施 Mule 4.x 策略。为此,我需要在策略操作实现中调用外部 API。外部 API 响应返回的结果将确定策略输出。
public class MyMulePolicyOperations
{
@MediaType( value = ANY, strict = false )
public void handle(
@Config MyMulePolicyConfiguration configuration,
@Alias( "httpRequestMethod" ) String httpRequestMethod,
CompletionCallback<String, HttpResponse> callback ) throws Exception
{
HttpResponseBuilder httpResponseBuilder = HttpResponse.builder();
String result = // call an external API and extract "result" from the response
if ( result.equals( configuration.getMyConfigValue() ) )
{
httpResponseBuilder.addHeader( "allow_request", "true" );
}
else
{
httpResponseBuilder.addHeader( "allow_request", "false" );
}
Result<String, HttpResponse> result = Result.<String, HttpResponse> builder()
.attributes( httpResponseBuilder.build() )
.build();
callback.success( result );
}
}
有人可以告诉我如何使用 Mule SDK 实现 REST 客户端吗?