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());
}
}
}
Aggregations