@@ -67,12 +67,12 @@ public APIMgrAppsAdapter(APIManagerAdapter apiManagerAdapter) {
6767 * @throws AppException if applications cannot be retrieved
6868 */
6969 private void readApplicationsFromAPIManager (ClientAppFilter filter ) throws AppException {
70- if (this . apiManagerResponse .get (filter ) != null ) return ;
70+ if (apiManagerResponse .get (filter ) != null ) return ;
7171 try {
7272 String requestedId = "" ;
7373 if (filter .getApplicationId () != null ) {
7474 if (applicationsCache .containsKey (filter .getApplicationId ())) {
75- this . apiManagerResponse .put (filter , applicationsCache .get (filter .getApplicationId ()));
75+ apiManagerResponse .put (filter , applicationsCache .get (filter .getApplicationId ()));
7676 return ;
7777 }
7878 requestedId = "/" + filter .getApplicationId ();
@@ -86,14 +86,14 @@ private void readApplicationsFromAPIManager(ClientAppFilter filter) throws AppEx
8686 int statusCode = httpResponse .getStatusLine ().getStatusCode ();
8787 if (statusCode == 404 ) {
8888 // Nothing found - Simulate an empty response
89- this . apiManagerResponse .put (filter , "[]" );
89+ apiManagerResponse .put (filter , "[]" );
9090 return ;
9191 }
9292 String response = EntityUtils .toString (httpResponse .getEntity (), "UTF-8" );
9393 if (response .startsWith ("{" )) { // Got a single response!
9494 response = "[" + response + "]" ;
9595 }
96- this . apiManagerResponse .put (filter , response );
96+ apiManagerResponse .put (filter , response );
9797 if (filter .getApplicationId () != null ) {
9898 applicationsCache .put (filter .getApplicationId (), response );
9999 }
@@ -118,8 +118,8 @@ public List<ClientApplication> getApplications(ClientAppFilter filter, boolean l
118118 readApplicationsFromAPIManager (filter );
119119 List <ClientApplication > apps ;
120120 try {
121- if (this . apiManagerResponse .get (filter ) == null ) return Collections .emptyList ();
122- apps = mapper .readValue (this . apiManagerResponse .get (filter ), new TypeReference <>() {
121+ if (apiManagerResponse .get (filter ) == null ) return Collections .emptyList ();
122+ apps = mapper .readValue (apiManagerResponse .get (filter ), new TypeReference <>() {
123123 });
124124 LOG .debug ("Found: {} applications" , apps .size ());
125125 for (int i = 0 ; i < apps .size (); i ++) {
@@ -136,7 +136,7 @@ public List<ClientApplication> getApplications(ClientAppFilter filter, boolean l
136136 Utils .progressPercentage (i , apps .size (), "Loading details of " + apps .size () + " applications" );
137137 }
138138 apps .removeIf (filter ::filter );
139- Utils .addCustomPropertiesForEntity (apps , this . apiManagerResponse .get (filter ), filter );
139+ Utils .addCustomPropertiesForEntity (apps , apiManagerResponse .get (filter ), filter );
140140 if (logProgress && apps .size () > 5 ) Console .print ("\n " );
141141 } catch (Exception e ) {
142142 throw new AppException ("Can't initialize API-Manager API-Representation." , ErrorCode .API_MANAGER_COMMUNICATION , e );
@@ -152,7 +152,7 @@ public List<ClientApplication> getAppsSubscribedWithAPI(String apiId) throws App
152152 readAppsSubscribedFromAPIManager (apiId );
153153 List <ClientApplication > subscribedApps ;
154154 try {
155- subscribedApps = mapper .readValue (this . subscribedAppAPIManagerResponse .get (apiId ), new TypeReference <>() {
155+ subscribedApps = mapper .readValue (subscribedAppAPIManagerResponse .get (apiId ), new TypeReference <>() {
156156 });
157157 } catch (IOException e ) {
158158 throw new AppException ("Error cant load subscribes applications from API-Manager." , ErrorCode .API_MANAGER_COMMUNICATION , e );
@@ -161,7 +161,7 @@ public List<ClientApplication> getAppsSubscribedWithAPI(String apiId) throws App
161161 }
162162
163163 private void readAppsSubscribedFromAPIManager (String apiId ) throws AppException {
164- if (this . subscribedAppAPIManagerResponse .get (apiId ) != null ) return ;
164+ if (subscribedAppAPIManagerResponse .get (apiId ) != null ) return ;
165165 if (applicationsSubscriptionCache .containsKey (apiId )) {
166166 subscribedAppAPIManagerResponse .put (apiId , applicationsSubscriptionCache .get (apiId ));
167167 return ;
@@ -171,7 +171,12 @@ private void readAppsSubscribedFromAPIManager(String apiId) throws AppException
171171 RestAPICall getRequest = new GETRequest (uri );
172172 LOG .debug ("Load subscribed applications for API-ID: {} from API-Manager" , apiId );
173173 try (CloseableHttpResponse httpResponse = (CloseableHttpResponse ) getRequest .execute ()) {
174+ int statusCode = httpResponse .getStatusLine ().getStatusCode ();
174175 String response = EntityUtils .toString (httpResponse .getEntity ());
176+ if (statusCode != 200 ) {
177+ LOG .error ("Response from API Manager : {}" , response );
178+ throw new AppException ("Error from API Manager" , ErrorCode .API_MANAGER_COMMUNICATION );
179+ }
175180 subscribedAppAPIManagerResponse .put (apiId , response );
176181 applicationsSubscriptionCache .put (apiId , response );
177182 }
0 commit comments