use of org.orcid.jaxb.model.record_rc3.Email in project camel by apache.
the class QuickfixjProducerTest method processInOutExchangeSuccess.
@Test
public void processInOutExchangeSuccess() throws Exception {
Mockito.when(mockExchange.getPattern()).thenReturn(ExchangePattern.InOut);
SessionID responseSessionID = new SessionID(sessionID.getBeginString(), sessionID.getTargetCompID(), sessionID.getSenderCompID());
Mockito.when(mockExchange.getProperty(QuickfixjProducer.CORRELATION_CRITERIA_KEY)).thenReturn(new MessagePredicate(responseSessionID, MsgType.EMAIL));
Mockito.when(mockExchange.getProperty(QuickfixjProducer.CORRELATION_TIMEOUT_KEY, 1000L, Long.class)).thenReturn(5000L);
org.apache.camel.Message mockOutboundCamelMessage = Mockito.mock(org.apache.camel.Message.class);
Mockito.when(mockExchange.getOut()).thenReturn(mockOutboundCamelMessage);
final Message outboundFixMessage = new Email();
outboundFixMessage.getHeader().setString(SenderCompID.FIELD, "TARGET");
outboundFixMessage.getHeader().setString(TargetCompID.FIELD, "SENDER");
Session mockSession = Mockito.spy(TestSupport.createSession(sessionID));
Mockito.doReturn(mockSession).when(producer).getSession(MessageUtils.getSessionID(inboundFixMessage));
Mockito.doAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
new Timer().schedule(new TimerTask() {
@Override
public void run() {
try {
quickfixjEngine.getMessageCorrelator().onEvent(QuickfixjEventCategory.AppMessageReceived, sessionID, outboundFixMessage);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}, 10);
return true;
}
}).when(mockSession).send(Matchers.isA(Message.class));
producer.process(mockExchange);
Mockito.verify(mockExchange, Mockito.never()).setException(Matchers.isA(IllegalStateException.class));
Mockito.verify(mockSession).send(inboundFixMessage);
Mockito.verify(mockOutboundCamelMessage).getHeaders();
Mockito.verify(mockOutboundCamelMessage).setBody(outboundFixMessage);
}
use of org.orcid.jaxb.model.record_rc3.Email in project camel by apache.
the class TestSupport method createEmailMessage.
public static Email createEmailMessage(String subject) {
Email email = new Email(new EmailThreadID("ID"), new EmailType(EmailType.NEW), new Subject(subject));
Email.LinesOfText text = new Email.LinesOfText();
text.set(new Text("Content"));
email.addGroup(text);
return email;
}
use of org.orcid.jaxb.model.record_rc3.Email in project camel by apache.
the class DynamicRoutingExample method sendMessage.
public void sendMessage() throws Exception {
DefaultCamelContext context = new DefaultCamelContext();
final CountDownLatch logonLatch = new CountDownLatch(4);
final CountDownLatch receivedMessageLatch = new CountDownLatch(1);
RouteBuilder routes = new RouteBuilder() {
@Override
public void configure() throws Exception {
// Release latch when session logon events are received
// We expect four logon events (four sessions)
from("quickfix:examples/gateway.cfg").filter(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.SessionLogon)).bean(new CountDownLatchDecrementer("logon", logonLatch));
// Dynamic router -- Uses FIX DeliverTo tags
from("quickfix:examples/gateway.cfg").filter(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageReceived)).recipientList(method(new FixMessageRouter("quickfix:examples/gateway.cfg")));
// Logger app messages as JSON
from("quickfix:examples/gateway.cfg").filter(PredicateBuilder.or(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageReceived), header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageSent))).bean(new QuickfixjMessageJsonPrinter());
// If the trader@2 session receives an email then release the latch
from("quickfix:examples/gateway.cfg?sessionID=FIX.4.2:TRADER@2->GATEWAY").filter(PredicateBuilder.and(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageReceived), header(QuickfixjEndpoint.MESSAGE_TYPE_KEY).isEqualTo(MsgType.EMAIL))).bean(new CountDownLatchDecrementer("message", receivedMessageLatch));
}
};
context.addRoutes(routes);
LOG.info("Starting Camel context");
context.start();
// synchronization due to app messages being sent before being logged on
if (!logonLatch.await(5, TimeUnit.SECONDS)) {
throw new IllegalStateException("Logon did not complete");
}
String gatewayUri = "quickfix:examples/gateway.cfg?sessionID=FIX.4.2:TRADER@1->GATEWAY";
Endpoint gatewayEndpoint = context.getEndpoint(gatewayUri);
Producer producer = gatewayEndpoint.createProducer();
Email email = TestSupport.createEmailMessage("Dynamic Routing Example");
email.getHeader().setString(DeliverToCompID.FIELD, "TRADER@2");
LOG.info("Sending routed message");
Exchange exchange = producer.createExchange(ExchangePattern.InOnly);
exchange.getIn().setBody(email);
producer.process(exchange);
if (!receivedMessageLatch.await(5, TimeUnit.SECONDS)) {
throw new IllegalStateException("Message did not reach target");
}
LOG.info("Message received, shutting down Camel context");
context.stop();
LOG.info("Dynamic routing example complete");
}
use of org.orcid.jaxb.model.record_rc3.Email in project camel by apache.
the class QuickfixjEngineTest method doApplicationMessageEventsTest.
private void doApplicationMessageEventsTest(SessionID acceptorSessionID, SessionID initiatorSessionID, QuickfixjEngine quickfixjEngine) throws SessionNotFound, InterruptedException, FieldNotFound {
final List<EventRecord> events = new ArrayList<EventRecord>();
final CountDownLatch messageLatch = new CountDownLatch(1);
QuickfixjEventListener messageListener = new QuickfixjEventListener() {
@Override
public synchronized void onEvent(QuickfixjEventCategory eventCategory, SessionID sessionID, Message message) {
EventRecord event = new EventRecord(eventCategory, sessionID, message);
events.add(event);
if (eventCategory == QuickfixjEventCategory.AppMessageReceived) {
messageLatch.countDown();
}
}
};
quickfixjEngine.addEventListener(messageListener);
Email email = TestSupport.createEmailMessage("Test");
Session.sendToTarget(email, initiatorSessionID);
assertTrue("Application message not received", messageLatch.await(5000, TimeUnit.MILLISECONDS));
quickfixjEngine.removeEventListener(messageListener);
assertThat(events.size(), is(2));
EventRecord sendEvent = new EventRecord(QuickfixjEventCategory.AppMessageSent, initiatorSessionID, new Message());
assertTrue(events.contains(sendEvent));
int sendEventIndex = events.indexOf(sendEvent);
assertThat(events.get(sendEventIndex).message.getHeader().getString(MsgType.FIELD), is(MsgType.EMAIL));
EventRecord receiveEvent = new EventRecord(QuickfixjEventCategory.AppMessageReceived, acceptorSessionID, new Message());
assertTrue(events.contains(receiveEvent));
int receiveEventIndex = events.indexOf(receiveEvent);
assertThat(events.get(receiveEventIndex).message.getHeader().getString(MsgType.FIELD), is(MsgType.EMAIL));
}
use of org.orcid.jaxb.model.record_rc3.Email in project ORCID-Source by ORCID.
the class MemberV2ApiServiceDelegatorImpl method viewEmails.
@Override
public Response viewEmails(String orcid) {
Emails emails = null;
long lastModified = getLastModifiedTime(orcid);
try {
// return all emails if client has /email/read-private scope
orcidSecurityManager.checkClientAccessAndScopes(orcid, ScopePathType.EMAIL_READ_PRIVATE);
emails = emailManagerReadOnly.getEmails(orcid, lastModified);
// Lets copy the list so we don't modify the cached collection
List<Email> filteredList = new ArrayList<Email>(emails.getEmails());
emails = new Emails();
emails.setEmails(filteredList);
} catch (OrcidAccessControlException e) {
emails = emailManagerReadOnly.getEmails(orcid, lastModified);
// Lets copy the list so we don't modify the cached collection
List<Email> filteredList = new ArrayList<Email>(emails.getEmails());
emails = new Emails();
emails.setEmails(filteredList);
// Filter just in case client doesn't have the /email/read-private
// scope
orcidSecurityManager.checkAndFilter(orcid, emails.getEmails(), ScopePathType.ORCID_BIO_READ_LIMITED);
}
ElementUtils.setPathToEmail(emails, orcid);
Api2_0_LastModifiedDatesHelper.calculateLastModified(emails);
sourceUtils.setSourceName(emails);
return Response.ok(emails).build();
}
Aggregations