use of org.orcid.jaxb.model.record_rc2.Email in project camel by apache.
the class SimpleMessagingExample method sendMessage.
public void sendMessage() throws Exception {
DefaultCamelContext context = new DefaultCamelContext();
final CountDownLatch logonLatch = new CountDownLatch(2);
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 two events, one for the trader session and one for the market session
from("quickfix:examples/inprocess.cfg").filter(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.SessionLogon)).bean(new CountDownLatchDecrementer("logon", logonLatch));
// For all received messages, print the JSON-formatted message to stdout
from("quickfix:examples/inprocess.cfg").filter(PredicateBuilder.or(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AdminMessageReceived), header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageReceived))).bean(new QuickfixjMessageJsonPrinter());
// If the market session receives an email then release the latch
from("quickfix:examples/inprocess.cfg?sessionID=FIX.4.2:MARKET->TRADER").filter(header(QuickfixjEndpoint.MESSAGE_TYPE_KEY).isEqualTo(MsgType.EMAIL)).bean(new CountDownLatchDecrementer("message", receivedMessageLatch));
}
};
context.addRoutes(routes);
LOG.info("Starting Camel context");
context.start();
if (!logonLatch.await(5L, TimeUnit.SECONDS)) {
throw new IllegalStateException("Logon did not succeed");
}
String marketUri = "quickfix:examples/inprocess.cfg?sessionID=FIX.4.2:TRADER->MARKET";
Producer producer = context.getEndpoint(marketUri).createProducer();
Email email = TestSupport.createEmailMessage("Example");
Exchange exchange = producer.createExchange(ExchangePattern.InOnly);
exchange.getIn().setBody(email);
producer.process(exchange);
if (!receivedMessageLatch.await(5L, TimeUnit.SECONDS)) {
throw new IllegalStateException("Message did not reach market");
}
LOG.info("Message received, shutting down Camel context");
context.stop();
LOG.info("Example complete");
}
use of org.orcid.jaxb.model.record_rc2.Email in project camel by apache.
the class QuickfixjComponentTest method messagePublication.
@Test
public void messagePublication() throws Exception {
setUpComponent();
// Create settings file with both acceptor and initiator
SessionSettings settings = new SessionSettings();
settings.setString(Acceptor.SETTING_SOCKET_ACCEPT_PROTOCOL, ProtocolFactory.getTypeString(ProtocolFactory.VM_PIPE));
settings.setString(Initiator.SETTING_SOCKET_CONNECT_PROTOCOL, ProtocolFactory.getTypeString(ProtocolFactory.VM_PIPE));
settings.setBool(Session.SETTING_USE_DATA_DICTIONARY, false);
SessionID acceptorSessionID = new SessionID(FixVersions.BEGINSTRING_FIX44, "ACCEPTOR", "INITIATOR");
settings.setString(acceptorSessionID, SessionFactory.SETTING_CONNECTION_TYPE, SessionFactory.ACCEPTOR_CONNECTION_TYPE);
settings.setLong(acceptorSessionID, Acceptor.SETTING_SOCKET_ACCEPT_PORT, 1234);
setSessionID(settings, acceptorSessionID);
SessionID initiatorSessionID = new SessionID(FixVersions.BEGINSTRING_FIX44, "INITIATOR", "ACCEPTOR");
settings.setString(initiatorSessionID, SessionFactory.SETTING_CONNECTION_TYPE, SessionFactory.INITIATOR_CONNECTION_TYPE);
settings.setLong(initiatorSessionID, Initiator.SETTING_SOCKET_CONNECT_PORT, 1234);
settings.setLong(initiatorSessionID, Initiator.SETTING_RECONNECT_INTERVAL, 1);
setSessionID(settings, initiatorSessionID);
writeSettings(settings, true);
Endpoint endpoint = component.createEndpoint(getEndpointUri(settingsFile.getName(), null));
// Start the component and wait for the FIX sessions to be logged on
final CountDownLatch logonLatch = new CountDownLatch(2);
final CountDownLatch messageLatch = new CountDownLatch(2);
Consumer consumer = endpoint.createConsumer(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
QuickfixjEventCategory eventCategory = (QuickfixjEventCategory) exchange.getIn().getHeader(QuickfixjEndpoint.EVENT_CATEGORY_KEY);
if (eventCategory == QuickfixjEventCategory.SessionLogon) {
logonLatch.countDown();
} else if (eventCategory == QuickfixjEventCategory.AppMessageReceived) {
messageLatch.countDown();
}
}
});
ServiceHelper.startService(consumer);
// will start the component
camelContext.start();
assertTrue("Session not created", logonLatch.await(5000, TimeUnit.MILLISECONDS));
Endpoint producerEndpoint = component.createEndpoint(getEndpointUri(settingsFile.getName(), acceptorSessionID));
Producer producer = producerEndpoint.createProducer();
// FIX message to send
Email email = new Email(new EmailThreadID("ID"), new EmailType(EmailType.NEW), new Subject("Test"));
Exchange exchange = producer.createExchange(ExchangePattern.InOnly);
exchange.getIn().setBody(email);
producer.process(exchange);
// Produce with no session ID specified, session ID must be in message
Producer producer2 = endpoint.createProducer();
email.getHeader().setString(SenderCompID.FIELD, acceptorSessionID.getSenderCompID());
email.getHeader().setString(TargetCompID.FIELD, acceptorSessionID.getTargetCompID());
producer2.process(exchange);
assertTrue("Messages not received", messageLatch.await(5000, TimeUnit.MILLISECONDS));
}
use of org.orcid.jaxb.model.record_rc2.Email in project camel by apache.
the class QuickfixjProducerTest method processInOutExchangeSendUnsuccessful.
@Test
public void processInOutExchangeSendUnsuccessful() throws Exception {
Mockito.when(mockExchange.getPattern()).thenReturn(ExchangePattern.InOut);
Mockito.when(mockExchange.getProperty(QuickfixjProducer.CORRELATION_CRITERIA_KEY)).thenReturn(new MessagePredicate(sessionID, 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 false;
}
}).when(mockSession).send(Matchers.isA(Message.class));
producer.process(mockExchange);
Mockito.verify(mockOutboundCamelMessage, Mockito.never()).setBody(Matchers.isA(Message.class));
Mockito.verify(mockSession).send(inboundFixMessage);
Mockito.verify(mockExchange).setException(Matchers.isA(CannotSendException.class));
}
use of org.orcid.jaxb.model.record_rc2.Email in project ORCID-Source by ORCID.
the class EmailManagerReadOnlyImpl method getEmails.
private Emails getEmails(String orcid, Visibility visibility) {
List<EmailEntity> entities = new ArrayList<EmailEntity>();
if (visibility == null) {
entities = emailDao.findByOrcid(orcid);
} else {
entities = emailDao.findByOrcid(orcid, Visibility.PUBLIC);
}
List<org.orcid.jaxb.model.record_v2.Email> emailList = jpaJaxbEmailAdapter.toEmailList(entities);
Emails emails = new Emails();
emails.setEmails(emailList);
return emails;
}
use of org.orcid.jaxb.model.record_rc2.Email in project ORCID-Source by ORCID.
the class PersonDetailsManagerReadOnlyImpl method getPersonDetails.
@Override
public Person getPersonDetails(String orcid) {
long lastModifiedTime = getLastModified(orcid);
Person person = new Person();
person.setName(recordNameManager.getRecordName(orcid, lastModifiedTime));
person.setBiography(biographyManager.getBiography(orcid, lastModifiedTime));
Addresses addresses = addressManager.getAddresses(orcid, lastModifiedTime);
if (addresses.getAddress() != null) {
Addresses filteredAddresses = new Addresses();
filteredAddresses.setAddress(new ArrayList<Address>(addresses.getAddress()));
person.setAddresses(filteredAddresses);
}
PersonExternalIdentifiers extIds = externalIdentifierManager.getExternalIdentifiers(orcid, lastModifiedTime);
if (extIds.getExternalIdentifiers() != null) {
PersonExternalIdentifiers filteredExtIds = new PersonExternalIdentifiers();
filteredExtIds.setExternalIdentifiers(new ArrayList<PersonExternalIdentifier>(extIds.getExternalIdentifiers()));
person.setExternalIdentifiers(filteredExtIds);
}
Keywords keywords = profileKeywordManager.getKeywords(orcid, lastModifiedTime);
if (keywords.getKeywords() != null) {
Keywords filteredKeywords = new Keywords();
filteredKeywords.setKeywords(new ArrayList<Keyword>(keywords.getKeywords()));
person.setKeywords(filteredKeywords);
}
OtherNames otherNames = otherNameManager.getOtherNames(orcid, lastModifiedTime);
if (otherNames.getOtherNames() != null) {
OtherNames filteredOtherNames = new OtherNames();
filteredOtherNames.setOtherNames(new ArrayList<OtherName>(otherNames.getOtherNames()));
person.setOtherNames(filteredOtherNames);
}
ResearcherUrls rUrls = researcherUrlManager.getResearcherUrls(orcid, lastModifiedTime);
if (rUrls.getResearcherUrls() != null) {
ResearcherUrls filteredRUrls = new ResearcherUrls();
filteredRUrls.setResearcherUrls(new ArrayList<ResearcherUrl>(rUrls.getResearcherUrls()));
person.setResearcherUrls(filteredRUrls);
}
Emails emails = emailManager.getEmails(orcid, lastModifiedTime);
if (emails.getEmails() != null) {
Emails filteredEmails = new Emails();
filteredEmails.setEmails(new ArrayList<Email>(emails.getEmails()));
person.setEmails(filteredEmails);
}
return person;
}
Aggregations