Search code examples
cxf

CXF interceptor to preprocess incoming message


I have an operation that has an input message like this:

InputMessageType

  • messageType: String
  • other properties ...

I'd like to modify this messageType before it hits the target WS method and I wrote an interceptor for the Phase.USER_LOGICAL. However, in the handleMessage if I try to do:

message.getContent(InputMessageType.class) it returns null.

How could I get the reference to the InputMessageType, change it's messageType property and then let CXF call the WS with the modified input parameter?


Solution

  • I had the same problem as yours : message.getContent(xxx.class) returns null. I do not know why and I will check later this behaviour.

    So instead I use the interceptor like this (I retrieve the MessageContentsList) :

    public class ApiSoapActionInInterceptorService extends AbstractPhaseInterceptor<Message> {
    
    public ApiSoapActionInInterceptorService(){
        super(Phase.PRE_INVOKE);
    }
    
    @Override
    public void handleMessage(Message message) throws Fault {
        MessageContentsList inObjects = MessageContentsList.getContentsList(message);
        if (inObjects != null && !inObjects.isEmpty()){
            for (Iterator<Object> it = inObjects.iterator(); it.hasNext() ;){
                Object ob = it.next();
                if (ob instanceof InputMessageType){
                    //TODO
                }
            }
        } else {
            //TODO 
        }
    }
    

    }