Improved error printouts 64/3164/3
authorPatrikBuhr <patrik.buhr@est.tech>
Mon, 6 Apr 2020 14:49:58 +0000 (16:49 +0200)
committerPatrikBuhr <patrik.buhr@est.tech>
Tue, 7 Apr 2020 12:28:53 +0000 (14:28 +0200)
Run code formatting

Change-Id: I5ec9aad31455065377c9e0c6cc1ff48a9d8f0cab
Issue-ID: NONRTRIC-152
Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
15 files changed:
webapp-backend/src/main/java/org/oransc/portal/nonrtric/controlpanel/config/AdminConfiguration.java
webapp-backend/src/main/java/org/oransc/portal/nonrtric/controlpanel/controller/CustomResponseEntityExceptionHandler.java
webapp-backend/src/main/java/org/oransc/portal/nonrtric/controlpanel/controller/PolicyController.java
webapp-backend/src/main/java/org/oransc/portal/nonrtric/controlpanel/controller/SimpleErrorController.java
webapp-backend/src/main/java/org/oransc/portal/nonrtric/controlpanel/policyagentapi/PolicyAgentApiImpl.java
webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/ControlPanelUserManagerTest.java
webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/config/PolicyControllerMockConfiguration.java
webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/config/WebSecurityMockConfiguration.java
webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/policyagentapi/PolicyAgentApiImplTest.java
webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/portalapi/PortalAuthManagerTest.java
webapp-frontend/ng [changed mode: 0644->0755]
webapp-frontend/src/app/policy-control/policy-instance-dialog.component.ts
webapp-frontend/src/app/policy-control/policy-instance.component.ts
webapp-frontend/src/app/policy-control/policy-instance.datasource.ts
webapp-frontend/src/app/policy-control/policy-type.datasource.ts

index 836f462..4ec8e38 100644 (file)
@@ -22,6 +22,7 @@ package org.oransc.portal.nonrtric.controlpanel.config;
 
 import java.io.IOException;
 import java.lang.invoke.MethodHandles;
+
 import org.oransc.portal.nonrtric.controlpanel.ControlPanelUserManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
index 6f3421b..44d5244 100644 (file)
@@ -25,6 +25,7 @@ import io.swagger.annotations.ApiOperation;
 import java.lang.invoke.MethodHandles;
 
 import javax.servlet.http.HttpServletResponse;
+
 import org.oransc.portal.nonrtric.controlpanel.ControlPanelConstants;
 import org.oransc.portal.nonrtric.controlpanel.policyagentapi.PolicyAgentApi;
 import org.slf4j.Logger;
index da2a900..156acf4 100644 (file)
@@ -60,7 +60,7 @@ public class SimpleErrorController implements ErrorController {
 
     private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
-    @SuppressWarnings("squid:S1075") //URIs should not be hardcoded
+    @SuppressWarnings("squid:S1075") // URIs should not be hardcoded
     public static final String ERROR_PATH = "/error";
 
     private final ErrorAttributes errorAttributes;
index c084443..ef90b5d 100644 (file)
@@ -50,6 +50,8 @@ import org.springframework.http.HttpStatus;
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Component;
+import org.springframework.web.client.HttpClientErrorException;
+import org.springframework.web.client.HttpServerErrorException;
 import org.springframework.web.client.RestTemplate;
 
 @Component("PolicyAgentApi")
@@ -110,7 +112,7 @@ public class PolicyAgentApiImpl implements PolicyAgentApi {
             }
             return new ResponseEntity<>(gson.toJson(result), rsp.getStatusCode());
         } catch (Exception e) {
-            return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
+            return handleException(e);
         }
     }
 
@@ -132,7 +134,7 @@ public class PolicyAgentApiImpl implements PolicyAgentApi {
             }
             return new ResponseEntity<>(gson.toJson(result), rsp.getStatusCode());
         } catch (Exception e) {
-            return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
+            return handleException(e);
         }
     }
 
@@ -158,7 +160,7 @@ public class PolicyAgentApiImpl implements PolicyAgentApi {
             this.restTemplate.put(url, createJsonHttpEntity(json), uriVariables);
             return new ResponseEntity<>(HttpStatus.OK);
         } catch (Exception e) {
-            return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
+            return handleException(e);
         }
     }
 
@@ -170,7 +172,7 @@ public class PolicyAgentApiImpl implements PolicyAgentApi {
             this.restTemplate.delete(url, uriVariables);
             return new ResponseEntity<>(HttpStatus.OK);
         } catch (Exception e) {
-            return new ResponseEntity<>(e.getMessage(), HttpStatus.NOT_FOUND);
+            return handleException(e);
         }
 
     }
@@ -200,7 +202,7 @@ public class PolicyAgentApiImpl implements PolicyAgentApi {
             }
             return new ResponseEntity<>(gson.toJson(result), HttpStatus.OK);
         } catch (Exception e) {
-            return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
+            return handleException(e);
         }
     }
 
@@ -210,4 +212,15 @@ public class PolicyAgentApiImpl implements PolicyAgentApi {
         return new HttpEntity<>(content, headers);
     }
 
+    private ResponseEntity<String> handleException(Exception throwable) {
+        if (throwable instanceof HttpClientErrorException) {
+            HttpClientErrorException e = (HttpClientErrorException) throwable;
+            return new ResponseEntity<>(e.getMessage(), e.getStatusCode());
+        } else if (throwable instanceof HttpServerErrorException) {
+            HttpServerErrorException e = (HttpServerErrorException) throwable;
+            return new ResponseEntity<>(e.getResponseBodyAsString(), e.getStatusCode());
+        }
+        return new ResponseEntity<>(throwable.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
+    }
+
 }
index 00686eb..8f9d913 100644 (file)
@@ -29,8 +29,6 @@ import org.junit.jupiter.api.Test;
 import org.onap.portalsdk.core.onboarding.exception.PortalAPIException;
 import org.onap.portalsdk.core.restful.domain.EcompRole;
 import org.onap.portalsdk.core.restful.domain.EcompUser;
-import org.oransc.portal.nonrtric.controlpanel.ControlPanelConstants;
-import org.oransc.portal.nonrtric.controlpanel.ControlPanelUserManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.test.context.ActiveProfiles;
index 0f9599b..ff17d06 100644 (file)
@@ -34,12 +34,13 @@ import java.util.Map;
 import java.util.Optional;
 import java.util.Vector;
 import java.util.stream.Collectors;
+
+import org.oransc.portal.nonrtric.controlpanel.model.ImmutablePolicyInfo;
 import org.oransc.portal.nonrtric.controlpanel.model.PolicyInfo;
 import org.oransc.portal.nonrtric.controlpanel.model.PolicyInstances;
 import org.oransc.portal.nonrtric.controlpanel.model.PolicyType;
 import org.oransc.portal.nonrtric.controlpanel.model.PolicyTypes;
 import org.oransc.portal.nonrtric.controlpanel.policyagentapi.PolicyAgentApi;
-import org.oransc.portal.nonrtric.controlpanel.model.ImmutablePolicyInfo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.boot.test.context.TestConfiguration;
index e4007e3..1566044 100644 (file)
@@ -21,8 +21,8 @@
 package org.oransc.portal.nonrtric.controlpanel.config;
 
 import java.lang.invoke.MethodHandles;
+
 import org.oransc.portal.nonrtric.controlpanel.ControlPanelConstants;
-import org.oransc.portal.nonrtric.controlpanel.config.WebSecurityConfiguration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Value;
index b376c3b..dcbce40 100644 (file)
@@ -45,19 +45,18 @@ import java.util.Map;
 
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.oransc.portal.nonrtric.controlpanel.model.ImmutablePolicyInfo;
 import org.oransc.portal.nonrtric.controlpanel.model.PolicyInfo;
 import org.oransc.portal.nonrtric.controlpanel.model.PolicyInstances;
 import org.oransc.portal.nonrtric.controlpanel.model.PolicyType;
 import org.oransc.portal.nonrtric.controlpanel.model.PolicyTypes;
-import org.oransc.portal.nonrtric.controlpanel.policyagentapi.PolicyAgentApiImpl;
 import org.oransc.portal.nonrtric.controlpanel.policyagentapi.PolicyAgentApiImpl.RicInfo;
-import org.oransc.portal.nonrtric.controlpanel.model.ImmutablePolicyInfo;
 import org.springframework.http.HttpEntity;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
-import org.springframework.web.client.RestClientException;
+import org.springframework.web.client.HttpClientErrorException;
 import org.springframework.web.client.RestTemplate;
 
 public class PolicyAgentApiImplTest {
@@ -78,7 +77,7 @@ public class PolicyAgentApiImplTest {
     private static final String RIC_1_ID = "ric1";
     private static final String RIC_1_INFO_VALID = "{\"name\":\"ric1\",\"policyTypes\":[\"type1\"]}";
     private static final String RIC_1_INFO_INVALID = "{\"name\":\"ric1\",\"policyTypes\":\"type1\"]}";
-    private static final String CLIENT_ERROR_MESSAGE = "Exception: Client returned failure";
+    private static final String CLIENT_ERROR_MESSAGE = "XXXXXXX";
 
     private static com.google.gson.Gson gson = new GsonBuilder() //
         .serializeNulls() //
@@ -203,15 +202,16 @@ public class PolicyAgentApiImplTest {
             "id", POLICY_1_ID, //
             "ric", RIC_1_ID, //
             "service", "controlpanel");
-        doThrow(new RestClientException(CLIENT_ERROR_MESSAGE)).when(restTemplateMock)
-            .put(eq(URL_PREFIX + URL_PUT_POLICY), eq(jsonHttpEntity), eq(uriVariables));
+        HttpClientErrorException exception = new HttpClientErrorException(HttpStatus.NOT_FOUND, CLIENT_ERROR_MESSAGE);
+        doThrow(exception).when(restTemplateMock).put(eq(URL_PREFIX + URL_PUT_POLICY), eq(jsonHttpEntity),
+            eq(uriVariables));
 
         ResponseEntity<String> returnedResp =
             apiUnderTest.putPolicy(POLICY_TYPE_1_ID, POLICY_1_ID, POLICY_1_VALID, RIC_1_ID);
 
         verify(restTemplateMock).put(URL_PREFIX + URL_PUT_POLICY, jsonHttpEntity, uriVariables);
-        assertTrue(returnedResp.getBody().contains("Exception"));
-        assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, returnedResp.getStatusCode());
+        assertTrue(returnedResp.getBody().contains(CLIENT_ERROR_MESSAGE));
+        assertEquals(HttpStatus.NOT_FOUND, returnedResp.getStatusCode());
     }
 
     @Test
@@ -234,13 +234,13 @@ public class PolicyAgentApiImplTest {
     @Test
     public void testDeletePolicyFailure() {
         Map<String, ?> uriVariables = Map.of("id", POLICY_1_ID);
-        doThrow(new RestClientException(CLIENT_ERROR_MESSAGE)).when(restTemplateMock)
-            .delete(eq(URL_PREFIX + URL_DELETE_POLICY), eq(uriVariables));
+        HttpClientErrorException exception = new HttpClientErrorException(HttpStatus.NOT_FOUND, CLIENT_ERROR_MESSAGE);
+        doThrow(exception).when(restTemplateMock).delete(eq(URL_PREFIX + URL_DELETE_POLICY), eq(uriVariables));
 
         ResponseEntity<String> returnedResp = apiUnderTest.deletePolicy(POLICY_1_ID);
 
         verify(restTemplateMock).delete(URL_PREFIX + URL_DELETE_POLICY, uriVariables);
-        assertTrue(returnedResp.getBody().contains("Exception"));
+        assertTrue(returnedResp.getBody().contains(CLIENT_ERROR_MESSAGE));
         assertEquals(HttpStatus.NOT_FOUND, returnedResp.getStatusCode());
     }
 
index 55637d2..38daac6 100644 (file)
@@ -32,8 +32,6 @@ import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
 import org.oransc.portal.nonrtric.controlpanel.ControlPanelUserManager;
-import org.oransc.portal.nonrtric.controlpanel.portalapi.PortalAuthManager;
-import org.oransc.portal.nonrtric.controlpanel.portalapi.PortalAuthenticationFilter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Value;
old mode 100644 (file)
new mode 100755 (executable)
index b4ad194..aea3453 100644 (file)
@@ -28,6 +28,7 @@ import { PolicyService } from '../services/policy/policy.service';
 import { ErrorDialogService } from '../services/ui/error-dialog.service';
 import { NotificationService } from './../services/ui/notification.service';
 import { UiService } from '../services/ui/ui.service';
+import { HttpErrorResponse } from '@angular/common/http';
 
 
 @Component({
@@ -91,7 +92,7 @@ export class PolicyInstanceDialogComponent implements OnInit, AfterViewInit {
                     self.allRics = value;
                     console.log(value);
                 },
-                error(error) {
+                error(error: HttpErrorResponse) {
                     self.errorService.displayError('Fetching of rics failed: ' + error.message);
                 },
                 complete() { }
@@ -138,8 +139,8 @@ export class PolicyInstanceDialogComponent implements OnInit, AfterViewInit {
                 next(value) {
                     self.notificationService.success('Policy ' + self.policyTypeName + ':' + self.policyInstanceId + ' submitted');
                 },
-                error(error) {
-                    self.errorService.displayError('updatePolicy failed: ' + error.message);
+                error(error: HttpErrorResponse) {
+                    self.errorService.displayError('Submit failed: ' + error.error);
                 },
                 complete() { }
             });
index adc6a6d..55f50f7 100644 (file)
@@ -114,11 +114,11 @@ export class PolicyInstanceComponent implements OnInit, AfterViewInit {
                                             this.instanceDataSource.loadTable();
                                             break;
                                         default:
-                                            this.notificationService.warn('Delete failed.');
+                                            this.notificationService.warn('Delete failed ' + response.status + ' ' + response.body);
                                     }
                                 },
                                 (error: HttpErrorResponse) => {
-                                    this.errorDialogService.displayError(error.message);
+                                    this.errorDialogService.displayError(error.statusText + ', ' + error.error);
                                 });
                     }
                 });
index ea7e4a2..9cf1d72 100644 (file)
@@ -54,7 +54,7 @@ export class PolicyInstanceDataSource extends DataSource<PolicyInstance> {
         this.policySvc.getPolicyInstances(this.policyType.name)
             .pipe(
                 catchError((her: HttpErrorResponse) => {
-                    this.notificationService.error('Failed to get policy instances: ' + her.message);
+                    this.notificationService.error('Failed to get policy instances: ' + her.error);
                     return of([]);
                 }),
                 finalize(() => this.loadingSubject.next(false))
index 97d792e..983fc96 100644 (file)
@@ -51,7 +51,7 @@ export class PolicyTypeDataSource extends DataSource<PolicyType> {
         this.policySvc.getPolicyTypes()
             .pipe(
                 catchError((her: HttpErrorResponse) => {
-                    this.notificationService.error('Failed to get policy types: ' + her.message);
+                    this.notificationService.error('Failed to get policy types: ' + her.statusText + ', ' + her.error);
                     return of([]);
                 }),
                 finalize(() => this.loadingSubject.next(false))