use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class AbstractConduitSelector method findCompatibleConduit.
/**
* If address protocol was changed, conduit should be re-initialised
*
* @param message the current Message
*/
protected Conduit findCompatibleConduit(Message message) {
Conduit c = message.get(Conduit.class);
if (c == null && message.getExchange() != null && message.getExchange().getOutMessage() != null && message.getExchange().getOutMessage() != message) {
c = message.getExchange().getOutMessage().get(Conduit.class);
}
if (c != null) {
return c;
}
ContextualBooleanGetter cbg = new ContextualBooleanGetter(message);
for (Conduit c2 : conduits) {
if (c2.getTarget() == null || c2.getTarget().getAddress() == null || c2.getTarget().getAddress().getValue() == null) {
continue;
}
String conduitAddress = c2.getTarget().getAddress().getValue();
EndpointInfo ei = endpoint.getEndpointInfo();
String actualAddress = ei.getAddress();
String messageAddress = (String) message.get(Message.ENDPOINT_ADDRESS);
if (messageAddress != null) {
actualAddress = messageAddress;
}
if (matchAddresses(conduitAddress, actualAddress, cbg)) {
return c2;
}
}
for (Conduit c2 : conduits) {
if (c2.getTarget() == null || c2.getTarget().getAddress() == null || c2.getTarget().getAddress().getValue() == null) {
return c2;
}
}
return null;
}
use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class AbstractConduitSelector method getSelectedConduit.
/**
* Mechanics to actually get the Conduit from the ConduitInitiator
* if necessary.
*
* @param message the current Message
*/
protected Conduit getSelectedConduit(Message message) {
Conduit c = findCompatibleConduit(message);
if (c == null) {
Exchange exchange = message.getExchange();
EndpointInfo ei = endpoint.getEndpointInfo();
String transportID = ei.getTransportId();
try {
ConduitInitiatorManager conduitInitiatorMgr = exchange.getBus().getExtension(ConduitInitiatorManager.class);
if (conduitInitiatorMgr != null) {
ConduitInitiator conduitInitiator = conduitInitiatorMgr.getConduitInitiator(transportID);
if (conduitInitiator != null) {
c = createConduit(message, exchange, conduitInitiator);
} else {
getLogger().warning("ConduitInitiator not found: " + ei.getAddress());
}
} else {
getLogger().warning("ConduitInitiatorManager not found");
}
} catch (BusException ex) {
throw new Fault(ex);
} catch (IOException ex) {
throw new Fault(ex);
}
}
if (c != null && c.getTarget() != null && c.getTarget().getAddress() != null) {
replaceEndpointAddressPropertyIfNeeded(message, c.getTarget().getAddress().getValue(), c);
}
// the search for the conduit could cause extra properties to be reset/loaded.
message.resetContextCache();
message.put(Conduit.class, c);
return c;
}
use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class DeferredConduitSelector method selectConduit.
/**
* Called when a Conduit is actually required.
*
* @param message
* @return the Conduit to use for mediation of the message
*/
public Conduit selectConduit(Message message) {
Conduit c = message.get(Conduit.class);
if (c == null) {
c = getSelectedConduit(message);
message.put(Conduit.class, c);
}
return c;
}
use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class MessageSenderInterceptor method getConduit.
public static Conduit getConduit(Message message) throws IOException {
Exchange exchange = message.getExchange();
Conduit conduit = exchange.getConduit(message);
if (conduit == null && (exchange.getOutMessage() != null || exchange.getOutFaultMessage() != null)) {
conduit = OutgoingChainInterceptor.getBackChannelConduit(message);
}
return conduit;
}
use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class OneWayProcessorInterceptor method handleMessage.
public void handleMessage(Message message) throws Fault {
if (message.getExchange().isOneWay() && !isRequestor(message) && message.get(OneWayProcessorInterceptor.class) == null && message.getExchange().get(Executor.class) == null) {
// one way on server side, fork the rest of this chain onto the
// workqueue, call the Outgoing chain directly.
message.put(OneWayProcessorInterceptor.class, this);
final InterceptorChain chain = message.getInterceptorChain();
boolean robust = MessageUtils.getContextualBoolean(message, Message.ROBUST_ONEWAY, false);
boolean useOriginalThread = MessageUtils.getContextualBoolean(message, USE_ORIGINAL_THREAD, false);
if (!useOriginalThread && !robust) {
// need to suck in all the data from the input stream as
// the transport might discard any data on the stream when this
// thread unwinds or when the empty response is sent back
DelegatingInputStream in = message.getContent(DelegatingInputStream.class);
if (in != null) {
in.cacheInput();
}
}
if (robust) {
// continue to invoke the chain
chain.pause();
chain.resume();
if (message.getContent(Exception.class) != null) {
// CXF-5629 fault has been delivered alread in resume()
return;
}
}
try {
Message partial = createMessage(message.getExchange());
partial.remove(Message.CONTENT_TYPE);
partial.setExchange(message.getExchange());
Conduit conduit = message.getExchange().getDestination().getBackChannel(message);
if (conduit != null) {
message.getExchange().setInMessage(null);
// for a one-way, the back channel could be
// null if it knows it cannot send anything.
conduit.prepare(partial);
conduit.close(partial);
message.getExchange().setInMessage(message);
}
} catch (IOException e) {
// IGNORE
}
if (!useOriginalThread && !robust) {
chain.pause();
try {
final Object lock = new Object();
synchronized (lock) {
message.getExchange().getBus().getExtension(WorkQueueManager.class).getAutomaticWorkQueue().execute(new Runnable() {
public void run() {
synchronized (lock) {
lock.notifyAll();
}
chain.resume();
}
});
// wait a few milliseconds for the background thread to start processing
// Mostly just to make an attempt at keeping the ordering of the
// messages coming in from a client. Not guaranteed though.
lock.wait(20);
}
} catch (RejectedExecutionException e) {
LOG.warning("Executor queue is full, run the oneway invocation task in caller thread." + " Users can specify a larger executor queue to avoid this.");
// only block the thread if the prop is unset or set to false, otherwise let it go
if (!MessageUtils.getContextualBoolean(message, "org.apache.cxf.oneway.rejected_execution_exception", false)) {
// the executor queue is full, so run the task in the caller thread
chain.unpause();
}
} catch (InterruptedException e) {
// ignore - likely a busy work queue so we'll just let the one-way go
}
}
}
}
Aggregations