import java.io.IOException;
import java.lang.invoke.MethodHandles;
+
import org.oransc.portal.nonrtric.controlpanel.ControlPanelUserManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package org.oransc.portal.nonrtric.controlpanel.controller;
import java.lang.invoke.MethodHandles;
+
import org.oransc.portal.nonrtric.controlpanel.model.ErrorTransport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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;
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;
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")
}
return new ResponseEntity<>(gson.toJson(result), rsp.getStatusCode());
} catch (Exception e) {
- return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
+ return handleException(e);
}
}
}
return new ResponseEntity<>(gson.toJson(result), rsp.getStatusCode());
} catch (Exception e) {
- return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
+ return handleException(e);
}
}
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);
}
}
this.restTemplate.delete(url, uriVariables);
return new ResponseEntity<>(HttpStatus.OK);
} catch (Exception e) {
- return new ResponseEntity<>(e.getMessage(), HttpStatus.NOT_FOUND);
+ return handleException(e);
}
}
}
return new ResponseEntity<>(gson.toJson(result), HttpStatus.OK);
} catch (Exception e) {
- return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
+ return handleException(e);
}
}
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);
+ }
+
}
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;
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;
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;
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 {
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() //
"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
@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());
}
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;
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({
self.allRics = value;
console.log(value);
},
- error(error) {
+ error(error: HttpErrorResponse) {
self.errorService.displayError('Fetching of rics failed: ' + error.message);
},
complete() { }
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() { }
});
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);
});
}
});
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))
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))