2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
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.openecomp.mso.adapters.nwrest;
26 import java.io.ByteArrayOutputStream;
28 import javax.xml.bind.JAXBContext;
29 import javax.xml.bind.Marshaller;
31 import com.fasterxml.jackson.databind.ObjectMapper;
32 import com.fasterxml.jackson.databind.SerializationFeature;
33 import org.openecomp.mso.logger.MsoLogger;
35 * Everything that is common between all Volume Group Responses, except for QueryVolumeGroupResponse.
37 public abstract class NetworkResponseCommon {
38 private String messageId;
39 private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
41 public NetworkResponseCommon() {
45 public NetworkResponseCommon(String messageId) {
46 this.messageId = messageId;
49 public String getMessageId() {
53 public void setMessageId(String messageId) {
54 this.messageId = messageId;
57 public String toJsonString() {
58 String jsonString = null;
60 ObjectMapper mapper = new ObjectMapper();
61 mapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
62 jsonString = mapper.writeValueAsString(this);
63 } catch (Exception e) {
64 LOGGER.debug("Exception:", e);
69 public String toXmlString() {
71 ByteArrayOutputStream bs = new ByteArrayOutputStream();
72 JAXBContext context = JAXBContext.newInstance(this.getClass());
73 Marshaller marshaller = context.createMarshaller();
74 marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); //pretty print XML
75 marshaller.marshal(this, bs);
77 } catch (Exception e) {
78 LOGGER.debug("Exception:", e);