Script error send email example on PaymentService.preview

Any issue about Cyclos 4 scripting and Webservices

Moderators: hugo, alexandre, rmvanarkel

Post Reply
cycloshost
Posts: 578
Joined: Mon Jan 30, 2012 8:12 am
Contact:

Script error send email example on PaymentService.preview

Post by cycloshost »

Hi,

we are following the example of triggering an email when PaymentService.preview from section 3.2.7.9. in:
http://documentation.cyclos.org/4.3/cyc ... 03s02.html

We added a new script type Extension point with the code suggested when the data is saved:

Code: Select all

import javax.mail.internet.InternetAddress

import org.cyclos.model.ValidationException
import org.cyclos.server.utils.MessageProcessingHelper
import org.springframework.mail.javamail.MimeMessageHelper

// Get the e-mail subject and body
def tx = scriptHelper.wrap(transaction)
def vars = [
    payer: tx.fromOwner.name,
    amount: formatter.format(tx.currencyAmount),
    date: formatter.formatAsDate(new Date()),
    time: formatter.formatAsTime(new Date())
]
def subject = MessageProcessingHelper.processVariables(scriptParameters.subject, vars)
if (subject == null || subject.empty) {
    throw new ValidationException("Missing the 'subject' script parameter")
}
def body = MessageProcessingHelper.processVariables(scriptParameters.message, vars)
if (body == null || body.empty) {
    throw new ValidationException("Missing the 'message' script parameter")
}
def toEmail = tx.email
def fromEmail = sessionData.configuration.smtpConfiguration.fromAddress
def sender = mailHandler.mailSender

// Send the message after commit, so we guarantee the transaction is persisted when the e-mail is sent
scriptHelper.addOnCommit {
    def message = sender.createMimeMessage()
    def helper = new MimeMessageHelper(message)
    helper.to = new InternetAddress(toEmail)
    helper.from = new InternetAddress(fromEmail)
    helper.subject = subject
    helper.text = body
    // Send the message
    sender.send message
}
Then, we added a new extension point type Transaction for a Transfer Type and event preview. But we receive the following error:

Code: Select all

org.cyclos.model.system.scripts.CustomScriptException: Error invoking the custom script CustomScript#3: Send Email to Sender, function SAVED
at org.cyclos.impl.system.CustomScriptServiceImpl$CustomScriptAccessorImpl$1.call(CustomScriptServiceImpl.java:210)
at org.cyclos.impl.InvokerHandlerImpl.runAs(InvokerHandlerImpl.java:329)
at org.cyclos.impl.system.CustomScriptServiceImpl$CustomScriptAccessorImpl.run(CustomScriptServiceImpl.java:201)
at org.cyclos.impl.system.ExtensionPointServiceImpl$ExtensionPointAccessorImpl.run(ExtensionPointServiceImpl.java:170)
at org.cyclos.impl.system.ExtensionPointServiceImpl$ExtensionPointAccessorImpl.fireSaved(ExtensionPointServiceImpl.java:158)
at org.cyclos.impl.banking.PaymentServiceImpl.preview(PaymentServiceImpl.java:280)
at org.cyclos.security.banking.PaymentServiceSecurity.preview(PaymentServiceSecurity.java:89)
at sun.reflect.GeneratedMethodAccessor2516.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.cyclos.impl.InvokerHandlerImpl$ServiceInvocationTransactionCallback.doInTransaction(InvokerHandlerImpl.java:195)
at org.cyclos.impl.InvokerHandlerImpl$ServiceInvocationTransactionCallback.doInTransaction(InvokerHandlerImpl.java:123)
at org.cyclos.impl.InvokerHandlerImpl$2.invokeCallback(InvokerHandlerImpl.java:432)
at org.cyclos.impl.InvokerHandlerImpl$2.doInTransaction(InvokerHandlerImpl.java:424)
at org.cyclos.impl.utils.transaction.TransactionHandlerImpl.run(TransactionHandlerImpl.java:179)
at org.cyclos.impl.utils.transaction.TransactionHandlerImpl.run(TransactionHandlerImpl.java:201)
at org.cyclos.impl.utils.transaction.TransactionHandlerImpl.run(TransactionHandlerImpl.java:157)
at org.cyclos.impl.utils.transaction.TransactionHandlerImpl.run(TransactionHandlerImpl.java:87)
at org.cyclos.impl.InvokerHandlerImpl.doRunInTransaction(InvokerHandlerImpl.java:445)
at org.cyclos.impl.InvokerHandlerImpl.doRunAsInTransaction(InvokerHandlerImpl.java:386)
at org.cyclos.impl.InvokerHandlerImpl.runAsInTransaction(InvokerHandlerImpl.java:360)
at org.cyclos.impl.InvokerHandlerImpl.invoke(InvokerHandlerImpl.java:279)
at org.cyclos.impl.access.ServiceFacadeImpl.invoke(ServiceFacadeImpl.java:191)
at org.cyclos.server.spring.root.RequestServiceFactory$ServiceProxyInvocationHandler.invoke(RequestServiceFactory.java:72)
at com.sun.proxy.$Proxy91.preview(Unknown Source)
at sun.reflect.GeneratedMethodAccessor2515.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.cyclos.server.spring.gwtrpc.GwtRpcRequestHandler.invokeServiceMethod(GwtRpcRequestHandler.java:385)
at org.cyclos.server.spring.gwtrpc.GwtRpcRequestHandler.invokeAndEncodeResponse(GwtRpcRequestHandler.java:342)
at org.cyclos.server.spring.gwtrpc.GwtRpcRequestHandler.processCall(GwtRpcRequestHandler.java:136)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:373)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at org.cyclos.server.spring.gwtrpc.GwtRpcRequestHandler.handleRequest(GwtRpcRequestHandler.java:120)
at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:51)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:301)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.cyclos.server.http.GwtCacheFilter.doFilter(GwtCacheFilter.java:120)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:721)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:466)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:391)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:318)
at org.cyclos.server.http.RequestDataFilter.doFilterInternal(RequestDataFilter.java:117)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.cyclos.server.http.RequestContextFilter.doFilterInternal(RequestContextFilter.java:98)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.cyclos.server.http.CORSFilter.doFilter(CORSFilter.java:77)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:74)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
at org.apache.coyote.ajp.AbstractAjpProcessor.process(AbstractAjpProcessor.java:799)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:652)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1575)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1533)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: transaction for class: Script12
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:348)
at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:41)
at javax.script.CompiledScript.eval(CompiledScript.java:92)
at org.cyclos.impl.system.CustomScriptServiceImpl$CustomScriptAccessorImpl$1.call(CustomScriptServiceImpl.java:205)
... 89 more
Caused by: groovy.lang.MissingPropertyException: No such property: transaction for class: Script12
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)
at Script12.run(Script12.groovy:8)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:345)
... 92 more
cycloshost.com
Cyclos administration and hosting

Post Reply