Object params = null;
if (o instanceof List) {
params = CastUtils.cast((List<?>)o);
} else if (o != null) {
params = new MessageContentsList(o);
}
CxfExchange cxfExchange = endpoint.createExchange(exchange.getInMessage());
BindingOperationInfo bop = exchange.get(BindingOperationInfo.class);
MethodDispatcher md = (MethodDispatcher)
exchange.get(Service.class).get(MethodDispatcher.class.getName());
Method m = md.getMethod(bop);
cxfExchange.setProperty(BindingOperationInfo.class.toString(), bop);
// The SEI could be the provider class which will not have the bop information.
if (bop != null && bop.getOperationInfo().isOneWay()) {
cxfExchange.setPattern(ExchangePattern.InOnly);
} else {
cxfExchange.setPattern(ExchangePattern.InOut);
}
if (bop != null && bop.getName() != null) {
cxfExchange.getIn().setHeader(CxfConstants.OPERATION_NAMESPACE, bop.getName().getNamespaceURI());
cxfExchange.getIn().setHeader(CxfConstants.OPERATION_NAME, bop.getName().getLocalPart());
} else {
cxfExchange.getIn().setHeader(CxfConstants.OPERATION_NAME, m.getName());
}
CxfHeaderHelper.propagateCxfToCamel(endpoint.getHeaderFilterStrategy(), exchange.getInMessage(),
cxfExchange.getIn().getHeaders());
cxfExchange.getIn().setBody(params);
try {
cxfConsumer.getProcessor().process(cxfExchange);
} catch (Exception ex) {
// catch the exception and send back to cxf client
throw new Fault(ex);
}
Object result = null;
if (cxfExchange.isFailed()) {
Throwable ex = (Throwable)cxfExchange.getFault().getBody();
if (ex instanceof Fault) {
throw (Fault)ex;
} else {
if (ex == null) {
ex = cxfExchange.getException();
}
throw new Fault(ex);
}
} else {
result = cxfExchange.getOut().getBody();
if (result != null) {
if (result instanceof MessageContentsList || result instanceof List || result.getClass().isArray()) {
return result;
} else { // if the result is the single object
MessageContentsList resList = new MessageContentsList();
resList.add(result);
return resList;
}
}
}
return result;