use of org.apache.camel.impl.DefaultMessage in project camel by apache.
the class BeanInfoOverloadedTest method testBeanInfoOverloaded.
public void testBeanInfoOverloaded() throws Exception {
BeanInfo beanInfo = new BeanInfo(context, Bean.class);
Message message = new DefaultMessage();
message.setBody(new RequestB());
Exchange exchange = new DefaultExchange(context);
exchange.setIn(message);
MethodInvocation methodInvocation = beanInfo.createInvocation(new Bean(), exchange);
Method method = methodInvocation.getMethod();
assertEquals("doSomething", method.getName());
assertEquals(RequestB.class, method.getGenericParameterTypes()[0]);
}
use of org.apache.camel.impl.DefaultMessage in project openremote by openremote.
the class EventSubscriptions method splitForSubscribers.
@SuppressWarnings("unchecked")
public <T extends SharedEvent> List<Message> splitForSubscribers(Exchange exchange) {
List<Message> messageList = new ArrayList<>();
SharedEvent event = exchange.getIn().getBody(SharedEvent.class);
if (event == null)
return messageList;
boolean accessibleForRestrictedUsers = exchange.getIn().getHeader(HEADER_ACCESS_RESTRICTED, false, Boolean.class);
Set<Map.Entry<String, SessionSubscriptions>> sessionSubscriptionsSet;
synchronized (this.sessionSubscriptions) {
sessionSubscriptionsSet = new HashSet<>(sessionSubscriptions.entrySet());
}
for (Map.Entry<String, SessionSubscriptions> entry : sessionSubscriptionsSet) {
String sessionKey = entry.getKey();
SessionSubscriptions subscriptions = entry.getValue();
for (SessionSubscription sessionSubscription : subscriptions) {
if (!sessionSubscription.matches(accessibleForRestrictedUsers, event))
continue;
if (sessionSubscription.subscription.getFilter() == null || sessionSubscription.subscription.getFilter().apply(event)) {
LOG.fine("Creating message for subscribed session '" + sessionKey + "': " + event);
if (sessionSubscription.subscription.getInternalConsumer() == null) {
Message msg = new DefaultMessage();
// Don't copy the event, use same reference
msg.setBody(event);
// Copy headers
msg.setHeaders(new HashMap<>(exchange.getIn().getHeaders()));
msg.setHeader(WebsocketConstants.SESSION_KEY, sessionKey);
messageList.add(msg);
} else {
sessionSubscription.subscription.getInternalConsumer().accept(event);
}
}
}
}
return messageList;
}
use of org.apache.camel.impl.DefaultMessage in project atlasmap by atlasmap.
the class AtlasMapMultiDocsTest method test.
@Test
@DirtiesContext
public void test() throws Exception {
result.setExpectedCount(1);
Map<String, Message> sourceMap = new HashMap<>();
SourceContact javaSource = new SourceContact();
javaSource.setFirstName("JavaFirstName");
javaSource.setLastName("JavaLastName");
javaSource.setPhoneNumber("JavaPhoneNumber");
javaSource.setZipCode("JavaZipCode");
Message msg = new DefaultMessage(camelContext);
msg.setBody(javaSource);
sourceMap.put("DOCID:JAVA:CONTACT:S", msg);
msg = new DefaultMessage(camelContext);
msg.setBody(JSON_SOURCE);
sourceMap.put("DOCID:JSON:CONTACT:S", msg);
msg = new DefaultMessage(camelContext);
msg.setBody(XML_SOURCE);
sourceMap.put("DOCID:XML:CONTACT:S", msg);
ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
producerTemplate.sendBodyAndProperty("direct:start", null, "CAPTURED_OUT_MESSAGES_MAP", sourceMap);
MockEndpoint.assertIsSatisfied(camelContext);
Exchange exchange = result.getExchanges().get(0);
Map<?, ?> targetMap = exchange.getProperty(AtlasConstants.ATLAS_TARGET_MAP, Map.class);
TargetContact javaTarget = (TargetContact) targetMap.get("DOCID:JAVA:CONTACT:T");
assertEquals("JavaFirstName", javaTarget.getFirstName());
assertEquals("XmlLastName", javaTarget.getLastName());
assertEquals("JsonPhoneNumber", javaTarget.getPhoneNumber());
String jsonTarget = (String) targetMap.get("DOCID:JSON:CONTACT:T");
ObjectMapper mapper = new ObjectMapper();
JsonNode jsonTargetNode = mapper.readTree(jsonTarget);
assertEquals("JsonFirstName", jsonTargetNode.get("firstName").asText());
assertEquals("JavaLastName", jsonTargetNode.get("lastName").asText());
assertEquals("XmlPhoneNumber", jsonTargetNode.get("phoneNumber").asText());
String xmlTarget = (String) targetMap.get("DOCID:XML:CONTACT:T");
JAXBElement<XmlContactAttribute> xmlTargetJaxb = AtlasXmlTestHelper.unmarshal(xmlTarget, XmlContactAttribute.class);
XmlContactAttribute xmlTargetObj = xmlTargetJaxb.getValue();
assertEquals("XmlFirstName", xmlTargetObj.getFirstName());
assertEquals("JsonLastName", xmlTargetObj.getLastName());
assertEquals("JavaPhoneNumber", xmlTargetObj.getPhoneNumber());
}
Aggregations