Repository: wso2/micro-integrator
Issue: NumberFormatException occurs when invoking the Management API resource for transaction count

**Description:**
The following NumberFormatException is printed in logs when invoking the following Management API resource for transaction count. 

`curl -X GET "https://localhost:9164/management/transactions" -H "accept: application/json" -H "Authorization: Bearer %AccessToken%"`

```
[2020-05-28 14:28:41,203] ERROR {RequestCountResource} - Invalid input. Cannot parse the input 'null' as an Integer: java.lang.NumberFormatException: null
        at java.lang.Integer.parseInt(Integer.java:542)
        at java.lang.Integer.parseInt(Integer.java:615)
        at org.wso2.micro.integrator.management.apis.RequestCountResource.tryParseInt(RequestCountResource.java:127)
        at org.wso2.micro.integrator.management.apis.RequestCountResource.invoke(RequestCountResource.java:68)
        at org.wso2.micro.integrator.management.apis.ApiResourceAdapter.invoke(ApiResourceAdapter.java:55)
        at org.wso2.carbon.inbound.endpoint.internal.http.api.InternalAPIDispatcher.dispatch(InternalAPIDispatcher.java:86)
        at org.wso2.carbon.inbound.endpoint.protocol.http.InboundHttpServerWorker.run(InboundHttpServerWorker.java:109)
        at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

```
 **Affected Product Version:**
MI-1.2.0 alpha

**OS, DB, other environment details and versions:**    
N/A

**Steps to reproduce:**
- enable the transaction counter component and management API (on port 9164) in the MI server
- Invoke `curl -X GET "https://hostname:9164/management/transactions" -H "accept: application/json" -H "Authorization: Bearer %AccessToken%"` 


Changed files:
components/org.wso2.micro.integrator.extensions/org.wso2.micro.integrator.management.apis/src/main/java/org/wso2/micro/integrator/management/apis/RequestCountResource.java

diff --git a/components/org.wso2.micro.integrator.extensions/org.wso2.micro.integrator.management.apis/src/main/java/org/wso2/micro/integrator/management/apis/RequestCountResource.java b/components/org.wso2.micro.integrator.extensions/org.wso2.micro.integrator.management.apis/src/main/java/org/wso2/micro/integrator/management/apis/RequestCountResource.java
index 106e73213..dccf3dd8a 100644
--- a/components/org.wso2.micro.integrator.extensions/org.wso2.micro.integrator.management.apis/src/main/java/org/wso2/micro/integrator/management/apis/RequestCountResource.java
+++ b/components/org.wso2.micro.integrator.extensions/org.wso2.micro.integrator.management.apis/src/main/java/org/wso2/micro/integrator/management/apis/RequestCountResource.java
@@ -61,21 +61,33 @@ public class RequestCountResource implements MiApiResource {
     public boolean invoke(MessageContext synCtx,
                           org.apache.axis2.context.MessageContext axis2MessageContext,
                           SynapseConfiguration synapseConfiguration) {
+        String errorMessage;
 
         String yearParameter = Utils.getQueryParameter(synCtx, "year");
         String monthParameter = Utils.getQueryParameter(synCtx, "month");
 
-        if (tryParseInt(yearParameter) != null && tryParseInt(monthParameter) != null) {
-            if (!StringUtils.isEmpty(yearParameter) && !StringUtils.isEmpty(monthParameter)) {
-                return takeRequestCountOfTheMonth(axis2MessageContext, Integer.parseInt(yearParameter),
-                                                  Integer.parseInt(monthParameter));
-            }
-        } else if (StringUtils.isEmpty(yearParameter) && StringUtils.isEmpty(monthParameter)) {
+        if (StringUtils.isEmpty(yearParameter) && StringUtils.isEmpty(monthParameter)) {
             Date date = new Date();
             LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
             return takeRequestCountOfTheMonth(axis2MessageContext, localDate.getYear(), localDate.getMonthValue());
+        } else if (StringUtils.isEmpty(yearParameter) || StringUtils.isEmpty(monthParameter)) {
+            errorMessage = "Either both \\"year\\" and \\"month\\" arguments or none should be specified.";
+        } else {
+            Integer year = tryParseInt(yearParameter);
+            Integer month = tryParseInt(monthParameter);
+
+            if (null != year && null != month) {
+                return takeRequestCountOfTheMonth(axis2MessageContext, year, month);
+            } else if (null == year && null == month){
+                errorMessage = "Invalid inputs for arguments \\"year\\" and \\"month\\".";
+            } else if (null == year){
+                errorMessage = "Invalid input for argument \\"year\\".";
+            } else {
+                errorMessage = "Invalid input for argument \\"month\\".";
+            }
         }
-        JSONObject response = Utils.createJsonError("Input parameters are not valid", axis2MessageContext, BAD_REQUEST);
+
+        JSONObject response = Utils.createJsonError(errorMessage, axis2MessageContext, BAD_REQUEST);
         Utils.setJsonPayLoad(axis2MessageContext, response);
         return true;
     }