当前位置: 首页>>代码示例>>Java>>正文


Java ContainerRequest.setEntityInputStream方法代码示例

本文整理汇总了Java中com.sun.jersey.spi.container.ContainerRequest.setEntityInputStream方法的典型用法代码示例。如果您正苦于以下问题:Java ContainerRequest.setEntityInputStream方法的具体用法?Java ContainerRequest.setEntityInputStream怎么用?Java ContainerRequest.setEntityInputStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.jersey.spi.container.ContainerRequest的用法示例。


在下文中一共展示了ContainerRequest.setEntityInputStream方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: safelyGetContent

import com.sun.jersey.spi.container.ContainerRequest; //导入方法依赖的package包/类
/**
 * Under normal circumstances, the body of the request can only be read once, because it is
 * backed by an {@code InputStream}, and thus is not easily consumed multiple times. This
 * method gets the request content and resets it so it can be read again later if necessary.
 */
private byte[] safelyGetContent(HttpRequestContext request) {
    ContainerRequest containerRequest = (ContainerRequest) request;
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    InputStream in = containerRequest.getEntityInputStream();

    try {
        ReaderWriter.writeTo(in, out);
        byte[] content = out.toByteArray();

        // Reset the input stream so that it can be read again by another filter or resource
        containerRequest.setEntityInputStream(new ByteArrayInputStream(content));
        return content;

    } catch (IOException ex) {
        throw new ContainerException(ex);
    }
}
 
开发者ID:bazaarvoice,项目名称:jersey-hmac-auth,代码行数:23,代码来源:RequestDecoder.java

示例2: validate

import com.sun.jersey.spi.container.ContainerRequest; //导入方法依赖的package包/类
private void validate(ContainerRequest request) {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    InputStream in = request.getEntityInputStream();
    try {
        ReaderWriter.writeTo(in, out);
        byte[] requestEntity = out.toByteArray();
        ByteArrayInputStream bais =
                new ByteArrayInputStream(requestEntity);
        request.setEntityInputStream(bais);
        String entity = new String(requestEntity, ReaderWriter
                .getCharset(request.getMediaType()));
        if (entity.isEmpty()) {
            throw new WebApplicationException(Status.BAD_REQUEST);
        }
        JsonNode tree;
        try {
            tree = reader.readTree(entity);
        } catch (JsonParseException e) {
            throw new WebApplicationException(e, Status.BAD_REQUEST);
        }
        JSONSchemaResourceFilterFactory.this.validate(tree, schema);
    } catch (IOException ex) {
        throw new ContainerException(ex);
    }
}
 
开发者ID:enviroCar,项目名称:enviroCar-server,代码行数:26,代码来源:JSONSchemaResourceFilterFactory.java

示例3: filter

import com.sun.jersey.spi.container.ContainerRequest; //导入方法依赖的package包/类
public ContainerRequest filter(ContainerRequest request) {
	ByteArrayOutputStream baos = getClonedInputStream(request.getEntityInputStream());
	request.setEntityInputStream(new ByteArrayInputStream(baos.toByteArray())); 
	authenticator.authenticate(request);
	request.setEntityInputStream(new ByteArrayInputStream(baos.toByteArray())); 
	return request;
}
 
开发者ID:PE-INTERNATIONAL,项目名称:soda4lca,代码行数:8,代码来源:SecurityFilter.java

示例4: build

import com.sun.jersey.spi.container.ContainerRequest; //导入方法依赖的package包/类
public static CacheRequestContext build(ContainerRequest request, Set<String> vary, boolean includeBody) {
    try {
        MessageDigest digest = MessageDigest.getInstance("SHA-1");

        for (String header : vary) {
            List<String> headerValues = request.getRequestHeader(header);

            if (headerValues != null && headerValues.size() > 0) {
                digest.update(header.getBytes(Charsets.UTF_8));
                digest.update((byte) 0xFD);

                for (String value : headerValues) {
                    digest.update(value.getBytes(Charsets.UTF_8));
                    digest.update((byte) 0xFE);
                }

                digest.update((byte) 0xFF);
            }
        }

        if (includeBody) {
            byte[] requestBody = request.getEntity(byte[].class);

            if (requestBody == null) {
                requestBody = new byte[0];
            }

            if (requestBody.length > 0) {
                digest.update("Body".getBytes(Charsets.UTF_8));
                digest.update((byte) 0xFD);

                digest.update(requestBody);
                digest.update((byte) 0xFF);
            }

            request.setEntityInputStream(new ByteArrayInputStream(requestBody));
        }

        String hash = new String(Base64.encode(digest.digest()), Charsets.US_ASCII);
        return new CacheRequestContext(request.getMethod(), request.getRequestUri(), request.getRequestHeaders(), hash);
    } catch (NoSuchAlgorithmException ex) {
        // This error should not occur since SHA-1 must be included with every java distribution
        throw Throwables.propagate(ex);
    }
}
 
开发者ID:bazaarvoice,项目名称:dropwizard-caching-bundle,代码行数:46,代码来源:CacheRequestContext.java


注:本文中的com.sun.jersey.spi.container.ContainerRequest.setEntityInputStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。