本文整理汇总了Java中org.eclipse.jetty.io.ByteArrayBuffer类的典型用法代码示例。如果您正苦于以下问题:Java ByteArrayBuffer类的具体用法?Java ByteArrayBuffer怎么用?Java ByteArrayBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ByteArrayBuffer类属于org.eclipse.jetty.io包,在下文中一共展示了ByteArrayBuffer类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sentRequest
import org.eclipse.jetty.io.ByteArrayBuffer; //导入依赖的package包/类
public static int sentRequest(final String url, final String method, final String content) throws Exception {
HttpClient httpClient = new HttpClient();
try {
httpClient.start();
ContentExchange contentExchange = new ContentExchange();
contentExchange.setMethod(method);
contentExchange.setRequestContentType(MediaType.APPLICATION_JSON);
contentExchange.setRequestContent(new ByteArrayBuffer(content.getBytes("UTF-8")));
httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
contentExchange.setURL(url);
httpClient.send(contentExchange);
contentExchange.waitForDone();
return contentExchange.getResponseStatus();
} finally {
httpClient.stop();
}
}
示例2: sentRequest
import org.eclipse.jetty.io.ByteArrayBuffer; //导入依赖的package包/类
private static ContentExchange sentRequest(final String content) throws Exception {
HttpClient httpClient = new HttpClient();
try {
httpClient.start();
ContentExchange result = new ContentExchange();
result.setMethod("POST");
result.setRequestContentType(MediaType.APPLICATION_JSON);
result.setRequestContent(new ByteArrayBuffer(content.getBytes("UTF-8")));
httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
result.setURL(URL);
httpClient.send(result);
result.waitForDone();
return result;
} finally {
httpClient.stop();
}
}
示例3: postData
import org.eclipse.jetty.io.ByteArrayBuffer; //导入依赖的package包/类
public static InvokeResult postData(String url, String params) {
if (StringUtils.isBlank(url) || StringUtils.isBlank(params)) {
return InvokeResult.errorResult;
}
ContentExchange contentExchange = new ContentExchange();
contentExchange.setMethod(HttpMethod.POST.getValue());
contentExchange.setURL(url);
try {
AbstractBuffer content = new ByteArrayBuffer(params.getBytes(InvokerMsg.CHARSET_UTF8));
contentExchange.setRequestContent(content);
return invoke(contentExchange);
} catch (UnsupportedEncodingException e) {
logger.error(e.getMessage(), e);
}
return InvokeResult.errorResult;
}
示例4: putData
import org.eclipse.jetty.io.ByteArrayBuffer; //导入依赖的package包/类
public static InvokeResult putData(String url, String params) {
if (StringUtils.isBlank(url) || StringUtils.isBlank(params)) {
return InvokeResult.errorResult;
}
ContentExchange contentExchange = new ContentExchange();
contentExchange.setMethod(HttpMethod.PUT.getValue());
contentExchange.setURL(url);
try {
AbstractBuffer content = new ByteArrayBuffer(params.getBytes(InvokerMsg.CHARSET_UTF8));
contentExchange.setRequestContent(content);
return invoke(contentExchange);
} catch (UnsupportedEncodingException e) {
logger.error(e.getMessage(), e);
}
return InvokeResult.errorResult;
}
示例5: asyncPost
import org.eclipse.jetty.io.ByteArrayBuffer; //导入依赖的package包/类
/**
* Sends an HTTP POST request using the asynchronous client
*
* @param Path
* Path of the requested resource
* @param Args
* Arguments for the request
* @param Callback
* Callback to handle the response with
*/
public HttpExchange asyncPost(String path, String args, FritzahaCallback callback) {
if (!isAuthenticated())
authenticate();
HttpExchange postExchange = new FritzahaContentExchange(callback);
postExchange.setMethod("POST");
postExchange.setURL(getURL(path));
try {
postExchange.setRequestContent(new ByteArrayBuffer(addSID(args).getBytes("UTF-8")));
} catch (UnsupportedEncodingException e1) {
logger.error("An encoding error occurred in the POST arguments");
return null;
}
postExchange.setRequestContentType("application/x-www-form-urlencoded;charset=utf-8");
try {
asyncclient.send(postExchange);
} catch (IOException e) {
logger.error("An I/O error occurred while sending the POST request to " + getURL(path));
return null;
}
return postExchange;
}
示例6: putDateField
import org.eclipse.jetty.io.ByteArrayBuffer; //导入依赖的package包/类
/**
* Sets the value of a date field.
*
* @param name the field name
* @param date the field date value
*/
public void putDateField(Buffer name, long date)
{
String d=formatDate(date);
Buffer v = new ByteArrayBuffer(d);
put(name, v);
}
示例7: addDateField
import org.eclipse.jetty.io.ByteArrayBuffer; //导入依赖的package包/类
/**
* Sets the value of a date field.
*
* @param name the field name
* @param date the field date value
*/
public void addDateField(String name, long date)
{
String d=formatDate(date);
Buffer n = HttpHeaders.CACHE.lookup(name);
Buffer v = new ByteArrayBuffer(d);
add(n, v);
}
示例8: sendHttpRequest
import org.eclipse.jetty.io.ByteArrayBuffer; //导入依赖的package包/类
private void sendHttpRequest(JsonRpcClientRequest rpcRequest) throws IOException {
// serialize the request
ObjectNode requestNode = rpcRequest.getRequest();
byte[] data = getMapper().writeValueAsBytes(requestNode);
ByteArrayBuffer bytes = new ByteArrayBuffer(data);
// build the HTTP exchange
JsonRpcHttpExchange exchange = new JsonRpcHttpExchange(this, rpcRequest);
exchange.setMethod("POST");
exchange.setURI(mUri);
exchange.setRequestContent(bytes);
exchange.setRequestContentType(mContentType);
// perform the exchange
mClient.send(exchange);
}
示例9: streamingHandshake
import org.eclipse.jetty.io.ByteArrayBuffer; //导入依赖的package包/类
public GenericContentExchange streamingHandshake(String instance, String sessionId) throws IOException {
GenericContentExchange exchange = new GenericContentExchange();
//ContentExchange exchange = new ContentExchange();
exchange.setMethod("POST");
exchange.setURL(instance + SfdcConstants.DEFAULT_PUSH_ENDPOINT + SfdcConstants.HANDSHAKE);
exchange.setRequestHeader("Authorization", "Bearer " + sessionId);
exchange.setRequestHeader("Content-Type", "application/json");
AbstractBuffer buffer = new ByteArrayBuffer(SfdcConstants.HANDSHAKE_MESSAGE.getBytes());
exchange.setRequestContent(buffer);
send(exchange);
return exchange;
}