本文整理汇总了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);
}
}
示例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);
}
}
示例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;
}
示例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);
}
}