当前位置: 首页>>代码示例>>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;未经允许,请勿转载。