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.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
27 import javax.ws.rs.core.Response;
28 import java.text.DateFormat;
29 import java.text.SimpleDateFormat;
30 import java.util.Date;
32 import static org.onap.vid.utils.Logging.getMethodCallerName;
35 * The Class RestObject.
37 * @param <T> the generic type
39 public class RestObject<T> {
41 final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
43 final static ObjectMapper objectMapper = new ObjectMapper();
46 * Generic version of the RestObject class.
49 // T stands for "Type"
52 // The string source of t, if available
55 /** The status code. */
56 private int statusCode= 0;
61 public RestObject(Response cres, Class<?> tClass, EELFLoggerDelegate logger) {
63 String rawEntity = null;
66 rawEntity = cres.readEntity(String.class);
67 T t = (T) objectMapper.readValue(rawEntity, tClass);
70 catch ( Exception e ) {
72 this.setRaw(rawEntity);
73 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + getMethodCallerName() + " Error reading response entity as " + tClass + ": , e="
74 + e.getMessage() + ", Entity=" + rawEntity);
75 } catch (Exception e2) {
76 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + getMethodCallerName() + " No response entity, this is probably ok, e="
81 int status = cres.getStatus();
82 this.setStatusCode (status);
91 public void set(T t) { this.t = t; }
98 public T get() { return t; }
101 * Sets the status code.
103 * @param v the new status code
105 public void setStatusCode(int v) { this.statusCode = v; }
108 * Gets the status code.
110 * @return the status code
112 public int getStatusCode() { return this.statusCode; }
114 public String getRaw() {
118 public void setRaw(String rawT) {
123 public String toString() {
124 return MoreObjects.toStringHelper(this)
127 .add("statusCode", statusCode)