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.core.JsonProcessingException;
24 import com.fasterxml.jackson.databind.ObjectMapper;
25 import org.glassfish.jersey.client.ClientResponse;
26 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
28 import java.text.DateFormat;
29 import java.text.SimpleDateFormat;
31 import static org.onap.vid.utils.Logging.getMethodName;
36 public class MsoUtil {
39 private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MsoUtil.class);
41 /** The Constant dateFormat. */
42 final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
47 * @param body the body
48 * @param statusCode the status code
49 * @return the mso response wrapper
51 public static MsoResponseWrapper wrapResponse ( String body, int statusCode ) {
53 MsoResponseWrapper w = new MsoResponseWrapper();
54 w.setStatus (statusCode);
63 * @param cres the cres
64 * @return the mso response wrapper
66 public static MsoResponseWrapper wrapResponse (ClientResponse cres) {
69 resp_str = cres.readEntity(String.class);
71 int statuscode = cres.getStatus();
72 MsoResponseWrapper w = MsoUtil.wrapResponse ( resp_str, statuscode );
80 * @return the mso response wrapper
82 public static MsoResponseWrapper wrapResponse (RestObject<String> rs) {
83 String resp_str = null;
86 resp_str = rs.get() != null ? rs.get() : rs.getRaw();
87 status = rs.getStatusCode();
89 MsoResponseWrapper w = MsoUtil.wrapResponse ( resp_str, status );
94 * Convert pojo to string.
96 * @param <T> the generic type
99 * @throws JsonProcessingException the json processing exception
101 public static <T> String convertPojoToString ( T t ) {
103 String methodName = "convertPojoToString";
104 ObjectMapper mapper = new ObjectMapper();
105 String r_json_str = "";
108 r_json_str = mapper.writeValueAsString(t);
110 catch ( com.fasterxml.jackson.core.JsonProcessingException j ) {
111 logger.debug(EELFLoggerDelegate.debugLogger,getMethodName() + " Unable to parse object of type " + t.getClass().getName() + " as json", j);
120 * @param args the arguments
122 public static void main(String[] args) {
123 // TODO Auto-generated method stub