Java Code Examples for org.apache.cxf.message.Message#getInterceptorChain()
The following examples show how to use
org.apache.cxf.message.Message#getInterceptorChain() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractEndpointSelectionInterceptor.java From cxf with Apache License 2.0 | 6 votes |
public void handleMessage(Message message) { Exchange ex = message.getExchange(); Set<Endpoint> endpoints = CastUtils.cast((Set<?>)ex.get(MultipleEndpointObserver.ENDPOINTS)); Endpoint ep = selectEndpoint(message, endpoints); if (ep == null) { return; } ex.put(Endpoint.class, ep); ex.put(Binding.class, ep.getBinding()); ex.put(Service.class, ep.getService()); InterceptorChain chain = message.getInterceptorChain(); chain.add(ep.getInInterceptors()); chain.add(ep.getBinding().getInInterceptors()); chain.add(ep.getService().getInInterceptors()); chain.setFaultObserver(ep.getOutFaultObserver()); }
Example 2
Source File: CustomerSecurityInterceptor.java From servicemix with Apache License 2.0 | 5 votes |
public void handleMessage(Message message) throws Fault { Map<String, Object> outProps = new HashMap<String, Object>(); outProps.put("action", "UsernameToken"); outProps.put("passwordType", "PasswordText"); outProps.put("user", "smx"); outProps.put("passwordCallbackClass", "org.apache.servicemix.examples.cxf.ClientPasswordCallback"); for (Interceptor inteceptor : message.getInterceptorChain()) { //set properties for WSS4JOutInterceptor if (inteceptor.getClass().getName().equals("org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor")) { ((WSS4JOutInterceptor)inteceptor).setProperties(outProps); } } }
Example 3
Source File: CustomerSecurityInterceptor.java From servicemix with Apache License 2.0 | 5 votes |
public void handleMessage(Message message) throws Fault { Map<String, Object> outProps = new HashMap<String, Object>(); outProps.put("action", "UsernameToken"); outProps.put("passwordType", "PasswordText"); outProps.put("user", "smx"); outProps.put("passwordCallbackClass", "org.apache.servicemix.examples.cxf.ClientPasswordCallback"); for (Interceptor inteceptor : message.getInterceptorChain()) { //set properties for WSS4JOutInterceptor if (inteceptor.getClass().getName().equals("org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor")) { ((WSS4JOutInterceptor)inteceptor).setProperties(outProps); } } }
Example 4
Source File: RMManager.java From cxf with Apache License 2.0 | 5 votes |
/** * Clones and saves the interceptor chain the first time this is called, so that it can be used for retransmission. * Calls after the first are ignored. * * @param msg */ public void initializeInterceptorChain(Message msg) { Endpoint ep = msg.getExchange().getEndpoint(); synchronized (ep) { if (ep.get(WSRM_RETRANSMIT_CHAIN) == null) { LOG.info("Setting retransmit chain from message"); PhaseInterceptorChain chain = (PhaseInterceptorChain)msg.getInterceptorChain(); chain = chain.cloneChain(); ep.put(WSRM_RETRANSMIT_CHAIN, chain); } } }
Example 5
Source File: RMInInterceptorTest.java From cxf with Apache License 2.0 | 5 votes |
private void testAppMessage(boolean onServer, boolean deferredAbort) throws SequenceFault, RMException, NoSuchMethodException { Method m1 = RMInInterceptor.class.getDeclaredMethod("processAcknowledgments", new Class[] {RMEndpoint.class, RMProperties.class, ProtocolVariation.class}); Method m2 = RMInInterceptor.class.getDeclaredMethod("processAcknowledgmentRequests", new Class[] {Destination.class, Message.class}); Method m3 = RMInInterceptor.class.getDeclaredMethod("processSequence", new Class[] {Destination.class, Message.class}); Method m4 = RMInInterceptor.class.getDeclaredMethod("processDeliveryAssurance", new Class[] {RMProperties.class}); interceptor = EasyMock.createMockBuilder(RMInInterceptor.class) .addMockedMethods(m1, m2, m3, m4).createMock(control); Message message = setupInboundMessage("greetMe", true); Destination d = control.createMock(Destination.class); EasyMock.expect(manager.getDestination(message)).andReturn(d); interceptor.processAcknowledgments(rme, rmps, ProtocolVariation.RM10WSA200408); EasyMock.expectLastCall(); interceptor.processAcknowledgmentRequests(d, message); EasyMock.expectLastCall(); interceptor.processSequence(d, message); EasyMock.expectLastCall(); interceptor.processDeliveryAssurance(rmps); EasyMock.expectLastCall(); EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(null); Exchange ex = control.createMock(Exchange.class); message.getExchange(); EasyMock.expectLastCall().andReturn(ex).anyTimes(); ex.get("deferred.uncorrelated.message.abort"); EasyMock.expectLastCall().andReturn(Boolean.TRUE); InterceptorChain chain = control.createMock(InterceptorChain.class); message.getInterceptorChain(); EasyMock.expectLastCall().andReturn(chain); chain.abort(); EasyMock.expectLastCall(); control.replay(); interceptor.handle(message); }
Example 6
Source File: OutgoingChainInterceptor.java From cxf with Apache License 2.0 | 5 votes |
public void handleMessage(Message message) { Exchange ex = message.getExchange(); BindingOperationInfo binding = ex.getBindingOperationInfo(); //if we get this far, we're going to be outputting some valid content, but we COULD //also be "echoing" some of the content from the input. Thus, we need to //mark it as requiring the input to be cached. if (message.getExchange().get(CACHE_INPUT_PROPERTY) == null) { message.put(CACHE_INPUT_PROPERTY, Boolean.TRUE); } if (null != binding && null != binding.getOperationInfo() && binding.getOperationInfo().isOneWay()) { closeInput(message); return; } Message out = ex.getOutMessage(); if (out != null) { try { getBackChannelConduit(message); } catch (IOException ioe) { throw new Fault(ioe); } if (binding != null) { out.put(MessageInfo.class, binding.getOperationInfo().getOutput()); out.put(BindingMessageInfo.class, binding.getOutput()); } InterceptorChain outChain = out.getInterceptorChain(); if (outChain == null) { outChain = OutgoingChainInterceptor.getChain(ex, chainCache); out.setInterceptorChain(outChain); } else if (outChain.getState() == InterceptorChain.State.PAUSED) { outChain.resume(); return; } outChain.doIntercept(out); } }
Example 7
Source File: MessageLossSimulator.java From cxf with Apache License 2.0 | 4 votes |
public void handleMessage(Message message) throws Fault { AddressingProperties maps = RMContextUtils.retrieveMAPs(message, false, true); String action = null; if (maps != null && null != maps.getAction()) { action = maps.getAction().getValue(); } if (RMContextUtils.isRMProtocolMessage(action)) { return; } if (MessageUtils.isPartialResponse(message)) { return; } if (Boolean.TRUE.equals(message.get(RMMessageConstants.RM_RETRANSMISSION))) { return; } if (mode == 1) { // never lose return; } else if (mode == -1) { // always lose } else { // alternatively lose synchronized (this) { appMessageCount++; if (0 != (appMessageCount % 2)) { return; } } } InterceptorChain chain = message.getInterceptorChain(); ListIterator<Interceptor<? extends Message>> it = chain.getIterator(); while (it.hasNext()) { PhaseInterceptor<?> pi = (PhaseInterceptor<? extends Message>)it.next(); if (MessageSenderInterceptor.class.getName().equals(pi.getId())) { chain.remove(pi); LOG.fine("Removed MessageSenderInterceptor from interceptor chain."); break; } } message.setContent(OutputStream.class, new WrappedOutputStream(message)); message.getInterceptorChain().add(new MessageLossEndingInterceptor(throwsException)); }
Example 8
Source File: InternalContextUtils.java From cxf with Apache License 2.0 | 4 votes |
/** * Rebase response on replyTo * * @param reference the replyTo reference * @param inMAPs the inbound MAPs * @param inMessage the current message */ //CHECKSTYLE:OFF Max executable statement count limitation public static void rebaseResponse(EndpointReferenceType reference, AddressingProperties inMAPs, final Message inMessage) { String namespaceURI = inMAPs.getNamespaceURI(); if (!ContextUtils.retrievePartialResponseSent(inMessage)) { ContextUtils.storePartialResponseSent(inMessage); Exchange exchange = inMessage.getExchange(); Message fullResponse = exchange.getOutMessage(); Message partialResponse = ContextUtils.createMessage(exchange); ensurePartialResponseMAPs(partialResponse, namespaceURI); // ensure the inbound MAPs are available in the partial response // message (used to determine relatesTo etc.) ContextUtils.propogateReceivedMAPs(inMAPs, partialResponse); Destination target = inMessage.getDestination(); if (target == null) { return; } try { if (reference == null) { reference = ContextUtils.getNoneEndpointReference(); } Conduit backChannel = target.getBackChannel(inMessage); if (backChannel != null) { partialResponse.put(Message.PARTIAL_RESPONSE_MESSAGE, Boolean.TRUE); partialResponse.put(Message.EMPTY_PARTIAL_RESPONSE_MESSAGE, Boolean.TRUE); boolean robust = MessageUtils.getContextualBoolean(inMessage, Message.ROBUST_ONEWAY, false); if (robust) { BindingOperationInfo boi = exchange.getBindingOperationInfo(); // insert the executor in the exchange to fool the OneWayProcessorInterceptor exchange.put(Executor.class, getExecutor(inMessage)); // pause dispatch on current thread and resume... inMessage.getInterceptorChain().pause(); inMessage.getInterceptorChain().resume(); // restore the BOI for the partial response handling exchange.put(BindingOperationInfo.class, boi); } // set up interceptor chains and send message InterceptorChain chain = fullResponse != null ? fullResponse.getInterceptorChain() : OutgoingChainInterceptor.getOutInterceptorChain(exchange); exchange.setOutMessage(partialResponse); partialResponse.setInterceptorChain(chain); exchange.put(ConduitSelector.class, new PreexistingConduitSelector(backChannel, exchange.getEndpoint())); if (chain != null && !chain.doIntercept(partialResponse) && partialResponse.getContent(Exception.class) != null) { if (partialResponse.getContent(Exception.class) instanceof Fault) { throw (Fault)partialResponse.getContent(Exception.class); } throw new Fault(partialResponse.getContent(Exception.class)); } if (chain != null) { chain.reset(); } exchange.put(ConduitSelector.class, new NullConduitSelector()); if (fullResponse == null) { fullResponse = ContextUtils.createMessage(exchange); } exchange.setOutMessage(fullResponse); Destination destination = createDecoupledDestination( exchange, reference); exchange.setDestination(destination); } } catch (Exception e) { LOG.log(Level.WARNING, "SERVER_TRANSPORT_REBASE_FAILURE_MSG", e); } } }
Example 9
Source File: ColocOutInterceptor.java From cxf with Apache License 2.0 | 4 votes |
public void handleMessage(Message message) throws Fault { if (bus == null) { bus = message.getExchange().getBus(); if (bus == null) { bus = BusFactory.getDefaultBus(false); } if (bus == null) { throw new Fault(new org.apache.cxf.common.i18n.Message("BUS_NOT_FOUND", BUNDLE)); } } ServerRegistry registry = bus.getExtension(ServerRegistry.class); if (registry == null) { throw new Fault(new org.apache.cxf.common.i18n.Message("SERVER_REGISTRY_NOT_FOUND", BUNDLE)); } Exchange exchange = message.getExchange(); Endpoint senderEndpoint = exchange.getEndpoint(); if (senderEndpoint == null) { throw new Fault(new org.apache.cxf.common.i18n.Message("ENDPOINT_NOT_FOUND", BUNDLE)); } BindingOperationInfo boi = exchange.getBindingOperationInfo(); if (boi == null) { throw new Fault(new org.apache.cxf.common.i18n.Message("OPERATIONINFO_NOT_FOUND", BUNDLE)); } Server srv = isColocated(registry.getServers(), senderEndpoint, boi); if (srv != null) { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Operation:" + boi.getName() + " dispatched as colocated call."); } InterceptorChain outChain = message.getInterceptorChain(); outChain.abort(); exchange.put(Bus.class, bus); message.put(COLOCATED, Boolean.TRUE); message.put(Message.WSDL_OPERATION, boi.getName()); message.put(Message.WSDL_INTERFACE, boi.getBinding().getInterface().getName()); invokeColocObserver(message, srv.getEndpoint()); if (!exchange.isOneWay()) { invokeInboundChain(exchange, senderEndpoint); } } else { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Operation:" + boi.getName() + " dispatched as remote call."); } message.put(COLOCATED, Boolean.FALSE); } }
Example 10
Source File: EjbInterceptor.java From tomee with Apache License 2.0 | 4 votes |
@AroundInvoke public Object intercept(InvocationContext context) throws Exception { Endpoint endpoint = this.exchange.get(Endpoint.class); Service service = endpoint.getService(); Binding binding = ((JaxWsEndpointImpl) endpoint).getJaxwsBinding(); this.exchange.put(InvocationContext.class, context); if (binding.getHandlerChain() == null || binding.getHandlerChain().isEmpty()) { // no handlers so let's just directly invoke the bean log.debug("No handlers found."); EjbMethodInvoker invoker = (EjbMethodInvoker) service.getInvoker(); return invoker.directEjbInvoke(this.exchange, this.method, this.params); } else { // have handlers so have to run handlers now and redo data binding // as handlers can change the soap message log.debug("Handlers found."); Message inMessage = exchange.getInMessage(); PhaseInterceptorChain chain = new PhaseInterceptorChain(bus.getExtension(PhaseManager.class).getInPhases()); chain.setFaultObserver(endpoint.getOutFaultObserver()); /* * Since we have to re-do data binding and the XMLStreamReader * contents are already consumed by prior data binding step * we have to reinitialize the XMLStreamReader from the SOAPMessage * created by SAAJInInterceptor. */ if (inMessage instanceof SoapMessage) { try { reserialize((SoapMessage) inMessage); } catch (Exception e) { throw new ServerRuntimeException("Failed to reserialize soap message", e); } } else { // TODO: how to handle XML/HTTP binding? } this.exchange.setOutMessage(null); // install default interceptors chain.add(new ServiceInvokerInterceptor()); //chain.add(new OutgoingChainInterceptor()); // it is already in the enclosing chain, if we add it there we are in the tx so we write the message in the tx! // See http://cwiki.apache.org/CXF20DOC/interceptors.html // install Holder and Wrapper interceptors chain.add(new WrapperClassInInterceptor()); chain.add(new HolderInInterceptor()); // install interceptors for handler processing chain.add(new MustUnderstandInterceptor()); chain.add(new LogicalHandlerInInterceptor(binding)); chain.add(new SOAPHandlerInterceptor(binding)); // install data binding interceptors - todo: check we need it copyDataBindingInterceptors(chain, inMessage.getInterceptorChain()); InterceptorChain oldChain = inMessage.getInterceptorChain(); inMessage.setInterceptorChain(chain); try { chain.doIntercept(inMessage); } finally { inMessage.setInterceptorChain(oldChain); } // TODO: the result should be deserialized from SOAPMessage Object result = getResult(); return result; } }