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.openecomp.mso.adapters.vnfrest;
24 import java.io.ByteArrayOutputStream;
26 import javax.xml.bind.JAXBContext;
27 import javax.xml.bind.Marshaller;
29 import org.codehaus.jackson.map.ObjectMapper;
30 import org.codehaus.jackson.map.SerializationConfig;
33 * Everything that is common between all VfModule and VolumeGroup Responses,
34 * except for QueryVfModuleResponse and QueryVolumeGroupResponse.
36 public abstract class VfResponseCommon {
37 private String messageId;
39 public VfResponseCommon() {
43 public VfResponseCommon(String messageId) {
44 this.messageId = messageId;
47 public String getMessageId() {
51 public void setMessageId(String messageId) {
52 this.messageId = messageId;
55 public String toJsonString() {
57 String jsonString = null;
58 ObjectMapper mapper = new ObjectMapper();
59 mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
60 jsonString = mapper.writeValueAsString(this);
62 } catch (Exception e) {
63 // Shouldn't happen...
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 // Shouldn't happen...