Hi all,
I have a wsdl that contains one service with many one-way operations. I'm
using CXF v3.3.0 to handle the heavy duty and wsdl2java to generate the
JAX-WS server side code. I publish my endpoint at the *"/ip"* path.
The situation:
1. SOAP message is signed with a custom certificate and encoded in base64 by
client
2. receiving it on my side I have to unsign/verify/validate the
base64-encoded message with a custom validation logic
3. validation logic returns the original SOAP envelope
4. SOAP envelope is routed to the proper WS-method by CXF
I've been trying to solve it with a custom *interceptor* that runs before
*StaxInInterceptor* interceptor, but no luck so far. It feels strange to
manipulate the payload with interceptor in this case. I don't know if this
is the only option or there are other ways.
Could you suggest a solution for it?
I would greatly appreciate it.
Best regards,
Szabolcs
Code:
public class ValidatorInterceptor extends AbstractPhaseInterceptor<Message> {
public ValidatorInterceptor() {
super(Phase.PRE_STREAM);
addBefore(StaxInInterceptor.class.getName());
//super(Phase.RECEIVE);
//addBefore(WireTapIn.class.getName());
}
@Override
public void handleMessage(Message message) throws Fault {
final boolean isInbound = message ==
message.getExchange().getInMessage();
if (isInbound) {
try {
if
(HuHttpHeaders.HEADER_SIGNING_ACCEPT_VALUE.equalsIgnoreCase((String)
message.get(Message.ACCEPT_CONTENT_TYPE))) {
final CachedOutputStream cachedOutputStream =
message.getContent(CachedOutputStream.class);
final byte[] signedMessage =
IOUtils.readBytesFromStream(cachedOutputStream.getInputStream());
final String verificationResult =
Validator.verify(signedMessage);
final byte[] soapMessageAsByte =
verificationResult.getBytes(StandardCharsets.UTF_8);
cachedOutputStream.resetOut(null, false);
cachedOutputStream.write(soapMessageAsByte);
cachedOutputStream.flush();
message.setContent(CachedOutputStream.class,
cachedOutputStream);
final LoadingByteArrayOutputStream
loadingByteArrayOutputStream = new LoadingByteArrayOutputStream();
loadingByteArrayOutputStream.write(soapMessageAsByte);
message.setContent(InputStream.class,
loadingByteArrayOutputStream.createInputStream());
}
} catch (IOException ioe) {
throw new Fault(ioe);
}
}
}
}