use of org.apache.cxf.message.Exchange in project tesb-rt-se by Talend.
the class CorrelationIDProcessor method process.
static void process(Message message, Assertion policy) throws SAXException, IOException, ParserConfigurationException {
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "Message process for correlation ID started");
}
String correlationId = null;
// get ID from SOAP header
correlationId = CorrelationIdSoapCodec.readCorrelationId(message);
// get ID from Http header
if (null == correlationId) {
correlationId = CorrelationIdProtocolHeaderCodec.readCorrelationId(message);
}
// get from message
if (null == correlationId) {
// Get ID from Message
correlationId = (String) message.get(CorrelationIDFeature.MESSAGE_CORRELATION_ID);
}
if ((message.getContent(javax.xml.stream.XMLStreamWriter.class) != null) && (message.getContent(javax.xml.stream.XMLStreamWriter.class) instanceof SAAJStreamWriter)) {
NodeList nodeList = ((SAAJStreamWriter) message.getContent(javax.xml.stream.XMLStreamWriter.class)).getDocument().getElementsByTagNameNS("http://www.talend.com/esb/sam/correlationId/v1", "correlationId");
if (nodeList.getLength() > 0) {
correlationId = nodeList.item(0).getTextContent();
}
}
// get from message exchange
if (null == correlationId) {
// Get ID from Message exchange
Exchange ex = message.getExchange();
if (null != ex) {
Message reqMsg = null;
if (MessageUtils.isOutbound(message)) {
reqMsg = ex.getInMessage();
} else {
reqMsg = ex.getOutMessage();
}
if (null != reqMsg) {
correlationId = (String) reqMsg.get(CorrelationIDFeature.MESSAGE_CORRELATION_ID);
}
}
}
// If correlationId is null we should add it to headers
if (null == correlationId) {
MethodType mType = CorrelationIDAssertion.MethodType.CALLBACK;
if (policy instanceof CorrelationIDAssertion) {
mType = ((CorrelationIDAssertion) policy).getMethodType();
}
if (MethodType.XPATH.equals(mType) && !MessageUtils.isFault(message)) {
XPathProcessor proc = new XPathProcessor(policy, message);
correlationId = proc.getCorrelationID();
} else if (MethodType.CALLBACK.equals(mType)) {
CorrelationIDCallbackHandler handler = (CorrelationIDCallbackHandler) message.get(CorrelationIDFeature.CORRELATION_ID_CALLBACK_HANDLER);
if (null == handler) {
handler = (CorrelationIDCallbackHandler) message.getContextualProperty(CorrelationIDFeature.CORRELATION_ID_CALLBACK_HANDLER);
}
if (handler != null)
correlationId = handler.getCorrelationId();
}
// request
if (null == correlationId) {
correlationId = ContextUtils.generateUUID();
}
}
message.put(CorrelationIDFeature.MESSAGE_CORRELATION_ID, correlationId);
if (isRestMessage(message)) {
// Add correlationId to http header
if (null == CorrelationIdProtocolHeaderCodec.readCorrelationId(message)) {
CorrelationIdProtocolHeaderCodec.writeCorrelationId(message, correlationId);
}
} else {
// Add correlationId to soap header
if (null == CorrelationIdSoapCodec.readCorrelationId(message)) {
CorrelationIdSoapCodec.writeCorrelationId(message, correlationId);
}
}
}
use of org.apache.cxf.message.Exchange in project tesb-rt-se by Talend.
the class XPathProcessor method getEncoding.
private String getEncoding(Message message) {
Exchange ex = message.getExchange();
String encoding = (String) message.get(Message.ENCODING);
if (encoding == null && ex.getInMessage() != null) {
encoding = (String) ex.getInMessage().get(Message.ENCODING);
message.put(Message.ENCODING, encoding);
}
if (encoding == null) {
encoding = "UTF-8";
message.put(Message.ENCODING, encoding);
}
return encoding;
}
use of org.apache.cxf.message.Exchange in project jbossws-cxf by jbossws.
the class SOAPConnectionImpl method get.
@Override
public SOAPMessage get(Object addressObject) throws SOAPException {
checkClosed();
String address = getAddress(addressObject);
ConduitInitiator ci = getConduitInitiator(address);
// create a new Message and Exchange
EndpointInfo info = new EndpointInfo();
info.setAddress(address);
Message outMessage = new MessageImpl();
Exchange exch = new ExchangeImpl();
outMessage.setExchange(exch);
// sent GET request
try {
// TODO verify bus
final Conduit c = ci.getConduit(info, BusFactory.getThreadDefaultBus(false));
if (c instanceof HTTPConduit) {
((HTTPConduit) c).getClient().setAutoRedirect(true);
}
outMessage.put(Message.HTTP_REQUEST_METHOD, "GET");
c.prepare(outMessage);
c.setMessageObserver(createMessageObserver(c));
c.close(outMessage);
} catch (Exception ex) {
throw MESSAGES.getRequestCouldNotBeSent(ex);
}
// read SOAPMessage
return readSoapMessage(exch);
}
use of org.apache.cxf.message.Exchange in project jbossws-cxf by jbossws.
the class HandlerChainSortInterceptor method handleMessage.
@Override
@SuppressWarnings("rawtypes")
public void handleMessage(Message message) throws Fault {
if (binding != null) {
Exchange ex = message.getExchange();
if (ex.get(HandlerChainInvoker.class) == null) {
List<Handler> hc = binding.getHandlerChain();
if (hc.size() > 1) {
// no need to sort etc if the chain is empty or has one handler only
Collections.sort(hc, comparator);
// install a new HandlerChainInvoker using the sorted handler chain;
// the AbstractJAXWSHandlerInterceptor will be using this invoker
// instead of creating a new one
ex.put(HandlerChainInvoker.class, new HandlerChainInvoker(hc, isOutbound(message, ex)));
}
}
}
}
use of org.apache.cxf.message.Exchange in project jbossws-cxf by jbossws.
the class JBossWSInvokerTest method getTestExchange.
// build up a fake exchange instance, the minimum required to let the flow proceed till the JBossWSInvoker
private Exchange getTestExchange() {
Exchange exchange = new ExchangeImpl();
Message message = new MessageImpl();
message.setExchange(exchange);
exchange.setInMessage(message);
exchange.put(BindingOperationInfo.class, new BindingOperationInfo());
Service service = new ServiceImpl();
MethodDispatcher md = new MethodDispatcher() {
@Override
public Method getMethod(BindingOperationInfo op) {
return this.getClass().getMethods()[0];
}
@Override
public BindingOperationInfo getBindingOperation(Method m, Endpoint endpoint) {
return null;
}
@Override
public void bind(OperationInfo o, Method... methods) {
}
};
service.put(MethodDispatcher.class.getName(), md);
exchange.put(Service.class, service);
return exchange;
}
Aggregations