1

In the below code I'm transforming the payload to a different payload and sending it as a request body to a POST API call. I want to outsource that transformation through a external method call. Is that possible?

    @Bean
            public IntegrationFlow flow3(){
                return integrationFlowDefinition -> integrationFlowDefinition
                        .channel(c -> c.executor(Executors.newCachedThreadPool())).log()
//                        .split("payload.employee")
//                        .transform(Transformers.toJson()).log()
                        .transform(Transformers.fromJson(Map.class)).log("json payload to Map object")
                        .<Map<String, String>, Map<String,String>>transform(
                                payload -> {
                                    payload.put("name","Somnath Mukhopadhyay");
                                    payload.put("company","xyz");
//                                    payload.put("salary", "20000");
                                    return payload;
                                }
                        ).log("Modifying the payload")
                        .transform(Transformers.toJson()).log("modified Map object to JSON")
                        .enrichHeaders(headerEnricherSpec -> headerEnricherSpec.header("ContentType","application/json"))
                        .handle(Http.outboundGateway("http://localhost:8888/Employee")
                                .httpMethod(HttpMethod.POST)
                                .expectedResponseType(String.class)
                                )
                        .log("Getting response back from flow3");
            }

1 Answers1

0

There is this one for you:

/**

 * Populate the {@code MessageTransformingHandler} for the {@link MethodInvokingTransformer}

 * to invoke the service method at runtime.

 * @param service the service to use.

 * @param methodName the method to invoke.

 * @return the current {@link BaseIntegrationFlowDefinition}.

 * @see MethodInvokingTransformer

 */

public B transform(Object service, String methodName) {

Read javadocs for those DSL operators.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118