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();
}
}
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);
}
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");
}
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");
}
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");
}
Aggregations