Classification: UNCLASSIFIED Caveats: NONE Hi, Simon and others,
I did not get any response for my request for help on the 2.0 Policy issues (see the thread under " How to add new security extension to Tuscany binding.ws?" and " Tuscany 2.0 policy"), so I went ahead down to the second path Simon suggested - to work with PolicyHandler extension point in 1.6.x (see the thread under " How to add new security extension to Tuscany binding.ws?"). Everything went well on the reference side until I was testing the service side. I think the current PolicyHandler calling sequence has some defect and the model does not fit the need to add WS-security to the binding.ws.axis2 binding implementation. Here's what the current code is doing: Axis2ServiceInOutSyncMessageReceiver. invokeBusinessLogic() calls Axis2ServiceProvider.invokeTarget() which inturn calls PolicyHandler.beforeInvoke(), wire.invoke() and then immediately PolicyHandler.afterInvoke(). But at this point, the outbound MessageContext, outMC, has not been constructed, which is needed by WS-security logic in my PolicyHandler.xxxInvoke(). What I would like is to delay the calling of PolicyHandler.afterInvoke() to a later time after the outbound MessageContext, outMC, has not been constructed and call the PolicyHandler.afterInvoke() with the outMC instead of inMC, which does not make sense since the endpoint method has been invoked. So I modified Axis2ServiceInOutSyncMessageReceiver and Axis2ServiceProvider to delay the calling of PolicyHandler.afterInvoke() until after outMC has been constructed in Axis2ServiceInOutSyncMessageReceiver. invokeBusinessLogic() (see the following code segments) and it seems to work out well for my need. This in my opinion a better model since upon return from wire.invoke(), we are not dealing with response (out bound) rather than request (in bound). However, I do not know if this would break any thing and if you are willing to make that change. Thanks, Gang Code segments: Axis2ServiceInOutSyncMessageReceiver.Axis2ServiceInOutSyncMessageReceive r(...) { .... OMElement responseOM = (OMElement)provider.invokeTarget(operation, args, inMC); /* for ( PolicyHandler policyHandler : policyHandlerList ) { policyHandler.afterInvoke(operation, args, inMC, responseOM); } */ SOAPEnvelope soapEnvelope = getSOAPFactory(inMC).getDefaultEnvelope(); if (null != responseOM ) { soapEnvelope.getBody().addChild(responseOM); } outMC.setEnvelope(soapEnvelope); outMC.getOperationContext().setProperty(Constants.RESPONSE_WRITTEN, Constants.VALUE_TRUE); // Gang: Added for ( PolicyHandler policyHandler : policyHandlerList ) { policyHandler.afterInvoke(responseOM, outMC); } ... } Axis2ServiceProvider.invokeTarget(...) { ... // find the runtime wire and invoke it with the message RuntimeWire wire = ((RuntimeComponentService)contract).getRuntimeWire(getBinding()); Object response = wire.invoke(op, msg); // Gang: Commented out // for ( PolicyHandler policyHandler : policyHandlerList ) { // policyHandler.afterInvoke(response, inMC); //} return response; } Classification: UNCLASSIFIED Caveats: NONE