2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package org.openecomp.vid.mso;
\r
22 import java.text.DateFormat;
\r
23 import java.text.SimpleDateFormat;
\r
24 import java.util.Date;
\r
26 import org.glassfish.jersey.client.ClientResponse;
\r
28 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
\r
29 import org.openecomp.vid.controller.MsoController;
\r
30 import com.fasterxml.jackson.databind.ObjectMapper;
\r
33 * The Class MsoUtil.
\r
35 public class MsoUtil {
\r
38 private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MsoController.class);
\r
40 /** The Constant dateFormat. */
\r
41 final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
\r
46 * @param body the body
\r
47 * @param statusCode the status code
\r
48 * @return the mso response wrapper
\r
50 public static MsoResponseWrapper wrapResponse ( String body, int statusCode ) {
\r
52 MsoResponseWrapper w = new MsoResponseWrapper();
\r
53 w.setStatus (statusCode);
\r
62 * @param cres the cres
\r
63 * @return the mso response wrapper
\r
65 public static MsoResponseWrapper wrapResponse (ClientResponse cres) {
\r
66 String resp_str = "";
\r
67 if ( cres != null ) {
\r
68 resp_str = cres.readEntity(String.class);
\r
70 int statuscode = cres.getStatus();
\r
71 MsoResponseWrapper w = MsoUtil.wrapResponse ( resp_str, statuscode );
\r
79 * @return the mso response wrapper
\r
81 public static MsoResponseWrapper wrapResponse (RestObject<String> rs) {
\r
82 String resp_str = "";
\r
85 resp_str = rs.get();
\r
86 status = rs.getStatusCode();
\r
88 MsoResponseWrapper w = MsoUtil.wrapResponse ( resp_str, status );
\r
93 * Convert pojo to string.
\r
95 * @param <T> the generic type
\r
97 * @return the string
\r
98 * @throws JsonProcessingException the json processing exception
\r
100 public static <T> String convertPojoToString ( T t ) throws com.fasterxml.jackson.core.JsonProcessingException {
\r
102 String methodName = "convertPojoToString";
\r
103 ObjectMapper mapper = new ObjectMapper();
\r
104 String r_json_str = "";
\r
107 r_json_str = mapper.writeValueAsString(t);
\r
109 catch ( com.fasterxml.jackson.core.JsonProcessingException j ) {
\r
110 logger.debug(EELFLoggerDelegate.debugLogger,dateFormat.format(new Date()) + "<== " + methodName + " Unable to parse object as json");
\r
113 return (r_json_str);
\r
119 * @param args the arguments
\r
121 public static void main(String[] args) {
\r
122 // TODO Auto-generated method stub
\r