Hi Dan
I need full access to the message but I want to transform and update the
message before it is parsed by the corresponding soap parser.
I've done the following in which case the client blocks. If I uncomment the
line where I close the steam os, the client doesn't block but an empty message
is sent to the server:
public PMPOutInterceptor() {
super(Phase.PRE_STREAM);
...
OutputStream os = message.getContent(OutputStream.class);
CachedStream cs = new CachedStream();
message.setContent(OutputStream.class, cs);
message.getInterceptorChain().doIntercept(message);
try {
cs.flush();
CachedOutputStream csnew = (CachedOutputStream) message
.getContent(OutputStream.class);
String processingMsg = new String(csnew.getBytes());
String processedMsg = transform(processingMsg);
ByteArrayOutputStream encOutput = new ByteArrayOutputStream();
byte[] date = encryptedMessage.getBytes();
for (int i = 0; i < date.length; i++) {
encOutput.write(date[i]);
}
encOutput.flush();
cs.close();
message.setContent(OutputStream.class, encOutput);
//os.close(); //If I close this stream an empty message is
sent otherwise, the client blocks
...
private class CachedStream extends CachedOutputStream {
public CachedStream() {
super();
}
protected void doFlush() throws IOException {
currentStream.flush();
}
protected void doClose() throws IOException {
}
protected void onWrite() throws IOException {
}
}
What am I missing?
Thanks a lot
Oliver
-----Ursprüngliche Nachricht-----
Von: Daniel Kulp [mailto:[EMAIL PROTECTED]
Gesendet: Mo 29.09.2008 18:07
An: [email protected]
Cc: Wulff, Oliver
Betreff: Re: StreamInterceptor in configuration_interceptor
Oliver,
It kind of depends on what you are trying to do with the stream.
If you can do your transformation in a streaming fasion, that's the ideal
scenario. An example is gzipping the stream. You can just wrapper the
original stream with a gzip stream and the "write" methods on the new stream
handle everything.
If you need access to the entire message (like as a byte[] or similar) for
your transform, you need a way to obtain the whole message. That's where
the caching streams come in. The caching streams cache everything that is
written to them, first in a byte[] and then into a temp file once a
threshold is crossed. They then let you manipulate the temp file/byte[] as
need before you then write it into the original stream.
It really depends on your needs and how your transformation works. If it can
be implemented in a streaming manner, the performance it much better and
memory usage is lower and such, but a lot of things cannot be implemented
that way.
Dan
On Friday 26 September 2008 9:02:32 am Wulff, Oliver wrote:
> Hi there
>
> I've to develop an interceptor where I want to do some transformations on
> the stream before the soap message is sent and some transformations on the
> stream before the soap message is parsed on the server side.
>
> I had a look to the sample StreamInterceptor.java in the demo
> configuration_interceptor. I don't understand the implemention. Could you
> give some background information for it?
>
> - What is the value of the class CachedOutputStream?
> - What is the need to implement the class CachedStream?
> - What is the need to run
> "message.getInterceptorChain().doIntercept(message);"?
>
>
> Thanks a lot for clarification
> Oliver
--
Daniel Kulp
[EMAIL PROTECTED]
http://www.dankulp.com/blog