Search in sources :

Example 11 with ServiceName

use of org.apache.axis2.addressing.metadata.ServiceName in project carbon-data by wso2.

the class DBDeployer method undeploy.

/**
 * Undeploys a service.
 */
public void undeploy(String servicePath) throws DeploymentException {
    try {
        DataService dataService = this.getDataServiceByServicePath(servicePath);
        if (dataService == null) {
            /* must be a faulty service */
            /* the faulty service should be removed at this point from the axis configuration.
                   otherwise the service would still be shown as a faulty service in the management
                   console UI since it queries and lists out the faulty services from the
                   axisConfiguration itself.
                   */
            this.axisConfig.removeFaultyService(servicePath);
            return;
        }
        String serviceHierarchy = Utils.getServiceHierarchy(servicePath, this.repoDir);
        if (serviceHierarchy == null) {
            serviceHierarchy = "";
        }
        String serviceName = serviceHierarchy + dataService.getName();
        /* In the context of dataservices one service group will only contain one dataservice.
            *  Hence assigning the service group as the service group name */
        AxisServiceGroup serviceGroup = this.axisConfig.getServiceGroup(serviceName);
        CarbonContext cCtx = CarbonContext.getThreadLocalCarbonContext();
        if (serviceGroup == null) {
            /* must be a faulty service */
            this.axisConfig.removeFaultyService(servicePath);
            for (String configID : dataService.getConfigs().keySet()) {
                if (dataService.getConfig(configID).isODataEnabled()) {
                    removeODataHandler(cCtx.getTenantDomain(), dataService.getName() + configID);
                }
            }
        } else {
            /* cleanup data service */
            for (String configID : dataService.getConfigs().keySet()) {
                if (dataService.getConfig(configID).isODataEnabled()) {
                    removeODataHandler(cCtx.getTenantDomain(), dataService.getName() + configID);
                }
            }
            dataService.cleanup();
            this.axisConfig.removeService(serviceName);
            /* if the service group is now empty, remove it as well */
            if (!serviceGroup.getServices().hasNext()) {
                /* when the service group is removed re-deployment causes problems */
                this.axisConfig.removeServiceGroup(serviceGroup.getServiceGroupName());
            }
        }
        if (log.isDebugEnabled()) {
            log.debug(Messages.getMessage(DeploymentErrorMsgs.SERVICE_REMOVED, serviceName));
        }
        super.undeploy(servicePath);
    } catch (Exception e) {
        String msg = "Error in undeploying service";
        log.error(msg, e);
        throw new DeploymentException(msg, e);
    }
}
Also used : DeploymentException(org.apache.axis2.deployment.DeploymentException) AxisServiceGroup(org.apache.axis2.description.AxisServiceGroup) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) CarbonContext(org.wso2.carbon.context.CarbonContext) XMLStreamException(javax.xml.stream.XMLStreamException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) DeploymentException(org.apache.axis2.deployment.DeploymentException) FileNotFoundException(java.io.FileNotFoundException) DataSourceException(org.wso2.carbon.ndatasource.common.DataSourceException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) DataService(org.wso2.carbon.dataservices.core.engine.DataService)

Example 12 with ServiceName

use of org.apache.axis2.addressing.metadata.ServiceName in project carbon-data by wso2.

the class DataServiceAdmin method saveDataService.

/**
 * Saves the data service in service repository.
 * @param serviceName The name of the data service to be saved
 * @param serviceHierarchy The hierarchical path of the service
 * @param serviceContents The content of the service
 * @throws AxisFault
 */
public void saveDataService(String serviceName, String serviceHierarchy, String serviceContents) throws AxisFault {
    String dataServiceFilePath;
    ConfigurationContext configCtx = this.getConfigContext();
    AxisConfiguration axisConfig = configCtx.getAxisConfiguration();
    AxisService axisService = DBUtils.getActiveAxisServiceAccordingToDataServiceGroup(axisConfig, serviceName);
    // existing functionality
    if (serviceName.contains("/")) {
        String[] splitArray = serviceName.split("\\/");
        if (splitArray.length >= 1) {
            String fullServiceName = serviceName;
            serviceName = splitArray[splitArray.length - 1];
            serviceHierarchy = splitArray[splitArray.length - 2];
            serviceContents = serviceContents.replace(fullServiceName, serviceName);
        }
    }
    if (serviceHierarchy == null) {
        serviceHierarchy = "";
    }
    if (axisService == null) {
        /* new service */
        String axis2RepoDirectory = axisConfig.getRepository().getPath();
        String repoDirectory = (String) configCtx.getProperty(DBConstants.DB_SERVICE_REPO);
        String fileExtension = this.getDataServiceFileExtension();
        String dataServiceDirectory = axis2RepoDirectory + File.separator + repoDirectory + File.separator + serviceHierarchy;
        dataServiceFilePath = dataServiceDirectory + File.separator + serviceName + "." + fileExtension;
        /* create the directory, if it does not exist */
        /*
			    Security Comment :
			    This dataServiceDirectory path is trustworthy, constructed dataServiceDirectory path cannot be access by the user.
			*/
        File directory = new File(dataServiceDirectory);
        if (!directory.exists() && !directory.mkdirs()) {
            throw new AxisFault("Cannot create directory: " + directory.getAbsolutePath());
        }
    } else {
        dataServiceFilePath = ((DataService) axisService.getParameter(DBConstants.DATA_SERVICE_OBJECT).getValue()).getDsLocation();
        AxisServiceGroup axisServiceGroup = axisService.getAxisServiceGroup();
        axisServiceGroup.addParameter(CarbonConstants.KEEP_SERVICE_HISTORY_PARAM, Boolean.TRUE.toString());
        axisServiceGroup.addParameter(CarbonConstants.PRESERVE_SERVICE_HISTORY_PARAM, Boolean.TRUE.toString());
        axisService.addParameter(CarbonConstants.KEEP_SERVICE_HISTORY_PARAM, Boolean.TRUE.toString());
        axisService.addParameter(CarbonConstants.PRESERVE_SERVICE_HISTORY_PARAM, Boolean.TRUE.toString());
    }
    serviceContents = DBUtils.prettifyXML(serviceContents);
    /* save contents to .dbs file */
    try {
        /*
			    Security Comment :
			    This path is trustworthy, constructed file path cannot be access by the user.
			*/
        BufferedWriter out = new BufferedWriter(new FileWriter(dataServiceFilePath));
        out.write(serviceContents);
        out.close();
    } catch (IOException e) {
        log.error("Error while saving " + serviceName, e);
        throw new AxisFault("Error occurred while writing the contents for the service config file for the new service " + serviceName, e);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) AxisService(org.apache.axis2.description.AxisService) FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File) AxisServiceGroup(org.apache.axis2.description.AxisServiceGroup) BufferedWriter(java.io.BufferedWriter)

Example 13 with ServiceName

use of org.apache.axis2.addressing.metadata.ServiceName in project carbon-data by wso2.

the class DSTask method checkServiceInit.

private boolean checkServiceInit() {
    if (this.isServiceInit()) {
        return true;
    }
    String serviceName = this.getProperties().get(DSTaskConstants.DATA_SERVICE_NAME);
    String opName = this.getProperties().get(DSTaskConstants.DATA_SERVICE_OPERATION_NAME);
    String tidProp = this.getProperties().get(TaskInfo.TENANT_ID_PROP);
    if (tidProp == null) {
        throw new RuntimeException("Cannot determine the tenant domain for the scheduled service: " + serviceName);
    }
    int tid = Integer.parseInt(tidProp);
    AxisService axisService = DSTaskUtils.lookupAxisService(tid, serviceName);
    if (axisService == null) {
        return false;
    }
    if (axisService == null || !axisService.isActive()) {
        return false;
    }
    String httpEPR = DSTaskUtils.extractHTTPEPR(axisService);
    if (httpEPR == null) {
        throw new RuntimeException("No HTTP endpoint found for service: " + serviceName + " for scheduling service calls");
    }
    this.getProperties().put(WebServiceCallTask.SERVICE_TARGET_EPR, httpEPR);
    String mep;
    if (DSTaskUtils.isInOutMEPInOperation(axisService, opName)) {
        mep = WebServiceCallTask.SERVICE_MEP_IN_OUT;
    } else {
        mep = WebServiceCallTask.SERVICE_MEP_IN_ONLY;
    }
    this.getProperties().put(WebServiceCallTask.SERVICE_MEP, mep);
    this.serviceInit = true;
    super.init();
    return this.isServiceInit();
}
Also used : AxisService(org.apache.axis2.description.AxisService)

Example 14 with ServiceName

use of org.apache.axis2.addressing.metadata.ServiceName in project carbon-data by wso2.

the class DataTaskContext method getDataService.

private DataService getDataService(String serviceName) {
    AxisService axisService = DSTaskUtils.lookupAxisService(this.axisConfig, serviceName);
    if (axisService == null) {
        return null;
    }
    DataService dataService = (DataService) axisService.getParameterValue(DBConstants.DATA_SERVICE_OBJECT);
    return dataService;
}
Also used : AxisService(org.apache.axis2.description.AxisService) DataService(org.wso2.carbon.dataservices.core.engine.DataService)

Example 15 with ServiceName

use of org.apache.axis2.addressing.metadata.ServiceName in project axis-axis2-java-core by apache.

the class AxisServiceBasedMultiLanguageEmitter method loadOperations.

/**
 * Loads the operations
 *
 * @param doc
 * @param rootElement
 * @param mep
 * @return boolean
 */
protected boolean loadOperations(Document doc, Element rootElement, String mep) {
    Element methodElement;
    String serviceName = makeJavaClassName(axisService.getName());
    Iterator bindingOperations = this.axisBinding.getChildren();
    boolean opsFound = false;
    AxisBindingOperation axisBindingOperation = null;
    AxisOperation axisOperation = null;
    while (bindingOperations.hasNext()) {
        axisBindingOperation = (AxisBindingOperation) bindingOperations.next();
        axisOperation = axisBindingOperation.getAxisOperation();
        // populate info holder with mep information. This will used in determining which
        // message receiver to use, etc.,
        String messageExchangePattern = axisOperation.getMessageExchangePattern();
        if (infoHolder.get(messageExchangePattern) == null) {
            infoHolder.put(messageExchangePattern, Boolean.TRUE);
        }
        if (mep == null) {
            opsFound = true;
            methodElement = generateMethodElement(doc, serviceName, axisBindingOperation);
            rootElement.appendChild(methodElement);
        } else {
            if (mep.equals(axisOperation.getMessageExchangePattern())) {
                // at this point we know it's true
                opsFound = true;
                methodElement = generateMethodElement(doc, serviceName, axisBindingOperation);
                rootElement.appendChild(methodElement);
            // ////////////////////
            }
        }
    }
    return opsFound;
}
Also used : AxisOperation(org.apache.axis2.description.AxisOperation) Element(org.w3c.dom.Element) Iterator(java.util.Iterator) AxisBindingOperation(org.apache.axis2.description.AxisBindingOperation)

Aggregations

AxisService (org.apache.axis2.description.AxisService)116 AxisFault (org.apache.axis2.AxisFault)54 AxisOperation (org.apache.axis2.description.AxisOperation)36 QName (javax.xml.namespace.QName)27 ArrayList (java.util.ArrayList)26 OMElement (org.apache.axiom.om.OMElement)26 IOException (java.io.IOException)21 URL (java.net.URL)19 ServiceClient (org.apache.axis2.client.ServiceClient)19 Options (org.apache.axis2.client.Options)18 HashMap (java.util.HashMap)17 Service (javax.xml.ws.Service)17 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)17 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)17 File (java.io.File)16 Iterator (java.util.Iterator)16 EndpointReference (org.apache.axis2.addressing.EndpointReference)16 List (java.util.List)15 Map (java.util.Map)15 MessageContext (org.apache.axis2.context.MessageContext)15