Search in sources :

Example 1 with AbstractWrapperHelper

use of org.apache.cxf.databinding.AbstractWrapperHelper in project cxf by apache.

the class WrapperClassOutInterceptor method handleMessage.

public void handleMessage(Message message) throws Fault {
    Exchange ex = message.getExchange();
    BindingOperationInfo bop = ex.getBindingOperationInfo();
    MessageInfo messageInfo = message.get(MessageInfo.class);
    if (messageInfo == null || bop == null || !bop.isUnwrapped()) {
        return;
    }
    BindingOperationInfo newbop = bop.getWrappedOperation();
    MessageInfo wrappedMsgInfo;
    if (Boolean.TRUE.equals(message.get(Message.REQUESTOR_ROLE))) {
        wrappedMsgInfo = newbop.getInput().getMessageInfo();
    } else {
        wrappedMsgInfo = newbop.getOutput().getMessageInfo();
    }
    Class<?> wrapped = null;
    if (wrappedMsgInfo.getMessagePartsNumber() > 0) {
        wrapped = wrappedMsgInfo.getFirstMessagePart().getTypeClass();
    }
    if (wrapped != null) {
        MessagePartInfo firstMessagePart = wrappedMsgInfo.getFirstMessagePart();
        MessageContentsList objs = MessageContentsList.getContentsList(message);
        WrapperHelper helper = firstMessagePart.getProperty("WRAPPER_CLASS", WrapperHelper.class);
        if (helper == null) {
            helper = getWrapperHelper(message, messageInfo, wrappedMsgInfo, wrapped, firstMessagePart);
        }
        if (helper == null) {
            return;
        }
        try {
            MessageContentsList newObjs = new MessageContentsList();
            if (ServiceUtils.isSchemaValidationEnabled(SchemaValidationType.OUT, message) && helper instanceof AbstractWrapperHelper) {
                ((AbstractWrapperHelper) helper).setValidate(true);
            }
            Object o2 = helper.createWrapperObject(objs);
            newObjs.put(firstMessagePart, o2);
            for (MessagePartInfo p : messageInfo.getMessageParts()) {
                if (Boolean.TRUE.equals(p.getProperty(ReflectionServiceFactoryBean.HEADER))) {
                    MessagePartInfo mpi = wrappedMsgInfo.getMessagePart(p.getName());
                    if (objs.hasValue(p)) {
                        newObjs.put(mpi, objs.get(p));
                    }
                }
            }
            message.setContent(List.class, newObjs);
        } catch (Fault f) {
            throw f;
        } catch (Exception e) {
            throw new Fault(e);
        }
        // we've now wrapped the object, so use the wrapped binding op
        ex.put(BindingOperationInfo.class, newbop);
        if (messageInfo == bop.getOperationInfo().getInput()) {
            message.put(MessageInfo.class, newbop.getOperationInfo().getInput());
            message.put(BindingMessageInfo.class, newbop.getInput());
        } else if (messageInfo == bop.getOperationInfo().getOutput()) {
            message.put(MessageInfo.class, newbop.getOperationInfo().getOutput());
            message.put(BindingMessageInfo.class, newbop.getOutput());
        }
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) MessageContentsList(org.apache.cxf.message.MessageContentsList) AbstractWrapperHelper(org.apache.cxf.databinding.AbstractWrapperHelper) AbstractWrapperHelper(org.apache.cxf.databinding.AbstractWrapperHelper) WrapperHelper(org.apache.cxf.databinding.WrapperHelper) Fault(org.apache.cxf.interceptor.Fault) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) MessageInfo(org.apache.cxf.service.model.MessageInfo) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo)

Aggregations

AbstractWrapperHelper (org.apache.cxf.databinding.AbstractWrapperHelper)1 WrapperHelper (org.apache.cxf.databinding.WrapperHelper)1 Fault (org.apache.cxf.interceptor.Fault)1 Exchange (org.apache.cxf.message.Exchange)1 MessageContentsList (org.apache.cxf.message.MessageContentsList)1 BindingMessageInfo (org.apache.cxf.service.model.BindingMessageInfo)1 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)1 MessageInfo (org.apache.cxf.service.model.MessageInfo)1 MessagePartInfo (org.apache.cxf.service.model.MessagePartInfo)1