Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto E. Escobar2014-06-24 18:22:24 +0000
committerRoberto E. Escobar2014-08-28 23:58:46 +0000
commit9a0382281fe192fe3feeef7dc8ff1d56d2bb7034 (patch)
tree8b4e6a202813fc57f9df961f6b9cd89d5ebb8513 /plugins/org.eclipse.osee.mail
parentb8f60e8c0631db1ae4f38ec04bba0441088c8605 (diff)
downloadorg.eclipse.osee-9a0382281fe192fe3feeef7dc8ff1d56d2bb7034.tar.gz
org.eclipse.osee-9a0382281fe192fe3feeef7dc8ff1d56d2bb7034.tar.xz
org.eclipse.osee-9a0382281fe192fe3feeef7dc8ff1d56d2bb7034.zip
refactor: Mail JAX-RS API
Remove static mail service access Clean-up produces/consumes annotations Move JAX-RS Mail application into org.eclipse.osee.mail Delete org.eclipse.osee.mail.rest bundle Change-Id: I5bd1c9453048c199882145ce64d19e46f19f8b91
Diffstat (limited to 'plugins/org.eclipse.osee.mail')
-rw-r--r--plugins/org.eclipse.osee.mail/META-INF/MANIFEST.MF6
-rw-r--r--plugins/org.eclipse.osee.mail/OSGI-INF/mail.jaxrs.application.xml8
-rw-r--r--plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/internal/resources/MailApplication.java45
-rw-r--r--plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/internal/resources/MailConfigResource.java55
-rw-r--r--plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/internal/resources/MailResource.java95
5 files changed, 207 insertions, 2 deletions
diff --git a/plugins/org.eclipse.osee.mail/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.mail/META-INF/MANIFEST.MF
index 02cef4314cc..30429f7af6a 100644
--- a/plugins/org.eclipse.osee.mail/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.mail/META-INF/MANIFEST.MF
@@ -1,6 +1,6 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
-Bundle-Name: Osee Mail
+Bundle-Name: OSEE Mail (Incubation)
Bundle-SymbolicName: org.eclipse.osee.mail
Bundle-Version: 0.18.0.qualifier
Bundle-Vendor: Eclipse Open System Engineering Environment
@@ -9,9 +9,11 @@ Import-Package: javax.activation,
javax.mail;version="1.4.1",
javax.mail.event;version="1.4.1",
javax.mail.internet;version="1.4.1",
+ javax.ws.rs;version="2.0.0",
+ javax.ws.rs.core;version="2.0.0",
javax.xml.bind.annotation,
+ org.eclipse.osee.event,
org.eclipse.osee.framework.jdk.core.util,
org.eclipse.osee.framework.jdk.core.util.windows
Service-Component: OSGI-INF/*.xml
Export-Package: org.eclipse.osee.mail
-Require-Bundle: org.eclipse.osee.event
diff --git a/plugins/org.eclipse.osee.mail/OSGI-INF/mail.jaxrs.application.xml b/plugins/org.eclipse.osee.mail/OSGI-INF/mail.jaxrs.application.xml
new file mode 100644
index 00000000000..09171a75f74
--- /dev/null
+++ b/plugins/org.eclipse.osee.mail/OSGI-INF/mail.jaxrs.application.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" deactivate="stop">
+ <implementation class="org.eclipse.osee.mail.internal.resources.MailApplication"/>
+ <service>
+ <provide interface="javax.ws.rs.core.Application"/>
+ </service>
+ <reference bind="setMailService" cardinality="1..1" interface="org.eclipse.osee.mail.MailService" name="MailService" policy="static"/>
+</scr:component>
diff --git a/plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/internal/resources/MailApplication.java b/plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/internal/resources/MailApplication.java
new file mode 100644
index 00000000000..fce64f7e68b
--- /dev/null
+++ b/plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/internal/resources/MailApplication.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.mail.internal.resources;
+
+import java.util.HashSet;
+import java.util.Set;
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+import org.eclipse.osee.mail.MailService;
+
+/**
+ * @author Roberto E. Escobar
+ */
+@ApplicationPath("mail")
+public class MailApplication extends Application {
+
+ private final Set<Object> singletons = new HashSet<Object>();
+ private MailService mailService;
+
+ public void setMailService(MailService mailService) {
+ this.mailService = mailService;
+ }
+
+ public void start() {
+ singletons.add(new MailResource(mailService));
+ singletons.add(new MailConfigResource(mailService));
+ }
+
+ public void stop() {
+ singletons.clear();
+ }
+
+ @Override
+ public Set<Object> getSingletons() {
+ return singletons;
+ }
+}
diff --git a/plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/internal/resources/MailConfigResource.java b/plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/internal/resources/MailConfigResource.java
new file mode 100644
index 00000000000..2c66a6bfe8f
--- /dev/null
+++ b/plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/internal/resources/MailConfigResource.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.mail.internal.resources;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.xml.bind.JAXBElement;
+import org.eclipse.osee.mail.MailService;
+import org.eclipse.osee.mail.MailServiceConfig;
+
+/**
+ * @author Roberto E. Escobar
+ */
+@Path("config")
+public class MailConfigResource {
+
+ private final MailService mailService;
+
+ public MailConfigResource(MailService mailService) {
+ super();
+ this.mailService = mailService;
+ }
+
+ @GET
+ @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
+ public MailServiceConfig getConfig() {
+ return mailService.getConfiguration();
+ }
+
+ @POST
+ @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
+ @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
+ public Response updateConfig(JAXBElement<MailServiceConfig> jaxConfig) {
+ MailServiceConfig config = jaxConfig.getValue();
+ return postAndGetResponse(config);
+ }
+
+ private Response postAndGetResponse(MailServiceConfig config) {
+ mailService.setConfiguration(config);
+ return Response.ok("Mail Service Configuration Updated", MediaType.TEXT_PLAIN).build();
+ }
+}
diff --git a/plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/internal/resources/MailResource.java b/plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/internal/resources/MailResource.java
new file mode 100644
index 00000000000..20c20d3d4a8
--- /dev/null
+++ b/plugins/org.eclipse.osee.mail/src/org/eclipse/osee/mail/internal/resources/MailResource.java
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.mail.internal.resources;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import javax.activation.DataHandler;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import org.eclipse.osee.mail.MailMessage;
+import org.eclipse.osee.mail.MailService;
+import org.eclipse.osee.mail.SendMailStatus;
+
+/**
+ * @author Roberto E. Escobar
+ */
+@Path("send")
+public class MailResource {
+
+ private static long STATUS_WAIT_TIME = 60;
+ private static int testEmailCount = 0;
+
+ private final MailService mailService;
+
+ public MailResource(MailService mailService) {
+ super();
+ this.mailService = mailService;
+ }
+
+ @GET
+ @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
+ public MailMessage getTestMailMessage() {
+ return mailService.createSystemTestMessage(++testEmailCount);
+ }
+
+ @POST
+ @Path("test")
+ @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
+ public SendMailStatus sendTestMail() throws Exception {
+ MailMessage message = mailService.createSystemTestMessage(++testEmailCount);
+
+ List<SendMailStatus> results = sendMail(message);
+ return results.iterator().next();
+ }
+
+ @POST
+ @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
+ @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
+ public List<SendMailStatus> sendXmlMail(MailMessage mailMessage) throws Exception {
+ Collection<? extends DataHandler> handlers = mailMessage.getAttachments();
+ for (DataHandler handler : handlers) {
+ System.out.println(handler.getName() + " " + handler.getContentType());
+ }
+ return sendMail(mailMessage);
+ }
+
+ private List<SendMailStatus> sendMail(MailMessage... messages) throws InterruptedException, ExecutionException {
+ List<Callable<SendMailStatus>> calls = mailService.createSendCalls(STATUS_WAIT_TIME, TimeUnit.SECONDS, messages);
+ List<Future<SendMailStatus>> futures = new ArrayList<Future<SendMailStatus>>();
+
+ if (messages.length > 0) {
+ ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
+ for (Callable<SendMailStatus> task : calls) {
+ Future<SendMailStatus> future = executor.submit(task);
+ futures.add(future);
+ }
+ executor.shutdown();
+ executor.awaitTermination(100, TimeUnit.MINUTES);
+ }
+ List<SendMailStatus> results = new ArrayList<SendMailStatus>();
+ for (Future<SendMailStatus> future : futures) {
+ results.add(future.get());
+ }
+ return results;
+ }
+}

Back to the top