use of org.apache.cxf.transport.MessageObserver in project jbossws-cxf by jbossws.
the class SOAPConnectionImpl method createMessageObserver.
@SuppressWarnings("unchecked")
private MessageObserver createMessageObserver(final Conduit c) {
return new MessageObserver() {
public void onMessage(Message inMessage) {
LoadingByteArrayOutputStream bout = new LoadingByteArrayOutputStream();
try {
IOUtils.copy(inMessage.getContent(InputStream.class), bout);
inMessage.getExchange().put(InputStream.class, bout.createInputStream());
Map<String, List<String>> inHeaders = (Map<String, List<String>>) inMessage.get(Message.PROTOCOL_HEADERS);
inMessage.getExchange().put(Message.PROTOCOL_HEADERS, inHeaders);
c.close(inMessage);
} catch (IOException e) {
// ignore
Logger.getLogger(SOAPConnectionImpl.class).trace(e);
}
}
};
}
use of org.apache.cxf.transport.MessageObserver in project tomee by apache.
the class ClientImpl method doInvoke.
private Object[] doInvoke(final ClientCallback callback, BindingOperationInfo oi, Object[] params, Map<String, Object> context, Exchange exchange) throws Exception {
Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
ClassLoaderHolder origLoader = null;
Map<String, Object> resContext = null;
try {
ClassLoader loader = bus.getExtension(ClassLoader.class);
if (loader != null) {
origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
}
if (exchange == null) {
exchange = new ExchangeImpl();
}
exchange.setSynchronous(callback == null);
Endpoint endpoint = getEndpoint();
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Invoke, operation info: " + oi + ", params: " + Arrays.toString(params));
}
Message message = endpoint.getBinding().createMessage();
// on message
if (context == null) {
context = new HashMap<>();
}
Map<String, Object> reqContext = CastUtils.cast((Map<?, ?>) context.get(REQUEST_CONTEXT));
resContext = CastUtils.cast((Map<?, ?>) context.get(RESPONSE_CONTEXT));
if (reqContext == null) {
reqContext = new HashMap<>(getRequestContext());
context.put(REQUEST_CONTEXT, reqContext);
}
if (resContext == null) {
resContext = new ResponseContext(responseContext);
context.put(RESPONSE_CONTEXT, resContext);
}
message.put(Message.INVOCATION_CONTEXT, context);
setContext(reqContext, message);
exchange.putAll(reqContext);
setParameters(params, message);
if (null != oi) {
exchange.setOneWay(oi.getOutput() == null);
}
exchange.setOutMessage(message);
exchange.put(ClientCallback.class, callback);
setOutMessageProperties(message, oi);
setExchangeProperties(exchange, endpoint, oi);
PhaseInterceptorChain chain = setupInterceptorChain(endpoint);
message.setInterceptorChain(chain);
if (callback == null) {
chain.setFaultObserver(outFaultObserver);
} else {
// We need to wrap the outFaultObserver if the callback is not null
// calling the conduitSelector.complete to make sure the fail over feature works
chain.setFaultObserver(new MessageObserver() {
public void onMessage(Message message) {
Exception ex = message.getContent(Exception.class);
if (ex != null) {
completeExchange(message.getExchange());
if (message.getContent(Exception.class) == null) {
// handle the right response
Message inMsg = message.getExchange().getInMessage();
Map<String, Object> ctx = responseContext.get(Thread.currentThread());
List<Object> resList = CastUtils.cast(inMsg.getContent(List.class));
Object[] result = resList == null ? null : resList.toArray();
callback.handleResponse(ctx, result);
return;
}
}
outFaultObserver.onMessage(message);
}
});
}
prepareConduitSelector(message);
// add additional interceptors and such
modifyChain(chain, message, false);
try {
chain.doIntercept(message);
} catch (Fault fault) {
enrichFault(fault);
throw fault;
}
if (callback != null) {
return null;
}
return processResult(message, exchange, oi, resContext);
} finally {
// ensure ResponseContext has HTTP RESPONSE CODE
if (null != exchange) {
Integer responseCode = (Integer) exchange.get(Message.RESPONSE_CODE);
resContext.put(MessageContext.HTTP_RESPONSE_CODE, responseCode);
resContext.put(org.apache.cxf.message.Message.RESPONSE_CODE, responseCode);
setResponseContext(resContext);
}
if (origLoader != null) {
origLoader.reset();
}
if (origBus != bus) {
BusFactory.setThreadDefaultBus(origBus);
}
}
}
use of org.apache.cxf.transport.MessageObserver in project tomee by apache.
the class ClientImpl method setExchangeProperties.
protected void setExchangeProperties(Exchange exchange, Endpoint endpoint, BindingOperationInfo boi) {
if (endpoint != null) {
exchange.put(Endpoint.class, endpoint);
exchange.put(Service.class, endpoint.getService());
exchange.put(Binding.class, endpoint.getBinding());
}
if (boi != null) {
exchange.put(BindingOperationInfo.class, boi);
}
if (exchange.isSynchronous() || executor == null) {
exchange.put(MessageObserver.class, this);
} else {
exchange.put(Executor.class, executor);
exchange.put(MessageObserver.class, new MessageObserver() {
public void onMessage(final Message message) {
if (!message.getExchange().containsKey(Executor.class.getName() + ".USING_SPECIFIED")) {
executor.execute(new Runnable() {
public void run() {
ClientImpl.this.onMessage(message);
}
});
} else {
ClientImpl.this.onMessage(message);
}
}
});
}
exchange.put(Retryable.class, this);
exchange.put(Client.class, this);
exchange.put(Bus.class, bus);
if (endpoint != null) {
EndpointInfo endpointInfo = endpoint.getEndpointInfo();
if (boi != null) {
exchange.put(Message.WSDL_OPERATION, boi.getName());
}
QName serviceQName = endpointInfo.getService().getName();
exchange.put(Message.WSDL_SERVICE, serviceQName);
QName interfaceQName = endpointInfo.getService().getInterface().getName();
exchange.put(Message.WSDL_INTERFACE, interfaceQName);
QName portQName = endpointInfo.getName();
exchange.put(Message.WSDL_PORT, portQName);
URI wsdlDescription = endpointInfo.getProperty("URI", URI.class);
if (wsdlDescription == null) {
String address = endpointInfo.getAddress();
try {
wsdlDescription = new URI(address + "?wsdl");
} catch (URISyntaxException e) {
// do nothing
}
endpointInfo.setProperty("URI", wsdlDescription);
}
exchange.put(Message.WSDL_DESCRIPTION, wsdlDescription);
}
}
use of org.apache.cxf.transport.MessageObserver in project cxf by apache.
the class AbstractConduitSelector method createConduit.
protected Conduit createConduit(Message message, Exchange exchange, ConduitInitiator conduitInitiator) throws IOException {
Conduit c;
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.MessageObserver in project cxf by apache.
the class ContextUtils method createDecoupledDestination.
public static Destination createDecoupledDestination(Exchange exchange, final EndpointReferenceType reference) {
final EndpointInfo ei = exchange.getEndpoint().getEndpointInfo();
return new Destination() {
public EndpointReferenceType getAddress() {
return reference;
}
public Conduit getBackChannel(Message inMessage) throws IOException {
Bus bus = inMessage.getExchange().getBus();
// this is a response targeting a decoupled endpoint. Treat it as a oneway so
// we don't wait for a response.
inMessage.getExchange().setOneWay(true);
ConduitInitiator conduitInitiator = bus.getExtension(ConduitInitiatorManager.class).getConduitInitiatorForUri(reference.getAddress().getValue());
if (conduitInitiator != null) {
Conduit c = conduitInitiator.getConduit(ei, reference, bus);
// ensure decoupled back channel input stream is closed
c.setMessageObserver(new MessageObserver() {
public void onMessage(Message m) {
InputStream is = m.getContent(InputStream.class);
if (is != null) {
try {
is.close();
} catch (Exception e) {
// ignore
}
}
}
});
return c;
}
return null;
}
public MessageObserver getMessageObserver() {
return null;
}
public void shutdown() {
}
public void setMessageObserver(MessageObserver observer) {
}
};
}
Aggregations