當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。