Saving a response persistently

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Saving a response persistently

Jorge Zapata
This post was updated on .
Hi, I'm having problems to save a response that I obtain from a receive method, I have tried everything but still don't figure out a way to do this. My code is something like this:
  receive(action -> action.endpoint("receiveQueueEndpoint")
                .payload(new ClassPathResource("templates/10714155_RES.XML"))
                .name("response"));


I want to save the response that comes in this receive: first taking it to a variable. In order to do so I save the response with the following:
       variable("msg", "citrus:message(response.payload())");
        echo("${msg}");

So far it appears to be working as I'm able to see the display of my response, but now I'm struggling to take this variable into an xml file on my local files.

Any suggestions to do this?

Reply | Threaded
Open this post in threaded view
|

Re: Saving a response persistently

Christoph Deppisch
Administrator
Use a custom test action that is able to access the message content in test context:

action(new AbstractTestAction() {
            @Override
            public void doExecute(TestContext context) {
                String messagePayload = context.getMessageStore().getMessage("myMessage").getPayload(String.class);

                try {
                    FileCopyUtils.copy(messagePayload, new FileWriter(new File("output.xml")));
                } catch (IOException e) {
                    throw new CitrusRuntimeException("Failed to write message to file", e);
                }
            }
        });