Search in sources :

Example 26 with Analyzer

use of org.wso2.carbon.apimgt.core.api.Analyzer in project carbon-apimgt by wso2.

the class SubscriptionApiServiceImpl method subscriptionListGet.

/**
 * Get list of subscriptions info over time
 *
 * @param startTime Filter for start time stamp
 * @param endTime   Filter for end time stamp
 * @param createdBy Filter for createdBy
 * @param request   MSF4J request
 * @return Subscriptions information over time
 * @throws NotFoundException When the particular resource does not exist in the system
 */
@Override
public Response subscriptionListGet(String startTime, String endTime, String createdBy, Request request) throws NotFoundException {
    String username = RestApiUtil.getLoggedInUsername(request);
    try {
        log.debug("Retrieving subscriptions info. [From: {}  To: {} Created By: {}]", startTime, endTime, createdBy);
        Analyzer analyzer = RestApiUtil.getAnalyzer(username);
        ZoneId requestTimezone = RestApiUtil.getRequestTimeZone(startTime);
        List<SubscriptionInfo> subscriptionInfoList = analyzer.getSubscriptionInfo(fromISO8601ToInstant(startTime), fromISO8601ToInstant(endTime), createdBy);
        SubscriptionInfoListDTO subscriptionInfoListDTO = AnalyticsMappingUtil.fromSubscriptionInfoListToDTO(subscriptionInfoList, requestTimezone);
        return Response.ok().entity(subscriptionInfoListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving subscription information";
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : ZoneId(java.time.ZoneId) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) SubscriptionInfoListDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.SubscriptionInfoListDTO) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) SubscriptionInfo(org.wso2.carbon.apimgt.core.models.analytics.SubscriptionInfo) Analyzer(org.wso2.carbon.apimgt.core.api.Analyzer)

Example 27 with Analyzer

use of org.wso2.carbon.apimgt.core.api.Analyzer in project carbon-apimgt by wso2.

the class JSONAnalyzerTestCase method testConfigureAnalyzerException.

@Test(expectedExceptions = UnsupportedOperationException.class)
public void testConfigureAnalyzerException() throws Exception {
    JSONAnalyzer analyzer = new JSONAnalyzer();
    XMLConfig config = new XMLConfig();
    analyzer.configure(config);
}
Also used : JSONAnalyzer(org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.JSONAnalyzer) XMLConfig(org.wso2.carbon.apimgt.ballerina.threatprotection.configurations.XMLConfig) Test(org.testng.annotations.Test)

Example 28 with Analyzer

use of org.wso2.carbon.apimgt.core.api.Analyzer in project carbon-apimgt by wso2.

the class JSONAnalyzerTestCase method testMaxFieldLengthPass.

@Test
public void testMaxFieldLengthPass() throws Exception {
    JSONConfig config = Mockito.mock(JSONConfig.class);
    Mockito.when(config.getMaxKeyLength()).thenReturn(5);
    JSONAnalyzer analyzer = new JSONAnalyzer();
    analyzer.configure(config);
    String jsonString = "{\"abcde\": [1, 2, 3, 4, 5]}";
    analyzer.analyze(jsonString, "/foo");
}
Also used : JSONAnalyzer(org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.JSONAnalyzer) JSONConfig(org.wso2.carbon.apimgt.ballerina.threatprotection.configurations.JSONConfig) Test(org.testng.annotations.Test)

Example 29 with Analyzer

use of org.wso2.carbon.apimgt.core.api.Analyzer in project carbon-apimgt by wso2.

the class JSONAnalyzerTestCase method testMaxArrayElementCountFail.

@Test(expectedExceptions = APIMThreatAnalyzerException.class)
public void testMaxArrayElementCountFail() throws Exception {
    JSONConfig config = Mockito.mock(JSONConfig.class);
    Mockito.when(config.getMaxArrayElementCount()).thenReturn(5);
    JSONAnalyzer analyzer = new JSONAnalyzer();
    analyzer.configure(config);
    String jsonString = "{\"a\": [1, 2, 3, 4, 5, 6]}";
    analyzer.analyze(jsonString, "/foo");
}
Also used : JSONAnalyzer(org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.JSONAnalyzer) JSONConfig(org.wso2.carbon.apimgt.ballerina.threatprotection.configurations.JSONConfig) Test(org.testng.annotations.Test)

Example 30 with Analyzer

use of org.wso2.carbon.apimgt.core.api.Analyzer in project carbon-apimgt by wso2.

the class JSONAnalyzerTestCase method testMaxStringLengthInsideAnArrayPass.

@Test
public void testMaxStringLengthInsideAnArrayPass() throws Exception {
    JSONConfig config = Mockito.mock(JSONConfig.class);
    Mockito.when(config.getMaxStringLength()).thenReturn(5);
    JSONAnalyzer analyzer = new JSONAnalyzer();
    analyzer.configure(config);
    String jsonString = "{\"abcdef\": [1, \"12345\", 3, 4, 5, 6]}";
    analyzer.analyze(jsonString, "/foo");
}
Also used : JSONAnalyzer(org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.JSONAnalyzer) JSONConfig(org.wso2.carbon.apimgt.ballerina.threatprotection.configurations.JSONConfig) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)27 JSONConfig (org.wso2.carbon.apimgt.ballerina.threatprotection.configurations.JSONConfig)15 JSONAnalyzer (org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.JSONAnalyzer)14 Analyzer (org.wso2.carbon.apimgt.core.api.Analyzer)13 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)12 BeforeTest (org.testng.annotations.BeforeTest)7 XMLAnalyzer (org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.XMLAnalyzer)7 ArrayList (java.util.ArrayList)6 AnalyticsDAO (org.wso2.carbon.apimgt.core.dao.AnalyticsDAO)6 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)6 ZoneId (java.time.ZoneId)5 APISubscriptionCount (org.wso2.carbon.apimgt.core.models.analytics.APISubscriptionCount)3 BBoolean (org.ballerinalang.model.values.BBoolean)2 APIMThreatAnalyzer (org.wso2.carbon.apimgt.ballerina.threatprotection.analyzer.APIMThreatAnalyzer)2 XMLConfig (org.wso2.carbon.apimgt.ballerina.threatprotection.configurations.XMLConfig)2 APICount (org.wso2.carbon.apimgt.core.models.analytics.APICount)2 APIInfo (org.wso2.carbon.apimgt.core.models.analytics.APIInfo)2 ApplicationCount (org.wso2.carbon.apimgt.core.models.analytics.ApplicationCount)2 SubscriptionCount (org.wso2.carbon.apimgt.core.models.analytics.SubscriptionCount)2 SubscriptionInfo (org.wso2.carbon.apimgt.core.models.analytics.SubscriptionInfo)2