2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.vid.mso;
23 import com.fasterxml.jackson.databind.ObjectMapper;
24 import com.google.common.base.MoreObjects;
25 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
27 import javax.ws.rs.core.Response;
29 import static org.onap.vid.utils.Logging.getMethodCallerName;
32 * The Class RestObject.
34 * @param <T> the generic type
36 public class RestObject<T> {
38 static final ObjectMapper objectMapper = new ObjectMapper();
41 * Generic version of the RestObject class.
44 // T stands for "Type"
47 // The string source of t, if available
50 /** The status code. */
51 private int statusCode= 0;
56 public void copyFrom(RestObject<T> src) {
59 setStatusCode(src.getStatusCode());
62 public RestObject(Response cres, Class<?> tClass, EELFLoggerDelegate logger) {
64 String rawEntity = null;
67 rawEntity = cres.readEntity(String.class);
68 T t = (T) objectMapper.readValue(rawEntity, tClass);
71 catch ( Exception e ) {
73 this.setRaw(rawEntity);
74 logger.debug(EELFLoggerDelegate.debugLogger, "<== " + getMethodCallerName() + " Error reading response entity as " + tClass + ": , e="
75 + e.getMessage() + ", Entity=" + rawEntity);
76 } catch (Exception e2) {
77 logger.debug(EELFLoggerDelegate.debugLogger, "<== " + getMethodCallerName() + " No response entity, this is probably ok, e="
82 int status = cres.getStatus();
83 this.setStatusCode (status);
92 public void set(T t) { this.t = t; }
99 public T get() { return t; }
102 * Sets the status code.
104 * @param v the new status code
106 public void setStatusCode(int v) { this.statusCode = v; }
109 * Gets the status code.
111 * @return the status code
113 public int getStatusCode() { return this.statusCode; }
115 public String getRaw() {
119 public void setRaw(String rawT) {
124 public String toString() {
125 return MoreObjects.toStringHelper(this)
128 .add("statusCode", statusCode)