Author: gnodet
Date: Thu Jul 3 16:05:15 2008
New Revision: 673862
URL: http://svn.apache.org/viewvc?rev=673862&view=rev
Log:
SM-1387: make servicemix-mail osgi friendly
Added:
servicemix/components/bindings/servicemix-mail/trunk/src/main/resources/META-INF/
servicemix/components/bindings/servicemix-mail/trunk/src/main/resources/META-INF/spring/
servicemix/components/bindings/servicemix-mail/trunk/src/main/resources/META-INF/spring/servicemix-mail.xml
Modified:
servicemix/components/bindings/servicemix-mail/trunk/pom.xml
servicemix/components/bindings/servicemix-mail/trunk/src/main/java/org/apache/servicemix/mail/marshaler/DefaultMailMarshaler.java
Modified: servicemix/components/bindings/servicemix-mail/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-mail/trunk/pom.xml?rev=673862&r1=673861&r2=673862&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-mail/trunk/pom.xml (original)
+++ servicemix/components/bindings/servicemix-mail/trunk/pom.xml Thu Jul 3
16:05:15 2008
@@ -42,6 +42,17 @@
<previous.releases>3.1.2,3.2,3.2.1</previous.releases>
<servicemix-version>3.2.1</servicemix-version>
<servicemix-shared-version>4.0-SNAPSHOT</servicemix-shared-version>
+
+ <servicemix.osgi.import>
+ org.apache.servicemix.common.osgi,
+ org.apache.xbean.spring.context.v2,
+ org.springframework.beans.factory.xml,
+ *
+ </servicemix.osgi.import>
+ <servicemix.osgi.export>
+ org.apache.servicemix*;version=${project.version},
+
META-INF.services.org.apache.xbean.spring.http.servicemix.apache.org.mail
+ </servicemix.osgi.export>
</properties>
<dependencies>
@@ -52,9 +63,8 @@
</dependency>
<dependency>
<groupId>org.apache.servicemix</groupId>
- <artifactId>servicemix-core</artifactId>
+ <artifactId>servicemix-jbi</artifactId>
<version>${servicemix-version}</version>
- <scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
@@ -64,6 +74,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
Modified:
servicemix/components/bindings/servicemix-mail/trunk/src/main/java/org/apache/servicemix/mail/marshaler/DefaultMailMarshaler.java
URL:
http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-mail/trunk/src/main/java/org/apache/servicemix/mail/marshaler/DefaultMailMarshaler.java?rev=673862&r1=673861&r2=673862&view=diff
==============================================================================
---
servicemix/components/bindings/servicemix-mail/trunk/src/main/java/org/apache/servicemix/mail/marshaler/DefaultMailMarshaler.java
(original)
+++
servicemix/components/bindings/servicemix-mail/trunk/src/main/java/org/apache/servicemix/mail/marshaler/DefaultMailMarshaler.java
Thu Jul 3 16:05:15 2008
@@ -21,6 +21,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.text.DateFormat;
import java.util.Enumeration;
import java.util.Iterator;
@@ -36,6 +37,7 @@
import javax.mail.Message;
import javax.mail.Multipart;
import javax.mail.Part;
+import javax.mail.util.ByteArrayDataSource;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
@@ -45,8 +47,6 @@
import org.apache.commons.logging.LogFactory;
import org.apache.servicemix.jbi.jaxp.SourceTransformer;
import org.apache.servicemix.jbi.jaxp.StringSource;
-import org.apache.servicemix.jbi.util.ByteArrayDataSource;
-import org.apache.servicemix.jbi.util.FileUtil;
/**
* this is the default marshaler for conversion between the normalized message
@@ -137,7 +137,7 @@
DataHandler dh = nmsg.getAttachment(oneAttachmentName);
File f = File.createTempFile("" +
System.currentTimeMillis() + "-", dh.getDataSource().getName());
BufferedOutputStream bos = new BufferedOutputStream(new
FileOutputStream(f));
- FileUtil.copyInputStream(dh.getInputStream(), bos);
+ copyInputStream(dh.getInputStream(), bos);
bos.close();
log.debug("Saved temp file: " + f.getName() + " with
length: " + f.length());
@@ -605,4 +605,23 @@
nmsg.addAttachment(bads.getName(), new DataHandler(bads));
}
}
+
+ /**
+ * Copy in stream to an out stream
+ *
+ * @param in
+ * @param out
+ * @throws IOException
+ */
+ public static void copyInputStream(InputStream in, OutputStream out)
throws IOException {
+ byte[] buffer = new byte[8192];
+ int len = in.read(buffer);
+ while (len >= 0) {
+ out.write(buffer, 0, len);
+ len = in.read(buffer);
+ }
+ in.close();
+ out.close();
+ }
+
}
Added:
servicemix/components/bindings/servicemix-mail/trunk/src/main/resources/META-INF/spring/servicemix-mail.xml
URL:
http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-mail/trunk/src/main/resources/META-INF/spring/servicemix-mail.xml?rev=673862&view=auto
==============================================================================
---
servicemix/components/bindings/servicemix-mail/trunk/src/main/resources/META-INF/spring/servicemix-mail.xml
(added)
+++
servicemix/components/bindings/servicemix-mail/trunk/src/main/resources/META-INF/spring/servicemix-mail.xml
Thu Jul 3 16:05:15 2008
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:osgi="http://www.springframework.org/schema/osgi"
+ xmlns:util="http://www.springframework.org/schema/util"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/util
+ http://www.springframework.org/schema/util/spring-util.xsd
+ http://www.springframework.org/schema/osgi
+ http://www.springframework.org/schema/osgi/spring-osgi.xsd">
+
+ <bean id="servicemix-mail"
class="org.apache.servicemix.mail.MailComponent">
+ </bean>
+
+ <bean id="endpoint-tracker"
class="org.apache.servicemix.common.osgi.EndpointTracker">
+ <property name="component" ref="servicemix-mail" />
+ </bean>
+
+ <osgi:list id="endpoints"
+ interface="org.apache.servicemix.common.osgi.EndpointWrapper"
+ cardinality="0..N">
+ <osgi:listener ref="endpoint-tracker" bind-method="register"
unbind-method="unregister" />
+ </osgi:list>
+
+ <osgi:service ref="servicemix-mail"
interface="javax.jbi.component.Component">
+ <osgi:service-properties>
+ <entry key="NAME" value="servicemix-mail" />
+ <entry key="TYPE" value="binding-component" />
+ </osgi:service-properties>
+ </osgi:service>
+
+</beans>