Search in sources :

Example 1 with CallBackService

use of org.wso2.carbon.humantask.core.CallBackService in project carbon-business-process by wso2.

the class HumanTaskStore method createCallBackService.

private void createCallBackService(TaskConfiguration taskConf) throws HumanTaskDeploymentException {
    EndpointConfiguration endpointConfig = taskConf.getEndpointConfiguration(taskConf.getCallbackServiceName().getLocalPart(), taskConf.getCallbackPortName());
    CallBackServiceImpl callbackService = new CallBackServiceImpl(tenantId, taskConf.getCallbackServiceName(), taskConf.getCallbackPortName(), taskConf.getName(), taskConf.getResponseWSDL(), taskConf.getResponseOperation(), endpointConfig);
    taskConf.setCallBackService(callbackService);
}
Also used : EndpointConfiguration(org.wso2.carbon.bpel.common.config.EndpointConfiguration) CallBackServiceImpl(org.wso2.carbon.humantask.core.integration.CallBackServiceImpl)

Example 2 with CallBackService

use of org.wso2.carbon.humantask.core.CallBackService in project carbon-business-process by wso2.

the class HTRenderingApiImpl method setTaskOutput.

public SetTaskOutputResponse setTaskOutput(URI taskIdentifier, SetOutputValuesType values) throws SetTaskOutputFaultException {
    // Retrieve task information
    TaskDAO htTaskDAO;
    try {
        htTaskDAO = getTaskDAO(taskIdentifier);
    } catch (Exception e) {
        log.error("Error occurred while retrieving task data", e);
        throw new SetTaskOutputFaultException(e);
    }
    QName taskName = QName.valueOf(htTaskDAO.getName());
    // Check hash map for output message template
    Element outputMsgTemplate = outputTemplates.get(taskName);
    if (outputMsgTemplate == null) {
        try {
            // generate output message template
            int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId();
            HumanTaskBaseConfiguration htConf = HumanTaskServiceComponent.getHumanTaskServer().getTaskStoreManager().getHumanTaskStore(tenantID).getTaskConfiguration(taskName);
            TaskConfiguration taskConf = (TaskConfiguration) htConf;
            // retrieve response binding
            Service callbackService = (Service) taskConf.getResponseWSDL().getServices().get(taskConf.getCallbackServiceName());
            Port callbackPort = (Port) callbackService.getPorts().get(taskConf.getCallbackPortName());
            String callbackBinding = callbackPort.getBinding().getQName().getLocalPart();
            outputMsgTemplate = createSoapTemplate(taskConf.getResponseWSDL().getDocumentBaseURI(), taskConf.getResponsePortType().getLocalPart(), taskConf.getResponseOperation(), callbackBinding);
        } catch (Exception e) {
            log.error("Error occurred while output message template generation", e);
            throw new SetTaskOutputFaultException("Unable to generate output message", e);
        }
        // add to the template HashMap
        if (outputMsgTemplate != null) {
            outputTemplates.put(taskName, outputMsgTemplate);
        } else {
            log.error("Unable to create output message template");
            throw new SetTaskOutputFaultException("Unable to generate output message");
        }
    }
    // update template with new values
    try {
        // TODO improve this section with caching
        QName renderingType = new QName(htRenderingNS, "output", "wso2");
        String outputRenderings = (String) taskOps.getRendering(taskIdentifier, renderingType);
        SetOutputvalueType[] valueSet = values.getValue();
        if (outputRenderings != null && valueSet.length > 0) {
            Element outputRenderingsElement = DOMUtils.stringToDOM(outputRenderings);
            // update elements in the template to create output xml
            for (int i = 0; i < valueSet.length; i++) {
                Element outElement = getOutputElementById(valueSet[i].getId(), outputRenderingsElement);
                if (outElement != null) {
                    outputMsgTemplate = updateXmlByXpath(outputMsgTemplate, outElement.getElementsByTagNameNS(htRenderingNS, "xpath").item(0).getTextContent(), valueSet[i].getString(), outputRenderingsElement.getOwnerDocument());
                }
            }
        } else {
            log.error("Retrieving output renderings failed");
            throw new SetTaskOutputFaultException("Retrieving output renderings failed");
        }
        // TODO what is this NCName?
        taskOps.setOutput(taskIdentifier, new NCName("message"), DOMUtils.domToString(outputMsgTemplate));
    } catch (IllegalArgumentFault illegalArgumentFault) {
        // Error occurred while retrieving HT renderings and set output message
        throw new SetTaskOutputFaultException(illegalArgumentFault);
    } catch (SAXException e) {
        log.error("Error occured while parsing output renderings", e);
        throw new SetTaskOutputFaultException("Response message generation failed");
    } catch (XPathExpressionException e) {
        // Error occured while updating elements in the template to create output xml
        log.error("XPath evaluation failed", e);
        throw new SetTaskOutputFaultException("Internal Error Occurred");
    } catch (Exception e) {
        // Error occurred while updating template with new values
        log.error("Error occurred while updating template with new values", e);
        throw new SetTaskOutputFaultException("Internal Error Occurred");
    }
    SetTaskOutputResponse response = new SetTaskOutputResponse();
    response.setSuccess(true);
    return response;
}
Also used : QName(javax.xml.namespace.QName) XPathExpressionException(javax.xml.xpath.XPathExpressionException) Element(org.w3c.dom.Element) Port(javax.wsdl.Port) SetTaskOutputResponse(org.wso2.carbon.humantask.rendering.api.SetTaskOutputResponse) TaskConfiguration(org.wso2.carbon.humantask.core.store.TaskConfiguration) Service(javax.wsdl.Service) HumanTaskBaseConfiguration(org.wso2.carbon.humantask.core.store.HumanTaskBaseConfiguration) XPathExpressionException(javax.xml.xpath.XPathExpressionException) SetTaskOutputFaultException(org.wso2.carbon.humantask.rendering.api.SetTaskOutputFaultException) GetRenderingsFaultException(org.wso2.carbon.humantask.rendering.api.GetRenderingsFaultException) SAXException(org.xml.sax.SAXException) CompleteTaskFaultException(org.wso2.carbon.humantask.rendering.api.CompleteTaskFaultException) IOException(java.io.IOException) HumanTaskIllegalAccessException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException) NCName(org.apache.axis2.databinding.types.NCName) SAXException(org.xml.sax.SAXException) SetOutputvalueType(org.wso2.carbon.humantask.rendering.api.SetOutputvalueType) TaskDAO(org.wso2.carbon.humantask.core.dao.TaskDAO) IllegalArgumentFault(org.wso2.carbon.humantask.client.api.IllegalArgumentFault) SetTaskOutputFaultException(org.wso2.carbon.humantask.rendering.api.SetTaskOutputFaultException)

Example 3 with CallBackService

use of org.wso2.carbon.humantask.core.CallBackService in project carbon-business-process by wso2.

the class ArchiveBasedHumanTaskDeploymentUnitBuilder method buildWSDLs.

@Override
public void buildWSDLs() throws HumanTaskDeploymentException {
    HashSet<Definition> tmpWsdlDefinitions = new HashSet<>();
    URI baseUri = humantaskDir.toURI();
    for (File file : FileUtils.directoryEntriesInPath(humantaskDir, wsdlFilter)) {
        try {
            URI uri = baseUri.relativize(file.toURI());
            if (!uri.isAbsolute()) {
                File f = new File(baseUri.getPath() + File.separator + uri.getPath());
                URI abUri = f.toURI();
                if (abUri.isAbsolute()) {
                    uri = abUri;
                }
            }
            WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
            reader.setFeature(HumanTaskConstants.JAVAX_WSDL_VERBOSE_MODE_KEY, false);
            reader.setFeature("javax.wsdl.importDocuments", true);
            Definition definition = reader.readWSDL(new HumanTaskWSDLLocator(uri));
            if (definition != null) {
                tmpWsdlDefinitions.add(definition);
            }
        } catch (WSDLException e) {
            log.error("Error processing wsdl " + file.getName());
            throw new HumanTaskDeploymentException(" Error processing wsdl ", e);
        } catch (URISyntaxException e) {
            log.error("Invalid uri in reading wsdl ", e);
            throw new HumanTaskDeploymentException(" Invalid uri in reading wsdl ", e);
        }
    }
    // Optimizing WSDLs imports. Using HashSet to avoid duplicate entices.
    HashSet<Definition> optimizedDefinitions = new HashSet<>();
    HTDeploymentConfigDocument htDeploymentConfigDocument = getHTDeploymentConfigDocument();
    // Iterating Tasks.
    THTDeploymentConfig.Task[] taskArray = htDeploymentConfigDocument.getHTDeploymentConfig().getTaskArray();
    if (taskArray != null) {
        for (THTDeploymentConfig.Task task : taskArray) {
            QName taskService = task.getPublish().getService().getName();
            Definition taskServiceDefinition = getDefinition(taskService, tmpWsdlDefinitions);
            if (log.isDebugEnabled()) {
                log.debug("Optimizing WSDL import for Task : " + task.getName());
            }
            if (taskServiceDefinition != null) {
                optimizedDefinitions.add(taskServiceDefinition);
                if (log.isDebugEnabled()) {
                    log.debug("Added WSDL for Task : " + task.getName() + ", Service : " + taskService + ", Imported/Total definition : " + optimizedDefinitions.size() + "/" + tmpWsdlDefinitions.size());
                }
            } else {
                log.warn("Can't find valid WSDL definition for Task" + task.getName() + ", Service: " + taskService);
            }
            QName callbackService = task.getCallback().getService().getName();
            Definition callbackServiceDefinition = getDefinition(callbackService, tmpWsdlDefinitions);
            if (callbackServiceDefinition != null) {
                optimizedDefinitions.add(callbackServiceDefinition);
                if (log.isDebugEnabled()) {
                    log.debug("Added WSDL for Task : " + task.getName() + ", Callback Service : " + callbackService + ", Imported/Total definition : " + optimizedDefinitions.size() + "/" + tmpWsdlDefinitions.size());
                }
            } else {
                log.warn("Can't find valid WSDL definition for Task : " + task.getName() + ", Callback Service" + callbackService);
            }
        }
    }
    // Iterating Notifications.
    THTDeploymentConfig.Notification[] notificationsArray = htDeploymentConfigDocument.getHTDeploymentConfig().getNotificationArray();
    if (notificationsArray != null) {
        for (THTDeploymentConfig.Notification notification : notificationsArray) {
            QName notificationService = notification.getPublish().getService().getName();
            Definition notificationServiceDefinition = getDefinition(notificationService, tmpWsdlDefinitions);
            if (notificationServiceDefinition != null) {
                optimizedDefinitions.add(notificationServiceDefinition);
                if (log.isDebugEnabled()) {
                    log.debug("Added WSDL for Task : " + notification.getName() + ", Callback Service : " + notificationService + ", Imported/Total definition : " + optimizedDefinitions.size() + "/" + tmpWsdlDefinitions.size());
                }
            } else {
                log.warn("Can't find valid WSDL definition for Notification " + notification.getName() + ", Service: " + notificationService);
            }
        }
    }
    // Converting HashSet to ArrayList.
    wsdlDefinitions = new ArrayList<>(optimizedDefinitions);
    if (log.isDebugEnabled()) {
        log.debug("Optimized Imported/Total definition : " + wsdlDefinitions.size() + "/" + tmpWsdlDefinitions.size());
    }
}
Also used : WSDLException(javax.wsdl.WSDLException) QName(javax.xml.namespace.QName) Definition(javax.wsdl.Definition) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) THTDeploymentConfig(org.wso2.carbon.humantask.core.deployment.config.THTDeploymentConfig) HTDeploymentConfigDocument(org.wso2.carbon.humantask.core.deployment.config.HTDeploymentConfigDocument) WSDLReader(javax.wsdl.xml.WSDLReader)

Aggregations

QName (javax.xml.namespace.QName)2 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Definition (javax.wsdl.Definition)1 Port (javax.wsdl.Port)1 Service (javax.wsdl.Service)1 WSDLException (javax.wsdl.WSDLException)1 WSDLReader (javax.wsdl.xml.WSDLReader)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 NCName (org.apache.axis2.databinding.types.NCName)1 Element (org.w3c.dom.Element)1 EndpointConfiguration (org.wso2.carbon.bpel.common.config.EndpointConfiguration)1 IllegalArgumentFault (org.wso2.carbon.humantask.client.api.IllegalArgumentFault)1 TaskDAO (org.wso2.carbon.humantask.core.dao.TaskDAO)1 HTDeploymentConfigDocument (org.wso2.carbon.humantask.core.deployment.config.HTDeploymentConfigDocument)1 THTDeploymentConfig (org.wso2.carbon.humantask.core.deployment.config.THTDeploymentConfig)1 HumanTaskIllegalAccessException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException)1 CallBackServiceImpl (org.wso2.carbon.humantask.core.integration.CallBackServiceImpl)1 HumanTaskBaseConfiguration (org.wso2.carbon.humantask.core.store.HumanTaskBaseConfiguration)1