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;
28 import javax.xml.bind.JAXBContext;
29 import javax.xml.bind.Marshaller;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import com.fasterxml.jackson.databind.ObjectMapper;
34 import com.fasterxml.jackson.databind.SerializationFeature;
36 public abstract class CatalogQueryExceptionCommon {
37 private String messageId;
38 protected static Logger logger = LoggerFactory.getLogger(CatalogQueryExceptionCommon.class);
40 public CatalogQueryExceptionCommon() { messageId = null; }
41 public CatalogQueryExceptionCommon(String messageId) { this.messageId = messageId; }
43 public String getMessageId() { return messageId; }
44 public void setMessageId(String messageId) { this.messageId = messageId; }
46 public String toJsonString() {
49 ObjectMapper mapper = new ObjectMapper();
50 mapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
51 jsonString = mapper.writeValueAsString(this);
53 } catch (Exception e) {
54 logger.error ("Exception:", e);
59 public String toXmlString() {
61 ByteArrayOutputStream bs = new ByteArrayOutputStream();
62 JAXBContext context = JAXBContext.newInstance(this.getClass());
63 Marshaller marshaller = context.createMarshaller();
64 marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); //pretty print XML
65 marshaller.marshal(this, bs);
67 } catch (Exception e) {
68 logger.error ("Exception:", e);
74 public String toString(){
75 return toJsonString();