use of org.apache.cxf.databinding.WrapperCapableDatabinding in project cxf by apache.
the class WrapperClassInInterceptor method handleMessage.
public void handleMessage(Message message) throws Fault {
Exchange ex = message.getExchange();
BindingOperationInfo boi = ex.getBindingOperationInfo();
if (Boolean.TRUE.equals(message.get(Message.PARTIAL_RESPONSE_MESSAGE)) || boi == null) {
return;
}
Method method = ex.get(Method.class);
if (method != null && method.getName().endsWith("Async")) {
Class<?> retType = method.getReturnType();
if (retType.getName().equals("java.util.concurrent.Future") || retType.getName().equals("javax.xml.ws.Response")) {
return;
}
}
if (boi.isUnwrappedCapable()) {
BindingOperationInfo boi2 = boi.getUnwrappedOperation();
OperationInfo op = boi2.getOperationInfo();
BindingMessageInfo bmi;
MessageInfo wrappedMessageInfo = message.get(MessageInfo.class);
MessageInfo messageInfo;
if (wrappedMessageInfo == boi.getOperationInfo().getInput()) {
messageInfo = op.getInput();
bmi = boi2.getInput();
} else {
messageInfo = op.getOutput();
bmi = boi2.getOutput();
}
// Sometimes, an operation can be unwrapped according to WSDLServiceFactory,
// but not according to JAX-WS. We should unify these at some point, but
// for now check for the wrapper class.
MessageContentsList lst = MessageContentsList.getContentsList(message);
if (lst == null) {
return;
}
message.put(MessageInfo.class, messageInfo);
message.put(BindingMessageInfo.class, bmi);
ex.put(BindingOperationInfo.class, boi2);
if (isGET(message)) {
LOG.fine("WrapperClassInInterceptor skipped in HTTP GET method");
return;
}
MessagePartInfo wrapperPart = wrappedMessageInfo.getFirstMessagePart();
Class<?> wrapperClass = wrapperPart.getTypeClass();
Object wrappedObject = lst.get(wrapperPart.getIndex());
if (wrapperClass == null || wrappedObject == null || (wrapperClass != null && !wrapperClass.isInstance(wrappedObject))) {
return;
}
WrapperHelper helper = wrapperPart.getProperty("WRAPPER_CLASS", WrapperHelper.class);
if (helper == null) {
Service service = ServiceModelUtil.getService(message.getExchange());
DataBinding dataBinding = service.getDataBinding();
if (dataBinding instanceof WrapperCapableDatabinding) {
helper = createWrapperHelper((WrapperCapableDatabinding) dataBinding, messageInfo, wrappedMessageInfo, wrapperClass);
wrapperPart.setProperty("WRAPPER_CLASS", helper);
} else {
return;
}
}
MessageContentsList newParams;
try {
newParams = new MessageContentsList(helper.getWrapperParts(wrappedObject));
List<Integer> removes = null;
int count = 0;
for (MessagePartInfo part : messageInfo.getMessageParts()) {
if (Boolean.TRUE.equals(part.getProperty(ReflectionServiceFactoryBean.HEADER))) {
MessagePartInfo mpi = null;
for (MessagePartInfo mpi2 : wrappedMessageInfo.getMessageParts()) {
if (mpi2.getConcreteName().equals(part.getConcreteName())) {
mpi = mpi2;
}
}
if (mpi != null && lst.hasValue(mpi)) {
count++;
newParams.put(part, lst.get(mpi));
} else if (mpi == null || mpi.getTypeClass() == null) {
// header, but not mapped to a param on the method
if (removes == null) {
removes = new ArrayList<>();
}
removes.add(part.getIndex());
}
} else {
++count;
}
}
if (count == 0) {
newParams.clear();
} else if (removes != null) {
Collections.sort(removes, Collections.reverseOrder());
for (Integer i : removes) {
if (i < newParams.size()) {
newParams.remove(i.intValue());
}
}
}
} catch (Exception e) {
throw new Fault(e);
}
message.setContent(List.class, newParams);
}
}
use of org.apache.cxf.databinding.WrapperCapableDatabinding in project cxf by apache.
the class WrapperClassOutInterceptor method getWrapperHelper.
private synchronized WrapperHelper getWrapperHelper(Message message, MessageInfo messageInfo, MessageInfo wrappedMessageInfo, Class<?> wrapClass, MessagePartInfo messagePartInfo) {
WrapperHelper helper = messagePartInfo.getProperty("WRAPPER_CLASS", WrapperHelper.class);
if (helper == null) {
Service service = ServiceModelUtil.getService(message.getExchange());
DataBinding dataBinding = service.getDataBinding();
if (dataBinding instanceof WrapperCapableDatabinding) {
helper = createWrapperHelper((WrapperCapableDatabinding) dataBinding, messageInfo, wrappedMessageInfo, wrapClass);
messagePartInfo.setProperty("WRAPPER_CLASS", helper);
}
}
return helper;
}
Aggregations