2 * ============LICENSE_START======================================================= ONAP
3 * ================================================================================ Copyright (C) 2019 AT&T Intellectual
4 * Property. All rights reserved. ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
11 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
12 * specific language governing permissions and limitations under the License.
13 * ============LICENSE_END=========================================================
16 package org.onap.policy.models.sim.dmaap.rest;
18 import java.io.BufferedReader;
19 import java.io.IOException;
20 import java.io.InputStream;
21 import java.io.InputStreamReader;
22 import java.lang.annotation.Annotation;
23 import java.lang.reflect.Type;
24 import javax.ws.rs.Consumes;
25 import javax.ws.rs.Produces;
26 import javax.ws.rs.core.MediaType;
27 import javax.ws.rs.core.MultivaluedMap;
28 import javax.ws.rs.ext.MessageBodyReader;
29 import javax.ws.rs.ext.Provider;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
34 * Provider that serializes and de-serializes JSON via gson.
37 @Consumes(MediaType.APPLICATION_JSON)
38 @Produces(MediaType.APPLICATION_JSON)
39 public class JsonMessageBodyHandler implements MessageBodyReader<Object> {
40 public static final Logger logger = LoggerFactory.getLogger(JsonMessageBodyHandler.class);
43 public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
44 return MediaType.APPLICATION_JSON.equals(mediaType.toString());
48 public String readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType,
49 MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
52 String jsonString = "";
53 try (BufferedReader bufferedReader = new BufferedReader(
54 new InputStreamReader(entityStream))) {
56 while ((line = bufferedReader.readLine()) != null) {