}
BusFactory.setThreadDefaultBus(bus);
if (LOG.isLoggable(Level.FINER)) {
LOG.finer("Processing Message at collocated endpoint. Request message: " + m);
}
Exchange ex = new ExchangeImpl();
setExchangeProperties(ex, m);
Message inMsg = endpoint.getBinding().createMessage();
MessageImpl.copyContent(m, inMsg);
//Copy Request Context to Server inBound Message
//TODO a Context Filter Strategy required.
inMsg.putAll(m);
inMsg.put(COLOCATED, Boolean.TRUE);
inMsg.put(Message.REQUESTOR_ROLE, Boolean.FALSE);
inMsg.put(Message.INBOUND_MESSAGE, Boolean.TRUE);
OperationInfo oi = ex.get(OperationInfo.class);
if (oi != null) {
inMsg.put(MessageInfo.class, oi.getInput());
}
ex.setInMessage(inMsg);
inMsg.setExchange(ex);
if (LOG.isLoggable(Level.FINEST)) {
LOG.finest("Build inbound interceptor chain.");
}
//Add all interceptors between USER_LOGICAL and INVOKE.
SortedSet<Phase> phases = new TreeSet<Phase>(bus.getExtension(PhaseManager.class).getInPhases());
ColocUtil.setPhases(phases, Phase.USER_LOGICAL, Phase.INVOKE);
InterceptorChain chain = ColocUtil.getInInterceptorChain(ex, phases);
chain.add(addColocInterceptors());
inMsg.setInterceptorChain(chain);
//Convert the coloc object type if necessary
OperationInfo soi = m.getExchange().get(OperationInfo.class);
if (soi != null && oi != null) {
if (ColocUtil.isAssignableOperationInfo(soi, Source.class)
&& !ColocUtil.isAssignableOperationInfo(oi, Source.class)) {
// converting source -> pojo
ColocUtil.convertSourceToObject(inMsg);
} else if (ColocUtil.isAssignableOperationInfo(oi, Source.class)
&& !ColocUtil.isAssignableOperationInfo(soi, Source.class)) {
// converting pojo -> source
ColocUtil.convertObjectToSource(inMsg);
}
}
chain.doIntercept(inMsg);
if (soi != null && oi != null) {
if (ColocUtil.isAssignableOperationInfo(soi, Source.class)
&& !ColocUtil.isAssignableOperationInfo(oi, Source.class)
&& ex.getOutMessage() != null) {
// converting pojo -> source
ColocUtil.convertObjectToSource(ex.getOutMessage());
} else if (ColocUtil.isAssignableOperationInfo(oi, Source.class)
&& !ColocUtil.isAssignableOperationInfo(soi, Source.class)
&& ex.getOutMessage() != null) {
// converting pojo -> source
ColocUtil.convertSourceToObject(ex.getOutMessage());
}
}
//Set Server OutBound Message onto InBound Exchange.
setOutBoundMessage(ex, m.getExchange());
} finally {