use of org.apache.cxf.phase.Phase in project cxf by apache.
the class CryptoCoverageCheckerTest method testOrder.
@Test
public void testOrder() throws Exception {
// make sure the interceptors get ordered correctly
SortedSet<Phase> phases = new TreeSet<>();
phases.add(new Phase(Phase.PRE_PROTOCOL, 1));
List<Interceptor<? extends Message>> lst = new ArrayList<>();
lst.add(new MustUnderstandInterceptor());
lst.add(new WSS4JInInterceptor());
lst.add(new SAAJInInterceptor());
lst.add(new CryptoCoverageChecker());
PhaseInterceptorChain chain = new PhaseInterceptorChain(phases);
chain.add(lst);
String output = chain.toString();
assertTrue(output.contains("MustUnderstandInterceptor, SAAJInInterceptor, " + "WSS4JInInterceptor, CryptoCoverageChecker"));
}
use of org.apache.cxf.phase.Phase in project tesb-rt-se by Talend.
the class DemoInterceptor method addInterceptors.
/**
* This method will add a DemoInterceptor into every in and every out phase
* of the interceptor chains.
*
* @param provider
*/
public static void addInterceptors(InterceptorProvider provider) {
PhaseManager phases = BusFactory.getDefaultBus().getExtension(PhaseManager.class);
for (Phase p : phases.getInPhases()) {
provider.getInInterceptors().add(new DemoInterceptor(p.getName()));
provider.getInFaultInterceptors().add(new DemoInterceptor(p.getName()));
}
for (Phase p : phases.getOutPhases()) {
provider.getOutInterceptors().add(new DemoInterceptor(p.getName()));
provider.getOutFaultInterceptors().add(new DemoInterceptor(p.getName()));
}
}
use of org.apache.cxf.phase.Phase in project cxf by apache.
the class ChainInitiationObserverTest method setUp.
@Before
public void setUp() {
control = EasyMock.createNiceControl();
message = control.createMock(Message.class);
Phase phase1 = new Phase("phase1", 1);
SortedSet<Phase> phases = new TreeSet<>();
phases.add(phase1);
chain = new TestChain(phases);
observer = new ChainInitiationObserver(null, null);
}
use of org.apache.cxf.phase.Phase in project cxf by apache.
the class RMInInterceptorTest method testOrdering.
@Test
public void testOrdering() {
control.replay();
Phase p = new Phase(Phase.PRE_LOGICAL, 1);
SortedSet<Phase> phases = new TreeSet<>();
phases.add(p);
PhaseInterceptorChain chain = new PhaseInterceptorChain(phases);
MAPAggregator map = new MAPAggregator();
RMInInterceptor rmi = new RMInInterceptor();
chain.add(rmi);
chain.add(map);
Iterator<Interceptor<? extends Message>> it = chain.iterator();
assertSame("Unexpected order.", rmi, it.next());
assertSame("Unexpected order.", map, it.next());
}
use of org.apache.cxf.phase.Phase in project cxf by apache.
the class ColocMessageObserver method onMessage.
public void onMessage(Message m) {
Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
ClassLoaderHolder origLoader = null;
try {
if (loader != null) {
origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
}
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);
BindingOperationInfo boi = ex.getBindingOperationInfo();
OperationInfo oi = boi != null ? boi.getOperationInfo() : null;
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<>(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
BindingOperationInfo bop = m.getExchange().getBindingOperationInfo();
OperationInfo soi = bop != null ? bop.getOperationInfo() : null;
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 {
if (origBus != bus) {
BusFactory.setThreadDefaultBus(origBus);
}
if (origLoader != null) {
origLoader.reset();
}
}
}
Aggregations