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 * Modifications Copyright (C) 2018 IBM.
9 * ================================================================================
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.so.adapters.catalogdb.catalogrest;
26 import java.io.ByteArrayOutputStream;
27 import javax.xml.bind.JAXBContext;
28 import javax.xml.bind.Marshaller;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
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 Logger logger = LoggerFactory.getLogger(CatalogQueryExceptionCommon.class);
38 public CatalogQueryExceptionCommon() {
42 public CatalogQueryExceptionCommon(String messageId) {
43 this.messageId = messageId;
46 public String getMessageId() {
50 public void setMessageId(String messageId) {
51 this.messageId = messageId;
54 public String toJsonString() {
57 ObjectMapper mapper = new ObjectMapper();
58 mapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
59 jsonString = mapper.writeValueAsString(this);
61 } catch (Exception e) {
62 logger.error("Exception:", e);
67 public String toXmlString() {
69 ByteArrayOutputStream bs = new ByteArrayOutputStream();
70 JAXBContext context = JAXBContext.newInstance(this.getClass());
71 Marshaller marshaller = context.createMarshaller();
72 marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); // pretty print XML
73 marshaller.marshal(this, bs);
75 } catch (Exception e) {
76 logger.error("Exception:", e);
82 public String toString() {
83 return toJsonString();