Search in sources :

Example 1 with NHINDClientConfig

use of org.nhindirect.nhindclient.config.NHINDClientConfig in project nhin-d by DirectProject.

the class NHINDClientTest method testClient.

/**
     * Quick integration test for the NHINDClient class.
     * 
     * @throws Exception
     */
public void testClient() throws Exception {
    String sender = "lewistower1@gmail.com";
    // Collection<String> receivers = Arrays.asList("beau+receiver@nologs.org", "beau+receiver2@nologs.org", "http://ELS4055:8080/xd/services/DocumentRepository_Service");
    Collection<String> receivers = Arrays.asList("beau+receiver@nologs.org", "beau+receiver2@nologs.org");
    DirectMessage message = new DirectMessage(sender, receivers);
    message.setSubject("This is a test message (subject)");
    message.setBody("Please find the attached data.");
    message.setDirectDocuments(getTestDirectDocuments());
    NHINDClient client = new NHINDClientImpl(new NHINDClientConfig("gmail-smtp.l.google.com", "lewistower1@gmail.com", "hadron106"));
    try {
        client.send(message);
    } catch (Throwable t) {
        Throwable inner = t.getCause();
        if (inner != null && inner instanceof MessagingException) {
            Throwable nextInner = inner.getCause();
            if (nextInner != null && nextInner instanceof ConnectException) {
                // if this occurs
                return;
            }
        }
    }
    message.getDirectDocuments().getSubmissionSet().setIntendedRecipient(Arrays.asList("|beau+document2@nologs.org^Smith^John^^^Dr^^^&amp;1.3.6.1.4.1.21367.3100.1&amp;ISO"));
    try {
        client.send(message);
    } catch (Throwable t) {
        Throwable inner = t.getCause();
        if (inner != null && inner instanceof MessagingException) {
            Throwable nextInner = inner.getCause();
            if (nextInner != null && nextInner instanceof ConnectException) {
                // if this occurs
                return;
            }
        }
    }
}
Also used : DirectMessage(org.nhindirect.xd.common.DirectMessage) MessagingException(javax.mail.MessagingException) NHINDClientConfig(org.nhindirect.nhindclient.config.NHINDClientConfig) NHINDClientImpl(org.nhindirect.nhindclient.impl.NHINDClientImpl) ConnectException(java.net.ConnectException)

Aggregations

ConnectException (java.net.ConnectException)1 MessagingException (javax.mail.MessagingException)1 NHINDClientConfig (org.nhindirect.nhindclient.config.NHINDClientConfig)1 NHINDClientImpl (org.nhindirect.nhindclient.impl.NHINDClientImpl)1 DirectMessage (org.nhindirect.xd.common.DirectMessage)1