Java Code Examples for org.apache.cxf.message.Exchange#get()
The following examples show how to use
org.apache.cxf.message.Exchange#get() .
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: EjbMethodInvoker.java From tomee with Apache License 2.0 | 6 votes |
@Override protected Object performInvocation(final Exchange exchange, final Object serviceObject, final Method m, final Object[] paramArray) throws Exception { InvocationContext invContext = exchange.get(InvocationContext.class); invContext.setParameters(paramArray); Object res = invContext.proceed(); EjbMessageContext ctx = (EjbMessageContext) invContext.getContextData(); Map<String, Object> handlerProperties = (Map<String, Object>) exchange .get(HANDLER_PROPERTIES); addHandlerProperties(ctx, handlerProperties); updateWebServiceContext(exchange, ctx); return res; }
Example 2
Source File: FailoverTargetSelector.java From cxf with Apache License 2.0 | 6 votes |
/** * Check if the exchange is suitable for a failover. * * @param exchange the current Exchange * @return boolean true if a failover should be attempted */ protected boolean requiresFailover(Exchange exchange, Exception ex) { getLogger().log(Level.FINE, "CHECK_LAST_INVOKE_FAILED", new Object[] {ex != null}); Throwable curr = ex; boolean failover = false; while (curr != null) { failover = curr instanceof java.io.IOException; curr = curr.getCause(); } if (ex != null) { getLogger().log(Level.INFO, "CHECK_FAILURE_IN_TRANSPORT", new Object[] {ex, failover}); } if (isSupportNotAvailableErrorsOnly() && exchange.get(Message.RESPONSE_CODE) != null) { failover = PropertyUtils.isTrue(exchange.get("org.apache.cxf.transport.service_not_available")); } return failover; }
Example 3
Source File: ExchangeUtils.java From fuchsia with Apache License 2.0 | 6 votes |
public static void closeConduit(Exchange exchange) throws IOException { ConduitSelector conduitSelector = null; synchronized (exchange) { conduitSelector = exchange.get(ConduitSelector.class); if (conduitSelector != null) { exchange.remove(ConduitSelector.class.getName()); } } Conduit selectedConduit = null; Message message = exchange.getInMessage() == null ? exchange .getOutMessage() : exchange.getInMessage(); if (conduitSelector != null && message != null) { selectedConduit = conduitSelector.selectConduit(message); selectedConduit.close(message); } //TODO the line below was removed, check the impact on the protobuffer importer/exporter //selectedConduit.close(message); }
Example 4
Source File: ResponseTimeMessageOutInterceptor.java From cxf with Apache License 2.0 | 6 votes |
@Override public void handleFault(Message message) { Exchange ex = message.getExchange(); if (ex.get("org.apache.cxf.management.counter.enabled") != null) { if (ex.isOneWay()) { // do nothing, done by the ResponseTimeInvokerInterceptor } else { FaultMode faultMode = message.get(FaultMode.class); if (faultMode == null) { // client side exceptions don't have FaultMode set un the message properties (as of 2.1.4) faultMode = FaultMode.RUNTIME_FAULT; } ex.put(FaultMode.class, faultMode); endHandlingMessage(ex); } } }
Example 5
Source File: ExchangeUtils.java From fuchsia with Apache License 2.0 | 5 votes |
public static Exception getException(Exchange exchange) { Exception throwable = exchange.get(Exception.class); if (exchange.getInFaultMessage() != null) { return exchange.getInFaultMessage().getContent(Exception.class); } else if (exchange.getOutFaultMessage() != null) { return exchange.getOutFaultMessage().getContent(Exception.class); } if (throwable != null) { return throwable; } throwable = getException(exchange.getOutMessage()); if (throwable != null) { return throwable; } throwable = getException(exchange.getInMessage()); if (throwable != null) { return throwable; } return null; }
Example 6
Source File: AbstractLoggingInterceptor.java From cxf with Apache License 2.0 | 5 votes |
public void createExchangeId(Message message) { Exchange exchange = message.getExchange(); String exchangeId = (String)exchange.get(LogEvent.KEY_EXCHANGE_ID); if (exchangeId == null) { exchangeId = UUID.randomUUID().toString(); exchange.put(LogEvent.KEY_EXCHANGE_ID, exchangeId); } }
Example 7
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 8
Source File: AbstractMessageResponseTimeInterceptor.java From cxf with Apache License 2.0 | 5 votes |
protected void setOneWayMessage(Exchange ex) { MessageHandlingTimeRecorder mhtr = ex.get(MessageHandlingTimeRecorder.class); if (null == mhtr) { mhtr = new MessageHandlingTimeRecorder(ex); } else { mhtr.endHandling(); } mhtr.setOneWay(true); increaseCounter(ex, mhtr); }
Example 9
Source File: JAXRSInvoker.java From cxf with Apache License 2.0 | 5 votes |
public Object getServiceObject(Exchange exchange) { Object root = exchange.remove(JAXRSUtils.ROOT_INSTANCE); if (root != null) { return root; } OperationResourceInfo ori = exchange.get(OperationResourceInfo.class); ClassResourceInfo cri = ori.getClassResourceInfo(); return cri.getResourceProvider().getInstance(exchange.getInMessage()); }
Example 10
Source File: JAXRSInvoker.java From cxf with Apache License 2.0 | 5 votes |
private ResourceProvider getResourceProvider(Exchange exchange) { Object provider = exchange.remove(JAXRSUtils.ROOT_PROVIDER); if (provider == null) { OperationResourceInfo ori = exchange.get(OperationResourceInfo.class); ClassResourceInfo cri = ori.getClassResourceInfo(); return cri.getResourceProvider(); } return (ResourceProvider)provider; }
Example 11
Source File: AbstractMessageResponseTimeInterceptor.java From cxf with Apache License 2.0 | 5 votes |
protected void endHandlingMessage(Exchange ex) { if (null == ex) { return; } MessageHandlingTimeRecorder mhtr = ex.get(MessageHandlingTimeRecorder.class); if (null != mhtr) { mhtr.endHandling(); mhtr.setFaultMode(ex.get(FaultMode.class)); increaseCounter(ex, mhtr); } // else can't get the MessageHandling Infor }
Example 12
Source File: AbstractJAXWSHandlerInterceptor.java From cxf with Apache License 2.0 | 5 votes |
protected HandlerChainInvoker getInvoker(T message) { Exchange ex = message.getExchange(); HandlerChainInvoker invoker = ex.get(HandlerChainInvoker.class); if (null == invoker) { invoker = new HandlerChainInvoker(binding.getHandlerChain(), isOutbound(message)); ex.put(HandlerChainInvoker.class, invoker); } boolean outbound = isOutbound(message, ex); if (outbound) { invoker.setOutbound(); } else { invoker.setInbound(); } invoker.setRequestor(isRequestor(message)); if (ex.isOneWay() || ((isRequestor(message) && !outbound) || (!isRequestor(message) && outbound))) { invoker.setResponseExpected(false); } else { invoker.setResponseExpected(true); } return invoker; }
Example 13
Source File: AbstractClient.java From cxf with Apache License 2.0 | 5 votes |
private Integer getResponseCode(Exchange exchange) { Integer responseCode = (Integer)exchange.get(Message.RESPONSE_CODE); if (responseCode == null && exchange.getInMessage() != null) { responseCode = (Integer)exchange.getInMessage().get(Message.RESPONSE_CODE); } if (responseCode == null && exchange.isOneWay() && !state.getBaseURI().toString().startsWith("http")) { responseCode = 202; } return responseCode; }
Example 14
Source File: JAXRSInvoker.java From cxf with Apache License 2.0 | 4 votes |
protected Object getActualServiceObject(Exchange exchange, Object rootInstance) { Object last = exchange.get(LAST_SERVICE_OBJECT); return last != null ? last : rootInstance; }
Example 15
Source File: ClientRequestFilterInterceptor.java From cxf with Apache License 2.0 | 4 votes |
public void handleMessage(Message outMessage) throws Fault { ClientProviderFactory pf = ClientProviderFactory.getInstance(outMessage); if (pf == null) { return; } // create an empty proxy output stream that the filter can interact with // and save a reference for later ProxyOutputStream pos = new ProxyOutputStream(); outMessage.setContent(OutputStream.class, pos); outMessage.setContent(ProxyOutputStream.class, pos); List<ProviderInfo<ClientRequestFilter>> filters = pf.getClientRequestFilters(); if (!filters.isEmpty()) { final Exchange exchange = outMessage.getExchange(); final ClientRequestContext context = new ClientRequestContextImpl(outMessage, false); for (ProviderInfo<ClientRequestFilter> filter : filters) { InjectionUtils.injectContexts(filter.getProvider(), filter, outMessage); try { filter.getProvider().filter(context); @SuppressWarnings("unchecked") Map<String, List<Object>> headers = CastUtils.cast((Map<String, List<Object>>) outMessage.get(Message.PROTOCOL_HEADERS)); HttpUtils.convertHeaderValuesToString(headers, false); Response response = outMessage.getExchange().get(Response.class); if (response != null) { outMessage.getInterceptorChain().abort(); Message inMessage = new MessageImpl(); inMessage.setExchange(exchange); inMessage.put(Message.RESPONSE_CODE, response.getStatus()); inMessage.put(Message.PROTOCOL_HEADERS, response.getMetadata()); exchange.setInMessage(inMessage); MessageObserver observer = exchange.get(MessageObserver.class); observer.onMessage(inMessage); return; } } catch (IOException ex) { throw new ProcessingException(ex); } } } }
Example 16
Source File: JAXRSInvoker.java From cxf with Apache License 2.0 | 4 votes |
public Object invoke(Exchange exchange, Object request) { MessageContentsList responseList = checkExchangeForResponse(exchange); if (responseList != null) { return responseList; } AsyncResponse asyncResp = exchange.get(AsyncResponse.class); if (asyncResp != null) { AsyncResponseImpl asyncImpl = (AsyncResponseImpl)asyncResp; asyncImpl.prepareContinuation(); try { asyncImpl.handleTimeout(); return handleAsyncResponse(exchange, asyncImpl); } catch (Throwable t) { return handleAsyncFault(exchange, asyncImpl, t); } } ResourceProvider provider = getResourceProvider(exchange); Object rootInstance = null; Message inMessage = exchange.getInMessage(); try { rootInstance = getServiceObject(exchange); Object serviceObject = getActualServiceObject(exchange, rootInstance); return invoke(exchange, request, serviceObject); } catch (WebApplicationException ex) { responseList = checkExchangeForResponse(exchange); if (responseList != null) { return responseList; } return handleFault(ex, inMessage); } finally { boolean suspended = isSuspended(exchange); if (suspended || exchange.isOneWay() || inMessage.get(Message.THREAD_CONTEXT_SWITCHED) != null) { ServerProviderFactory.clearThreadLocalProxies(inMessage); } if (suspended || isServiceObjectRequestScope(inMessage)) { persistRoots(exchange, rootInstance, provider); } else { provider.releaseInstance(inMessage, rootInstance); } } }
Example 17
Source File: FailoverTargetSelector.java From cxf with Apache License 2.0 | 4 votes |
private Exception getExceptionIfPresent(Exchange exchange) { Message outMessage = exchange.getOutMessage(); return outMessage.get(Exception.class) != null ? outMessage.get(Exception.class) : exchange.get(Exception.class); }
Example 18
Source File: JsonpJaxrsWriterInterceptor.java From cxf with Apache License 2.0 | 4 votes |
protected String getCallbackValue(Message message) { Exchange exchange = message.getExchange(); return (String) exchange.get(JsonpInInterceptor.CALLBACK_KEY); }
Example 19
Source File: AbstractJsonpOutInterceptor.java From cxf with Apache License 2.0 | 4 votes |
protected String getCallbackValue(Message message) { Exchange exchange = message.getExchange(); return (String) exchange.get(JsonpInInterceptor.CALLBACK_KEY); }
Example 20
Source File: JMSConduit.java From cxf with Apache License 2.0 | 4 votes |
/** * Send the JMS message and if the MEP is not oneway receive the response. * * @param exchange the Exchange containing the outgoing message * @param request the payload of the outgoing JMS message */ public void sendExchange(final Exchange exchange, final Object request) { LOG.log(Level.FINE, "JMSConduit send message"); final Message outMessage = exchange.getOutMessage() == null ? exchange.getOutFaultMessage() : exchange.getOutMessage(); if (outMessage == null) { throw new RuntimeException("Exchange to be sent has no outMessage"); } jmsConfig.ensureProperlyConfigured(); assertIsNotTextMessageAndMtom(outMessage); try (ResourceCloser closer = new ResourceCloser()) { Connection c; if (jmsConfig.isOneSessionPerConnection()) { c = closer.register(JMSFactory.createConnection(jmsConfig)); c.start(); } else { c = getConnection(); } Session session = closer.register(c.createSession(false, Session.AUTO_ACKNOWLEDGE)); if (exchange.isOneWay()) { sendMessage(request, outMessage, null, null, closer, session); } else { sendAndReceiveMessage(exchange, request, outMessage, closer, session); } } catch (JMSException e) { if (this.jmsListener != null) { this.jmsListener.shutdown(); } this.jmsListener = null; // Close connection so it will be refreshed on next try if (!jmsConfig.isOneSessionPerConnection()) { if (exchange.get(JMSUtil.JMS_MESSAGE_CONSUMER) != null) { ResourceCloser.close(exchange.get(JMSUtil.JMS_MESSAGE_CONSUMER)); } ResourceCloser.close(connection); this.connection = null; jmsConfig.resetCachedReplyDestination(); } this.staticReplyDestination = null; try { Thread.sleep(1000); } catch (InterruptedException e1) { // Ignore } throw JMSUtil.convertJmsException(e); } }