OK so it was actually simpler than I expected to achieve this, would
appreciate any feedback about potential problems.
So my jaxws:client (using bindingId xformat), have 3 new interceptors
ReplaceMessageSenderInterceptor
CachedOutputStreamInterceptor
MessageSenderEndingInterceptor
public class ReplaceMessageSenderInterceptor extends AbstractPhaseInterceptor {
public ReplaceMessageSenderInterceptor() {
super(Phase.SETUP);
}
@Override
public void handleMessage(Message message) throws Fault {
InterceptorUtils.removeInterceptor(MessageSenderInterceptor.class, message);
}
}
public class CachedOutputStreamInterceptor extends AbstractPhaseInterceptor {
public CachedOutputStreamInterceptor() {
super(Phase.PRE_STREAM);
addBefore(StaxOutInterceptor.class.getName());
}
@Override
public void handleMessage(Message message) throws Fault {
CachedOutputStream outputStream = new CachedOutputStream();
message.setContent(OutputStream.class, outputStream);
}
}
public class MessageSenderEndingInterceptor extends AbstractPhaseInterceptor {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final MessageSenderInterceptor realMessageSender;
public MessageSenderEndingInterceptor() {
super(Phase.PRE_STREAM_ENDING);
addAfter(StaxOutEndingInterceptor.class.getName());
realMessageSender = new MessageSenderInterceptor();
}
@Override
public void handleMessage(Message message) throws Fault {
CachedOutputStream cachedOutputStream = (CachedOutputStream)
message.getContent(OutputStream.class);
// I would throttle before calling handleMessage on the original
Message Sender
realMessageSender.handleMessage(message);
try
{
OutputStream outputStream =
message.getContent(OutputStream.class);
IOUtils.write(cachedOutputStream.getBytes(), outputStream);
}
catch(IOException ex)
{
// TODO - add throws Fault
logger.error("something bad happened", ex);
}
}
}
On Tue, May 29, 2012 at 4:00 PM, Jason Pell <[email protected]> wrote:
> Also when I referred to PREPARE_SEND phase I was actually mean
> PRE_STREAM_ENDING
>
> Apologies for confusion