本文整理汇总了Java中org.apache.http.io.SessionInputBuffer类的典型用法代码示例。如果您正苦于以下问题:Java SessionInputBuffer类的具体用法?Java SessionInputBuffer怎么用?Java SessionInputBuffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SessionInputBuffer类属于org.apache.http.io包,在下文中一共展示了SessionInputBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSessionInputBuffer
import org.apache.http.io.SessionInputBuffer; //导入依赖的package包/类
@Override
protected SessionInputBuffer createSessionInputBuffer(
final Socket socket,
int buffersize,
final HttpParams params) throws IOException {
if (buffersize == -1) {
buffersize = 8192;
}
SessionInputBuffer inbuffer = super.createSessionInputBuffer(
socket,
buffersize,
params);
if (wireLog.isDebugEnabled()) {
inbuffer = new LoggingSessionInputBuffer(
inbuffer,
new Wire(wireLog),
HttpProtocolParams.getHttpElementCharset(params));
}
return inbuffer;
}
示例2: init
import org.apache.http.io.SessionInputBuffer; //导入依赖的package包/类
/**
* Initializes this connection object with {@link SessionInputBuffer} and
* {@link SessionOutputBuffer} instances to be used for sending and
* receiving data. These session buffers can be bound to any arbitrary
* physical output medium.
* <p>
* This method will invoke {@link #createHttpResponseFactory()},
* {@link #createRequestWriter(SessionOutputBuffer, HttpParams)}
* and {@link #createResponseParser(SessionInputBuffer, HttpResponseFactory, HttpParams)}
* methods to initialize HTTP request writer and response parser for this
* connection.
*
* @param inbuffer the session input buffer.
* @param outbuffer the session output buffer.
* @param params HTTP parameters.
*/
protected void init(
final SessionInputBuffer inbuffer,
final SessionOutputBuffer outbuffer,
final HttpParams params) {
if (inbuffer == null) {
throw new IllegalArgumentException("Input session buffer may not be null");
}
if (outbuffer == null) {
throw new IllegalArgumentException("Output session buffer may not be null");
}
this.inbuffer = inbuffer;
this.outbuffer = outbuffer;
if (inbuffer instanceof EofSensor) {
this.eofSensor = (EofSensor) inbuffer;
}
this.responseParser = createResponseParser(
inbuffer,
createHttpResponseFactory(),
params);
this.requestWriter = createRequestWriter(
outbuffer, params);
this.metrics = createConnectionMetrics(
inbuffer.getMetrics(),
outbuffer.getMetrics());
}
示例3: init
import org.apache.http.io.SessionInputBuffer; //导入依赖的package包/类
/**
* Initializes this connection object with {@link SessionInputBuffer} and
* {@link SessionOutputBuffer} instances to be used for sending and
* receiving data. These session buffers can be bound to any arbitrary
* physical output medium.
* <p>
* This method will invoke {@link #createHttpRequestFactory},
* {@link #createRequestParser(SessionInputBuffer, HttpRequestFactory, HttpParams)}
* and {@link #createResponseWriter(SessionOutputBuffer, HttpParams)}
* methods to initialize HTTP request parser and response writer for this
* connection.
*
* @param inbuffer the session input buffer.
* @param outbuffer the session output buffer.
* @param params HTTP parameters.
*/
protected void init(
final SessionInputBuffer inbuffer,
final SessionOutputBuffer outbuffer,
final HttpParams params) {
if (inbuffer == null) {
throw new IllegalArgumentException("Input session buffer may not be null");
}
if (outbuffer == null) {
throw new IllegalArgumentException("Output session buffer may not be null");
}
this.inbuffer = inbuffer;
this.outbuffer = outbuffer;
if (inbuffer instanceof EofSensor) {
this.eofSensor = (EofSensor) inbuffer;
}
this.requestParser = createRequestParser(
inbuffer,
createHttpRequestFactory(),
params);
this.responseWriter = createResponseWriter(
outbuffer, params);
this.metrics = createConnectionMetrics(
inbuffer.getMetrics(),
outbuffer.getMetrics());
}
示例4: AbstractMessageParser
import org.apache.http.io.SessionInputBuffer; //导入依赖的package包/类
/**
* Creates an instance of this class.
*
* @param buffer the session input buffer.
* @param parser the line parser.
* @param params HTTP parameters.
*/
public AbstractMessageParser(
final SessionInputBuffer buffer,
final LineParser parser,
final HttpParams params) {
super();
if (buffer == null) {
throw new IllegalArgumentException("Session input buffer may not be null");
}
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
this.sessionBuffer = buffer;
this.maxHeaderCount = params.getIntParameter(
CoreConnectionPNames.MAX_HEADER_COUNT, -1);
this.maxLineLen = params.getIntParameter(
CoreConnectionPNames.MAX_LINE_LENGTH, -1);
this.lineParser = (parser != null) ? parser : BasicLineParser.DEFAULT;
this.headerLines = new ArrayList<CharArrayBuffer>();
this.state = HEAD_LINE;
}
示例5: createSessionInputBuffer
import org.apache.http.io.SessionInputBuffer; //导入依赖的package包/类
@Override
protected SessionInputBuffer createSessionInputBuffer(final Socket socket, int buffersize, final HttpParams params)
throws IOException
{
if (buffersize == -1)
{
buffersize = 8192;
}
SessionInputBuffer inbuffer = super.createSessionInputBuffer(socket, buffersize, params);
if (wireLog.isDebugEnabled())
{
inbuffer =
new LoggingSessionInputBuffer(inbuffer, new Wire(wireLog),
HttpProtocolParams.getHttpElementCharset(params));
}
return inbuffer;
}
示例6: createSessionInputBuffer
import org.apache.http.io.SessionInputBuffer; //导入依赖的package包/类
@Override
protected SessionInputBuffer createSessionInputBuffer(
final Socket socket,
final int buffersize,
final HttpParams params) throws IOException {
SessionInputBuffer inbuffer = super.createSessionInputBuffer(
socket,
buffersize > 0 ? buffersize : 8192,
params);
if (wireLog.isDebugEnabled()) {
inbuffer = new LoggingSessionInputBuffer(
inbuffer,
new Wire(wireLog),
HttpProtocolParams.getHttpElementCharset(params));
}
return inbuffer;
}
示例7: testResponseParsingWithSomeGarbage
import org.apache.http.io.SessionInputBuffer; //导入依赖的package包/类
@Test
public void testResponseParsingWithSomeGarbage() throws Exception {
final String s =
"garbage\r\n" +
"garbage\r\n" +
"more garbage\r\n" +
"HTTP/1.1 200 OK\r\n" +
"header1: value1\r\n" +
"header2: value2\r\n" +
"\r\n";
final SessionInputBuffer inbuffer = new SessionInputBufferMock(s, Consts.ASCII);
final HttpMessageParser<HttpResponse> parser = new DefaultHttpResponseParser(inbuffer);
final HttpResponse response = parser.parse();
Assert.assertNotNull(response);
Assert.assertEquals(HttpVersion.HTTP_1_1, response.getProtocolVersion());
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
final Header[] headers = response.getAllHeaders();
Assert.assertNotNull(headers);
Assert.assertEquals(2, headers.length);
Assert.assertEquals("header1", headers[0].getName());
Assert.assertEquals("header2", headers[1].getName());
}
示例8: testResponseParsingWithTooMuchGarbage
import org.apache.http.io.SessionInputBuffer; //导入依赖的package包/类
@Test(expected=ProtocolException.class)
public void testResponseParsingWithTooMuchGarbage() throws Exception {
final String s =
"garbage\r\n" +
"garbage\r\n" +
"more garbage\r\n" +
"HTTP/1.1 200 OK\r\n" +
"header1: value1\r\n" +
"header2: value2\r\n" +
"\r\n";
final SessionInputBuffer inbuffer = new SessionInputBufferMock(s, Consts.ASCII);
final HttpMessageParser<HttpResponse> parser = new DefaultHttpResponseParser(inbuffer) {
@Override
protected boolean reject(final CharArrayBuffer line, final int count) {
return count >= 2;
}
};
parser.parse();
}
示例9: createSessionInputBuffer
import org.apache.http.io.SessionInputBuffer; //导入依赖的package包/类
@Override
protected SessionInputBuffer createSessionInputBuffer(
final Socket socket,
int buffersize,
final HttpParams params) throws IOException {
if (buffersize == -1) {
buffersize = 8192;
}
SessionInputBuffer inbuffer = super.createSessionInputBuffer(
socket,
buffersize,
params);
if (wireLog.isDebugEnabled()) {
inbuffer = new LoggingSessionInputBuffer(inbuffer, new Wire(wireLog));
}
return inbuffer;
}
示例10: acceptClient
import org.apache.http.io.SessionInputBuffer; //导入依赖的package包/类
private void acceptClient(@NotNull Socket client) throws IOException {
final SessionInputBuffer inputBuffer = wrapInputStream(client.getInputStream());
final HttpMessageParser<HttpRequest> parser = new DefaultHttpRequestParser(inputBuffer,
new BasicLineParser(),
new DefaultHttpRequestFactory(),
MessageConstraints.DEFAULT
);
final SessionOutputBuffer outputBuffer = wrapOutputStream(client.getOutputStream());
final HttpMessageWriter<HttpResponse> writer = new DefaultHttpResponseWriter(outputBuffer);
while (!socket.isClosed()) {
try {
service(inputBuffer, outputBuffer, parser, writer);
} catch (ConnectionClosedException ignored) {
break;
} catch (HttpException e) {
log.error(e.getMessage(), e);
break;
}
}
}
示例11: createResponseParser
import org.apache.http.io.SessionInputBuffer; //导入依赖的package包/类
@Override
protected HttpMessageParser<HttpResponse> createResponseParser(
final SessionInputBuffer buffer,
final HttpResponseFactory responseFactory,
final HttpParams params) {
// override in derived class to specify a line parser
return new DefaultHttpResponseParser
(buffer, null, responseFactory, params);
}
示例12: LoggingSessionInputBuffer
import org.apache.http.io.SessionInputBuffer; //导入依赖的package包/类
/**
* Create an instance that wraps the specified session input buffer.
* @param in The session input buffer.
* @param wire The wire log to use.
* @param charset protocol charset, <code>ASCII</code> if <code>null</code>
*/
public LoggingSessionInputBuffer(
final SessionInputBuffer in, final Wire wire, final String charset) {
super();
this.in = in;
this.eofSensor = in instanceof EofSensor ? (EofSensor) in : null;
this.wire = wire;
this.charset = charset != null ? charset : Consts.ASCII.name();
}
示例13: DefaultResponseParser
import org.apache.http.io.SessionInputBuffer; //导入依赖的package包/类
public DefaultResponseParser(
final SessionInputBuffer buffer,
final LineParser parser,
final HttpResponseFactory responseFactory,
final HttpParams params) {
super(buffer, parser, params);
if (responseFactory == null) {
throw new IllegalArgumentException
("Response factory may not be null");
}
this.responseFactory = responseFactory;
this.lineBuf = new CharArrayBuffer(128);
this.maxGarbageLines = getMaxGarbageLines(params);
}
示例14: DefaultHttpResponseParser
import org.apache.http.io.SessionInputBuffer; //导入依赖的package包/类
public DefaultHttpResponseParser(
final SessionInputBuffer buffer,
final LineParser parser,
final HttpResponseFactory responseFactory,
final HttpParams params) {
super(buffer, parser, params);
if (responseFactory == null) {
throw new IllegalArgumentException
("Response factory may not be null");
}
this.responseFactory = responseFactory;
this.lineBuf = new CharArrayBuffer(128);
}
示例15: doDeserialize
import org.apache.http.io.SessionInputBuffer; //导入依赖的package包/类
/**
* Creates a {@link BasicHttpEntity} based on properties of the given
* message. The content of the entity is created by wrapping
* {@link SessionInputBuffer} with a content decoder depending on the
* transfer mechanism used by the message.
* <p>
* This method is called by the public
* {@link #deserialize(SessionInputBuffer, HttpMessage)}.
*
* @param inbuffer the session input buffer.
* @param message the message.
* @return HTTP entity.
* @throws HttpException in case of HTTP protocol violation.
* @throws IOException in case of an I/O error.
*/
protected BasicHttpEntity doDeserialize(
final SessionInputBuffer inbuffer,
final HttpMessage message) throws HttpException, IOException {
BasicHttpEntity entity = new BasicHttpEntity();
long len = this.lenStrategy.determineLength(message);
if (len == ContentLengthStrategy.CHUNKED) {
entity.setChunked(true);
entity.setContentLength(-1);
entity.setContent(new ChunkedInputStream(inbuffer));
} else if (len == ContentLengthStrategy.IDENTITY) {
entity.setChunked(false);
entity.setContentLength(-1);
entity.setContent(new IdentityInputStream(inbuffer));
} else {
entity.setChunked(false);
entity.setContentLength(len);
entity.setContent(new ContentLengthInputStream(inbuffer, len));
}
Header contentTypeHeader = message.getFirstHeader(HTTP.CONTENT_TYPE);
if (contentTypeHeader != null) {
entity.setContentType(contentTypeHeader);
}
Header contentEncodingHeader = message.getFirstHeader(HTTP.CONTENT_ENCODING);
if (contentEncodingHeader != null) {
entity.setContentEncoding(contentEncodingHeader);
}
return entity;
}