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;
29 import javax.xml.bind.JAXBContext;
30 import javax.xml.bind.Marshaller;
31 import com.fasterxml.jackson.annotation.JsonIgnore;
32 import com.fasterxml.jackson.annotation.JsonProperty;
33 import com.fasterxml.jackson.databind.ObjectMapper;
34 import com.fasterxml.jackson.databind.SerializationFeature;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
39 * Everything that is common between all Network Requests.
41 public abstract class NetworkRequestCommon implements Serializable {
42 private static final long serialVersionUID = -6732431343649282079L;
43 private static final Logger logger = LoggerFactory.getLogger(NetworkRequestCommon.class);
44 private Boolean skipAAI = false;
45 private String messageId;
46 private String notificationUrl;
48 private boolean synchronous = true;
50 public Boolean getSkipAAI() {
54 public void setSkipAAI(Boolean skipAAI) {
55 this.skipAAI = skipAAI;
58 public String getMessageId() {
62 public void setMessageId(String messageId) {
63 this.messageId = messageId;
66 public String getNotificationUrl() {
67 return notificationUrl;
70 public void setNotificationUrl(String notificationUrl) {
71 this.notificationUrl = notificationUrl;
72 this.synchronous = notificationUrl == null || (notificationUrl.isEmpty());
75 public boolean isSynchronous() {
76 return this.synchronous;
80 protected void setSynchronous(boolean synchronous) {
81 this.synchronous = synchronous;
84 public String toJsonString() {
85 String jsonString = null;
87 ObjectMapper mapper = new ObjectMapper();
88 mapper.enable(SerializationFeature.WRAP_ROOT_VALUE);
89 jsonString = mapper.writeValueAsString(this);
90 } catch (Exception e) {
91 logger.debug("Exception:", e);
96 public String toXmlString() {
98 ByteArrayOutputStream bs = new ByteArrayOutputStream();
99 JAXBContext context = JAXBContext.newInstance(this.getClass());
100 Marshaller marshaller = context.createMarshaller();
101 marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); // pretty print XML
102 marshaller.marshal(this, bs);
103 return bs.toString();
104 } catch (Exception e) {
105 logger.debug("Exception:", e);