0

I'm using CXF to send messages with SOAP over JMS.

I'm trying to write a CXF Interceptor in the POST_MARSHALL phase. I want to change some attributes when the xml is generated.

I know i can get the content from the message via

message.getContent(java.io.Writer.class).

This happens to be in the form of JMSConduit$1. Which - I think - is a StringWriter (if I debug my code I can see a buf field).

I can get the xml in String format and make my changes, but the problems is putting it back in the message.

I can not change the JMSConduit$1 to something else, otherwise CXF won't send it to the JMS Endpoint. (it must be a JMSConduit).

I can't find a way to put the modified xml back in a JMSConduit, which i can get through

message.getExchange().getConduit();

So, how can I put my modified xml back into the message/JMSConduit?

4

1 回答 1

0

终于找到答案了。我使用了FilterWriter。

public void handleMessage(Message message) throws Fault {
    final Writer writer = message.getContent(Writer.class);
    message.setContent(Writer.class, new OutWriter(message, writer));
}

class OutWriter extends FilterWriter {
    @Override
    public void close() throws IOException {
        // Modify String (in xml form).
        message.setContent(Writer.class, out);
    }
}
于 2014-01-28T10:04:09.453 回答