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();
}
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();
}
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;
}
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);
}
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);
}
}
Aggregations