Search in sources :

Example 46 with Conduit

use of org.apache.cxf.transport.Conduit in project camel by apache.

the class CamelDestinationTest method testRoundTripDestination.

@Test
public void testRoundTripDestination() throws Exception {
    inMessage = null;
    EndpointInfo conduitEpInfo = new EndpointInfo();
    conduitEpInfo.setAddress("camel://direct:Producer");
    // set up the conduit send to be true
    CamelConduit conduit = setupCamelConduit(conduitEpInfo, true, false);
    final Message outMessage = new MessageImpl();
    endpointInfo.setAddress("camel://direct:EndpointA");
    final CamelDestination destination = setupCamelDestination(endpointInfo, true);
    // set up MessageObserver for handling the conduit message
    MessageObserver observer = new MessageObserver() {

        public void onMessage(Message m) {
            try {
                Exchange exchange = new ExchangeImpl();
                exchange.setInMessage(m);
                m.setExchange(exchange);
                verifyReceivedMessage(m, "HelloWorld");
                //verifyHeaders(m, outMessage);
                // setup the message for
                Conduit backConduit;
                backConduit = getBackChannel(destination, m);
                // wait for the message to be got from the conduit
                Message replyMessage = new MessageImpl();
                sendoutMessage(backConduit, replyMessage, true, "HelloWorld Response");
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    MockEndpoint error = context.getEndpoint("mock:error", MockEndpoint.class);
    error.expectedMessageCount(0);
    //this call will active the camelDestination
    destination.setMessageObserver(observer);
    // set is one way false for get response from destination
    // need to use another thread to send the request message
    sendoutMessage(conduit, outMessage, false, "HelloWorld");
    // wait for the message to be got from the destination,
    // create the thread to handler the Destination incoming message
    verifyReceivedMessage(inMessage, "HelloWorld Response");
    error.assertIsSatisfied();
    destination.shutdown();
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.cxf.message.Exchange) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Conduit(org.apache.cxf.transport.Conduit) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) NoSuchEndpointException(org.apache.camel.NoSuchEndpointException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) IOException(java.io.IOException) WebServiceException(javax.xml.ws.WebServiceException) Test(org.junit.Test)

Example 47 with Conduit

use of org.apache.cxf.transport.Conduit in project cxf by apache.

the class PolicyEngineTest method testSetEffectiveClientRequestPolicy.

@Test
public void testSetEffectiveClientRequestPolicy() throws Exception {
    engine = new PolicyEngineImpl();
    EndpointInfo ei = createMockEndpointInfo();
    BindingOperationInfo boi = createMockBindingOperationInfo();
    EffectivePolicy effectivePolicy = control.createMock(EffectivePolicy.class);
    control.replay();
    engine.setEffectiveClientRequestPolicy(ei, boi, effectivePolicy);
    assertSame(effectivePolicy, engine.getEffectiveClientRequestPolicy(ei, boi, (Conduit) null, msg));
    control.verify();
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Conduit(org.apache.cxf.transport.Conduit) Test(org.junit.Test)

Example 48 with Conduit

use of org.apache.cxf.transport.Conduit in project cxf by apache.

the class SimpleBatchSTSClient method findOperation.

protected BindingOperationInfo findOperation(String suffix) {
    BindingInfo bi = client.getEndpoint().getBinding().getBindingInfo();
    for (BindingOperationInfo boi : bi.getOperations()) {
        SoapOperationInfo soi = boi.getExtensor(SoapOperationInfo.class);
        if (soi != null && soi.getAction() != null && soi.getAction().endsWith(suffix)) {
            PolicyEngine pe = bus.getExtension(PolicyEngine.class);
            Conduit conduit = client.getConduit();
            EffectivePolicy effectivePolicy = pe.getEffectiveClientRequestPolicy(client.getEndpoint().getEndpointInfo(), boi, conduit, PhaseInterceptorChain.getCurrentMessage());
            setPolicyInternal(effectivePolicy.getPolicy());
            return boi;
        }
    }
    // we can at least find it by name and then set the action and such manually later.
    for (BindingOperationInfo boi : bi.getOperations()) {
        if (boi.getInput().getMessageInfo().getMessageParts().size() > 0) {
            MessagePartInfo mpi = boi.getInput().getMessageInfo().getMessagePart(0);
            if ("RequestSecurityToken".equals(mpi.getConcreteName().getLocalPart())) {
                return boi;
            }
        }
    }
    return null;
}
Also used : EffectivePolicy(org.apache.cxf.ws.policy.EffectivePolicy) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Conduit(org.apache.cxf.transport.Conduit) BindingInfo(org.apache.cxf.service.model.BindingInfo) SoapOperationInfo(org.apache.cxf.binding.soap.model.SoapOperationInfo) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo)

Example 49 with Conduit

use of org.apache.cxf.transport.Conduit in project cxf by apache.

the class CircuitBreakerTargetSelector method selectConduit.

@Override
public synchronized Conduit selectConduit(Message message) {
    Conduit c = message.get(Conduit.class);
    if (c != null) {
        return c;
    }
    Exchange exchange = message.getExchange();
    InvocationKey key = new InvocationKey(exchange);
    InvocationContext invocation = inProgress.get(key);
    if (invocation != null && !invocation.getContext().containsKey(IS_SELECTED)) {
        final String address = (String) message.get(Message.ENDPOINT_ADDRESS);
        if (isFailoverRequired(address)) {
            Endpoint target = getFailoverTarget(exchange, invocation);
            if (target == null) {
                throw new Fault(new FailoverFailedException("None of alternative addresses are available at the moment"));
            }
            if (isEndpointChanged(address, target)) {
                setEndpoint(target);
                message.put(Message.ENDPOINT_ADDRESS, target.getEndpointInfo().getAddress());
                overrideAddressProperty(invocation.getContext());
                invocation.getContext().put(IS_SELECTED, null);
            }
        }
    }
    return getSelectedConduit(message);
}
Also used : Exchange(org.apache.cxf.message.Exchange) Endpoint(org.apache.cxf.endpoint.Endpoint) Conduit(org.apache.cxf.transport.Conduit) Fault(org.apache.cxf.interceptor.Fault)

Example 50 with Conduit

use of org.apache.cxf.transport.Conduit in project cxf by apache.

the class FailoverTargetSelector method complete.

/**
 * Called on completion of the MEP for which the Conduit was required.
 *
 * @param exchange represents the completed MEP
 */
public void complete(Exchange exchange) {
    InvocationKey key = new InvocationKey(exchange);
    InvocationContext invocation = getInvocationContext(key);
    if (invocation == null) {
        super.complete(exchange);
        return;
    }
    boolean failover = false;
    final Exception ex = getExceptionIfPresent(exchange);
    if (requiresFailover(exchange, ex)) {
        onFailure(invocation, ex);
        Conduit old = (Conduit) exchange.getOutMessage().remove(Conduit.class.getName());
        Endpoint failoverTarget = getFailoverTarget(exchange, invocation);
        if (failoverTarget != null) {
            setEndpoint(failoverTarget);
            removeConduit(old);
            failover = performFailover(exchange, invocation);
        } else {
            exchange.remove(COMPLETE_IF_SERVICE_NOT_AVAIL_PROPERTY);
            setOriginalEndpoint(invocation);
        }
    } else {
        getLogger().fine("FAILOVER_NOT_REQUIRED");
        onSuccess(invocation);
    }
    if (!failover) {
        inProgress.remove(key);
        doComplete(exchange);
    }
}
Also used : Endpoint(org.apache.cxf.endpoint.Endpoint) Conduit(org.apache.cxf.transport.Conduit)

Aggregations

Conduit (org.apache.cxf.transport.Conduit)83 Test (org.junit.Test)36 Message (org.apache.cxf.message.Message)35 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)30 Exchange (org.apache.cxf.message.Exchange)28 IOException (java.io.IOException)18 MessageImpl (org.apache.cxf.message.MessageImpl)17 Endpoint (org.apache.cxf.endpoint.Endpoint)16 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)13 MessageObserver (org.apache.cxf.transport.MessageObserver)12 EndpointReferenceType (org.apache.cxf.ws.addressing.EndpointReferenceType)12 OutputStream (java.io.OutputStream)11 Bus (org.apache.cxf.Bus)11 Destination (org.apache.cxf.transport.Destination)11 ConduitInitiator (org.apache.cxf.transport.ConduitInitiator)10 InputStream (java.io.InputStream)9 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)9 ConduitInitiatorManager (org.apache.cxf.transport.ConduitInitiatorManager)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6