Java Code Examples for org.apache.cxf.message.Exchange#isOneWay()

The following examples show how to use org.apache.cxf.message.Exchange#isOneWay() . 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: JMSDestination.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * Rethrow exceptions for one way exchanges so the jms transaction can be rolled back.
 * Do not roll back for request/reply as client might expect a response
 */
private void processExceptions(Exchange exchange) {
    if (!exchange.isOneWay()) {

        return;
    }
    Message inMessage = exchange.getInMessage();
    if (inMessage == null) {
        return;
    }
    Exception ex = inMessage.getContent(Exception.class);

    if (ex != null) {
        if (ex.getCause() instanceof RuntimeException) {
            throw (RuntimeException)ex.getCause();
        }
        throw new RuntimeException(ex);
    }
}
 
Example 2
Source File: ResponseTimeMessageOutInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void handleMessage(Message message) throws Fault {
    Exchange ex = message.getExchange();
    boolean forceDisabled = Boolean.FALSE.equals(ex.get("org.apache.cxf.management.counter.enabled"));
    if (!forceDisabled && isServiceCounterEnabled(ex)) {
        if (ex.get(Exception.class) != null) {
            endHandlingMessage(ex);
            return;
        }
        if (Boolean.TRUE.equals(message.get(Message.PARTIAL_RESPONSE_MESSAGE))) {
            return;
        }
        if (isClient(message)) {
            if (ex.isOneWay()) {
                message.getInterceptorChain().add(ending);
            }
            beginHandlingMessage(ex);
        } else { // the message is handled by server
            endHandlingMessage(ex);
        }
    }
}
 
Example 3
Source File: ResponseTimeMessageOutInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: AbstractClient.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void checkClientException(Message outMessage, Exception ex) throws Exception {
    Throwable actualEx = ex instanceof Fault ? ((Fault)ex).getCause() : ex;

    Exchange exchange = outMessage.getExchange();
    Integer responseCode = getResponseCode(exchange);
    if (actualEx instanceof ResponseProcessingException) {
        throw (ResponseProcessingException)actualEx;
    } else if (responseCode == null
        || responseCode < 300 && !(actualEx instanceof IOException)
        || actualEx instanceof IOException && exchange.get("client.redirect.exception") != null) {
        if (actualEx instanceof ProcessingException) {
            throw (RuntimeException)actualEx;
        } else if (actualEx != null) {
            Object useProcExProp = exchange.get("wrap.in.processing.exception");
            if (actualEx instanceof RuntimeException
                && useProcExProp != null && PropertyUtils.isFalse(useProcExProp)) {
                throw (Exception)actualEx;
            }
            throw new ProcessingException(actualEx);
        } else if (!exchange.isOneWay() || cfg.isResponseExpectedForOneway()) {
            waitForResponseCode(exchange);
        }
    }
}
 
Example 5
Source File: BackChannelConduit.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void sendExchange(Exchange exchange, final Object replyObj) {
    if (exchange.isOneWay()) {
        //Don't need to send anything
        return;
    }
    final Message outMessage = exchange.getOutMessage();
    try (ResourceCloser closer = new ResourceCloser()) {
        send(outMessage, replyObj, closer);
    } catch (JMSException ex) {
        throw JMSUtil.convertJmsException(ex);
    }
}
 
Example 6
Source File: HTTPConduitURLEasyMockTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void setUpExchange(Message message, boolean oneway) {
    Exchange exchange = control.createMock(Exchange.class);
    message.setExchange(exchange);
    exchange.isOneWay();
    EasyMock.expectLastCall().andReturn(oneway).anyTimes();
    exchange.isSynchronous();
    EasyMock.expectLastCall().andReturn(true).anyTimes();
    exchange.isEmpty();
    EasyMock.expectLastCall().andReturn(true).anyTimes();
}
 
Example 7
Source File: CorbaServerConduit.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void buildRequestResult(CorbaMessage msg) {
    Exchange exg = msg.getExchange();
    ServerRequest request = exg.get(ServerRequest.class);
    try {
        if (!exg.isOneWay()) {
            CorbaMessage inMsg = (CorbaMessage)msg.getExchange().getInMessage();
            NVList list = inMsg.getList();

            if (msg.getStreamableException() != null) {
                Any exAny = CorbaAnyHelper.createAny(orb);
                CorbaStreamable exception = msg.getStreamableException();
                exAny.insert_Streamable(exception);
                request.set_exception(exAny);
                if (msg.getExchange() != null) {
                    msg.getExchange().setOutFaultMessage(msg);
                }
            } else {
                CorbaStreamable[] arguments = msg.getStreamableArguments();
                if (arguments != null) {
                    for (int i = 0; i < arguments.length; ++i) {
                        if (list.item(i).flags() != org.omg.CORBA.ARG_IN.value) {
                            arguments[i].getObject().setIntoAny(list.item(i).value(),
                                                                arguments[i], true);
                        }
                    }
                }

                CorbaStreamable resultValue = msg.getStreamableReturn();
                if (resultValue != null) {
                    Any resultAny = CorbaAnyHelper.createAny(orb);
                    resultValue.getObject().setIntoAny(resultAny, resultValue, true);
                    request.set_result(resultAny);
                }
            }
        }

    } catch (java.lang.Exception ex) {
        throw new CorbaBindingException("Exception during buildRequestResult", ex);
    }
}
 
Example 8
Source File: ColocInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleMessage(Message msg) throws Fault {
    Exchange ex = msg.getExchange();
    if (ex.isOneWay()) {
        return;
    }

    Bus bus = ex.getBus();
    SortedSet<Phase> phases = new TreeSet<>(bus.getExtension(PhaseManager.class).getOutPhases());

    //TODO Set Coloc FaultObserver chain
    ColocUtil.setPhases(phases, Phase.SETUP, Phase.USER_LOGICAL);
    InterceptorChain chain = ColocUtil.getOutInterceptorChain(ex, phases);

    if (LOG.isLoggable(Level.FINER)) {
        LOG.finer("Processing Message at collocated endpoint.  Response message: " + msg);
    }

    //Initiate OutBound Processing
    BindingOperationInfo boi = ex.getBindingOperationInfo();
    Message outBound = ex.getOutMessage();
    if (boi != null) {
        outBound.put(MessageInfo.class,
                     boi.getOperationInfo().getOutput());
    }

    outBound.put(Message.INBOUND_MESSAGE, Boolean.FALSE);
    outBound.setInterceptorChain(chain);
    chain.doIntercept(outBound);
}
 
Example 9
Source File: ResponseTimeMessageInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleMessage(Message message) throws Fault {
    Exchange ex = message.getExchange();
    //if serviceCounter is disabled , all responseTimeInterceptors will be skipped
    boolean forceDisabled = Boolean.FALSE.equals(ex.get("org.apache.cxf.management.counter.enabled"));
    if (!forceDisabled && isServiceCounterEnabled(ex)) {
        if (isClient(message)) {
            if (!ex.isOneWay()) {
                endHandlingMessage(ex);
            }
        } else {
            beginHandlingMessage(ex);
        }
    }
}
 
Example 10
Source File: ResponseTimeMessageInvokerInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public void handleFault(Message message) {
    Exchange ex = message.getExchange();
    boolean forceDisabled = Boolean.FALSE.equals(ex.get("org.apache.cxf.management.counter.enabled"));
    if (isServiceCounterEnabled(ex) && !forceDisabled) {
        ex.put(FaultMode.class, message.get(FaultMode.class));
        if (ex.isOneWay() && !isClient(message)) {
            endHandlingMessage(ex);
        }
    }
}
 
Example 11
Source File: AbstractClient.java    From cxf with Apache License 2.0 5 votes vote down vote up
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 12
Source File: AbstractClient.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected Object[] preProcessResult(Message message) throws Exception {
    Exchange exchange = message.getExchange();

    Exception ex = message.getContent(Exception.class);
    if (ex == null) {
        ex = message.getExchange().get(Exception.class);
    }
    if (ex == null && !exchange.isOneWay()) {
        synchronized (exchange) {
            while (exchange.get("IN_CHAIN_COMPLETE") == null) {
                exchange.wait(cfg.getSynchronousTimeout());
            }
        }
    }
    if (ex == null) {
        ex = message.getContent(Exception.class);
    }
    if (ex != null
        || PropertyUtils.isTrue(exchange.get(SERVICE_NOT_AVAIL_PROPERTY))
            && PropertyUtils.isTrue(exchange.get(COMPLETE_IF_SERVICE_NOT_AVAIL_PROPERTY))) {
        getConfiguration().getConduitSelector().complete(exchange);
    }
    if (ex != null) {
        checkClientException(message, ex);
    }
    checkClientException(message, exchange.get(Exception.class));

    List<?> result = exchange.get(List.class);
    return result != null ? result.toArray() : null;
}
 
Example 13
Source File: JMSConduit.java    From cxf with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
    }
}
 
Example 14
Source File: AbstractHTTPDestination.java    From cxf with Apache License 2.0 4 votes vote down vote up
/**
 * @param message the message under consideration
 * @return true iff the message has been marked as oneway
 */
protected final boolean isOneWay(Message message) {
    Exchange ex = message.getExchange();
    return ex != null && ex.isOneWay();
}
 
Example 15
Source File: ResponseTimeMessageInvokerInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void handleMessage(Message message) throws Fault {
    Exchange ex = message.getExchange();
    if (ex.isOneWay() && !isClient(message)) {
        setOneWayMessage(ex);
    }
}
 
Example 16
Source File: ColocOutInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
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 17
Source File: MetricsMessageInOneWayInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void handleMessage(Message message) throws Fault {
    Exchange ex = message.getExchange();
    if (ex.isOneWay() && !isRequestor(message)) {
        stop(message);
    }
}
 
Example 18
Source File: MAPAggregatorTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void setUpExchangeOneway(Exchange exchange, boolean oneway) {
    exchange.isOneWay();
    EasyMock.expectLastCall().andReturn(oneway).anyTimes();
    //exchange.setOneWay(oneway);
}
 
Example 19
Source File: JAXRSInvoker.java    From cxf with Apache License 2.0 4 votes vote down vote up
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 20
Source File: HTTPConduit.java    From cxf with Apache License 2.0 2 votes vote down vote up
/**
 * This predicate returns true if the exchange indicates
 * a oneway MEP.
 *
 * @param exchange The exchange in question
 */
private boolean isOneway(Exchange exchange) {
    return exchange != null && exchange.isOneWay();
}