From 880c8580cc3b52b725e6993967e1da8840eaf8f3 Mon Sep 17 00:00:00 2001 From: guochuyicmri Date: Mon, 10 Dec 2018 17:37:41 +0800 Subject: Modify the get request body method Change-Id: Id11555490f6fc7758933a537e76d862af9eb6a05 Issue-ID: USECASEUI-170 Signed-off-by: guochuyicmri --- server/pom.xml | 6 ++++++ .../java/org/onap/usecaseui/server/util/RestfulServices.java | 12 +++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/server/pom.xml b/server/pom.xml index 0817d8ef..71adf3c7 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -204,6 +204,12 @@ fastjson 1.2.23 + + + com.alibaba + dubbo + 2.6.5 + org.openecomp.sdc.jtosca jtosca diff --git a/server/src/main/java/org/onap/usecaseui/server/util/RestfulServices.java b/server/src/main/java/org/onap/usecaseui/server/util/RestfulServices.java index 6441d0ef..5aa22344 100644 --- a/server/src/main/java/org/onap/usecaseui/server/util/RestfulServices.java +++ b/server/src/main/java/org/onap/usecaseui/server/util/RestfulServices.java @@ -15,7 +15,9 @@ */ package org.onap.usecaseui.server.util; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStreamReader; import javax.servlet.ServletInputStream; import javax.servlet.http.HttpServletRequest; @@ -23,6 +25,8 @@ import javax.servlet.http.HttpServletRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.alibaba.dubbo.common.utils.IOUtils; + import okhttp3.MediaType; import okhttp3.RequestBody; import retrofit2.Retrofit; @@ -58,14 +62,12 @@ public class RestfulServices { } public static RequestBody extractBody(HttpServletRequest request) throws IOException { - int len = request.getContentLength(); ServletInputStream inStream = null; try { inStream = request.getInputStream(); - byte[] buffer = new byte[len]; - inStream.read(buffer, 0, len); - logger.info("The request body content is: "+new String(buffer)); - return RequestBody.create(MediaType.parse("application/json"), buffer); + BufferedReader reader = new BufferedReader(new InputStreamReader(inStream)); + logger.info("The request body content is: "+IOUtils.read(reader)); + return RequestBody.create(MediaType.parse("application/json"), IOUtils.read(reader)); }finally { if (inStream != null) { inStream.close(); -- cgit 1.2.3-korg