2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.oauthprovider.http.client;
24 import com.fasterxml.jackson.core.JsonProcessingException;
25 import com.fasterxml.jackson.databind.JsonMappingException;
26 import com.fasterxml.jackson.databind.ObjectMapper;
27 import org.onap.ccsdk.features.sdnr.wt.common.http.BaseHTTPResponse;
28 import org.onap.ccsdk.features.sdnr.wt.oauthprovider.data.CustomObjectMapper;
30 public class MappedBaseHttpResponse<T> {
33 public static final int CODE404 = 404;
34 public static final int CODE200 = 200;
35 public static final MappedBaseHttpResponse<String> UNKNOWN = new MappedBaseHttpResponse<>(-1, null);
36 private static final ObjectMapper mapper = new CustomObjectMapper();
37 public final int code;
40 public MappedBaseHttpResponse(int code, String body, Class<T> clazz)
41 throws JsonMappingException, JsonProcessingException {
42 this(code, body != null ? mapper.readValue(body, clazz) : null);
45 private MappedBaseHttpResponse(int code, T body) {
50 public MappedBaseHttpResponse(BaseHTTPResponse response, Class<T> clazz)
51 throws JsonMappingException, JsonProcessingException {
52 this(response.code, response.body, clazz);
56 public String toString() {
57 return "BaseHTTPResponse [code=" + code + ", body=" + body + "]";
60 public boolean isSuccess() {
61 return this.code == CODE200;