2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2023 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.models.sim.dmaap.rest;
24 import jakarta.ws.rs.Consumes;
25 import jakarta.ws.rs.core.MediaType;
26 import jakarta.ws.rs.core.MultivaluedMap;
27 import jakarta.ws.rs.ext.MessageBodyReader;
28 import jakarta.ws.rs.ext.Provider;
29 import java.io.BufferedReader;
30 import java.io.IOException;
31 import java.io.InputStream;
32 import java.io.InputStreamReader;
33 import java.lang.annotation.Annotation;
34 import java.lang.reflect.Type;
35 import java.nio.charset.StandardCharsets;
36 import java.util.LinkedList;
37 import java.util.List;
40 * Provider that decodes "text/plain" messages.
43 @Consumes(TextMessageBodyHandler.MEDIA_TYPE_TEXT_PLAIN)
44 public class TextMessageBodyHandler implements MessageBodyReader<Object> {
45 public static final String MEDIA_TYPE_TEXT_PLAIN = "text/plain";
48 public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
49 return (mediaType != null && MEDIA_TYPE_TEXT_PLAIN.equals(mediaType.toString()));
53 public List<Object> readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType,
54 MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException {
56 try (var bufferedReader = new BufferedReader(new InputStreamReader(entityStream, StandardCharsets.UTF_8))) {
57 List<Object> messages = new LinkedList<>();
59 while ((msg = bufferedReader.readLine()) != null) {