use of org.talend.esb.policy.correlation.impl.CorrelationIDAssertion.MethodType 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.talend.esb.policy.correlation.impl.CorrelationIDAssertion.MethodType in project tesb-rt-se by Talend.
the class CorrelationIDInterceptorProvider method process.
static void process(Message message) throws SAXException, IOException, ParserConfigurationException {
AssertionInfoMap aim = message.get(AssertionInfoMap.class);
if (aim != null) {
Collection<AssertionInfo> ais = aim.get(CorrelationIDPolicyBuilder.CORRELATION_ID);
if (ais == null) {
return;
}
for (AssertionInfo ai : ais) {
if (ai.getAssertion() instanceof CorrelationIDAssertion) {
CorrelationIDAssertion cAssertion = (CorrelationIDAssertion) ai.getAssertion();
MethodType mType = cAssertion.getMethodType();
// String value = cAssetrion.getValue();
String correlationId = null;
// get ID from Http header
correlationId = CorrelationIdProtocolHeaderCodec.readCorrelationId(message);
// get ID from SOAP header
if (null == correlationId) {
correlationId = CorrelationIdSoapCodec.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) {
if (MethodType.XPATH.equals(mType)) {
XPathProcessor proc = new XPathProcessor(cAssertion, 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);
// MessageUtils.isOutbound(message)) {// RESP_OUT
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);
}
}
// }
ai.setAsserted(true);
}
}
}
}
Aggregations