當前位置: 首頁>>代碼示例>>Java>>正文


Java ContainerRequestContext.setEntityStream方法代碼示例

本文整理匯總了Java中javax.ws.rs.container.ContainerRequestContext.setEntityStream方法的典型用法代碼示例。如果您正苦於以下問題:Java ContainerRequestContext.setEntityStream方法的具體用法?Java ContainerRequestContext.setEntityStream怎麽用?Java ContainerRequestContext.setEntityStream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.ws.rs.container.ContainerRequestContext的用法示例。


在下文中一共展示了ContainerRequestContext.setEntityStream方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: extractRequestEntity

import javax.ws.rs.container.ContainerRequestContext; //導入方法依賴的package包/類
static String extractRequestEntity(ContainerRequestContext request) {
    if (request.hasEntity()) {
        InputStream inputStreamOriginal = request.getEntityStream();
        BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStreamOriginal, MAX_ENTITY_READ);
        bufferedInputStream.mark(MAX_ENTITY_READ);
        byte[] bytes = new byte[MAX_ENTITY_READ];
        int read;
        try {
            read = bufferedInputStream.read(bytes, 0, MAX_ENTITY_READ);
            bufferedInputStream.reset();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        request.setEntityStream(bufferedInputStream);

        return new String(bytes, Charsets.UTF_8);
    }
    return null;
}
 
開發者ID:code-obos,項目名稱:servicebuilder,代碼行數:20,代碼來源:ServerLogFilter.java

示例2: getEntityBody

import javax.ws.rs.container.ContainerRequestContext; //導入方法依賴的package包/類
/**
 * Return the body json in one String Object.
 */
public String getEntityBody(ContainerRequestContext requestContext) {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    InputStream in = requestContext.getEntityStream();

    String result = null;
    try {
        ReaderWriter.writeTo(in, out);

        byte[] requestEntity = out.toByteArray();
        if (requestEntity.length == 0) {
            result = "";
        } else {
            result = new String(requestEntity, "UTF-8");
        }
        requestContext.setEntityStream(new ByteArrayInputStream(requestEntity));

    } catch (IOException e) {
        LOGGER.error("Error to read the body of this request.");

        if (lyreProperties.isDebug()) {
            LOGGER.debug("Stacktrace", e);
        } else
            LOGGER.warn("\u21B3 " + "Enable debug mode to see stacktrace log");
    }
    return result;
}
 
開發者ID:groovylabs,項目名稱:lyre,代碼行數:30,代碼來源:EndpointUtils.java

示例3: getParametersMap

import javax.ws.rs.container.ContainerRequestContext; //導入方法依賴的package包/類
/**
 *  獲取請求參數
 * @param request
 * @param inputStream
 * @return
 * @throws IOException
 */
public static Map<String, Object> getParametersMap(ContainerRequestContext requestContext,
                                                   HttpServletRequest request) throws IOException {

    if (isMultipartContent(request)) {
        return buildQueryParamsMap(request);
    }

    Map<String, Object> parameters = buildQueryParamsMap(request);

    if (RestConst.GET_METHOD.equals(request.getMethod())) {
        return parameters;
    } else if (RestConst.POST_METHOD.equals(request.getMethod())) {

        byte[] byteArray = IOUtils.toByteArray(request.getInputStream());
        //reset InputStream
        requestContext.setEntityStream(new ByteArrayInputStream(byteArray));

        if (byteArray == null || byteArray.length == 0)
            return parameters;
        String content = new String(byteArray);
        //JSON 
        //			try {
        //				return JsonUtils.toObject(content, Map.class);
        //			} catch (Exception e) {}
        if (content.contains("{")) {
            content = StringUtils.left(content, 2048).trim();
            if (!content.endsWith("}"))
                content = content + "...\n}";
            parameters.put("data", content);
            return parameters;
        }

        String[] split = content.split("\\&");
        for (String s : split) {
            String[] split2 = s.split("=");
            if (split2.length == 2 && StringUtils.isNotBlank(split2[1])) {
                parameters.put(split2[0], split2[1]);
            }
        }
        return parameters;

    }
    return null;
}
 
開發者ID:warlock-china,項目名稱:azeroth,代碼行數:52,代碼來源:RequestUtils.java


注:本文中的javax.ws.rs.container.ContainerRequestContext.setEntityStream方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。