You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by is...@apache.org on 2013/07/26 11:26:00 UTC
git commit: Licence files are updated in pom file Stratos email
sender refac
Updated Branches:
refs/heads/master 7f09a628c -> d275c1247
Licence files are updated in pom file Stratos email sender refac
Signed-off-by: Isuru Perera <is...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/d275c124
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/d275c124
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/d275c124
Branch: refs/heads/master
Commit: d275c1247ee57b5ea7c657c480dfc73dc1d8be1d
Parents: 7f09a62
Author: Udara Liyanage <ud...@wso2.com>
Authored: Fri Jul 26 12:30:58 2013 +0530
Committer: Isuru Perera <is...@apache.org>
Committed: Fri Jul 26 14:55:01 2013 +0530
----------------------------------------------------------------------
.../org.apache.stratos.email.sender/pom.xml | 89 ++++++++++++
.../email/sender/api/BulkEmailSender.java | 100 ++++++++++++++
.../email/sender/api/EmailDataHolder.java | 26 ++++
.../stratos/email/sender/api/EmailSender.java | 108 +++++++++++++++
.../sender/api/EmailSenderConfiguration.java | 131 ++++++++++++++++++
.../internal/EmailSenderServiceComponent.java | 82 ++++++++++++
.../apache/stratos/email/sender/util/Util.java | 103 ++++++++++++++
components/pom.xml | 3 +-
.../org.wso2.carbon.email.sender/2.1.0/pom.xml | 86 ------------
.../email/sender/api/BulkEmailSender.java | 103 --------------
.../email/sender/api/EmailDataHolder.java | 26 ----
.../carbon/email/sender/api/EmailSender.java | 111 ---------------
.../sender/api/EmailSenderConfiguration.java | 134 -------------------
.../internal/EmailSenderServiceComponent.java | 83 ------------
.../org/wso2/carbon/email/sender/util/Util.java | 106 ---------------
15 files changed, 641 insertions(+), 650 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/d275c124/components/org.apache.stratos.email.sender/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.email.sender/pom.xml b/components/org.apache.stratos.email.sender/pom.xml
new file mode 100644
index 0000000..7c0568b
--- /dev/null
+++ b/components/org.apache.stratos.email.sender/pom.xml
@@ -0,0 +1,89 @@
+<!--
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.apache.stratos</groupId>
+ <artifactId>stratos-components-parent</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>org.apache.stratos.email.sender</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Stratos - Email Sender Component</name>
+
+ <build>
+
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+ <Bundle-Name>${project.artifactId}</Bundle-Name>
+ <Private-Package>
+ org.apache.stratos.email.sender.internal.*,
+ org.apache.stratos.email.senderder.util.*,
+ </Private-Package>
+ <Export-Package>
+ org.apache.stratos.email.sender.api.*
+ </Export-Package>
+ <Import-Package>
+ !javax.xml.namespace,
+ javax.xml.namespace; version=0.0.0,
+ javax.servlet;version="${imp.pkg.version.javax.servlet}",
+ javax.servlet.http;version="${imp.pkg.version.javax.servlet}",
+ *;resolution:=optional
+ </Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.axis2.wso2</groupId>
+ <artifactId>axis2</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.registry.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/d275c124/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/api/BulkEmailSender.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/api/BulkEmailSender.java b/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/api/BulkEmailSender.java
new file mode 100644
index 0000000..f8f3193
--- /dev/null
+++ b/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/api/BulkEmailSender.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.stratos.email.sender.api;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.transport.base.BaseConstants;
+import org.apache.axis2.transport.mail.MailConstants;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.email.sender.util.Util;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * The class that handles the bulk email sending logic for stratos.
+ */
+public class BulkEmailSender extends EmailSender{
+ private static Log log = LogFactory.getLog(BulkEmailSender.class);
+
+ public BulkEmailSender(EmailSenderConfiguration config) {
+ super(config);
+ }
+
+ /**
+ * Sends the email
+ * @param bulkEmailData List of email data holder objects
+ * @throws Exception, if sending the email notification failed.
+ */
+ public void sendBulkEmails(List<EmailDataHolder> bulkEmailData) throws Exception {
+
+ final List<EmailDataHolder> emailDataHolderList = bulkEmailData;
+
+ final ServiceClient serviceClient;
+ ConfigurationContext configContext = Util.getConfigurationContext();
+ if (configContext != null) {
+ serviceClient = new ServiceClient(configContext, null);
+ } else {
+ serviceClient = new ServiceClient();
+ }
+
+ new Thread() {
+ public void run() {
+
+ for(EmailDataHolder dataHolder : emailDataHolderList){
+
+ String subject = getMessageTitle(dataHolder.getEmailParameters());
+ String body = getMessageBody(dataHolder.getEmailParameters());
+ String email = dataHolder.getEmail(); // no change in here,
+
+ Map<String, String> headerMap = new HashMap<String, String>();
+ headerMap.put(MailConstants.MAIL_HEADER_SUBJECT, subject);
+ OMElement payload = OMAbstractFactory.getOMFactory().createOMElement(
+ BaseConstants.DEFAULT_TEXT_WRAPPER, null);
+ payload.setText(body);
+
+ try {
+ Options options = new Options();
+ options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE);
+ options.setProperty(MessageContext.TRANSPORT_HEADERS, headerMap);
+ options.setProperty(MailConstants.TRANSPORT_MAIL_FORMAT,
+ MailConstants.TRANSPORT_FORMAT_TEXT);
+ options.setTo(new EndpointReference("mailto:" + email));
+ serviceClient.setOptions(options);
+ serviceClient.fireAndForget(payload);
+ serviceClient.cleanup();
+ } catch (AxisFault e) {
+ String msg = "Error in delivering the message, " +
+ "subject: " + subject + ", to: " + email + ".";
+ log.error(msg);
+ }
+ }
+
+ }
+ }.start();
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/d275c124/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/api/EmailDataHolder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/api/EmailDataHolder.java b/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/api/EmailDataHolder.java
new file mode 100644
index 0000000..25d29b6
--- /dev/null
+++ b/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/api/EmailDataHolder.java
@@ -0,0 +1,26 @@
+package org.apache.stratos.email.sender.api;
+
+import java.util.Map;
+
+//This holds the email address and email parameter map
+public class EmailDataHolder {
+
+ private String email;
+ private Map<String, String> emailParameters;
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public Map<String, String> getEmailParameters() {
+ return emailParameters;
+ }
+
+ public void setEmailParameters(Map<String, String> emailParameters) {
+ this.emailParameters = emailParameters;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/d275c124/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/api/EmailSender.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/api/EmailSender.java b/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/api/EmailSender.java
new file mode 100644
index 0000000..b671502
--- /dev/null
+++ b/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/api/EmailSender.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.stratos.email.sender.api;
+
+import org.apache.stratos.email.sender.util.Util;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.axis2.transport.mail.MailConstants;
+import org.apache.axis2.transport.base.BaseConstants;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axis2.Constants;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.EndpointReference;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * The class that handles the email sending logic for stratos.
+ */
+public class EmailSender{
+ private static Log log = LogFactory.getLog(EmailSender.class);
+ private EmailSenderConfiguration config = null;
+
+ public EmailSender(EmailSenderConfiguration config) {
+ this.config = config;
+ }
+
+ /**
+ * Sends the email
+ * @param toEmail Email Address (To:)
+ * @param userParameters - map of user parameters
+ * @throws Exception, if sending the email notification failed.
+ */
+ public void sendEmail(String toEmail, Map<String, String>userParameters) throws Exception {
+ final String subject = getMessageTitle(userParameters);
+ final String body = getMessageBody(userParameters);
+ final String email = toEmail; // no change in here,
+ new Thread() {
+ public void run() {
+ Map<String, String> headerMap = new HashMap<String, String>();
+ headerMap.put(MailConstants.MAIL_HEADER_SUBJECT, subject);
+ OMElement payload = OMAbstractFactory.getOMFactory().createOMElement(
+ BaseConstants.DEFAULT_TEXT_WRAPPER, null);
+ payload.setText(body);
+
+ try {
+ ServiceClient serviceClient;
+ ConfigurationContext configContext = Util.getConfigurationContext();
+ if (configContext != null) {
+ serviceClient = new ServiceClient(configContext, null);
+ } else {
+ serviceClient = new ServiceClient();
+ }
+ Options options = new Options();
+ options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE);
+ options.setProperty(MessageContext.TRANSPORT_HEADERS, headerMap);
+ options.setProperty(MailConstants.TRANSPORT_MAIL_FORMAT,
+ MailConstants.TRANSPORT_FORMAT_TEXT);
+ options.setTo(new EndpointReference("mailto:" + email));
+ serviceClient.setOptions(options);
+ serviceClient.fireAndForget(payload);
+ log.debug("Sending confirmation mail to " + email);
+ } catch (AxisFault e) {
+ String msg = "Error in delivering the message, " +
+ "subject: " + subject + ", to: " + email + ".";
+ log.error(msg);
+ }
+ }
+ }.start();
+ }
+
+ /**
+ * gets the title of the message
+ * @param userParameters - map of user parameters
+ * @return the title of the message
+ */
+ protected String getMessageTitle(Map<String, String> userParameters) {
+ return Util.replacePlaceHolders(config.getSubject(), userParameters);
+ }
+
+ /**
+ * gets the body of the message
+ * @param userParameters - map of user parameters
+ * @return the body of the message
+ */
+ protected String getMessageBody(Map<String, String> userParameters) {
+ return Util.replacePlaceHolders(config.getBody(), userParameters);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/d275c124/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/api/EmailSenderConfiguration.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/api/EmailSenderConfiguration.java b/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/api/EmailSenderConfiguration.java
new file mode 100644
index 0000000..f50a717
--- /dev/null
+++ b/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/api/EmailSenderConfiguration.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.stratos.email.sender.api;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * The class that handles the configuration of the email sender for Stratos
+ */
+public class EmailSenderConfiguration {
+ private static Log log = LogFactory.getLog(EmailSenderConfiguration.class);
+
+ public final static String DEFAULT_VALUE_SUBJECT = "EmailSender";
+ public final static String DEFAULT_VALUE_MESSAGE = "Sent form WSO2 Carbon";
+
+ private String fromEmail;
+ private String subject = DEFAULT_VALUE_SUBJECT;
+ private String body = DEFAULT_VALUE_MESSAGE;
+ private Map<String, String> customParameters;
+
+ public Map<String, String> getCustomParameters() {
+ return customParameters;
+ }
+
+ public void setCustomParameters(Map<String, String> customParameters) {
+ this.customParameters = customParameters;
+ }
+
+
+ public String getSubject() {
+ return subject;
+ }
+
+ public void setSubject(String subject) {
+ this.subject = subject.trim();
+ }
+
+ public String getBody() {
+ return body;
+ }
+
+ public void setBody(String emailMessage) {
+ this.body = emailMessage.trim();
+ }
+
+ public String getFromEmail() {
+ return fromEmail;
+ }
+
+ public void setFromEmail(String fromEmail) {
+ this.fromEmail = fromEmail;
+ }
+
+ /**
+ * Loads the email sender configuration
+ * @param configFilename configuration file name
+ * @return EmailSenderConfiguration.
+ */
+ public static EmailSenderConfiguration loadEmailSenderConfiguration(String configFilename) {
+ File configFile = new File(configFilename);
+ if (!configFile.exists()) {
+ log.error("Email sender configuration File is not present at: " + configFilename);
+ return null;
+ }
+ EmailSenderConfiguration config = new EmailSenderConfiguration();
+ FileInputStream ip = null;
+ try {
+ ip = new FileInputStream(configFile);
+ XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(ip);
+ StAXOMBuilder builder = new StAXOMBuilder(parser);
+ OMElement documentElement = builder.getDocumentElement();
+ Iterator it = documentElement.getChildElements();
+ while (it.hasNext()) {
+ OMElement element = (OMElement) it.next();
+ if ("subject".equals(element.getLocalName())) {
+ config.setSubject(element.getText());
+ } else if ("body".equals(element.getLocalName())) {
+ config.setBody(element.getText());
+ } else if ("customParameters".equals(element.getLocalName())) {
+ Map<String, String> customParameters = new HashMap<String, String>();
+ Iterator customParamIt = element.getChildElements();
+ while (customParamIt.hasNext()) {
+ OMElement customElement = (OMElement) it.next();
+ customParameters.put(customElement.getLocalName(), customElement.getText());
+ }
+ config.setCustomParameters(customParameters);
+ }
+ }
+ return config;
+ } catch (Exception e) {
+ String msg = "Error in loading configuration for email verification: " +
+ configFilename + ".";
+ log.error(msg, e);
+ return null;
+ } finally {
+ if (ip != null) {
+ try {
+ ip.close();
+ } catch (IOException e) {
+ log.warn("Could not close InputStream for file " + configFile.getAbsolutePath());
+ }
+ }
+
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/d275c124/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/internal/EmailSenderServiceComponent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/internal/EmailSenderServiceComponent.java b/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/internal/EmailSenderServiceComponent.java
new file mode 100644
index 0000000..88e0d6e
--- /dev/null
+++ b/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/internal/EmailSenderServiceComponent.java
@@ -0,0 +1,82 @@
+/*
+* Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+*
+* WSO2 Inc. licenses this file to you under the Apache License,
+* Version 2.0 (the "License"); you may not use this file except
+* in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.stratos.email.sender.internal;
+
+import org.apache.stratos.email.sender.util.Util;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.osgi.service.component.ComponentContext;
+import org.wso2.carbon.registry.core.service.RegistryService;
+import org.wso2.carbon.user.core.service.RealmService;
+import org.wso2.carbon.utils.CarbonUtils;
+import org.wso2.carbon.utils.ConfigurationContextService;
+
+/**
+ * @scr.component name="org.apache.stratos.email.sender"
+ * immediate="true"
+ * @scr.reference name="registry.service"
+ * interface="org.wso2.carbon.registry.core.service.RegistryService" cardinality="1..1"
+ * policy="dynamic" bind="setRegistryService" unbind="unsetRegistryService"
+ * @scr.reference name="user.realmservice.default" interface="org.wso2.carbon.user.core.service.RealmService"
+ * cardinality="1..1" policy="dynamic" bind="setRealmService"
+ * unbind="unsetRealmService"
+ * @scr.reference name="configuration.context.service"
+ * interface="org.wso2.carbon.utils.ConfigurationContextService" cardinality="1..1"
+ * policy="dynamic" bind="setConfigurationContextService" unbind="unsetConfigurationContextService"
+ */
+public class EmailSenderServiceComponent {
+ private static Log log = LogFactory.getLog(EmailSenderServiceComponent.class);
+
+ protected void activate(ComponentContext context) {
+ try {
+ log.debug("******* Email Sender bundle is activated ******* ");
+ } catch (Exception e) {
+ log.error("******* Email Sender bundle failed activating ****", e);
+ }
+ }
+
+ protected void deactivate(ComponentContext context) {
+ log.debug("******* Email Sender bundle is deactivated ******* ");
+ }
+ protected void setRegistryService(RegistryService registryService) {
+ Util.setRegistryService(registryService);
+ }
+
+ protected void unsetRegistryService(RegistryService registryService) {
+ Util.setRegistryService(null);
+ }
+
+ protected void setRealmService(RealmService realmService) {
+ Util.setRealmService(realmService);
+ }
+
+ protected void unsetRealmService(RealmService realmService) {
+ Util.setRealmService(null);
+ }
+
+ protected void setConfigurationContextService(ConfigurationContextService configurationContextService){
+ log.debug("Receiving ConfigurationContext Service");
+ Util.setConfigurationContextService(configurationContextService);
+
+ }
+
+ protected void unsetConfigurationContextService(ConfigurationContextService configurationContextService){
+ log.debug("Unsetting ConfigurationContext Service");
+ Util.setConfigurationContextService(null);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/d275c124/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/util/Util.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/util/Util.java b/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/util/Util.java
new file mode 100644
index 0000000..a4f62d0
--- /dev/null
+++ b/components/org.apache.stratos.email.sender/src/main/java/org/apache/stratos/email/sender/util/Util.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.stratos.email.sender.util;
+
+import org.apache.axis2.context.ConfigurationContext;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
+import org.wso2.carbon.registry.core.service.RegistryService;
+import org.wso2.carbon.registry.core.session.UserRegistry;
+import org.wso2.carbon.user.api.RealmConfiguration;
+import org.wso2.carbon.user.core.service.RealmService;
+import org.wso2.carbon.user.core.tenant.TenantManager;
+import org.wso2.carbon.utils.ConfigurationContextService;
+
+import java.util.Map;
+import java.util.regex.Matcher;
+
+/**
+ * Utility methods for the email sender component
+ */
+public class Util {
+
+ private static RegistryService registryService;
+ private static RealmService realmService;
+ private static ConfigurationContextService configurationContextService;
+
+
+ public static ConfigurationContextService getConfigurationContextService() {
+ return configurationContextService;
+ }
+
+ public static void setConfigurationContextService(
+ ConfigurationContextService configurationContextService) {
+ Util.configurationContextService = configurationContextService;
+ }
+
+ public static ConfigurationContext getConfigurationContext() {
+ if (configurationContextService.getServerConfigContext() == null) {
+ return null;
+ }
+ return configurationContextService.getServerConfigContext();
+ }
+
+ public static synchronized void setRegistryService(RegistryService service) {
+ if (registryService == null) {
+ registryService = service;
+ }
+ }
+
+ public static RegistryService getRegistryService() {
+ return registryService;
+ }
+
+ public static synchronized void setRealmService(RealmService service) {
+ if (realmService == null) {
+ realmService = service;
+ }
+ }
+
+ public static RealmService getRealmService() {
+ return realmService;
+ }
+
+ public static TenantManager getTenantManager() {
+ return realmService.getTenantManager();
+ }
+
+ public static RealmConfiguration getBootstrapRealmConfiguration() {
+ return realmService.getBootstrapRealmConfiguration();
+ }
+
+ public static UserRegistry getGovernanceSystemRegistry(int tenantId) throws RegistryException {
+ return registryService.getGovernanceSystemRegistry(tenantId);
+ }
+
+ /**
+ * Replace the {place-holders} with the respective value provided
+ * @param text string
+ * @param userParameters - map of user parameters
+ * @return replaced text for the email {title or body}
+ */
+ public static String replacePlaceHolders(String text, Map<String, String> userParameters) {
+ if (userParameters != null) {
+ for (Map.Entry<String, String> entry : userParameters.entrySet()) {
+ String key = entry.getKey();
+ text = text.replaceAll("\\{" + key + "\\}", Matcher.quoteReplacement(entry.getValue()));
+ }
+ }
+ return text;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/d275c124/components/pom.xml
----------------------------------------------------------------------
diff --git a/components/pom.xml b/components/pom.xml
index c244696..ea00fde 100644
--- a/components/pom.xml
+++ b/components/pom.xml
@@ -74,6 +74,7 @@
<!-- Account Mgt -->
<module>org.apache.stratos.account.mgt</module>
<module>org.apache.stratos.account.mgt.ui</module>
+ <module>org.apache.stratos.email.sender</module>
<!-- Domain Validation -->
<module>org.apache.stratos.validate.domain</module>
<module>org.apache.stratos.validate.domain.ui</module>
@@ -85,7 +86,7 @@
<module>org.apache.stratos.sso.redirector.ui</module>
<module>org.apache.stratos.redirector.servlet</module>
<module>org.apache.stratos.redirector.servlet.ui</module>
- <!-- Status Monotor -->
+ <!-- Status Monitor -->
<module>org.apache.stratos.status.monitor.core</module>
<module>org.apache.stratos.status.monitor</module>
<module>org.apache.stratos.status.monitor.agent</module>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/d275c124/components/stratos/org.wso2.carbon.email.sender/2.1.0/pom.xml
----------------------------------------------------------------------
diff --git a/components/stratos/org.wso2.carbon.email.sender/2.1.0/pom.xml b/components/stratos/org.wso2.carbon.email.sender/2.1.0/pom.xml
deleted file mode 100644
index 99057a0..0000000
--- a/components/stratos/org.wso2.carbon.email.sender/2.1.0/pom.xml
+++ /dev/null
@@ -1,86 +0,0 @@
-<!--
-# Copyright (c) 2008, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
- -->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <parent>
- <groupId>org.wso2.carbon</groupId>
- <artifactId>stratos-components</artifactId>
- <version>2.1.0</version>
-<relativePath>../../pom.xml</relativePath>
- </parent>
-
- <modelVersion>4.0.0</modelVersion>
- <artifactId>org.wso2.carbon.email.sender</artifactId>
- <packaging>bundle</packaging>
- <name>WSO2 Stratos - Email Sender Component</name>
-
- <build>
-
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-scr-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
-
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
- <Bundle-Name>${project.artifactId}</Bundle-Name>
- <Private-Package>
- org.wso2.carbon.email.sender.internal.*,
- org.wso2.carbon.email.sender.util.*,
- </Private-Package>
- <Export-Package>
- org.wso2.carbon.email.sender.api.*
- </Export-Package>
- <Import-Package>
- !javax.xml.namespace,
- javax.xml.namespace; version=0.0.0,
- javax.servlet;version="${imp.pkg.version.javax.servlet}",
- javax.servlet.http;version="${imp.pkg.version.javax.servlet}",
- *;resolution:=optional
- </Import-Package>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.axis2.wso2</groupId>
- <artifactId>axis2</artifactId>
- </dependency>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- </dependency>
- <dependency>
- <groupId>org.wso2.carbon</groupId>
- <artifactId>org.wso2.carbon.registry.core</artifactId>
- </dependency>
- <dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- </dependency>
- </dependencies>
-
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/d275c124/components/stratos/org.wso2.carbon.email.sender/2.1.0/src/main/java/org/wso2/carbon/email/sender/api/BulkEmailSender.java
----------------------------------------------------------------------
diff --git a/components/stratos/org.wso2.carbon.email.sender/2.1.0/src/main/java/org/wso2/carbon/email/sender/api/BulkEmailSender.java b/components/stratos/org.wso2.carbon.email.sender/2.1.0/src/main/java/org/wso2/carbon/email/sender/api/BulkEmailSender.java
deleted file mode 100644
index 6b98c5f..0000000
--- a/components/stratos/org.wso2.carbon.email.sender/2.1.0/src/main/java/org/wso2/carbon/email/sender/api/BulkEmailSender.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.wso2.carbon.email.sender.api;
-
-import org.apache.axiom.om.OMAbstractFactory;
-import org.apache.axiom.om.OMElement;
-import org.apache.axis2.AxisFault;
-import org.apache.axis2.Constants;
-import org.apache.axis2.addressing.EndpointReference;
-import org.apache.axis2.client.Options;
-import org.apache.axis2.client.ServiceClient;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.transport.base.BaseConstants;
-import org.apache.axis2.transport.mail.MailConstants;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.wso2.carbon.email.sender.util.Util;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * The class that handles the bulk email sending logic for stratos.
- */
-public class BulkEmailSender extends EmailSender{
- private static Log log = LogFactory.getLog(BulkEmailSender.class);
-
- public BulkEmailSender(EmailSenderConfiguration config) {
- super(config);
- }
-
- /**
- * Sends the email
- * @param bulkEmailData List of email data holder objects
- * @throws Exception, if sending the email notification failed.
- */
- public void sendBulkEmails(List<EmailDataHolder> bulkEmailData) throws Exception {
-
- final List<EmailDataHolder> emailDataHolderList = bulkEmailData;
-
- final ServiceClient serviceClient;
- ConfigurationContext configContext = Util.getConfigurationContext();
- if (configContext != null) {
- serviceClient = new ServiceClient(configContext, null);
- } else {
- serviceClient = new ServiceClient();
- }
-
- new Thread() {
- public void run() {
-
- for(EmailDataHolder dataHolder : emailDataHolderList){
-
- String subject = getMessageTitle(dataHolder.getEmailParameters());
- String body = getMessageBody(dataHolder.getEmailParameters());
- String email = dataHolder.getEmail(); // no change in here,
-
- Map<String, String> headerMap = new HashMap<String, String>();
- headerMap.put(MailConstants.MAIL_HEADER_SUBJECT, subject);
- OMElement payload = OMAbstractFactory.getOMFactory().createOMElement(
- BaseConstants.DEFAULT_TEXT_WRAPPER, null);
- payload.setText(body);
-
- try {
- Options options = new Options();
- options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE);
- options.setProperty(MessageContext.TRANSPORT_HEADERS, headerMap);
- options.setProperty(MailConstants.TRANSPORT_MAIL_FORMAT,
- MailConstants.TRANSPORT_FORMAT_TEXT);
- options.setTo(new EndpointReference("mailto:" + email));
- serviceClient.setOptions(options);
- serviceClient.fireAndForget(payload);
- serviceClient.cleanup();
- } catch (AxisFault e) {
- String msg = "Error in delivering the message, " +
- "subject: " + subject + ", to: " + email + ".";
- log.error(msg);
- }
- }
-
- }
- }.start();
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/d275c124/components/stratos/org.wso2.carbon.email.sender/2.1.0/src/main/java/org/wso2/carbon/email/sender/api/EmailDataHolder.java
----------------------------------------------------------------------
diff --git a/components/stratos/org.wso2.carbon.email.sender/2.1.0/src/main/java/org/wso2/carbon/email/sender/api/EmailDataHolder.java b/components/stratos/org.wso2.carbon.email.sender/2.1.0/src/main/java/org/wso2/carbon/email/sender/api/EmailDataHolder.java
deleted file mode 100644
index 32ab7f9..0000000
--- a/components/stratos/org.wso2.carbon.email.sender/2.1.0/src/main/java/org/wso2/carbon/email/sender/api/EmailDataHolder.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package org.wso2.carbon.email.sender.api;
-
-import java.util.Map;
-
-//This holds the email address and email parameter map
-public class EmailDataHolder {
-
- private String email;
- private Map<String, String> emailParameters;
-
- public String getEmail() {
- return email;
- }
-
- public void setEmail(String email) {
- this.email = email;
- }
-
- public Map<String, String> getEmailParameters() {
- return emailParameters;
- }
-
- public void setEmailParameters(Map<String, String> emailParameters) {
- this.emailParameters = emailParameters;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/d275c124/components/stratos/org.wso2.carbon.email.sender/2.1.0/src/main/java/org/wso2/carbon/email/sender/api/EmailSender.java
----------------------------------------------------------------------
diff --git a/components/stratos/org.wso2.carbon.email.sender/2.1.0/src/main/java/org/wso2/carbon/email/sender/api/EmailSender.java b/components/stratos/org.wso2.carbon.email.sender/2.1.0/src/main/java/org/wso2/carbon/email/sender/api/EmailSender.java
deleted file mode 100644
index 0fc37e3..0000000
--- a/components/stratos/org.wso2.carbon.email.sender/2.1.0/src/main/java/org/wso2/carbon/email/sender/api/EmailSender.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.wso2.carbon.email.sender.api;
-
-import org.wso2.carbon.email.sender.util.Util;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.axis2.transport.mail.MailConstants;
-import org.apache.axis2.transport.base.BaseConstants;
-import org.apache.axis2.client.Options;
-import org.apache.axis2.client.ServiceClient;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.context.MessageContext;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMAbstractFactory;
-import org.apache.axis2.Constants;
-import org.apache.axis2.AxisFault;
-import org.apache.axis2.addressing.EndpointReference;
-
-import java.util.Map;
-import java.util.HashMap;
-
-/**
- * The class that handles the email sending logic for stratos.
- */
-public class EmailSender{
- private static Log log = LogFactory.getLog(EmailSender.class);
- private EmailSenderConfiguration config = null;
-
- public EmailSender(EmailSenderConfiguration config) {
- this.config = config;
- }
-
- /**
- * Sends the email
- * @param toEmail Email Address (To:)
- * @param userParameters - map of user parameters
- * @throws Exception, if sending the email notification failed.
- */
- public void sendEmail(String toEmail, Map<String, String>userParameters) throws Exception {
- final String subject = getMessageTitle(userParameters);
- final String body = getMessageBody(userParameters);
- final String email = toEmail; // no change in here,
- new Thread() {
- public void run() {
- Map<String, String> headerMap = new HashMap<String, String>();
- headerMap.put(MailConstants.MAIL_HEADER_SUBJECT, subject);
- OMElement payload = OMAbstractFactory.getOMFactory().createOMElement(
- BaseConstants.DEFAULT_TEXT_WRAPPER, null);
- payload.setText(body);
-
- try {
- ServiceClient serviceClient;
- ConfigurationContext configContext = Util.getConfigurationContext();
- if (configContext != null) {
- serviceClient = new ServiceClient(configContext, null);
- } else {
- serviceClient = new ServiceClient();
- }
- Options options = new Options();
- options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE);
- options.setProperty(MessageContext.TRANSPORT_HEADERS, headerMap);
- options.setProperty(MailConstants.TRANSPORT_MAIL_FORMAT,
- MailConstants.TRANSPORT_FORMAT_TEXT);
- options.setTo(new EndpointReference("mailto:" + email));
- serviceClient.setOptions(options);
- serviceClient.fireAndForget(payload);
- log.debug("Sending confirmation mail to " + email);
- } catch (AxisFault e) {
- String msg = "Error in delivering the message, " +
- "subject: " + subject + ", to: " + email + ".";
- log.error(msg);
- }
- }
- }.start();
- }
-
- /**
- * gets the title of the message
- * @param userParameters - map of user parameters
- * @return the title of the message
- */
- protected String getMessageTitle(Map<String, String> userParameters) {
- return Util.replacePlaceHolders(config.getSubject(), userParameters);
- }
-
- /**
- * gets the body of the message
- * @param userParameters - map of user parameters
- * @return the body of the message
- */
- protected String getMessageBody(Map<String, String> userParameters) {
- return Util.replacePlaceHolders(config.getBody(), userParameters);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/d275c124/components/stratos/org.wso2.carbon.email.sender/2.1.0/src/main/java/org/wso2/carbon/email/sender/api/EmailSenderConfiguration.java
----------------------------------------------------------------------
diff --git a/components/stratos/org.wso2.carbon.email.sender/2.1.0/src/main/java/org/wso2/carbon/email/sender/api/EmailSenderConfiguration.java b/components/stratos/org.wso2.carbon.email.sender/2.1.0/src/main/java/org/wso2/carbon/email/sender/api/EmailSenderConfiguration.java
deleted file mode 100644
index f1533bd..0000000
--- a/components/stratos/org.wso2.carbon.email.sender/2.1.0/src/main/java/org/wso2/carbon/email/sender/api/EmailSenderConfiguration.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.wso2.carbon.email.sender.api;
-
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.impl.builder.StAXOMBuilder;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-/**
- * The class that handles the configuration of the email sender for Stratos
- */
-public class EmailSenderConfiguration {
- private static Log log = LogFactory.getLog(EmailSenderConfiguration.class);
-
- public final static String DEFAULT_VALUE_SUBJECT = "EmailSender";
- public final static String DEFAULT_VALUE_MESSAGE = "Sent form WSO2 Carbon";
-
- private String fromEmail;
- private String subject = DEFAULT_VALUE_SUBJECT;
- private String body = DEFAULT_VALUE_MESSAGE;
- private Map<String, String> customParameters;
-
- public Map<String, String> getCustomParameters() {
- return customParameters;
- }
-
- public void setCustomParameters(Map<String, String> customParameters) {
- this.customParameters = customParameters;
- }
-
-
- public String getSubject() {
- return subject;
- }
-
- public void setSubject(String subject) {
- this.subject = subject.trim();
- }
-
- public String getBody() {
- return body;
- }
-
- public void setBody(String emailMessage) {
- this.body = emailMessage.trim();
- }
-
- public String getFromEmail() {
- return fromEmail;
- }
-
- public void setFromEmail(String fromEmail) {
- this.fromEmail = fromEmail;
- }
-
- /**
- * Loads the email sender configuration
- * @param configFilename configuration file name
- * @return EmailSenderConfiguration.
- */
- public static EmailSenderConfiguration loadEmailSenderConfiguration(String configFilename) {
- File configFile = new File(configFilename);
- if (!configFile.exists()) {
- log.error("Email sender configuration File is not present at: " + configFilename);
- return null;
- }
- EmailSenderConfiguration config = new EmailSenderConfiguration();
- FileInputStream ip = null;
- try {
- ip = new FileInputStream(configFile);
- XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(ip);
- StAXOMBuilder builder = new StAXOMBuilder(parser);
- OMElement documentElement = builder.getDocumentElement();
- Iterator it = documentElement.getChildElements();
- while (it.hasNext()) {
- OMElement element = (OMElement) it.next();
- if ("subject".equals(element.getLocalName())) {
- config.setSubject(element.getText());
- } else if ("body".equals(element.getLocalName())) {
- config.setBody(element.getText());
- } else if ("customParameters".equals(element.getLocalName())) {
- Map<String, String> customParameters = new HashMap<String, String>();
- Iterator customParamIt = element.getChildElements();
- while (customParamIt.hasNext()) {
- OMElement customElement = (OMElement) it.next();
- customParameters.put(customElement.getLocalName(), customElement.getText());
- }
- config.setCustomParameters(customParameters);
- }
- }
- return config;
- } catch (Exception e) {
- String msg = "Error in loading configuration for email verification: " +
- configFilename + ".";
- log.error(msg, e);
- return null;
- } finally {
- if (ip != null) {
- try {
- ip.close();
- } catch (IOException e) {
- log.warn("Could not close InputStream for file " + configFile.getAbsolutePath());
- }
- }
-
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/d275c124/components/stratos/org.wso2.carbon.email.sender/2.1.0/src/main/java/org/wso2/carbon/email/sender/internal/EmailSenderServiceComponent.java
----------------------------------------------------------------------
diff --git a/components/stratos/org.wso2.carbon.email.sender/2.1.0/src/main/java/org/wso2/carbon/email/sender/internal/EmailSenderServiceComponent.java b/components/stratos/org.wso2.carbon.email.sender/2.1.0/src/main/java/org/wso2/carbon/email/sender/internal/EmailSenderServiceComponent.java
deleted file mode 100644
index 3b9318c..0000000
--- a/components/stratos/org.wso2.carbon.email.sender/2.1.0/src/main/java/org/wso2/carbon/email/sender/internal/EmailSenderServiceComponent.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.wso2.carbon.email.sender.internal;
-
-import org.wso2.carbon.email.sender.util.Util;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.osgi.service.component.ComponentContext;
-import org.wso2.carbon.registry.core.service.RegistryService;
-import org.wso2.carbon.user.core.service.RealmService;
-import org.wso2.carbon.utils.CarbonUtils;
-import org.wso2.carbon.utils.ConfigurationContextService;
-
-/**
- * @scr.component name="org.wso2.carbon.email.sender"
- * immediate="true"
- * @scr.reference name="registry.service"
- * interface="org.wso2.carbon.registry.core.service.RegistryService" cardinality="1..1"
- * policy="dynamic" bind="setRegistryService" unbind="unsetRegistryService"
- * @scr.reference name="user.realmservice.default" interface="org.wso2.carbon.user.core.service.RealmService"
- * cardinality="1..1" policy="dynamic" bind="setRealmService"
- * unbind="unsetRealmService"
- * @scr.reference name="configuration.context.service"
- * interface="org.wso2.carbon.utils.ConfigurationContextService" cardinality="1..1"
- * policy="dynamic" bind="setConfigurationContextService" unbind="unsetConfigurationContextService"
- */
-public class EmailSenderServiceComponent {
- private static Log log = LogFactory.getLog(EmailSenderServiceComponent.class);
-
- protected void activate(ComponentContext context) {
- try {
- log.debug("******* Email Sender bundle is activated ******* ");
- } catch (Exception e) {
- log.error("******* Email Sender bundle failed activating ****", e);
- }
- }
-
- protected void deactivate(ComponentContext context) {
- log.debug("******* Email Sender bundle is deactivated ******* ");
- }
- protected void setRegistryService(RegistryService registryService) {
- Util.setRegistryService(registryService);
- }
-
- protected void unsetRegistryService(RegistryService registryService) {
- Util.setRegistryService(null);
- }
-
- protected void setRealmService(RealmService realmService) {
- Util.setRealmService(realmService);
- }
-
- protected void unsetRealmService(RealmService realmService) {
- Util.setRealmService(null);
- }
-
- protected void setConfigurationContextService(ConfigurationContextService configurationContextService){
- log.debug("Receiving ConfigurationContext Service");
- Util.setConfigurationContextService(configurationContextService);
-
- }
-
- protected void unsetConfigurationContextService(ConfigurationContextService configurationContextService){
- log.debug("Unsetting ConfigurationContext Service");
- Util.setConfigurationContextService(null);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/d275c124/components/stratos/org.wso2.carbon.email.sender/2.1.0/src/main/java/org/wso2/carbon/email/sender/util/Util.java
----------------------------------------------------------------------
diff --git a/components/stratos/org.wso2.carbon.email.sender/2.1.0/src/main/java/org/wso2/carbon/email/sender/util/Util.java b/components/stratos/org.wso2.carbon.email.sender/2.1.0/src/main/java/org/wso2/carbon/email/sender/util/Util.java
deleted file mode 100644
index ad91d9b..0000000
--- a/components/stratos/org.wso2.carbon.email.sender/2.1.0/src/main/java/org/wso2/carbon/email/sender/util/Util.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.wso2.carbon.email.sender.util;
-
-import org.apache.axis2.context.ConfigurationContext;
-import org.wso2.carbon.registry.core.exceptions.RegistryException;
-import org.wso2.carbon.registry.core.service.RegistryService;
-import org.wso2.carbon.registry.core.session.UserRegistry;
-import org.wso2.carbon.user.api.RealmConfiguration;
-import org.wso2.carbon.user.core.service.RealmService;
-import org.wso2.carbon.user.core.tenant.TenantManager;
-import org.wso2.carbon.utils.ConfigurationContextService;
-
-import java.util.Map;
-import java.util.regex.Matcher;
-
-/**
- * Utility methods for the email sender component
- */
-public class Util {
-
- private static RegistryService registryService;
- private static RealmService realmService;
- private static ConfigurationContextService configurationContextService;
-
-
- public static ConfigurationContextService getConfigurationContextService() {
- return configurationContextService;
- }
-
- public static void setConfigurationContextService(
- ConfigurationContextService configurationContextService) {
- Util.configurationContextService = configurationContextService;
- }
-
- public static ConfigurationContext getConfigurationContext() {
- if (configurationContextService.getServerConfigContext() == null) {
- return null;
- }
- return configurationContextService.getServerConfigContext();
- }
-
- public static synchronized void setRegistryService(RegistryService service) {
- if (registryService == null) {
- registryService = service;
- }
- }
-
- public static RegistryService getRegistryService() {
- return registryService;
- }
-
- public static synchronized void setRealmService(RealmService service) {
- if (realmService == null) {
- realmService = service;
- }
- }
-
- public static RealmService getRealmService() {
- return realmService;
- }
-
- public static TenantManager getTenantManager() {
- return realmService.getTenantManager();
- }
-
- public static RealmConfiguration getBootstrapRealmConfiguration() {
- return realmService.getBootstrapRealmConfiguration();
- }
-
- public static UserRegistry getGovernanceSystemRegistry(int tenantId) throws RegistryException {
- return registryService.getGovernanceSystemRegistry(tenantId);
- }
-
- /**
- * Replace the {place-holders} with the respective value provided
- * @param text string
- * @param userParameters - map of user parameters
- * @return replaced text for the email {title or body}
- */
- public static String replacePlaceHolders(String text, Map<String, String> userParameters) {
- if (userParameters != null) {
- for (Map.Entry<String, String> entry : userParameters.entrySet()) {
- String key = entry.getKey();
- text = text.replaceAll("\\{" + key + "\\}", Matcher.quoteReplacement(entry.getValue()));
- }
- }
- return text;
- }
-}
\ No newline at end of file