Search in sources :

Example 6 with ScriptingEngines

use of org.activiti.engine.impl.scripting.ScriptingEngines in project Activiti by Activiti.

the class JuelFormEngine method renderTaskForm.

public Object renderTaskForm(TaskFormData taskForm) {
    if (taskForm.getFormKey() == null) {
        return null;
    }
    String formTemplateString = getFormTemplateString(taskForm, taskForm.getFormKey());
    ScriptingEngines scriptingEngines = Context.getProcessEngineConfiguration().getScriptingEngines();
    TaskEntity task = (TaskEntity) taskForm.getTask();
    return scriptingEngines.evaluate(formTemplateString, ScriptingEngines.DEFAULT_SCRIPTING_LANGUAGE, task.getExecution());
}
Also used : TaskEntity(org.activiti.engine.impl.persistence.entity.TaskEntity) ScriptingEngines(org.activiti.engine.impl.scripting.ScriptingEngines)

Example 7 with ScriptingEngines

use of org.activiti.engine.impl.scripting.ScriptingEngines in project Activiti by Activiti.

the class ScriptTaskActivityBehavior method execute.

public void execute(ActivityExecution execution) throws Exception {
    ScriptingEngines scriptingEngines = Context.getProcessEngineConfiguration().getScriptingEngines();
    if (Context.getProcessEngineConfiguration().isEnableProcessDefinitionInfoCache()) {
        ObjectNode taskElementProperties = Context.getBpmnOverrideElementProperties(scriptTaskId, execution.getProcessDefinitionId());
        if (taskElementProperties != null && taskElementProperties.has(DynamicBpmnConstants.SCRIPT_TASK_SCRIPT)) {
            String overrideScript = taskElementProperties.get(DynamicBpmnConstants.SCRIPT_TASK_SCRIPT).asText();
            if (StringUtils.isNotEmpty(overrideScript) && overrideScript.equals(script) == false) {
                script = overrideScript;
            }
        }
    }
    boolean noErrors = true;
    try {
        Object result = scriptingEngines.evaluate(script, language, execution, storeScriptVariables);
        if (resultVariable != null) {
            execution.setVariable(resultVariable, result);
        }
    } catch (ActivitiException e) {
        LOGGER.warn("Exception while executing " + execution.getActivity().getId() + " : " + e.getMessage());
        noErrors = false;
        Throwable rootCause = ExceptionUtils.getRootCause(e);
        if (rootCause instanceof BpmnError) {
            ErrorPropagation.propagateError((BpmnError) rootCause, execution);
        } else {
            throw e;
        }
    }
    if (noErrors) {
        leave(execution);
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ScriptingEngines(org.activiti.engine.impl.scripting.ScriptingEngines) BpmnError(org.activiti.engine.delegate.BpmnError)

Example 8 with ScriptingEngines

use of org.activiti.engine.impl.scripting.ScriptingEngines in project Activiti by Activiti.

the class MuleSendActivitiBehavior method execute.

public void execute(ActivityExecution execution) throws Exception {
    String endpointUrlValue = this.getStringFromField(this.endpointUrl, execution);
    String languageValue = this.getStringFromField(this.language, execution);
    String payloadExpressionValue = this.getStringFromField(this.payloadExpression, execution);
    String resultVariableValue = this.getStringFromField(this.resultVariable, execution);
    String usernameValue = this.getStringFromField(this.username, execution);
    String passwordValue = this.getStringFromField(this.password, execution);
    ScriptingEngines scriptingEngines = Context.getProcessEngineConfiguration().getScriptingEngines();
    Object payload = scriptingEngines.evaluate(payloadExpressionValue, languageValue, execution);
    if (endpointUrlValue.startsWith("vm:")) {
        LocalMuleClient client = this.getMuleContext().getClient();
        MuleMessage message = new DefaultMuleMessage(payload, this.getMuleContext());
        MuleMessage resultMessage = client.send(endpointUrlValue, message);
        Object result = resultMessage.getPayload();
        if (resultVariableValue != null) {
            execution.setVariable(resultVariableValue, result);
        }
    } else {
        HttpClientBuilder clientBuilder = HttpClientBuilder.create();
        if (usernameValue != null && passwordValue != null) {
            CredentialsProvider provider = new BasicCredentialsProvider();
            UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(usernameValue, passwordValue);
            provider.setCredentials(new AuthScope("localhost", -1, "mule-realm"), credentials);
            clientBuilder.setDefaultCredentialsProvider(provider);
        }
        HttpClient client = clientBuilder.build();
        HttpPost request = new HttpPost(endpointUrlValue);
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(baos);
            oos.writeObject(payload);
            oos.flush();
            oos.close();
            request.setEntity(new ByteArrayEntity(baos.toByteArray()));
        } catch (Exception e) {
            throw new ActivitiException("Error setting message payload", e);
        }
        byte[] responseBytes = null;
        try {
            // execute the POST request
            HttpResponse response = client.execute(request);
            responseBytes = IOUtils.toByteArray(response.getEntity().getContent());
        } finally {
            // release any connection resources used by the method
            request.releaseConnection();
        }
        if (responseBytes != null) {
            try {
                ByteArrayInputStream in = new ByteArrayInputStream(responseBytes);
                ObjectInputStream is = new ObjectInputStream(in);
                Object result = is.readObject();
                if (resultVariableValue != null) {
                    execution.setVariable(resultVariableValue, result);
                }
            } catch (Exception e) {
                throw new ActivitiException("Failed to read response value", e);
            }
        }
    }
    this.leave(execution);
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) ActivitiException(org.activiti.engine.ActivitiException) ScriptingEngines(org.activiti.engine.impl.scripting.ScriptingEngines) HttpResponse(org.apache.http.HttpResponse) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ActivitiException(org.activiti.engine.ActivitiException) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) ByteArrayEntity(org.apache.http.entity.ByteArrayEntity) MuleMessage(org.mule.api.MuleMessage) DefaultMuleMessage(org.mule.DefaultMuleMessage) ByteArrayInputStream(java.io.ByteArrayInputStream) HttpClient(org.apache.http.client.HttpClient) AuthScope(org.apache.http.auth.AuthScope) LocalMuleClient(org.mule.api.client.LocalMuleClient) DefaultMuleMessage(org.mule.DefaultMuleMessage) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

ScriptingEngines (org.activiti.engine.impl.scripting.ScriptingEngines)8 ActivitiException (org.activiti.engine.ActivitiException)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 BpmnError (org.activiti.engine.delegate.BpmnError)1 VariableScope (org.activiti.engine.delegate.VariableScope)1 TaskEntity (org.activiti.engine.impl.persistence.entity.TaskEntity)1 BeansResolverFactory (org.activiti.engine.impl.scripting.BeansResolverFactory)1 ResolverFactory (org.activiti.engine.impl.scripting.ResolverFactory)1 ScriptBindingsFactory (org.activiti.engine.impl.scripting.ScriptBindingsFactory)1 VariableScopeResolverFactory (org.activiti.engine.impl.scripting.VariableScopeResolverFactory)1 HttpResponse (org.apache.http.HttpResponse)1 AuthScope (org.apache.http.auth.AuthScope)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1 CredentialsProvider (org.apache.http.client.CredentialsProvider)1 HttpClient (org.apache.http.client.HttpClient)1 HttpPost (org.apache.http.client.methods.HttpPost)1