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();
}
}
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;
}
Aggregations