2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.appc.services.dmaapService;
24 import com.att.eelf.configuration.EELFLogger;
25 import com.att.eelf.configuration.EELFManager;
27 public class PublishRequest {
29 private static final EELFLogger LOG = EELFManager.getInstance().getLogger(PublishRequest.class);
32 private String partition;
33 private String message;
36 private PublishRequest(String props, String partition, String topic, String message) {
38 this.partition = partition;
39 this.message = message;
43 public String getProps() {
47 public String getPartition() {
51 public String getMessage() {
55 public String getTopic() {
59 public static PublishRequest parsePublishRequest(String data) {
60 //body content: props, partition, topic, message
61 String[] bodyParameters = new String[4];
62 LOG.debug("Parsing message into " + bodyParameters.length + " parts: " + data);
63 int[] bodyParameterSizes = new int[bodyParameters.length];
64 for(int i = 0; i < bodyParameters.length; i ++) {
65 String[] split = data.split("\\.", 2);
67 bodyParameterSizes[i] = Integer.parseInt(split[0]);
68 } catch(NumberFormatException e) {
69 LOG.error("Could not parse message: " + data);
74 for(int i = 0; i < bodyParameters.length; i ++) {
75 if(bodyParameterSizes[i] > 0) {
76 bodyParameters[i] = data.substring(cursor, cursor + bodyParameterSizes[i]);
77 cursor = cursor + bodyParameterSizes[i];
80 return new PublishRequest(bodyParameters[0], bodyParameters[1], bodyParameters[2], bodyParameters[3]);