Search in sources :

Example 6 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-apimgt by wso2.

the class PolicyDAOImpl method addApplicationPolicy.

/**
 * Adds an Application Policy
 *
 * @param policy {@link ApplicationPolicy} instance
 * @param connection DB Connection instance
 * @throws SQLException if an error occurs while adding an Application Policy
 */
private static void addApplicationPolicy(ApplicationPolicy policy, Connection connection) throws SQLException {
    final String query = "INSERT INTO AM_APPLICATION_POLICY (UUID, NAME, DISPLAY_NAME, " + "DESCRIPTION, QUOTA_TYPE, QUOTA, QUOTA_UNIT, UNIT_TIME, TIME_UNIT, IS_DEPLOYED, CUSTOM_ATTRIBUTES) " + "VALUES (?,?,?,?,?,?,?,?,?,?,?)";
    Limit limit = policy.getDefaultQuotaPolicy().getLimit();
    try (PreparedStatement statement = connection.prepareStatement(query)) {
        statement.setString(1, policy.getUuid());
        statement.setString(2, policy.getPolicyName());
        statement.setString(3, policy.getDisplayName());
        statement.setString(4, policy.getDescription());
        statement.setString(5, policy.getDefaultQuotaPolicy().getType());
        setDefaultThrottlePolicyDetailsPreparedStmt(limit, statement);
        statement.setInt(8, policy.getDefaultQuotaPolicy().getLimit().getUnitTime());
        statement.setString(9, policy.getDefaultQuotaPolicy().getLimit().getTimeUnit());
        statement.setBoolean(10, policy.isDeployed());
        statement.setBytes(11, policy.getCustomAttributes());
        statement.execute();
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) Limit(org.wso2.carbon.apimgt.core.models.policy.Limit) RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) BandwidthLimit(org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)

Example 7 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-apimgt by wso2.

the class WSDL11ProcessorImpl method init.

/**
 * {@inheritDoc}
 * Will return true if the provided WSDL is of 1.1 and can be successfully parsed by WSDL4J.
 */
@Override
public boolean init(byte[] wsdlContent) throws APIMgtWSDLException {
    WSDLReader wsdlReader = getWsdlFactoryInstance().newWSDLReader();
    // switch off the verbose mode
    wsdlReader.setFeature(JAVAX_WSDL_VERBOSE_MODE, false);
    wsdlReader.setFeature(JAVAX_WSDL_IMPORT_DOCUMENTS, false);
    try {
        wsdlDefinition = wsdlReader.readWSDL(null, new InputSource(new ByteArrayInputStream(wsdlContent)));
        canProcess = true;
        if (log.isDebugEnabled()) {
            log.debug("Successfully initialized an instance of " + this.getClass().getSimpleName() + " with a single WSDL.");
        }
    } catch (WSDLException e) {
        // This implementation class cannot process the WSDL.
        log.debug("Cannot process the WSDL by " + this.getClass().getName(), e);
        canProcess = false;
    }
    return canProcess;
}
Also used : InputSource(org.xml.sax.InputSource) ByteArrayInputStream(java.io.ByteArrayInputStream) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) WSDLException(javax.wsdl.WSDLException) WSDLReader(javax.wsdl.xml.WSDLReader)

Example 8 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-apimgt by wso2.

the class WSDL20ProcessorImpl method init.

/**
 * {@inheritDoc}
 * Will return true if the provided WSDL is of 2.0 and can be successfully parsed by woden library.
 */
@Override
public boolean init(byte[] wsdlContent) throws APIMgtWSDLException {
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
        factory.setNamespaceAware(true);
        DocumentBuilder builder = factory.newDocumentBuilder();
        WSDLReader reader = getWsdlFactoryInstance().newWSDLReader();
        reader.setFeature(WSDLReader.FEATURE_VALIDATION, false);
        Document dom = builder.parse(new ByteArrayInputStream(wsdlContent));
        Element domElement = dom.getDocumentElement();
        WSDLSource wsdlSource = reader.createWSDLSource();
        wsdlSource.setSource(domElement);
        wsdlDescription = reader.readWSDL(wsdlSource);
        canProcess = true;
        if (log.isDebugEnabled()) {
            log.debug("Successfully initialized an instance of " + this.getClass().getSimpleName() + " with a single WSDL.");
        }
    } catch (WSDLException | ParserConfigurationException | SAXException | IOException e) {
        // This implementation class cannot process the WSDL.
        log.debug("Cannot process the WSDL by " + this.getClass().getName(), e);
        canProcess = false;
    }
    return canProcess;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) APIMgtWSDLException(org.wso2.carbon.apimgt.core.exception.APIMgtWSDLException) WSDLException(org.apache.woden.WSDLException) EndpointElement(org.apache.woden.wsdl20.xml.EndpointElement) Element(org.w3c.dom.Element) WSDLSource(org.apache.woden.WSDLSource) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) WSDLReader(org.apache.woden.WSDLReader) SAXException(org.xml.sax.SAXException)

Example 9 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-apimgt by wso2.

the class MappingUtil method toEndpoint.

/**
 * Convert EndPointDTO to Endpoint
 *
 * @param endPointDTO Contains data of a endpoint
 * @return Endpoint model instance containing endpoint data
 */
public static Endpoint toEndpoint(EndPointDTO endPointDTO) throws JsonProcessingException {
    ObjectMapper mapper = new ObjectMapper();
    Endpoint.Builder endPointBuilder = new Endpoint.Builder();
    endPointBuilder.endpointConfig(endPointDTO.getEndpointConfig());
    endPointBuilder.name(endPointDTO.getName());
    if (!StringUtils.isEmpty(endPointDTO.getId())) {
        endPointBuilder.id(endPointDTO.getId());
    } else {
        endPointBuilder.id(UUID.randomUUID().toString());
    }
    if (endPointDTO.getMaxTps() != null) {
        endPointBuilder.maxTps(endPointDTO.getMaxTps());
    }
    endPointBuilder.security(mapper.writeValueAsString(endPointDTO.getEndpointSecurity()));
    endPointBuilder.type(endPointDTO.getType());
    endPointBuilder.applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT);
    return endPointBuilder.build();
}
Also used : Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 10 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-apimgt by wso2.

the class FileBasedApiImportExportManager method getDocumentInfoFromExtractedArchive.

/**
 * Retrieves {@link DocumentInfo} instance from the directory containing docs
 *
 * @param documentImportLocation path to the directory containing docs
 * @param apiName                API name
 * @param version                API version
 * @return Set of {@link DocumentInfo} insjtaces
 */
private Set<DocumentInfo> getDocumentInfoFromExtractedArchive(String documentImportLocation, String apiName, String version) {
    Set<DocumentInfo> documents = new HashSet<>();
    File rootDocumentationDirectoryForAPI = new File(documentImportLocation);
    if (!rootDocumentationDirectoryForAPI.isDirectory()) {
        // no Docs!
        log.debug("No documentation found for API name: " + apiName + ", version: " + version);
        return documents;
    }
    File[] documentationDirectories = rootDocumentationDirectoryForAPI.listFiles(File::isDirectory);
    if (documentationDirectories == null) {
        // do docs!
        log.debug("No documents found at " + documentImportLocation);
        return documents;
    }
    for (File docDir : documentationDirectories) {
        // read the 'doc.json'
        String content;
        try {
            content = APIFileUtils.readFileContentAsText(docDir.getPath() + File.separator + DOCUMENTATION_DEFINITION_FILE);
            Gson gson = new GsonBuilder().create();
            documents.add(gson.fromJson(content, DocumentInfo.class));
        // add the doc
        } catch (APIManagementException e) {
            // no need to throw, log and continue
            log.error("Error in importing documentation from file: " + docDir.getPath() + " for API: " + apiName + ", version: " + version);
        }
    }
    return documents;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) File(java.io.File) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)28 Test (org.junit.Test)23 Response (javax.ws.rs.core.Response)22 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)21 APIManagerFactory (org.wso2.carbon.apimgt.core.impl.APIManagerFactory)20 HashMap (java.util.HashMap)15 Path (javax.ws.rs.Path)15 RuntimeService (org.activiti.engine.RuntimeService)15 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)15 InstanceManagementException (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.InstanceManagementException)14 Produces (javax.ws.rs.Produces)13 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)13 IOException (java.io.IOException)12 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)12 GET (javax.ws.rs.GET)11 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)11 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)10 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)9 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8