本文整理汇总了Java中org.apache.http.impl.io.SessionInputBufferImpl.bind方法的典型用法代码示例。如果您正苦于以下问题:Java SessionInputBufferImpl.bind方法的具体用法?Java SessionInputBufferImpl.bind怎么用?Java SessionInputBufferImpl.bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.impl.io.SessionInputBufferImpl
的用法示例。
在下文中一共展示了SessionInputBufferImpl.bind方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: withBody
import org.apache.http.impl.io.SessionInputBufferImpl; //导入方法依赖的package包/类
/**
* Set the body of the request by providing an InputStream
*
* @param body the bytes of the body
* @param contentLength how long the body is supposed to be
*/
public EventBuilder withBody(InputStream body, int contentLength) {
Objects.requireNonNull(body, "body");
if (contentLength < 0) {
throw new IllegalArgumentException("Invalid contentLength");
}
// This is for safety. Because we concatenate events, an input stream shorter than content length will cause
// the implementation to continue reading through to the next http request. We need to avoid a sort of
// buffer overrun.
// FIXME: Make InputStream handling simpler.
SessionInputBufferImpl sib = new SessionInputBufferImpl(new HttpTransportMetricsImpl(), 65535);
sib.bind(body);
this.body = new ContentLengthInputStream(sib, contentLength);
this.contentLength = contentLength;
return this;
}
示例2: unchunkResponse
import org.apache.http.impl.io.SessionInputBufferImpl; //导入方法依赖的package包/类
/**
* Converts chunked response data (returned by in the request body) <br>
* into a single piece, regular byte array.
*
* @param content Chunked data byte array
* @return Unchunked (regular) byte array
*/
public byte[] unchunkResponse(byte[] content) {
SessionInputBufferImpl buffer =
new SessionInputBufferImpl(new HttpTransportMetricsImpl(), 1024);
buffer.bind(new ByteArrayInputStream(content));
try {
if (content != null && content.length > 0) {
return IOUtils.toByteArray(new ChunkedInputStream(buffer));
}
} catch (IOException e) {
LOG.error("Cannot write chunked input stream to byte array!", e);
}
return content;
}
示例3: withBody
import org.apache.http.impl.io.SessionInputBufferImpl; //导入方法依赖的package包/类
public FnHttpEventBuilder withBody(InputStream body, int contentLength) {
Objects.requireNonNull(body, "body");
if (contentLength < 0) {
throw new IllegalArgumentException("Invalid contentLength");
}
// This is for safety. Because we concatenate events, an input stream shorter than content length will cause
// the implementation to continue reading through to the next http request. We need to avoid a sort of
// buffer overrun.
// FIXME: Make InputStream handling simpler.
SessionInputBufferImpl sib = new SessionInputBufferImpl(new HttpTransportMetricsImpl(), 65535);
sib.bind(body);
this.bodyStream = new ContentLengthInputStream(sib, contentLength);
this.contentLength = contentLength;
return this;
}
示例4: parseExpectedResponse
import org.apache.http.impl.io.SessionInputBufferImpl; //导入方法依赖的package包/类
private ExpectedResult parseExpectedResponse(Element element, Evaluator evaluator, ResultRecorder resultRecorder) {
String contents = getTextAndRemoveIndent(element);
contents = replaceVariableReferences(evaluator, contents, resultRecorder);
SessionInputBufferImpl buffer = new SessionInputBufferImpl(new HttpTransportMetricsImpl(), contents.length());
buffer.bind(new ByteArrayInputStream(contents.getBytes(StandardCharsets.UTF_8)));
DefaultHttpResponseParser defaultHttpResponseParser = new DefaultHttpResponseParser(buffer);
ExpectedResult.ExpectedResultBuilder builder = expectedResult();
String body = null;
try {
HttpResponse httpResponse = defaultHttpResponseParser.parse();
StatusLine statusLine = httpResponse.getStatusLine();
builder.withStatus(statusLine.getStatusCode());
for (Header header : httpResponse.getAllHeaders()) {
builder.withHeader(header.getName(), header.getValue());
}
if (buffer.hasBufferedData()) {
body = "";
while (buffer.hasBufferedData()) {
body += (char) buffer.read();
}
}
builder.withBody(body);
} catch (IOException | HttpException e) {
e.printStackTrace();
}
return builder.build();
}
示例5: setInput
import org.apache.http.impl.io.SessionInputBufferImpl; //导入方法依赖的package包/类
protected void setInput(final InputStream input) {
final SessionInputBufferImpl bufferImpl = new SessionInputBufferImpl(metrics, BUFFER_SIZE, 0, null, null);
bufferImpl.bind(input);
this.buffer = bufferImpl;
this.payload = null;
}
示例6: warpSessionInputBuffer
import org.apache.http.impl.io.SessionInputBufferImpl; //导入方法依赖的package包/类
public static SessionInputBuffer warpSessionInputBuffer(final InputStream input) {
final SessionInputBufferImpl bufferImpl = new SessionInputBufferImpl(new HttpTransportMetricsImpl(), 1024, 0, null, null);
bufferImpl.bind(input);
return bufferImpl;
}
示例7: run
import org.apache.http.impl.io.SessionInputBufferImpl; //导入方法依赖的package包/类
/** {@inheritDoc} */
public boolean run() {
boolean success = false;
String error = null;
try {
String bu = context.getSpecification().getBaseUrl();
if (bu.startsWith("https")) {
return true;
}
URI uri = new URI(bu);
String host = uri.getHost();
context.acquireRequestPermit();
Socket socket = new Socket(host, HTTP_PORT);
OutputStream os = socket.getOutputStream();
String request = "GET " + rawUri + " HTTP/1.1\n"
+ "Host: " + host + "\n"
+ "Accept: application/rdap+json\n\n";
os.write(request.getBytes("UTF-8"));
InputStream is = socket.getInputStream();
SessionInputBufferImpl sibl =
new SessionInputBufferImpl(
new HttpTransportMetricsImpl(),
BUFFER_SIZE
);
sibl.bind(is);
DefaultHttpResponseParser dhrp =
new DefaultHttpResponseParser(sibl);
HttpResponse hr = dhrp.parse();
HttpEntity he = hr.getEntity();
/* It is assumed that this class is used to produce
* invalid requests. The error codes aren't checked here;
* it's just for confirming that the content (if present)
* is JSON. With some servers, e.g. Jetty, it's not
* possible to do things like setting the content type in
* this sort of situation, so that is explicitly not
* checked. */
if ((he == null) || (he.getContentLength() == 0)) {
success = true;
} else {
InputStream isc = he.getContent();
InputStreamReader iscr = new InputStreamReader(isc, "UTF-8");
new Gson().fromJson(iscr, Map.class);
success = true;
}
} catch (Exception e) {
error = e.toString();
}
Result nr = new Result(proto);
nr.setPath(rawUri);
nr.setCode("content");
if (success) {
nr.setStatus(Status.Success);
} else if (!nr.getStatusSet()) {
nr.setStatus(Status.Failure);
}
String prefix = (expectedSuccess) ? "content" : "error content";
nr.setInfo(success ? prefix + " is empty or JSON"
: prefix + " is not empty or JSON: " + error);
context.addResult(nr);
return success;
}
示例8: parseRequest
import org.apache.http.impl.io.SessionInputBufferImpl; //导入方法依赖的package包/类
private HttpRequest parseRequest(Element element, Evaluator evaluator, ResultRecorder resultRecorder) {
String contents = getTextAndRemoveIndent(element);
contents = replaceVariableReferences(evaluator, contents, resultRecorder);
SessionInputBufferImpl buffer = new SessionInputBufferImpl(new HttpTransportMetricsImpl(), contents.length());
buffer.bind(new ByteArrayInputStream(contents.getBytes(StandardCharsets.UTF_8)));
DefaultHttpRequestParser defaultHttpRequestParser = new DefaultHttpRequestParser(buffer);
LinkedListMultimap<String, String> queryParameters = LinkedListMultimap.create();
String method = "";
String url = "";
LinkedListMultimap<String, String> headers = LinkedListMultimap.create();
String body = null;
String server = null;
try {
org.apache.http.HttpRequest httpRequest = defaultHttpRequestParser.parse();
method = httpRequest.getRequestLine().getMethod();
url = httpRequest.getRequestLine().getUri();
if (url.startsWith("#")) {
url = "" + evaluator.evaluate(url);
}
Matcher matcher = Pattern.compile("(https?://[^/]+)(/.*)").matcher(url);
if (matcher.matches()) {
server = matcher.group(1);
url = matcher.group(2);
}
if (url.contains("?")) {
String[] urlAndQueryParameters = url.split("\\?");
url = urlAndQueryParameters[0];
for (String queryParameter : urlAndQueryParameters[1].split("&")) {
String[] parameter = queryParameter.split("=");
queryParameters.put(parameter[0], parameter[1]);
}
}
for (Header header : httpRequest.getAllHeaders()) {
headers.put(header.getName(), header.getValue());
}
if (buffer.hasBufferedData()) {
body = "";
while (buffer.hasBufferedData()) {
body += (char) buffer.read();
}
}
} catch (IOException | HttpException e) {
e.printStackTrace();
}
return new HttpRequest(method, url, headers, body, server, queryParameters);
}