Search in sources :

Example 1 with HumanTaskCoordinationException

use of org.wso2.carbon.humantask.coordination.module.HumanTaskCoordinationException in project carbon-business-process by wso2.

the class ServiceUtils method getTaskProtocolHandlerURL.

/**
 * Returns URL of the of the Task engine's Protocol Handler Admin service.
 * eg: https://localhost:9443/services/HumanTaskProtocolHandler/
 *
 * @return HumanTask protocol handler admin service's url
 */
public static String getTaskProtocolHandlerURL(ConfigurationContext serverConfigurationContext) throws HumanTaskCoordinationException {
    HumanTaskServerConfiguration serverConfig = HTCoordinationModuleContentHolder.getInstance().getHtServer().getServerConfig();
    String baseURL;
    if (serverConfig.isClusteredTaskEngines()) {
        baseURL = serverConfig.getLoadBalancerURL();
    } else {
        String scheme = CarbonConstants.HTTPS_TRANSPORT;
        String host;
        try {
            host = NetworkUtils.getLocalHostname();
        } catch (SocketException e) {
            log.error(e.getMessage(), e);
            throw new HumanTaskCoordinationException(e.getLocalizedMessage(), e);
        }
        int port = 9443;
        port = CarbonUtils.getTransportProxyPort(serverConfigurationContext, scheme);
        if (port == -1) {
            port = CarbonUtils.getTransportPort(serverConfigurationContext, scheme);
        }
        baseURL = scheme + "://" + host + ":" + port;
    }
    String webContext = ServerConfiguration.getInstance().getFirstProperty("WebContextRoot");
    if (webContext == null || webContext.equals("/")) {
        webContext = "";
    }
    String tenantDomain = "";
    try {
        tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true);
    } catch (Throwable e) {
        tenantDomain = null;
    }
    String protocolHandlerURL = baseURL + webContext + ((tenantDomain != null && !MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) ? "/" + MultitenantConstants.TENANT_AWARE_URL_PREFIX + "/" + tenantDomain : "") + Constants.CARBON_ADMIN_SERVICE_CONTEXT_ROOT + "/" + Constants.HUMANTASK_ENGINE_COORDINATION_PROTOCOL_HANDLER_SERVICE;
    return protocolHandlerURL;
}
Also used : SocketException(java.net.SocketException) HumanTaskServerConfiguration(org.wso2.carbon.humantask.core.configuration.HumanTaskServerConfiguration) HumanTaskCoordinationException(org.wso2.carbon.humantask.coordination.module.HumanTaskCoordinationException)

Example 2 with HumanTaskCoordinationException

use of org.wso2.carbon.humantask.coordination.module.HumanTaskCoordinationException in project carbon-business-process by wso2.

the class HTCoordinationContextHandler method invoke.

@Override
public InvocationResponse invoke(MessageContext messageContext) throws AxisFault {
    if (serverConfig == null || !serverConfig.isTaskRegistrationEnabled()) {
        return InvocationResponse.CONTINUE;
    }
    SOAPHeader soapHeader;
    try {
        soapHeader = messageContext.getEnvelope().getHeader();
    } catch (OMException ex) {
        throw new AxisFault("Error while extracting SOAP header", ex);
    }
    if (soapHeader == null) {
        if (log.isDebugEnabled()) {
            log.debug("No SOAP Header received. Continuing as an uncoordinated HumanTask.");
        }
        return InvocationResponse.CONTINUE;
    }
    Iterator headers = soapHeader.getChildElements();
    SOAPHeaderBlock coordinationHeaderBlock = null;
    // Searching for WS-Coor Coordination Context
    while (headers.hasNext()) {
        SOAPHeaderBlock hb = (SOAPHeaderBlock) headers.next();
        if (hb.getLocalName().equals(Constants.WS_COOR_COORDINATION_CONTEXT) && hb.getNamespace().getNamespaceURI().equals(Constants.WS_COOR_NAMESPACE)) {
            coordinationHeaderBlock = hb;
            break;
        }
    }
    if (coordinationHeaderBlock == null) {
        if (log.isDebugEnabled()) {
            log.debug("No coordination context received. Processing as an uncoordinated HumanTask.");
        }
        return InvocationResponse.CONTINUE;
    }
    // We have received a ws-coordination context. Now validate it for HT coordination type
    String coordinationType = SOAPUtils.getCoordinationType(coordinationHeaderBlock);
    if (!Constants.WS_HT_COORDINATION_TYPE.equals(coordinationType)) {
        // Found wrong coordination Type. We Only support http://docs.oasis-open.org/ns/bpel4people/ws-humantask/protocol/200803.
        // So we cannot allow message to go forward.
        String errorMsg = "Message aborted ! Invalid coordination type" + coordinationType + " . Support only " + Constants.WS_HT_COORDINATION_TYPE;
        log.error(errorMsg);
        return InvocationResponse.ABORT;
    }
    if (log.isDebugEnabled()) {
        log.debug("HT coordination context received.");
    }
    String identifier = SOAPUtils.getCoordinationIdentifier(coordinationHeaderBlock);
    String registrationService = SOAPUtils.getRegistrationService(coordinationHeaderBlock);
    // validating values. These values cannot be empty
    if (identifier == null || identifier.isEmpty() || registrationService == null || registrationService.isEmpty()) {
        String errorMsg = "Message aborted ! Invalid coordination context parameters.";
        log.error(errorMsg);
        return InvocationResponse.ABORT;
    }
    // Service URL of the HumanTask Coordination Protocol Handler AdminService
    String humanTaskProtocolHandlerServiceURL;
    try {
        humanTaskProtocolHandlerServiceURL = ServiceUtils.getTaskProtocolHandlerURL(messageContext.getConfigurationContext());
    } catch (HumanTaskCoordinationException e) {
        String errorMsg = "Error while generating HumanTask engine's protocol Handler Service URL.";
        log.error(errorMsg);
        throw new AxisFault(e.getLocalizedMessage(), e);
    }
    // We are OK to invokeRegistrationService Registration service
    try {
        OMElement response = invokeRegistrationServiceUsingServiceClient(identifier, humanTaskProtocolHandlerServiceURL, registrationService);
        // But we are validating it for successful completion.
        if (!SOAPUtils.validateResponse(response, identifier)) {
            String errorMsg = "Message aborted ! registration response validation failed.";
            log.error(errorMsg);
            return InvocationResponse.ABORT;
        }
        // successful coordination
        if (log.isDebugEnabled()) {
            log.debug("RegistrationResponse received. Task is successfully coordinated with Task parent.");
        }
    } catch (AxisFault e) {
        String errorMsg = "Error while invoking registration service";
        log.error(errorMsg);
        throw new AxisFault(e.getLocalizedMessage(), e);
    }
    return InvocationResponse.CONTINUE;
}
Also used : AxisFault(org.apache.axis2.AxisFault) Iterator(java.util.Iterator) HumanTaskCoordinationException(org.wso2.carbon.humantask.coordination.module.HumanTaskCoordinationException) SOAPHeaderBlock(org.apache.axiom.soap.SOAPHeaderBlock) OMElement(org.apache.axiom.om.OMElement) OMException(org.apache.axiom.om.OMException) SOAPHeader(org.apache.axiom.soap.SOAPHeader)

Aggregations

HumanTaskCoordinationException (org.wso2.carbon.humantask.coordination.module.HumanTaskCoordinationException)2 SocketException (java.net.SocketException)1 Iterator (java.util.Iterator)1 OMElement (org.apache.axiom.om.OMElement)1 OMException (org.apache.axiom.om.OMException)1 SOAPHeader (org.apache.axiom.soap.SOAPHeader)1 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)1 AxisFault (org.apache.axis2.AxisFault)1 HumanTaskServerConfiguration (org.wso2.carbon.humantask.core.configuration.HumanTaskServerConfiguration)1