use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class MAPAggregatorTest method setUpConduit.
private void setUpConduit(Message message, Exchange exchange) {
setUpMessageExchange(message, exchange);
Conduit conduit = EasyMock.createMock(Conduit.class);
setUpExchangeConduit(message, exchange, conduit);
EndpointReferenceType to = ContextUtils.WSA_OBJECT_FACTORY.createEndpointReferenceType();
to.setAddress(ContextUtils.getAttributedURI(expectedTo));
conduit.getTarget();
EasyMock.expectLastCall().andReturn(to).anyTimes();
}
use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class ClientPolicyInFaultInterceptor method handle.
protected void handle(Message msg) {
if (!MessageUtils.isRequestor(msg)) {
LOG.fine("Not a requestor.");
return;
}
Exchange exchange = msg.getExchange();
assert null != exchange;
Endpoint e = exchange.getEndpoint();
if (null == e) {
LOG.fine("No endpoint.");
return;
}
EndpointInfo ei = e.getEndpointInfo();
Bus bus = exchange.getBus();
PolicyEngine pe = bus.getExtension(PolicyEngine.class);
if (null == pe) {
return;
}
Conduit conduit = exchange.getConduit(msg);
LOG.fine("conduit: " + conduit);
List<Interceptor<? extends Message>> faultInterceptors = new ArrayList<Interceptor<? extends Message>>();
Collection<Assertion> assertions = new ArrayList<>();
// 1. Check overridden policy
Policy p = (Policy) msg.getContextualProperty(PolicyConstants.POLICY_OVERRIDE);
if (p != null) {
EndpointPolicyImpl endpi = new EndpointPolicyImpl(p);
EffectivePolicyImpl effectivePolicy = new EffectivePolicyImpl();
effectivePolicy.initialise(endpi, pe, true, true, msg);
PolicyUtils.logPolicy(LOG, Level.FINEST, "Using effective policy: ", effectivePolicy.getPolicy());
faultInterceptors.addAll(effectivePolicy.getInterceptors());
assertions.addAll(effectivePolicy.getChosenAlternative());
} else {
// 2. Process endpoint policy
// We do not know the underlying message type yet - so we pre-emptively add interceptors
// that can deal with all faults returned to this client endpoint.
EndpointPolicy ep = pe.getClientEndpointPolicy(ei, conduit, msg);
LOG.fine("ep: " + ep);
if (ep != null) {
faultInterceptors.addAll(ep.getFaultInterceptors(msg));
assertions.addAll(ep.getFaultVocabulary(msg));
}
}
// add interceptors into message chain
LOG.fine("faultInterceptors: " + faultInterceptors);
for (Interceptor<? extends Message> i : faultInterceptors) {
msg.getInterceptorChain().add(i);
LOG.log(Level.FINE, "Added interceptor of type {0}", i.getClass().getSimpleName());
}
// insert assertions of endpoint's fault vocabulary into message
if (!assertions.isEmpty()) {
msg.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
}
}
use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class JMSDestinationTest method testProperty.
@Test
public void testProperty() throws Exception {
EndpointInfo ei = setupServiceInfo("HelloWorldService", "HelloWorldPort");
final String customPropertyName = "THIS_PROPERTY_WILL_NOT_BE_AUTO_COPIED";
// set up the conduit send to be true
JMSConduit conduit = setupJMSConduitWithObserver(ei);
final Message outMessage = new MessageImpl();
setupMessageHeader(outMessage, null);
JMSMessageHeadersType headers = (JMSMessageHeadersType) outMessage.get(JMSConstants.JMS_CLIENT_REQUEST_HEADERS);
headers.putProperty(customPropertyName, customPropertyName);
final JMSDestination destination = setupJMSDestination(ei);
// set up MessageObserver for handling the conduit message
MessageObserver observer = new MessageObserver() {
public void onMessage(Message m) {
Exchange exchange = new ExchangeImpl();
exchange.setInMessage(m);
m.setExchange(exchange);
verifyReceivedMessage(m);
verifyHeaders(m, outMessage);
// setup the message for
Conduit backConduit;
try {
backConduit = destination.getBackChannel(m);
// wait for the message to be got from the conduit
Message replyMessage = new MessageImpl();
// copy the message encoding
replyMessage.put(Message.ENCODING, m.get(Message.ENCODING));
sendOneWayMessage(backConduit, replyMessage);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
destination.setMessageObserver(observer);
sendMessageSync(conduit, outMessage);
// wait for the message to be got from the destination,
// create the thread to handler the Destination incoming message
waitForReceiveInMessage();
verifyReceivedMessage(inMessage);
verifyRequestResponseHeaders(inMessage, outMessage);
JMSMessageHeadersType inHeader = (JMSMessageHeadersType) inMessage.get(JMSConstants.JMS_CLIENT_RESPONSE_HEADERS);
assertNotNull("The inHeader should not be null", inHeader);
// TODO we need to check the SOAP JMS transport properties here
// wait for a while for the jms session recycling
Thread.sleep(1000);
conduit.close();
destination.shutdown();
}
use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class RequestResponseTest method sendAndReceiveMessages.
protected void sendAndReceiveMessages(EndpointInfo ei, boolean synchronous) throws IOException {
inMessage = null;
// set up the conduit send to be true
JMSConduit conduit = setupJMSConduitWithObserver(ei);
final Message outMessage = createMessage();
final JMSDestination destination = setupJMSDestination(ei);
MessageObserver observer = new MessageObserver() {
public void onMessage(Message m) {
Exchange exchange = new ExchangeImpl();
exchange.setInMessage(m);
m.setExchange(exchange);
verifyReceivedMessage(m);
verifyHeaders(m, outMessage);
// setup the message for
Conduit backConduit;
try {
backConduit = destination.getBackChannel(m);
// wait for the message to be got from the conduit
Message replyMessage = new MessageImpl();
sendOneWayMessage(backConduit, replyMessage);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
destination.setMessageObserver(observer);
try {
sendMessage(conduit, outMessage, synchronous);
// wait for the message to be got from the destination,
// create the thread to handler the Destination incoming message
waitForReceiveInMessage();
verifyReceivedMessage(inMessage);
} finally {
conduit.close();
destination.shutdown();
}
}
use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class RetransmissionQueueImpl method buildConduit.
/**
* @param message
* @param endpoint
* @param to
* @return
*/
protected Conduit buildConduit(SoapMessage message, final Endpoint endpoint, AttributedURIType to) {
Conduit c;
final String address = to.getValue();
DeferredConduitSelector cs = new DeferredConduitSelector() {
@Override
public synchronized Conduit selectConduit(Message message) {
Conduit conduit = null;
EndpointInfo endpointInfo = endpoint.getEndpointInfo();
EndpointReferenceType original = endpointInfo.getTarget();
try {
if (null != address) {
endpointInfo.setAddress(address);
}
conduit = super.selectConduit(message);
} finally {
endpointInfo.setAddress(original);
}
conduits.clear();
return conduit;
}
};
cs.setEndpoint(endpoint);
c = cs.selectConduit(message);
// REVISIT
// use application endpoint message observer instead?
c.setMessageObserver(new MessageObserver() {
public void onMessage(Message message) {
LOG.fine("Ignoring response to resent message.");
}
});
cs.close();
message.getExchange().setConduit(c);
return c;
}
Aggregations