I和Lambda的Im相当新鲜,但当Javamail图书馆无法找到特定监测类型的数据ContentHandler时,就会出现错误。 在该案中,在AWS Lambda console实施该守则时发生,而不是在当地通过邮政员进行测试。 这表明,AWS Lambda console的环境组合可能会出现问题。
One solution is to ensure that the necessary libraries are included in the deployment package of the AWS Lambda function. When testing locally, all the required libraries may be present in the classpath, but the same may not be true in the AWS Lambda environment. Make sure that all the required dependencies are included in the deployment package and that the classpath is set up correctly.
另一种解决办法是明确登记“多部分/混合”的“多功能和多功能”等“数据ContentHandler”。 可以通过制定习惯实施 j。 启动。 数据来源 Handler接口,并在Java Beans活动框架内登记。 举例说,执行(未经测试的法典):
import javax.activation.*;
import java.io.*;
public class MyDataContentHandler implements DataContentHandler {
public MyDataContentHandler() {
}
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[] { new DataFlavor("multipart/mixed") };
}
public Object getTransferData(DataFlavor flavor, DataSource dataSource)
throws UnsupportedFlavorException, IOException {
if (flavor.equals(new DataFlavor("multipart/mixed"))) {
return dataSource.getInputStream();
} else {
throw new UnsupportedFlavorException(flavor);
}
}
public Object getContent(DataSource dataSource) throws IOException {
return dataSource.getInputStream();
}
public void writeTo(Object object, String mimeType, OutputStream outputStream)
throws IOException {
throw new UnsupportedEncodingException("writeTo() not supported");
}
}
然后,在寄送电子邮件之前,将海关数据ContentHandler与JAF登记在Lambda功能守则中:
MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
mc.addMailcap("multipart/mixed;; x-java-content-handler=com.example.MyDataContentHandler");
CommandMap.setDefaultCommandMap(mc);
这应当登记用于“多功能/多功能”的MSContentHandler习俗,并解决问题。
确保检查AWS Lambda环境组合,并将所有必要的附属设施纳入部署一揽子计划,以确保必要的图书馆能够运行。