Reputation:
Can't find the way to attach a file from HDFS to email MimeBodyPart. Here is my attempt so far. I tried to use both FileDataSource and URLDataSource but no luck.
val attachmentPart = new MimeBodyPart()
val filePath = "FILE_PATH"
val fileName = s"FILE_NAME_${date}.html"
val fs = FileSystem.get(sctx.hadoopConfiguration)
val fullURL = fs.getFileStatus(new Path(filePath+fileName)).getPath.toUri.toURL
//val fullFilePath = fs.getFileStatus(new Path(filePath+fileName)).getPath.toString
val source = new URLDataSource(fullURL)
//val source = new FileDataSource(fullFilePath)
attachmentPart.setDataHandler(new DataHandler(source))
attachmentPart.setFileName("file name")
I am getting the following error in the case of the URLDataSource:
Exception in thread "main" java.net.MalformedURLException: unknown protocol: hdfs
Upvotes: 1
Views: 743
Reputation: 11587
try registering the hadoop's FsUrlStreamHandlerFactory to handle urls with schema hdfs.
import org.apache.hadoop.fs.FsUrlStreamHandlerFactory
import java.net.URL
URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory())
Upvotes: 1