Skip to content

Commit aa2d25b

Browse files
committed
CLOUDSTACK-5913:API rate limiting throws a different error than expected
when Throttle limit hit in the API.
1 parent 27fd490 commit aa2d25b

1 file changed

Lines changed: 41 additions & 39 deletions

File tree

server/src/com/cloud/api/ApiServer.java

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,37 @@
5353
import javax.servlet.http.HttpServletResponse;
5454
import javax.servlet.http.HttpSession;
5555

56+
import org.apache.commons.codec.binary.Base64;
57+
import org.apache.http.ConnectionClosedException;
58+
import org.apache.http.HttpException;
59+
import org.apache.http.HttpRequest;
60+
import org.apache.http.HttpResponse;
61+
import org.apache.http.HttpServerConnection;
62+
import org.apache.http.HttpStatus;
63+
import org.apache.http.NameValuePair;
64+
import org.apache.http.client.utils.URLEncodedUtils;
65+
import org.apache.http.entity.BasicHttpEntity;
66+
import org.apache.http.impl.DefaultHttpResponseFactory;
67+
import org.apache.http.impl.DefaultHttpServerConnection;
68+
import org.apache.http.impl.NoConnectionReuseStrategy;
69+
import org.apache.http.impl.SocketHttpServerConnection;
70+
import org.apache.http.params.BasicHttpParams;
71+
import org.apache.http.params.CoreConnectionPNames;
72+
import org.apache.http.params.CoreProtocolPNames;
73+
import org.apache.http.params.HttpParams;
74+
import org.apache.http.protocol.BasicHttpContext;
75+
import org.apache.http.protocol.BasicHttpProcessor;
76+
import org.apache.http.protocol.HttpContext;
77+
import org.apache.http.protocol.HttpRequestHandler;
78+
import org.apache.http.protocol.HttpRequestHandlerRegistry;
79+
import org.apache.http.protocol.HttpService;
80+
import org.apache.http.protocol.ResponseConnControl;
81+
import org.apache.http.protocol.ResponseContent;
82+
import org.apache.http.protocol.ResponseDate;
83+
import org.apache.http.protocol.ResponseServer;
84+
import org.apache.log4j.Logger;
85+
import org.springframework.stereotype.Component;
86+
5687
import org.apache.cloudstack.acl.APIChecker;
5788
import org.apache.cloudstack.api.APICommand;
5889
import org.apache.cloudstack.api.ApiErrorCode;
@@ -90,36 +121,6 @@
90121
import org.apache.cloudstack.framework.jobs.AsyncJobManager;
91122
import org.apache.cloudstack.framework.jobs.impl.AsyncJobVO;
92123
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
93-
import org.apache.commons.codec.binary.Base64;
94-
import org.apache.http.ConnectionClosedException;
95-
import org.apache.http.HttpException;
96-
import org.apache.http.HttpRequest;
97-
import org.apache.http.HttpResponse;
98-
import org.apache.http.HttpServerConnection;
99-
import org.apache.http.HttpStatus;
100-
import org.apache.http.NameValuePair;
101-
import org.apache.http.client.utils.URLEncodedUtils;
102-
import org.apache.http.entity.BasicHttpEntity;
103-
import org.apache.http.impl.DefaultHttpResponseFactory;
104-
import org.apache.http.impl.DefaultHttpServerConnection;
105-
import org.apache.http.impl.NoConnectionReuseStrategy;
106-
import org.apache.http.impl.SocketHttpServerConnection;
107-
import org.apache.http.params.BasicHttpParams;
108-
import org.apache.http.params.CoreConnectionPNames;
109-
import org.apache.http.params.CoreProtocolPNames;
110-
import org.apache.http.params.HttpParams;
111-
import org.apache.http.protocol.BasicHttpContext;
112-
import org.apache.http.protocol.BasicHttpProcessor;
113-
import org.apache.http.protocol.HttpContext;
114-
import org.apache.http.protocol.HttpRequestHandler;
115-
import org.apache.http.protocol.HttpRequestHandlerRegistry;
116-
import org.apache.http.protocol.HttpService;
117-
import org.apache.http.protocol.ResponseConnControl;
118-
import org.apache.http.protocol.ResponseContent;
119-
import org.apache.http.protocol.ResponseDate;
120-
import org.apache.http.protocol.ResponseServer;
121-
import org.apache.log4j.Logger;
122-
import org.springframework.stereotype.Component;
123124

124125
import com.cloud.api.response.ApiResponseSerializer;
125126
import com.cloud.configuration.Config;
@@ -625,14 +626,12 @@ public boolean verifyRequest(Map<String, Object[]> requestParameters, Long userI
625626
if (userId != null) {
626627
User user = ApiDBUtils.findUserById(userId);
627628

628-
try{
629+
try {
629630
checkCommandAvailable(user, commandName);
630-
}
631-
catch (RequestLimitException ex){
631+
} catch (RequestLimitException ex) {
632632
s_logger.debug(ex.getMessage());
633633
throw new ServerApiException(ApiErrorCode.API_LIMIT_EXCEED, ex.getMessage());
634-
}
635-
catch (PermissionDeniedException ex){
634+
} catch (PermissionDeniedException ex) {
636635
s_logger.debug("The given command:" + commandName + " does not exist or it is not available for user with id:" + userId);
637636
throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, "The given command does not exist or it is not available for user");
638637
}
@@ -730,12 +729,15 @@ else if ("signatureversion".equalsIgnoreCase(paramName)) {
730729
return false;
731730
}
732731

733-
try{
732+
try {
734733
checkCommandAvailable(user, commandName);
735-
}
736-
catch (PermissionDeniedException ex){
734+
} catch (RequestLimitException ex) {
735+
s_logger.debug(ex.getMessage());
736+
throw new ServerApiException(ApiErrorCode.API_LIMIT_EXCEED, ex.getMessage());
737+
} catch (PermissionDeniedException ex) {
737738
s_logger.debug("The given command:" + commandName + " does not exist or it is not available for user");
738-
throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, "The given command:" + commandName + " does not exist or it is not available for user with id:" + userId);
739+
throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, "The given command:" + commandName + " does not exist or it is not available for user with id:"
740+
+ userId);
739741
}
740742

741743
// verify secret key exists

0 commit comments

Comments
 (0)