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.onap.so.adapters.catalogdb.catalogrest;
24 import java.io.ByteArrayOutputStream;
26 import javax.xml.bind.JAXBContext;
27 import javax.xml.bind.Marshaller;
29 import org.onap.so.logger.MsoLogger;
31 import com.fasterxml.jackson.databind.ObjectMapper;
32 import com.fasterxml.jackson.databind.SerializationFeature;
34 public abstract class CatalogQueryExceptionCommon {
35 private String messageId;
36 protected static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA,CatalogQueryExceptionCommon.class);
38 public CatalogQueryExceptionCommon() { messageId = null; }
39 public CatalogQueryExceptionCommon(String messageId) { this.messageId = messageId; }
41 public String getMessageId() { return messageId; }
42 public void setMessageId(String messageId) { this.messageId = messageId; }
44 public String toJsonString() {
47 ObjectMapper mapper = new ObjectMapper();
48 mapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
49 jsonString = mapper.writeValueAsString(this);
51 } catch (Exception e) {
52 LOGGER.debug ("Exception:", e);
57 public String toXmlString() {
59 ByteArrayOutputStream bs = new ByteArrayOutputStream();
60 JAXBContext context = JAXBContext.newInstance(this.getClass());
61 Marshaller marshaller = context.createMarshaller();
62 marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); //pretty print XML
63 marshaller.marshal(this, bs);
65 } catch (Exception e) {
66 LOGGER.debug ("Exception:", e);
72 public String toString(){
73 return toJsonString();