我的servlet中有一个应该运行的脚本。在发布webapp“将其导出到WAR文件”之前,脚本会运行,但在发布后,它不会。 任何线索?我使用Tomcat 8,JAVA / JSP(Backend / Frontend) 我的脚本是python,它发送自动电子邮件,这就是我从servlet中调用它的方式。
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
String[] pythonscript = new String[3] ;
pythonscript[0] = "C:\\Program Files (x86)\\IronPython 2.7\\ipy64.exe";
pythonscript[1] = "C:\\Program Files\\Apache Software Foundation\\Tomcat 8.0\\webapps\\myapp\\db_monitor.py";
pythonscript[2] = "Email: Comment/Question: Hello ";
File file = new File("test.log");
PrintStream ps = new PrintStream(file);
try {
Runtime.getRuntime().exec(pythonscript);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace(ps);
}
}
这是用Python / IronPython
编写的脚本import clr
clr.AddReferenceToFileAndPath("C:\\Program Files (x86)\\Microsoft\\Exchange\\Web Services\\2.1\\Microsoft.Exchange.WebServices.dll")
from Microsoft.Exchange.WebServices.Data import *
def main():
ex_service = ExchangeService(ExchangeVersion.Exchange2010)
ex_service.UseDefaultCredentials = True
ex_service.AutodiscoverUrl("me@company.com", redirect_url_validation_callback)
email = EmailMessage(ex_service)
email.BccRecipients.Add("me@company.com");
email.Subject = "New Report / Test "
email.Body = '''A new report has been published'''
email.Send()
def redirect_url_validation_callback(redirect_url):
redirect_uri = Uri(redirect_url)
return redirect_uri.Scheme == "https"
if __name__ == "__main__":
main()
我是否需要修改从servlet调用的路径?据我所知并测试它们是正确的,但是当我发布该webapp时,脚本将无法运行...
更新:记录输出后,我发现了我遇到的错误:
Traceback (most recent call last):
File "C:\Program Files\Apache Software Foundation\Tomcat 8.0\webapps\myapp\db_monitor.py", line 26, in <module>
File "C:\Program Files\Apache Software Foundation\Tomcat 8.0\webapps\myapp\db_monitor.py", line 19, in main
Exception: SendOnly cannot be used by a user without a mailbox. Use SendAndSaveCopy and specify a folder ID in a mailbox to send an item from an account that doesn't have a mailbox.