+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
package org.onap.so.client.namingservice;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
+import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestTemplate;
@Autowired
private NamingClientResponseValidator namingClientResponseValidator;
- public String postNameGenRequest(NameGenRequest request) throws BadResponseException {
+ public String postNameGenRequest(NameGenRequest request) throws BadResponseException, IOException {
String targetUrl = env.getProperty(ENDPOINT);
HttpHeaders headers = setHeaders(env.getProperty(AUTH));
msoLogger.info("Sending postNameGenRequest to url: " + targetUrl);
HttpEntity<NameGenRequest> requestEntity = new HttpEntity<>(request, headers);
- ResponseEntity<NameGenResponse> response = restTemplate.postForEntity(targetUrl, requestEntity, NameGenResponse.class);
+ ResponseEntity<NameGenResponse> response;
+ try{
+ response = restTemplate.postForEntity(targetUrl, requestEntity, NameGenResponse.class);
+ }catch(HttpStatusCodeException e){
+ throw new BadResponseException(namingClientResponseValidator.formatError(e));
+ }
return namingClientResponseValidator.validateNameGenResponse(response);
}
- public String deleteNameGenRequest(NameGenDeleteRequest request) throws BadResponseException {
+ public String deleteNameGenRequest(NameGenDeleteRequest request) throws BadResponseException, IOException {
String targetUrl = env.getProperty(ENDPOINT);
HttpHeaders headers = setHeaders(env.getProperty(AUTH));
msoLogger.info("Sending deleteNameGenRequest to url: " + targetUrl);
HttpEntity<NameGenDeleteRequest> requestEntity = new HttpEntity<>(request, headers);
- ResponseEntity<NameGenDeleteResponse> response = restTemplate.exchange(targetUrl, HttpMethod.DELETE, requestEntity, NameGenDeleteResponse.class);
+ ResponseEntity<NameGenDeleteResponse> response;
+ try{
+ response = restTemplate.exchange(targetUrl, HttpMethod.DELETE, requestEntity, NameGenDeleteResponse.class);
+ }catch(HttpStatusCodeException e){
+ throw new BadResponseException(namingClientResponseValidator.formatError(e));
+ }
return namingClientResponseValidator.validateNameGenDeleteResponse(response);
}
headers.add(HttpHeaders.AUTHORIZATION, auth);
return headers;
}
-}
\ No newline at end of file
+}