Search in sources :

Example 1 with Bpmn2Import

use of org.jbpm.bpmn2.core.Bpmn2Import in project jbpm by kiegroup.

the class WebServiceWorkItemHandler method getWSClient.

@SuppressWarnings("unchecked")
protected Client getWSClient(WorkItem workItem, String interfaceRef) {
    if (clients.containsKey(interfaceRef)) {
        return clients.get(interfaceRef);
    }
    synchronized (this) {
        if (clients.containsKey(interfaceRef)) {
            return clients.get(interfaceRef);
        }
        String importLocation = (String) workItem.getParameter("Url");
        String importNamespace = (String) workItem.getParameter("Namespace");
        if (importLocation != null && importLocation.trim().length() > 0 && importNamespace != null && importNamespace.trim().length() > 0) {
            Client client = getDynamicClientFactory().createClient(importLocation, new QName(importNamespace, interfaceRef), getInternalClassLoader(), null);
            clients.put(interfaceRef, client);
            return client;
        }
        long processInstanceId = ((WorkItemImpl) workItem).getProcessInstanceId();
        WorkflowProcessImpl process = ((WorkflowProcessImpl) ksession.getProcessInstance(processInstanceId).getProcess());
        List<Bpmn2Import> typedImports = (List<Bpmn2Import>) process.getMetaData("Bpmn2Imports");
        if (typedImports != null) {
            Client client = null;
            for (Bpmn2Import importObj : typedImports) {
                if (WSDL_IMPORT_TYPE.equalsIgnoreCase(importObj.getType())) {
                    try {
                        client = getDynamicClientFactory().createClient(importObj.getLocation(), new QName(importObj.getNamespace(), interfaceRef), getInternalClassLoader(), null);
                        clients.put(interfaceRef, client);
                        return client;
                    } catch (Exception e) {
                        logger.error("Error when creating WS Client", e);
                        continue;
                    }
                }
            }
        }
    }
    return null;
}
Also used : Bpmn2Import(org.jbpm.bpmn2.core.Bpmn2Import) QName(javax.xml.namespace.QName) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) List(java.util.List) Client(org.apache.cxf.endpoint.Client) WorkflowProcessImpl(org.jbpm.workflow.core.impl.WorkflowProcessImpl)

Example 2 with Bpmn2Import

use of org.jbpm.bpmn2.core.Bpmn2Import in project jbpm by kiegroup.

the class ServiceTaskHandler method getWSClient.

@SuppressWarnings("unchecked")
protected synchronized Client getWSClient(WorkItem workItem, String interfaceRef) {
    if (clients.containsKey(interfaceRef)) {
        return clients.get(interfaceRef);
    }
    long processInstanceId = ((WorkItemImpl) workItem).getProcessInstanceId();
    WorkflowProcessImpl process = ((WorkflowProcessImpl) ksession.getProcessInstance(processInstanceId).getProcess());
    List<Bpmn2Import> typedImports = (List<Bpmn2Import>) process.getMetaData("Bpmn2Imports");
    if (typedImports != null) {
        Client client = null;
        for (Bpmn2Import importObj : typedImports) {
            if (WSDL_IMPORT_TYPE.equalsIgnoreCase(importObj.getType())) {
                try {
                    client = dcf.createClient(importObj.getLocation(), new QName(importObj.getNamespace(), interfaceRef), getInternalClassLoader(), null);
                    clients.put(interfaceRef, client);
                    logger.info("WS Client is created for {" + importObj.getNamespace() + "}" + interfaceRef);
                    return client;
                } catch (Exception e) {
                    logger.info("Error when creating WS Client. You can ignore this error as long as a client is eventually created", e);
                    continue;
                }
            }
        }
    }
    return null;
}
Also used : Bpmn2Import(org.jbpm.bpmn2.core.Bpmn2Import) QName(javax.xml.namespace.QName) WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) List(java.util.List) WorkflowProcessImpl(org.jbpm.workflow.core.impl.WorkflowProcessImpl) Client(org.apache.cxf.endpoint.Client) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

List (java.util.List)2 QName (javax.xml.namespace.QName)2 Client (org.apache.cxf.endpoint.Client)2 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)2 Bpmn2Import (org.jbpm.bpmn2.core.Bpmn2Import)2 WorkflowProcessImpl (org.jbpm.workflow.core.impl.WorkflowProcessImpl)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1