Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrescobar2011-08-10 03:28:05 +0000
committerRyan D. Brooks2011-08-10 03:28:05 +0000
commitf135d5263a3d0c5597e8a48f43ac9a8dc50ec1f8 (patch)
treec5fca6e4ec7272f1f78af0d4e064f356ed4c4180 /plugins/org.eclipse.osee.mail.rest
parent34711e00d3a815754426b86248b5d90d5c0f9902 (diff)
downloadorg.eclipse.osee-f135d5263a3d0c5597e8a48f43ac9a8dc50ec1f8.tar.gz
org.eclipse.osee-f135d5263a3d0c5597e8a48f43ac9a8dc50ec1f8.tar.xz
org.eclipse.osee-f135d5263a3d0c5597e8a48f43ac9a8dc50ec1f8.zip
feature[bgz_348148]: Update mail service to use callables
Diffstat (limited to 'plugins/org.eclipse.osee.mail.rest')
-rw-r--r--plugins/org.eclipse.osee.mail.rest/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.osee.mail.rest/src/org/eclipse/osee/mail/rest/internal/BodyPartDataSource.java55
-rw-r--r--plugins/org.eclipse.osee.mail.rest/src/org/eclipse/osee/mail/rest/internal/MailResource.java69
3 files changed, 41 insertions, 84 deletions
diff --git a/plugins/org.eclipse.osee.mail.rest/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.mail.rest/META-INF/MANIFEST.MF
index bf08d660862..778ceaaf6ea 100644
--- a/plugins/org.eclipse.osee.mail.rest/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.mail.rest/META-INF/MANIFEST.MF
@@ -9,6 +9,5 @@ Service-Component: OSGI-INF/*.xml
Import-Package: com.sun.jersey.multipart,
javax.ws.rs,
javax.ws.rs.core,
- org.eclipse.core.runtime,
org.eclipse.osee.framework.core.operation,
org.eclipse.osee.mail
diff --git a/plugins/org.eclipse.osee.mail.rest/src/org/eclipse/osee/mail/rest/internal/BodyPartDataSource.java b/plugins/org.eclipse.osee.mail.rest/src/org/eclipse/osee/mail/rest/internal/BodyPartDataSource.java
deleted file mode 100644
index c921286a782..00000000000
--- a/plugins/org.eclipse.osee.mail.rest/src/org/eclipse/osee/mail/rest/internal/BodyPartDataSource.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*******************************************************************************
- * 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.rest.internal;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import javax.activation.DataSource;
-import com.sun.jersey.multipart.BodyPart;
-import com.sun.jersey.multipart.BodyPartEntity;
-
-/**
- * @author Roberto E. Escobar
- */
-public class BodyPartDataSource implements DataSource {
-
- private final BodyPart part;
-
- public BodyPartDataSource(BodyPart part) {
- this.part = part;
- }
-
- @Override
- public String getContentType() {
- return part.getMediaType().getType();
- }
-
- @Override
- public InputStream getInputStream() throws IOException {
- Object entity = part.getEntity();
- if (entity instanceof BodyPartEntity) {
- BodyPartEntity partEntity = (BodyPartEntity) entity;
- return partEntity.getInputStream();
- }
- throw new IOException("Entity was not a BodyPartEntity");
- }
-
- @Override
- public String getName() {
- return "none";
- }
-
- @Override
- public OutputStream getOutputStream() {
- return null;
- }
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.osee.mail.rest/src/org/eclipse/osee/mail/rest/internal/MailResource.java b/plugins/org.eclipse.osee.mail.rest/src/org/eclipse/osee/mail/rest/internal/MailResource.java
index 93370855035..eeeb9604e35 100644
--- a/plugins/org.eclipse.osee.mail.rest/src/org/eclipse/osee/mail/rest/internal/MailResource.java
+++ b/plugins/org.eclipse.osee.mail.rest/src/org/eclipse/osee/mail/rest/internal/MailResource.java
@@ -10,20 +10,25 @@
*******************************************************************************/
package org.eclipse.osee.mail.rest.internal;
+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 javax.ws.rs.core.Response;
-import org.eclipse.osee.framework.core.operation.Operations;
import org.eclipse.osee.mail.MailMessage;
import org.eclipse.osee.mail.MailService;
-import org.eclipse.osee.mail.SendMailOperation;
-import com.sun.jersey.multipart.BodyPart;
-import com.sun.jersey.multipart.MultiPart;
+import org.eclipse.osee.mail.SendMailStatus;
/**
* @author Roberto E. Escobar
@@ -31,6 +36,7 @@ import com.sun.jersey.multipart.MultiPart;
@Path("send")
public class MailResource {
+ private static long STATUS_WAIT_TIME = 60;
private static int testEmailCount = 0;
protected MailService getMailService() {
@@ -45,36 +51,43 @@ public class MailResource {
@POST
@Path("test")
- @Produces(MediaType.TEXT_PLAIN)
- public String sendTestMail() throws Exception {
+ @Produces({MediaType.APPLICATION_XML, MediaType.TEXT_XML})
+ public SendMailStatus sendTestMail() throws Exception {
MailMessage message = getMailService().createSystemTestMessage(++testEmailCount);
- List<SendMailOperation> operations = getMailService().createSendOp(message);
- if (!operations.isEmpty()) {
- Operations.executeWorkAndCheckStatus(operations.iterator().next());
- }
- return "Test Email sent successfully";
+
+ List<SendMailStatus> results = sendMail(message);
+ return results.iterator().next();
}
@POST
- @Consumes("multipart/mixed")
- public Response sendMail(MultiPart multiPart) throws Exception {
- boolean isProcessed = true;
- MailMessage mailMessage = null;
- int count = 0;
+ @Consumes(MediaType.APPLICATION_XML)
+ @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 =
+ getMailService().createSendCalls(STATUS_WAIT_TIME, TimeUnit.SECONDS, messages);
+ List<Future<SendMailStatus>> futures = new ArrayList<Future<SendMailStatus>>();
- for (BodyPart part : multiPart.getBodyParts()) {
- if (count == 0) {
- mailMessage = part.getEntityAs(MailMessage.class);
- } else if (mailMessage != null) {
- mailMessage.addAttachment(new BodyPartDataSource(part));
+ 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);
}
- if (isProcessed) {
- return Response.status(Response.Status.ACCEPTED).entity("Attachements processed successfully.").type(
- MediaType.TEXT_PLAIN).build();
+ List<SendMailStatus> results = new ArrayList<SendMailStatus>();
+ for (Future<SendMailStatus> future : futures) {
+ results.add(future.get());
}
- return Response.status(Response.Status.BAD_REQUEST).entity("Failed to process attachments. Reason : ").type(
- MediaType.TEXT_PLAIN).build();
+ return results;
}
-
}

Back to the top