use of org.apache.cxf.message.Message 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.Message in project tesb-rt-se by Talend.
the class CompressionOutInterceptorTest method handleRuntimeException1.
@Test
public void handleRuntimeException1() throws Exception {
CompressionOutInterceptor c = new CompressionOutInterceptor() {
public void wrapOriginalOutputStream(Message message) throws Fault {
throw new RuntimeException();
}
};
try {
c.handleMessage(CompressionCommonTest.getMessageStub(null, null));
} catch (RuntimeException ex) {
return;
}
fail("No exception is not expected");
}
use of org.apache.cxf.message.Message in project tesb-rt-se by Talend.
the class CompressionPolicyBuilderTest method testCompressionPolicyBuilder.
@Test
public void testCompressionPolicyBuilder() {
Collection<Assertion> c = new ArrayList<Assertion>();
AssertionInfoMap aim = new AssertionInfoMap(c);
Message m = CompressionCommonTest.getMessageStub(aim, null);
try {
assertNull(CompressionPolicyBuilder.getAssertion(m));
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
}
use of org.apache.cxf.message.Message in project tesb-rt-se by Talend.
the class STSRESTOutInterceptorTest method handleMessageNotRequestor.
@Test
public void handleMessageNotRequestor() throws Exception {
STSRESTOutInterceptor i = new STSRESTOutInterceptor();
Message message = createMock(Message.class);
message.get(Message.REQUESTOR_ROLE);
expectLastCall().andReturn(false).anyTimes();
STSClient stsClient = createMock(STSClient.class);
i.setStsClient(stsClient);
assertSame(stsClient, i.getStsClient());
replay(message);
i.handleMessage(message);
verify(message);
}
use of org.apache.cxf.message.Message in project tesb-rt-se by Talend.
the class STSRESTOutInterceptorTest method handleMessageNoStsClient.
@Test
public void handleMessageNoStsClient() throws Exception {
STSRESTOutInterceptor i = new STSRESTOutInterceptor();
Message message = createMock(Message.class);
message.get(Message.REQUESTOR_ROLE);
expectLastCall().andReturn(true).anyTimes();
i.setStsClient(null);
assertSame(null, i.getStsClient());
replay(message);
i.handleMessage(message);
verify(message);
}
Aggregations