Search in sources :

Example 1 with Profile

use of com.google.api.services.gmail.model.Profile in project wildfly-camel by wildfly-extras.

the class GoogleMailIntegrationTest method profile.

@Test
public void profile() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    GoogleMailComponent gMailComponent = camelctx.getComponent("google-mail", GoogleMailComponent.class);
    GoogleApiEnv.configure(gMailComponent.getConfiguration(), getClass(), LOG);
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            final String pathPrefix = "users";
            // test route for attachments
            from("direct://GETPROFILE").to("google-mail://" + pathPrefix + "/getProfile?inBody=userId");
        }
    });
    try {
        camelctx.start();
        ProducerTemplate template = camelctx.createProducerTemplate();
        // using String message body for single parameter "userId"
        final Profile result = template.requestBody("direct://GETPROFILE", CURRENT_USERID, Profile.class);
        Assert.assertNotNull("getProfile result", result);
        Assert.assertNotNull("Should be email address associated with current account", result.getEmailAddress());
        System.out.println("getProfile: " + result);
    } finally {
        camelctx.stop();
    }
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) GoogleMailComponent(org.apache.camel.component.google.mail.GoogleMailComponent) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) MessagingException(javax.mail.MessagingException) IOException(java.io.IOException) Profile(com.google.api.services.gmail.model.Profile) Test(org.junit.Test)

Example 2 with Profile

use of com.google.api.services.gmail.model.Profile in project wildfly-camel by wildfly-extras.

the class GoogleMailIntegrationTest method createMessage.

private static Message createMessage(ProducerTemplate template, String subject) throws MessagingException, IOException {
    Profile profile = template.requestBody("google-mail://users/getProfile?inBody=userId", CURRENT_USERID, Profile.class);
    Session session = Session.getDefaultInstance(new Properties(), null);
    MimeMessage mm = new MimeMessage(session);
    mm.addRecipients(javax.mail.Message.RecipientType.TO, profile.getEmailAddress());
    mm.setSubject(subject);
    mm.setContent(// 
    "Camel rocks!\n" + DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(ZonedDateTime.now()) + // 
    "\n" + "user: " + System.getProperty("user.name"), "text/plain");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    mm.writeTo(baos);
    String encodedEmail = Base64.getUrlEncoder().encodeToString(baos.toByteArray());
    Message message = new Message();
    message.setRaw(encodedEmail);
    return message;
}
Also used : Message(com.google.api.services.gmail.model.Message) MimeMessage(javax.mail.internet.MimeMessage) MimeMessage(javax.mail.internet.MimeMessage) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Properties(java.util.Properties) Profile(com.google.api.services.gmail.model.Profile) Session(javax.mail.Session)

Aggregations

Profile (com.google.api.services.gmail.model.Profile)2 Message (com.google.api.services.gmail.model.Message)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 Properties (java.util.Properties)1 MessagingException (javax.mail.MessagingException)1 Session (javax.mail.Session)1 MimeMessage (javax.mail.internet.MimeMessage)1 CamelContext (org.apache.camel.CamelContext)1 ProducerTemplate (org.apache.camel.ProducerTemplate)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 GoogleMailComponent (org.apache.camel.component.google.mail.GoogleMailComponent)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 Test (org.junit.Test)1