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 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.adapters.nwrest;
27 import java.io.ByteArrayOutputStream;
28 import java.io.Serializable;
30 import javax.xml.bind.JAXBContext;
31 import javax.xml.bind.Marshaller;
33 import com.fasterxml.jackson.annotation.JsonIgnore;
34 import com.fasterxml.jackson.annotation.JsonProperty;
35 import com.fasterxml.jackson.databind.ObjectMapper;
36 import com.fasterxml.jackson.databind.SerializationFeature;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
41 * Everything that is common between all Network Requests.
43 public abstract class NetworkRequestCommon implements Serializable {
44 private static final long serialVersionUID = -6732431343649282079L;
45 private static final Logger logger = LoggerFactory.getLogger(NetworkRequestCommon.class);
46 private Boolean skipAAI = false;
47 private String messageId;
48 private String notificationUrl;
50 private boolean synchronous = true;
51 public Boolean getSkipAAI() {
55 public void setSkipAAI(Boolean skipAAI) {
56 this.skipAAI = skipAAI;
59 public String getMessageId() {
63 public void setMessageId(String messageId) {
64 this.messageId = messageId;
67 public String getNotificationUrl() {
68 return notificationUrl;
71 public void setNotificationUrl(String notificationUrl) {
72 this.notificationUrl = notificationUrl;
73 this.synchronous = notificationUrl == null || (notificationUrl.isEmpty());
76 public boolean isSynchronous() {
77 return this.synchronous;
81 protected void setSynchronous(boolean synchronous) {
82 this.synchronous = synchronous;
85 public String toJsonString() {
86 String jsonString = null;
88 ObjectMapper mapper = new ObjectMapper();
89 mapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
90 jsonString = mapper.writeValueAsString(this);
91 } catch (Exception e) {
92 logger.debug("Exception:", e);
97 public String toXmlString() {
99 ByteArrayOutputStream bs = new ByteArrayOutputStream();
100 JAXBContext context = JAXBContext.newInstance(this.getClass());
101 Marshaller marshaller = context.createMarshaller();
102 marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); //pretty print XML
103 marshaller.marshal(this, bs);
104 return bs.toString();
105 } catch (Exception e) {
106 logger.debug("Exception:", e);