Jt1995
Jt1995

Reputation: 159

Save out response Body into variable with Apache Camel

i have my WSDL file which i built with apache-cxf and i have created my own RouteBuilder to perform a SOAP request. I receive correctly the response using the .log file, so i see into the console, but i do not understand if i can save the response into a variable, so i can perform my operation.

        from("timer://start")
            .setBody(routeSettings.body)
            .log(CxfConstants.OPERATION_NAME+": "+routeSettings.operationName)
            .setHeader(CxfConstants.OPERATION_NAME, constant(routeSettings.operationName))
            .log(CxfConstants.OPERATION_NAMESPACE+": "+routeSettings.operationNamespace)
            .setHeader(CxfConstants.OPERATION_NAMESPACE, constant(routeSettings.operationNamespace))

            .to("cxf://"+routeSettings.endpointURL
                    + "?serviceClass="+routeSettings.packageURL
                    + "&wsdlURL=/wsdl/"+routeSettings.nameWSDL)

            .log("Result: ${body.get(0).toString()}")

            .to("log:results");

This is my configure() function, i would like to save the body content into a variable.

Upvotes: 0

Views: 802

Answers (1)

earthling paul
earthling paul

Reputation: 558

This allows you to get access to the response to perform operations:

...
.log("Result: ${body.get(0).toString()}")
.to("log:results");
.process(exchange -> {
  MyResponseType myResponse = exchange.getIn().getMandatoryBody(MyResponseType.class)
        })

Upvotes: 1

Related Questions