Search in sources :

Example 31 with URL

use of org.apache.axis2.util.URL in project carbon-business-process by wso2.

the class HumanTaskStore method createAxisService.

// Creates the AxisService object from the provided ServiceBuilder object.
private AxisService createAxisService(WSDL11ToAxisServiceBuilder serviceBuilder, HumanTaskBaseConfiguration config) throws AxisFault {
    AxisService axisService;
    axisService = serviceBuilder.populateService();
    axisService.setParent(getTenantAxisConfig());
    axisService.setWsdlFound(true);
    axisService.setCustomWsdl(true);
    // axisService.setFileName(new URL(taskConfig.getWsdlDefLocation()));
    axisService.setClassLoader(getTenantAxisConfig().getServiceClassLoader());
    Utils.setEndpointsToAllUsedBindings(axisService);
    axisService.addParameter(new Parameter("modifyUserWSDLPortAddress", "true"));
    /* Setting service type to use in service management*/
    axisService.addParameter(ServerConstants.SERVICE_TYPE, "humantask");
    /* Fix for losing of security configuration  when updating human-task package*/
    axisService.addParameter(new Parameter(CarbonConstants.PRESERVE_SERVICE_HISTORY_PARAM, "true"));
    Iterator operations = axisService.getOperations();
    AxisHumanTaskMessageReceiver msgReceiver = new AxisHumanTaskMessageReceiver();
    msgReceiver.setHumanTaskEngine(HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine());
    // Setting the task configuration to the message receiver. Hence no need to search for task configuration, when
    // the actual task invocation happens, we will already have the task configuration attached to the message receiver
    // itself
    msgReceiver.setTaskBaseConfiguration(config);
    while (operations.hasNext()) {
        AxisOperation operation = (AxisOperation) operations.next();
        // Setting Message Receiver even if operation has a message receiver specified.
        // This is to fix the issue when build service configuration using services.xml(Always RPCMessageReceiver
        // is set to operations).
        operation.setMessageReceiver(msgReceiver);
        getTenantAxisConfig().getPhasesInfo().setOperationPhases(operation);
    }
    Set<String> exposedTransports = getTenantAxisConfig().getTransportsIn().keySet();
    // Add the transports to axis2 service by reading from the tenant transport config
    for (String transport : exposedTransports) {
        axisService.addExposedTransport(transport);
    }
    if (HumanTaskServiceComponent.getHumanTaskServer().getServerConfig().isHtCoordinationEnabled() && HumanTaskServiceComponent.getHumanTaskServer().getServerConfig().isTaskRegistrationEnabled() && config.getConfigurationType() == HumanTaskBaseConfiguration.ConfigurationType.TASK) {
        // Only Engage coordination module in-case of Tasks. Coordination module is not required for notifications
        axisService.engageModule(getConfigContext().getAxisConfiguration().getModule("htcoordination"));
    }
    return axisService;
}
Also used : AxisOperation(org.apache.axis2.description.AxisOperation) AxisService(org.apache.axis2.description.AxisService) Iterator(java.util.Iterator) Parameter(org.apache.axis2.description.Parameter) AxisHumanTaskMessageReceiver(org.wso2.carbon.humantask.core.integration.AxisHumanTaskMessageReceiver)

Example 32 with URL

use of org.apache.axis2.util.URL in project carbon-business-process by wso2.

the class PeopleActivity method invoke.

public String invoke(ExtensionContext extensionContext) throws FaultException {
    BPELMessageContext taskMessageContext = new BPELMessageContext(hiWSDL);
    UUID messageID = null;
    int tenantId = B4PServiceComponent.getBPELServer().getMultiTenantProcessStore().getTenantId(processId);
    String tenantDomain = null;
    try {
        tenantDomain = B4PContentHolder.getInstance().getRealmService().getTenantManager().getDomain(tenantId);
    } catch (UserStoreException e) {
        log.error(" Cannot find the tenant domain " + e.toString());
    }
    if (tenantDomain == null) {
        tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
    }
    PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain);
    try {
        // Setting the attachment id attachmentIDList
        List<Long> attachmentIDList = extractAttachmentIDsToBeSentToHumanTask(extensionContext, taskMessageContext);
        taskMessageContext.setOperationName(getOperationName());
        SOAPHelper soapHelper = new SOAPHelper(getBinding(), getSoapFactory(), isRPC);
        MessageContext messageContext = new MessageContext();
        /*
            Adding attachment ID list as a method input to createSoapRequest makes no sense.
            Have to fix. Here we can't embed attachments in MessageContext, as we have only a
            list of attachment ids.
            */
        soapHelper.createSoapRequest(messageContext, (Element) extensionContext.readVariable(inputVarName), getOperation(extensionContext), attachmentIDList);
        // Coordination Context and skipable attribute is only valid for a Task.
        if (InteractionType.TASK.equals(activityType)) {
            // Note: If registration service is not enabled, we don't need to send coor-context.
            if (CoordinationConfiguration.getInstance().isHumantaskCoordinationEnabled() && CoordinationConfiguration.getInstance().isRegistrationServiceEnabled()) {
                messageID = UUID.randomUUID();
                soapHelper.addCoordinationContext(messageContext, messageID.toString(), getRegistrationServiceURL());
            }
            // Adding HumanTask Context overriding attributes.
            soapHelper.addOverridingHumanTaskAttributes(messageContext, isSkipable);
        }
        taskMessageContext.setInMessageContext(messageContext);
        taskMessageContext.setPort(getServicePort());
        taskMessageContext.setService(getServiceName());
        taskMessageContext.setRPCStyleOperation(isRPC);
        taskMessageContext.setTwoWay(isTwoWay);
        taskMessageContext.setSoapFactoryForCurrentMessageFlow(getSoapFactory());
        taskMessageContext.setWsdlBindingForCurrentMessageFlow(getBinding());
        taskMessageContext.setUep(getUnifiedEndpoint());
        taskMessageContext.setCaller(processId.getLocalPart());
        AxisServiceUtils.invokeService(taskMessageContext, getConfigurationContext());
    } catch (AxisFault axisFault) {
        log.error(axisFault, axisFault);
        throw new FaultException(BPEL4PeopleConstants.B4P_FAULT, "Error occurred while invoking service " + serviceName, axisFault);
    } catch (B4PCoordinationException coordinationFault) {
        throw new FaultException(BPEL4PeopleConstants.B4P_FAULT, "Error occurred while generating Registration Service URL" + serviceName, coordinationFault);
    }
    if (taskMessageContext.getFaultMessageContext() != null || taskMessageContext.getOutMessageContext().isFault()) {
        MessageContext faultContext = taskMessageContext.getFaultMessageContext() != null ? taskMessageContext.getFaultMessageContext() : taskMessageContext.getOutMessageContext();
        log.warn("SOAP Fault: " + faultContext.getEnvelope().toString());
        throw new FaultException(BPEL4PeopleConstants.B4P_FAULT, faultContext.getEnvelope().toString());
    }
    String taskID = SOAPHelper.parseResponseFeedback(taskMessageContext.getOutMessageContext().getEnvelope().getBody());
    // Ignore Notifications, since we are ignore coordination context for notification.
    if (CoordinationConfiguration.getInstance().isHumantaskCoordinationEnabled() && InteractionType.TASK.equals(activityType)) {
        Long instanceID = extensionContext.getProcessId();
        if (CoordinationConfiguration.getInstance().isRegistrationServiceEnabled()) {
            try {
                // Already coordinated with Registration service.
                updateCoordinationData(messageID.toString(), Long.toString(instanceID), taskID);
            } catch (Exception e) {
                log.error("Error occurred while updating humantask coordination data.", e);
            }
        } else {
            // Handler URL by manually.
            try {
                messageID = UUID.randomUUID();
                String protocolHandlerURL = generateTaskProtocolHandlerURL(taskMessageContext);
                if (log.isDebugEnabled()) {
                    log.debug("Generated Protocol Handler URL : " + protocolHandlerURL);
                }
                createCoordinationData(messageID.toString(), protocolHandlerURL, Long.toString(instanceID), taskID);
            } catch (Exception e) {
                log.error("Error occurred while creating humantask coordination data for coordinated task.", e);
            }
        }
    }
    return taskID;
}
Also used : AxisFault(org.apache.axis2.AxisFault) BPELMessageContext(org.wso2.carbon.bpel.core.ode.integration.BPELMessageContext) WSDL11Endpoint(org.apache.ode.bpel.epr.WSDL11Endpoint) UnifiedEndpoint(org.wso2.carbon.unifiedendpoint.core.UnifiedEndpoint) FaultException(org.apache.ode.bpel.common.FaultException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) B4PCoordinationException(org.wso2.carbon.bpel.b4p.coordination.B4PCoordinationException) SocketException(java.net.SocketException) SOAPHelper(org.wso2.carbon.bpel.b4p.utils.SOAPHelper) FaultException(org.apache.ode.bpel.common.FaultException) B4PCoordinationException(org.wso2.carbon.bpel.b4p.coordination.B4PCoordinationException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) BPELMessageContext(org.wso2.carbon.bpel.core.ode.integration.BPELMessageContext) MessageContext(org.apache.axis2.context.MessageContext) UUID(java.util.UUID)

Example 33 with URL

use of org.apache.axis2.util.URL in project carbon-business-process by wso2.

the class SOAPHelper method addCoordinationContext.

/**
 * Adding ws-Coordination context to soap request.
 *
 * @param msgCtx              MessageContext
 * @param messageID           UUID as a WS-Coordination identifier
 * @param registrationService URL of the ws-coordination registration service.
 */
public void addCoordinationContext(MessageContext msgCtx, String messageID, String registrationService) {
    SOAPHeader header = msgCtx.getEnvelope().getHeader();
    EndpointReference epr = new EndpointReference();
    epr.setAddress(registrationService);
    CoordinationContext context = new HumanTaskCoordinationContextImpl(messageID, epr);
    header.addChild(context.toOM());
}
Also used : HumanTaskCoordinationContextImpl(org.wso2.carbon.bpel.b4p.coordination.context.impl.HumanTaskCoordinationContextImpl) SOAPHeader(org.apache.axiom.soap.SOAPHeader) EndpointReference(org.apache.axis2.addressing.EndpointReference) CoordinationContext(org.wso2.carbon.bpel.b4p.coordination.context.CoordinationContext)

Example 34 with URL

use of org.apache.axis2.util.URL in project carbon-business-process by wso2.

the class BPELDeployer method createBPELRepository.

private File createBPELRepository(ConfigurationContext configCtx) throws DeploymentException {
    String axisRepoPath = configCtx.getAxisConfiguration().getRepository().getPath();
    if (CarbonUtils.isURL(axisRepoPath)) {
        throw new DeploymentException("URL Repositories are not supported: " + axisRepoPath);
    }
    File tenantsRepository = new File(axisRepoPath);
    File bpelRepo = new File(tenantsRepository, BPELConstants.BPEL_REPO_DIRECTORY);
    if (!bpelRepo.exists()) {
        boolean status = bpelRepo.mkdir();
        if (!status) {
            throw new DeploymentException("Failed to create BPEL repository directory " + bpelRepo.getAbsolutePath() + ".");
        }
    }
    return bpelRepo;
}
Also used : DeploymentException(org.apache.axis2.deployment.DeploymentException) File(java.io.File)

Example 35 with URL

use of org.apache.axis2.util.URL in project carbon-business-process by wso2.

the class BPELUploader method uploadService.

public void uploadService(UploadedFileItem[] fileItems) throws AxisFault {
    // First lets filter for jar resources
    ConfigurationContext configurationContext = getConfigContext();
    String repo = configurationContext.getAxisConfiguration().getRepository().getPath();
    if (CarbonUtils.isURL(repo)) {
        throw new AxisFault("URL Repositories are not supported: " + repo);
    }
    // Writting the artifacts to the proper location
    String bpelDirectory = repo + File.separator + BPELConstants.BPEL_REPO_DIRECTORY;
    String bpelTemp = CarbonUtils.getCarbonHome() + BPELConstants.BPEL_PACKAGE_TEMP_DIRECTORY;
    File bpelTempDir = new File(bpelTemp);
    if (!bpelTempDir.exists() && !bpelTempDir.mkdirs()) {
        throw new AxisFault("Fail to create the directory: " + bpelTempDir.getAbsolutePath());
    }
    File bpelDir = new File(bpelDirectory);
    if (!bpelDir.exists() && !bpelDir.mkdirs()) {
        throw new AxisFault("Fail to create the directory: " + bpelDir.getAbsolutePath());
    }
    for (UploadedFileItem uploadedFile : fileItems) {
        String fileName = uploadedFile.getFileName();
        if (fileName == null || fileName.equals("")) {
            throw new AxisFault("Invalid file name. File name is not available");
        }
        if (uploadedFile.getFileType().equals(BPELConstants.BPEL_PACKAGE_EXTENSION)) {
            try {
                writeResource(uploadedFile.getDataHandler(), bpelTemp, fileName, bpelDir);
            } catch (IOException e) {
                throw new AxisFault("IOError: Writing resource failed.", e);
            }
        } else {
            throw new AxisFault("Invalid file type : " + uploadedFile.getFileType() + " ." + BPELConstants.BPEL_PACKAGE_EXTENSION + " file type is expected");
        }
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) UploadedFileItem(org.wso2.carbon.bpel.deployer.services.types.UploadedFileItem) IOException(java.io.IOException) File(java.io.File)

Aggregations

IOException (java.io.IOException)31 EndpointReference (org.apache.axis2.addressing.EndpointReference)29 AxisFault (org.apache.axis2.AxisFault)27 URL (java.net.URL)21 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)19 URL (org.apache.axis2.util.URL)19 HttpClient (org.apache.http.client.HttpClient)19 Options (org.apache.axis2.client.Options)18 MalformedURLException (java.net.MalformedURLException)17 OMElement (org.apache.axiom.om.OMElement)17 MessageContext (org.apache.axis2.context.MessageContext)16 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)16 ServiceClient (org.apache.axis2.client.ServiceClient)13 SynapseException (org.apache.synapse.SynapseException)13 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)12 AxisService (org.apache.axis2.description.AxisService)10 StringEntity (org.apache.http.entity.StringEntity)9 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)9 Map (java.util.Map)7 JSONObject (org.json.JSONObject)7