Hi all,
Greetings !
I have designed a interceptor that runs in RECEIVE phase and takes a decision
whether to modify the header of an incoming SOAP request OR not.
It does so by reading the message's contents and parsing it into a XML document
instance.
Here is the code:
//get message as stream
InputStream ipStream = message.getContent(InputStream.class);
CachedOutputStream cos = new CachedOutputStream();
//create a re-readable inputstream
IOUtils.copy(ipStream, cos);
ipStream.close();
cos.flush();
//set the new inputstream
message.setContent(InputStream.class, cos.getInputStream());
//XML document instance
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
doc = dBuilder.parse(cos.getInputStream());
cos.close();
if (doc != null) {
takeDecisionOnHeaderModification(doc);
}
}
The code works fine.
As you can make out i needed a re-readable `inputStream` otherwise successive
application code/interceptors would have empty input stream.
so i used CachedOutputStream because cos.getInputStream() is re-readable.
Here are my queries about this approach :
Query#1 :
If CachedOutputStream is used for creating a re-readable inputStream why the
name is so misleading ? (It doesn't even have input word in it)
Query#2 :
For the requirement of re-readable inputStream, is CachedOutputStream the best
candidate, why not
DelegatingInputStream<https://cxf.apache.org/javadoc/latest/org/apache/cxf/io/DelegatingInputStream.html>,
if yes would you be kind enough to provide a working code snippet of same ?
I will be very grateful if anyone could shed light on these queries ?
Many Thanks !
Warm Regards,
Varun SINGHAL