Help on SMS service task

52 views
Skip to first unread message

Galina Popov

unread,
Jul 17, 2017, 11:47:06 AM7/17/17
to jBPM Development
Hi everyone,
I am new bie to jbpm I am trying to create some task where I am stuck in creating SMS service task.
When jbpm process starts I need to send a Twilio based SMS. (other third-party services are also okay if not Twilio).
I tried something like this:
I create SMSWorkItemHandler work item handler 

package com.redpine.helper;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.kie.api.runtime.process.WorkItem;
import org.kie.api.runtime.process.WorkItemHandler;
import org.kie.api.runtime.process.WorkItemManager;

import com.twilio.sdk.TwilioRestClient;
import com.twilio.sdk.TwilioRestException;
import com.twilio.sdk.resource.factory.MessageFactory;
import com.twilio.sdk.resource.instance.Account;


public class SMSWorkItemHandler implements WorkItemHandler{

public static final String ACCOUNT_SID = "AC2d4e8bb507fe5euhf3c83232b078bc";  
 public static final String AUTH_TOKEN = "fe870e063u4or43gfd52f761770725";  
 public static final String FROM = "+12402358093";  
 
@Override
public void abortWorkItem(WorkItem workItem, WorkItemManager workItemManger) {
// TODO Auto-generated method stub
System.out.println("Oh something went wrong");  
}

@Override
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
// TODO Auto-generated method stub
String to = (String)workItem.getParameter("TO");  
String text = (String)workItem.getParameter("TEXT");  
try {
SendSMS(to,text);
} catch (TwilioRestException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Message has been succesfully sent");  
 System.out.println("To: "+to);  
 System.out.println("From: "+FROM);  
 System.out.println("Text: "+text);  
 
 workItemManager.completeWorkItem(workItem.getId(), null);  
}
public void SendSMS(String to, String text) throws TwilioRestException  
 {  
TwilioRestClient twilioRestClient = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);
Account mainAccount = twilioRestClient.getAccount();
// Send an sms (using the new messages endpoint)
MessageFactory messageFactory = mainAccount.getMessageFactory();
List<NameValuePair> messageParams = new ArrayList<NameValuePair>();
messageParams.add(new BasicNameValuePair("To", "5105551212")); // Replace with a valid phone number
messageParams.add(new BasicNameValuePair("From", "(510) 555-1212")); // Replace with a valid phone
messageParams.add(new BasicNameValuePair("Body", "This is a test message!"));
messageFactory.create(messageParams);
 }  


}

I created .wid in this way

  [
  "name" : "SMS",
  "parameters" :[
  "TO" : new StringDataType(),
  "TEXT" : new StringDataType()
  ],
  "displayName" : "SendSMS",
  "icon" : "sms.png"
  ]


Nothing worked I don't know what I am missing. I don't have a perfect example in my hand.
Can anyone help with an example?
or any suggestions to complete the task successfully?
the suggestion will be appreciated.

Thank you
Galina


Galina Popov

unread,
Jul 17, 2017, 2:01:11 PM7/17/17
to jBPM Development
I am getting strange error when I add Twilio maven dependency

<dependency>
<groupId>com.twilio.sdk</groupId>
<artifactId>twilio-java-sdk</artifactId>
<version>6.3.0</version>
<!-- <scope>provided</scope> -->
</dependency>

23:16:17,496 ERROR [org.kie.server.services.jbpm.JbpmKieServerExtension] (default task-12) Error when creating container smsContainer by extension jBPM KIE Server extension: java.lang.RuntimeException: java.lang.IncompatibleClassChangeError: org.apache.http.impl.cookie.DateUtils and org.apache.http.impl.cookie.DateUtils$DateFormatHolder disagree on InnerClasses attribute
        at org.jbpm.kie.services.impl.KModuleDeploymentService.deploy(KModuleDeploymentService.java:202)
        at org.kie.server.services.jbpm.JbpmKieServerExtension.createContainer(JbpmKieServerExtension.java:388)
        at org.kie.server.services.impl.KieServerImpl.createContainer(KieServerImpl.java:280)
        at org.kie.server.remote.rest.common.resource.KieServerRestImpl.createContainer(KieServerRestImpl.java:109)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:139)
        at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:295)
        at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:249)
        at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:236)
        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:395)
        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:202)
        at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:221)
        at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
        at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
        at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
        at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
        at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
        at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
        at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
        at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
        at io.undertow.server.handlers.DisableCacheHandler.handleRequest(DisableCacheHandler.java:33)
        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
        at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:51)
        at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
        at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
        at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:56)
        at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
        at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
        at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
        at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
        at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
        at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:284)
        at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:263)
        at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
        at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:174)
        at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
        at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:793)
        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:748)
Caused by: java.lang.IncompatibleClassChangeError: org.apache.http.impl.cookie.DateUtils and org.apache.http.impl.cookie.DateUtils$DateFormatHolder disagree on InnerClasses attribute
        at java.lang.Class.getDeclaringClass0(Native Method)
        at java.lang.Class.getDeclaringClass(Class.java:1235)
        at java.lang.Class.getEnclosingClass(Class.java:1277)
        at java.lang.Class.getSimpleBinaryName(Class.java:1443)
        at java.lang.Class.isMemberClass(Class.java:1433)
        at org.jbpm.kie.services.impl.KModuleDeploymentService.filterClassesAddedToDeployedUnit(KModuleDeploymentService.java:476)
        at org.jbpm.kie.services.impl.KModuleDeploymentService.addClassToDeployedUnit(KModuleDeploymentService.java:411)
        at org.jbpm.kie.services.impl.KModuleDeploymentService.processResources(KModuleDeploymentService.java:395)
        at org.jbpm.kie.services.impl.KModuleDeploymentService.deploy(KModuleDeploymentService.java:167)
        ... 47 more

23:16:17,496 ERROR [org.kie.server.services.jbpm.JbpmKieServerExtension] (default task-12) Error when creating container smsContainer by extension jBPM KIE Server extension: java.lang.RuntimeException: java.lang.IncompatibleClassChangeError: org.apache.http.impl.cookie.DateUtils and org.apache.http.impl.cookie.DateUtils$DateFormatHolder disagree on InnerClasses attribute
        at org.jbpm.kie.services.impl.KModuleDeploymentService.deploy(KModuleDeploymentService.java:202)
        at org.kie.server.services.jbpm.JbpmKieServerExtension.createContainer(JbpmKieServerExtension.java:388)
        at org.kie.server.services.impl.KieServerImpl.createContainer(KieServerImpl.java:280)
        at org.kie.server.remote.rest.common.resource.KieServerRestImpl.createContainer(KieServerRestImpl.java:109)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:139)
        at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:295)
        at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:249)
        at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:236)
        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:395)
        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:202)
        at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:221)
        at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
        at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
        at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
        at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
        at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
        at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
        at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
        at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
        at io.undertow.server.handlers.DisableCacheHandler.handleRequest(DisableCacheHandler.java:33)
        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
        at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:51)
        at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
        at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
        at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:56)
        at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
        at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
        at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
        at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
        at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
        at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
        at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:284)
        at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:263)
        at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
        at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:174)
        at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
        at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:793)
        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:748)
Caused by: java.lang.IncompatibleClassChangeError: org.apache.http.impl.cookie.DateUtils and org.apache.http.impl.cookie.DateUtils$DateFormatHolder disagree on InnerClasses attribute
        at java.lang.Class.getDeclaringClass0(Native Method)
        at java.lang.Class.getDeclaringClass(Class.java:1235)
        at java.lang.Class.getEnclosingClass(Class.java:1277)
        at java.lang.Class.getSimpleBinaryName(Class.java:1443)
        at java.lang.Class.isMemberClass(Class.java:1433)
        at org.jbpm.kie.services.impl.KModuleDeploymentService.filterClassesAddedToDeployedUnit(KModuleDeploymentService.java:476)
        at org.jbpm.kie.services.impl.KModuleDeploymentService.addClassToDeployedUnit(KModuleDeploymentService.java:411)
        at org.jbpm.kie.services.impl.KModuleDeploymentService.processResources(KModuleDeploymentService.java:395)
        at org.jbpm.kie.services.impl.KModuleDeploymentService.deploy(KModuleDeploymentService.java:167)

Maciej Swiderski

unread,
Jul 18, 2017, 2:54:22 AM7/18/17
to Galina Popov, jBPM Development
looks like a conflict with apache http client library. Exclude the http client that comes with twilio or upgrade one in kie server

Maciej
-- 
You received this message because you are subscribed to the Google Groups "jBPM Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jbpm-developme...@googlegroups.com.
To post to this group, send email to jbpm-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jbpm-development/38a35a08-b5a7-4770-be72-8d6ebdace925%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages