本文整理了Java中com.vmware.xenon.common.Utils.encodeBody()
方法的一些代码示例,展示了Utils.encodeBody()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.encodeBody()
方法的具体详情如下:
包路径:com.vmware.xenon.common.Utils
类名称:Utils
方法名:encodeBody
暂无
代码示例来源:origin: vmware/xenon
public static byte[] encodeBody(Operation op, boolean isRequest) throws Exception {
return encodeBody(op, op.getBodyRaw(), op.getContentType(), isRequest);
}
代码示例来源:origin: vmware/xenon
byte[] data = Utils.encodeBody(request, false);
代码示例来源:origin: vmware/xenon
private void sendHttpRequest(Operation op) {
final Object originalBody = op.getBodyRaw();
try {
byte[] body = Utils.encodeBody(op, true);
if (op.getContentLength() > getRequestPayloadSizeLimit()) {
String error = String.format("Content length %d, limit is %d",
代码示例来源:origin: vmware/xenon
@Test
public void testEncodeGzipResponseBody() throws Throwable {
String body = "This is the original body content, but gzipped";
byte[] gzippedBody = compress(body);
Operation op = Operation
.createGet(null)
.setContentLength(body.length())
.setBody(body)
.addRequestHeader(Operation.ACCEPT_ENCODING_HEADER,
Operation.CONTENT_ENCODING_GZIP)
.addResponseHeader(Operation.CONTENT_TYPE_HEADER, Operation.MEDIA_TYPE_TEXT_PLAIN);
byte[] encodedBody = Utils.encodeBody(op, body, Operation.MEDIA_TYPE_TEXT_PLAIN, false);
assertTrue(Arrays.equals(gzippedBody, encodedBody));
// Content encoding header is present
assertEquals(op.getResponseHeader(Operation.CONTENT_ENCODING_HEADER),
Operation.CONTENT_ENCODING_GZIP);
}
代码示例来源:origin: com.vmware.xenon/xenon-common
@Test
public void testEncodeGzipResponseBody() throws Throwable {
String body = "This is the original body content, but gzipped";
byte[] gzippedBody = compress(body);
Operation op = Operation
.createGet(null)
.setContentLength(body.length())
.setBody(body)
.addRequestHeader(Operation.ACCEPT_ENCODING_HEADER,
Operation.CONTENT_ENCODING_GZIP)
.addResponseHeader(Operation.CONTENT_TYPE_HEADER, Operation.MEDIA_TYPE_TEXT_PLAIN);
byte[] encodedBody = Utils.encodeBody(op, body, Operation.MEDIA_TYPE_TEXT_PLAIN, false);
assertTrue(Arrays.equals(gzippedBody, encodedBody));
// Content encoding header is present
assertEquals(op.getResponseHeader(Operation.CONTENT_ENCODING_HEADER),
Operation.CONTENT_ENCODING_GZIP);
}
代码示例来源:origin: vmware/xenon
/**
* Infrastructure use. Serializes linked state associated with source operation
* and sets the result as the body of the target operation
*/
public static void encodeAndTransferLinkedStateToBody(Operation source, Operation target,
boolean useBinary) {
if (useBinary && source.getAction() != Action.POST) {
try {
byte[] encodedBody = Utils.encodeBody(source, source.getLinkedState(),
Operation.MEDIA_TYPE_APPLICATION_KRYO_OCTET_STREAM, true);
source.linkSerializedState(encodedBody);
} catch (Exception e2) {
Utils.logWarning("Failure binary serializing, will fallback to JSON: %s",
Utils.toString(e2));
}
}
if (!source.hasLinkedSerializedState()) {
target.setContentType(Operation.MEDIA_TYPE_APPLICATION_JSON);
target.setBodyNoCloning(Utils.toJson(source.getLinkedState()));
} else {
target.setContentType(Operation.MEDIA_TYPE_APPLICATION_KRYO_OCTET_STREAM);
target.setBodyNoCloning(source.getLinkedSerializedState());
}
}
内容来源于网络,如有侵权,请联系作者删除!