use of org.apache.cxf.phase.PhaseInterceptorChain in project cxf by apache.
the class RedeliveryQueueImpl method getRedeliveryInterceptorChain.
private static InterceptorChain getRedeliveryInterceptorChain(Message m, String phase) {
Exchange exchange = m.getExchange();
Endpoint ep = exchange.getEndpoint();
Bus bus = exchange.getBus();
PhaseManager pm = bus.getExtension(PhaseManager.class);
SortedSet<Phase> phases = new TreeSet<Phase>(pm.getInPhases());
for (Iterator<Phase> it = phases.iterator(); it.hasNext(); ) {
Phase p = it.next();
if (phase.equals(p.getName())) {
break;
}
it.remove();
}
PhaseInterceptorChain chain = new PhaseInterceptorChain(phases);
List<Interceptor<? extends Message>> il = ep.getInInterceptors();
addInterceptors(chain, il);
il = ep.getService().getInInterceptors();
addInterceptors(chain, il);
il = ep.getBinding().getInInterceptors();
addInterceptors(chain, il);
il = bus.getInInterceptors();
addInterceptors(chain, il);
if (ep.getService().getDataBinding() instanceof InterceptorProvider) {
il = ((InterceptorProvider) ep.getService().getDataBinding()).getInInterceptors();
addInterceptors(chain, il);
}
return chain;
}
use of org.apache.cxf.phase.PhaseInterceptorChain in project cxf by apache.
the class RetransmissionQueueImpl method doResend.
private void doResend(SoapMessage message) {
InputStream is = null;
try {
// initialize copied interceptor chain for message
PhaseInterceptorChain retransmitChain = manager.getRetransmitChain(message);
ProtocolVariation protocol = RMContextUtils.getProtocolVariation(message);
Endpoint endpoint = manager.getReliableEndpoint(message).getEndpoint(protocol);
PhaseChainCache cache = new PhaseChainCache();
boolean after = true;
if (retransmitChain == null) {
// no saved retransmit chain, so construct one from scratch (won't work for WS-Security on server, so
// need to fix)
retransmitChain = buildRetransmitChain(endpoint, cache);
after = false;
}
message.setInterceptorChain(retransmitChain);
// clear flag for SOAP out interceptor so envelope will be written
message.remove(SoapOutInterceptor.WROTE_ENVELOPE_START);
// discard all saved content
Set<Class<?>> formats = message.getContentFormats();
List<CachedOutputStreamCallback> callbacks = null;
for (Class<?> clas : formats) {
Object content = message.getContent(clas);
if (content != null) {
LOG.info("Removing " + clas.getName() + " content of actual type " + content.getClass().getName());
message.removeContent(clas);
if (clas == OutputStream.class && content instanceof WriteOnCloseOutputStream) {
callbacks = ((WriteOnCloseOutputStream) content).getCallbacks();
}
}
}
// read SOAP headers from saved input stream
CachedOutputStream cos = (CachedOutputStream) message.get(RMMessageConstants.SAVED_CONTENT);
// CachedOutputStream is hold until delivering was successful
cos.holdTempFile();
// instance is needed to close input stream later on
is = cos.getInputStream();
XMLStreamReader reader = StaxUtils.createXMLStreamReader(is, StandardCharsets.UTF_8.name());
message.getHeaders().clear();
if (reader.getEventType() != XMLStreamConstants.START_ELEMENT && reader.nextTag() != XMLStreamConstants.START_ELEMENT) {
throw new IllegalStateException("No document found");
}
readHeaders(reader, message);
int event;
while ((event = reader.nextTag()) != XMLStreamConstants.START_ELEMENT) {
if (event == XMLStreamConstants.END_ELEMENT) {
throw new IllegalStateException("No body content present");
}
}
// set message addressing properties
AddressingProperties maps = MAPCodec.getInstance(message.getExchange().getBus()).unmarshalMAPs(message);
RMContextUtils.storeMAPs(maps, message, true, MessageUtils.isRequestor(message));
AttributedURIType to = null;
if (null != maps) {
to = maps.getTo();
}
if (null == to) {
LOG.log(Level.SEVERE, "NO_ADDRESS_FOR_RESEND_MSG");
return;
}
if (RMUtils.getAddressingConstants().getAnonymousURI().equals(to.getValue())) {
LOG.log(Level.FINE, "Cannot resend to anonymous target");
return;
}
// initialize conduit for new message
Conduit c = message.getExchange().getConduit(message);
if (c == null) {
c = buildConduit(message, endpoint, to);
}
c.prepare(message);
// replace standard message marshaling with copy from saved stream
ListIterator<Interceptor<? extends Message>> iterator = retransmitChain.getIterator();
while (iterator.hasNext()) {
Interceptor<? extends Message> incept = iterator.next();
// remove JAX-WS interceptors which handle message modes and such
if (incept.getClass().getName().startsWith("org.apache.cxf.jaxws.interceptors")) {
retransmitChain.remove(incept);
} else if (incept instanceof PhaseInterceptor && (((PhaseInterceptor<?>) incept).getPhase() == Phase.MARSHAL)) {
// remove any interceptors from the marshal phase
retransmitChain.remove(incept);
}
}
retransmitChain.add(new CopyOutInterceptor(reader));
// restore callbacks on output stream
if (callbacks != null) {
OutputStream os = message.getContent(OutputStream.class);
if (os != null) {
WriteOnCloseOutputStream woc;
if (os instanceof WriteOnCloseOutputStream) {
woc = (WriteOnCloseOutputStream) os;
} else {
woc = new WriteOnCloseOutputStream(os);
message.setContent(OutputStream.class, woc);
}
for (CachedOutputStreamCallback cb : callbacks) {
woc.registerCallback(cb);
}
}
}
// send the message
message.put(RMMessageConstants.RM_RETRANSMISSION, Boolean.TRUE);
if (after) {
retransmitChain.doInterceptStartingAfter(message, RMCaptureOutInterceptor.class.getName());
} else {
retransmitChain.doIntercept(message);
}
if (LOG.isLoggable(Level.INFO)) {
RMProperties rmps = RMContextUtils.retrieveRMProperties(message, true);
SequenceType seq = rmps.getSequence();
LOG.log(Level.INFO, "Retransmitted message " + seq.getMessageNumber() + " in sequence " + seq.getIdentifier().getValue());
rmps = new RMProperties();
}
} catch (Exception ex) {
LOG.log(Level.SEVERE, "RESEND_FAILED_MSG", ex);
} finally {
// make sure to always close InputStreams of the CachedOutputStream to avoid leaving temp files undeleted
if (null != is) {
try {
is.close();
} catch (IOException e) {
// Ignore
}
}
}
}
use of org.apache.cxf.phase.PhaseInterceptorChain in project cxf by apache.
the class RetransmissionQueueImpl method buildRetransmitChain.
/**
* @param endpoint
* @param cache
* @return
*/
protected PhaseInterceptorChain buildRetransmitChain(final Endpoint endpoint, PhaseChainCache cache) {
PhaseInterceptorChain retransmitChain;
Bus bus = getManager().getBus();
List<Interceptor<? extends Message>> i1 = bus.getOutInterceptors();
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Interceptors contributed by bus: " + i1);
}
List<Interceptor<? extends Message>> i2 = endpoint.getOutInterceptors();
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Interceptors contributed by endpoint: " + i2);
}
List<Interceptor<? extends Message>> i3 = endpoint.getBinding().getOutInterceptors();
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Interceptors contributed by binding: " + i3);
}
PhaseManager pm = bus.getExtension(PhaseManager.class);
retransmitChain = cache.get(pm.getOutPhases(), i1, i2, i3);
return retransmitChain;
}
use of org.apache.cxf.phase.PhaseInterceptorChain 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<Phase>();
phases.add(new Phase(Phase.PRE_PROTOCOL, 1));
List<Interceptor<? extends Message>> lst = new ArrayList<Interceptor<? extends Message>>();
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.PhaseInterceptorChain in project tesb-rt-se by Talend.
the class DemoInterceptor method handleMessage.
public void handleMessage(Message message) throws Fault {
PhaseInterceptorChain pic = (PhaseInterceptorChain) message.getInterceptorChain();
if (!somethingMayHaveChanged(pic)) {
return;
}
System.out.println("Phase: " + phase);
System.out.println(" out: " + MessageUtils.isOutbound(message));
System.out.println(" contents: " + message.getContentFormats());
System.out.println(" keys: " + message.keySet());
XMLStreamReader reader = message.getContent(XMLStreamReader.class);
if (reader != null) {
// On an incoming message, once we have the XMLStreamReader,
// we can get the current event and the element Name
int event = reader.getEventType();
switch(event) {
case XMLStreamReader.START_ELEMENT:
case XMLStreamReader.END_ELEMENT:
System.out.println(" reader: " + event + " qname: " + reader.getName());
break;
default:
System.out.println(" reader: " + event);
}
}
List<?> params = message.getContent(List.class);
if (params != null) {
System.out.println(" params: " + params);
}
System.out.println(" chain: ");
printInterceptorChain(pic);
System.out.println();
System.out.println();
}
Aggregations