use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class AbstractConduitSelector method createConduit.
protected Conduit createConduit(Message message, Exchange exchange, ConduitInitiator conduitInitiator) throws IOException {
Conduit c = null;
synchronized (endpoint) {
if (!conduits.isEmpty()) {
c = findCompatibleConduit(message);
if (c != null) {
return c;
}
}
EndpointInfo ei = endpoint.getEndpointInfo();
String add = (String) message.get(Message.ENDPOINT_ADDRESS);
String basePath = (String) message.get(Message.BASE_PATH);
if (StringUtils.isEmpty(add) || add.equals(ei.getAddress())) {
c = conduitInitiator.getConduit(ei, exchange.getBus());
replaceEndpointAddressPropertyIfNeeded(message, add, c);
} else {
EndpointReferenceType epr = new EndpointReferenceType();
AttributedURIType ad = new AttributedURIType();
ad.setValue(StringUtils.isEmpty(basePath) ? add : basePath);
epr.setAddress(ad);
c = conduitInitiator.getConduit(ei, epr, exchange.getBus());
}
MessageObserver observer = exchange.get(MessageObserver.class);
if (observer != null) {
c.setMessageObserver(observer);
} else {
getLogger().warning("MessageObserver not found");
}
conduits.add(c);
}
return c;
}
use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class UpfrontConduitSelector method prepare.
/**
* Called prior to the interceptor chain being traversed.
*
* @param message the current Message
*/
public void prepare(Message message) {
Conduit c = message.get(Conduit.class);
if (c == null) {
c = getSelectedConduit(message);
message.put(Conduit.class, c);
}
}
use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class UpfrontConduitSelector 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 InternalContextUtils method rebaseResponse.
/**
* Rebase response on replyTo
*
* @param reference the replyTo reference
* @param inMAPs the inbound MAPs
* @param inMessage the current message
*/
// CHECKSTYLE:OFF Max executable statement count limitation
public static void rebaseResponse(EndpointReferenceType reference, AddressingProperties inMAPs, final Message inMessage) {
String namespaceURI = inMAPs.getNamespaceURI();
if (!ContextUtils.retrievePartialResponseSent(inMessage)) {
ContextUtils.storePartialResponseSent(inMessage);
Exchange exchange = inMessage.getExchange();
Message fullResponse = exchange.getOutMessage();
Message partialResponse = ContextUtils.createMessage(exchange);
ensurePartialResponseMAPs(partialResponse, namespaceURI);
// ensure the inbound MAPs are available in the partial response
// message (used to determine relatesTo etc.)
ContextUtils.propogateReceivedMAPs(inMAPs, partialResponse);
Destination target = inMessage.getDestination();
if (target == null) {
return;
}
try {
if (reference == null) {
reference = ContextUtils.getNoneEndpointReference();
}
Conduit backChannel = target.getBackChannel(inMessage);
if (backChannel != null) {
partialResponse.put(Message.PARTIAL_RESPONSE_MESSAGE, Boolean.TRUE);
partialResponse.put(Message.EMPTY_PARTIAL_RESPONSE_MESSAGE, Boolean.TRUE);
boolean robust = MessageUtils.getContextualBoolean(inMessage, Message.ROBUST_ONEWAY, false);
if (robust) {
BindingOperationInfo boi = exchange.getBindingOperationInfo();
// insert the executor in the exchange to fool the OneWayProcessorInterceptor
exchange.put(Executor.class, getExecutor(inMessage));
// pause dispatch on current thread and resume...
inMessage.getInterceptorChain().pause();
inMessage.getInterceptorChain().resume();
// restore the BOI for the partial response handling
exchange.put(BindingOperationInfo.class, boi);
}
// set up interceptor chains and send message
InterceptorChain chain = fullResponse != null ? fullResponse.getInterceptorChain() : OutgoingChainInterceptor.getOutInterceptorChain(exchange);
exchange.setOutMessage(partialResponse);
partialResponse.setInterceptorChain(chain);
exchange.put(ConduitSelector.class, new PreexistingConduitSelector(backChannel, exchange.getEndpoint()));
if (chain != null && !chain.doIntercept(partialResponse) && partialResponse.getContent(Exception.class) != null) {
if (partialResponse.getContent(Exception.class) instanceof Fault) {
throw (Fault) partialResponse.getContent(Exception.class);
}
throw new Fault(partialResponse.getContent(Exception.class));
}
if (chain != null) {
chain.reset();
}
exchange.put(ConduitSelector.class, new NullConduitSelector());
if (fullResponse == null) {
fullResponse = ContextUtils.createMessage(exchange);
}
exchange.setOutMessage(fullResponse);
Destination destination = createDecoupledDestination(exchange, reference);
exchange.setDestination(destination);
}
} catch (Exception e) {
LOG.log(Level.WARNING, "SERVER_TRANSPORT_REBASE_FAILURE_MSG", e);
}
}
}
use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class Proxy method createClient.
protected Client createClient(Bus bus, Endpoint endpoint, final ProtocolVariation protocol, Conduit conduit, final EndpointReferenceType address) {
ConduitSelector cs = new DeferredConduitSelector(conduit) {
@Override
public synchronized Conduit selectConduit(Message message) {
Conduit conduit = null;
EndpointInfo endpointInfo = getEndpoint().getEndpointInfo();
EndpointReferenceType original = endpointInfo.getTarget();
try {
if (null != address) {
endpointInfo.setAddress(address);
}
conduit = super.selectConduit(message);
} finally {
endpointInfo.setAddress(original);
}
return conduit;
}
};
RMClient client = new RMClient(bus, endpoint, cs);
// WS-RM requires ws-addressing
WSAddressingFeature wsa = new WSAddressingFeature();
wsa.setAddressingRequired(true);
wsa.initialize(client, bus);
Map<String, Object> context = client.getRequestContext();
context.put(MAPAggregator.ADDRESSING_NAMESPACE, protocol.getWSANamespace());
context.put(RMManager.WSRM_VERSION_PROPERTY, protocol.getWSRMNamespace());
context.put(RMManager.WSRM_WSA_VERSION_PROPERTY, protocol.getWSANamespace());
return client;
}
Aggregations