本文整理汇总了Java中org.apache.http.io.HttpMessageParser类的典型用法代码示例。如果您正苦于以下问题:Java HttpMessageParser类的具体用法?Java HttpMessageParser怎么用?Java HttpMessageParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpMessageParser类属于org.apache.http.io包,在下文中一共展示了HttpMessageParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testResponseParsingWithSomeGarbage
import org.apache.http.io.HttpMessageParser; //导入依赖的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());
}
示例2: testResponseParsingWithTooMuchGarbage
import org.apache.http.io.HttpMessageParser; //导入依赖的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();
}
示例3: acceptClient
import org.apache.http.io.HttpMessageParser; //导入依赖的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;
}
}
}
示例4: createResponseParser
import org.apache.http.io.HttpMessageParser; //导入依赖的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);
}
示例5: createResponseParser
import org.apache.http.io.HttpMessageParser; //导入依赖的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);
}
示例6: testResponseParsingOnlyGarbage
import org.apache.http.io.HttpMessageParser; //导入依赖的package包/类
@Test(expected=ProtocolException.class)
public void testResponseParsingOnlyGarbage() throws Exception {
final String s =
"garbage\r\n" +
"garbage\r\n" +
"more garbage\r\n" +
"a lot more garbage\r\n";
final SessionInputBuffer inbuffer = new SessionInputBufferMock(s, Consts.ASCII);
final HttpMessageParser<HttpResponse> parser = new DefaultHttpResponseParser(inbuffer);
parser.parse();
}
示例7: createResponseParser
import org.apache.http.io.HttpMessageParser; //导入依赖的package包/类
@Override
protected HttpMessageParser createResponseParser(
final SessionInputBuffer buffer,
final HttpResponseFactory responseFactory,
final HttpParams params) {
// override in derived class to specify a line parser
return new DefaultResponseParser
(buffer, null, responseFactory, params);
}
示例8: createResponseParser
import org.apache.http.io.HttpMessageParser; //导入依赖的package包/类
@Override
protected HttpMessageParser<HttpResponse> createResponseParser(
final SessionInputBuffer buffer,
final HttpResponseFactory responseFactory,
final HttpParams params) {
return new DefaultHttpResponseParser(
buffer,
new MyLineParser(),
responseFactory,
params);
}
示例9: service
import org.apache.http.io.HttpMessageParser; //导入依赖的package包/类
@SuppressWarnings("deprecation")
protected void service(@NotNull SessionInputBuffer inputBuffer, @NotNull SessionOutputBuffer outputBuffer, @NotNull HttpMessageParser<HttpRequest> parser, @NotNull HttpMessageWriter<HttpResponse> writer) throws IOException, HttpException {
try {
final HttpRequest request = parser.parse();
final HttpEntity entity;
if (request instanceof HttpEntityEnclosingRequest) {
final EntityDeserializer deserializer = new EntityDeserializer(new LaxContentLengthStrategy());
entity = deserializer.deserialize(inputBuffer, request);
((HttpEntityEnclosingRequest) request).setEntity(entity);
} else {
entity = null;
}
final HttpResponse response = service(request);
if (entity != null) {
entity.getContent().close();
}
if (response.getEntity() != null) {
response.addHeader(HttpHeaders.CONTENT_LENGTH, Long.toString(response.getEntity().getContentLength()));
response.addHeader(response.getEntity().getContentType());
response.addHeader(response.getEntity().getContentEncoding());
}
response.setHeader(HttpHeaders.SERVER, "Protobuf RPC");
writer.write(response);
if (response.getEntity() != null) {
final EntitySerializer serializer = new EntitySerializer(new LaxContentLengthStrategy());
serializer.serialize(outputBuffer, response, response.getEntity());
}
} finally {
outputBuffer.flush();
}
}
示例10: create
import org.apache.http.io.HttpMessageParser; //导入依赖的package包/类
public HttpMessageParser create(final SessionInputBuffer buffer,
final MessageConstraints constraints) {
return new DefaultHttpResponseParser(buffer, lineParser, responseFactory, constraints);
}
示例11: create
import org.apache.http.io.HttpMessageParser; //导入依赖的package包/类
public HttpMessageParser create(final SessionInputBuffer buffer,
final MessageConstraints constraints) {
return new DefaultHttpRequestParser(buffer, lineParser, requestFactory, constraints);
}
示例12: create
import org.apache.http.io.HttpMessageParser; //导入依赖的package包/类
@Override
public HttpMessageParser<HttpResponse> create(final SessionInputBuffer buffer,
final MessageConstraints constraints) {
return new DefaultHttpResponseParser(buffer, lineParser, responseFactory, constraints);
}
示例13: testResponseParsingNoResponse
import org.apache.http.io.HttpMessageParser; //导入依赖的package包/类
@Test(expected=NoHttpResponseException.class)
public void testResponseParsingNoResponse() throws Exception {
final SessionInputBuffer inbuffer = new SessionInputBufferMock("", Consts.ASCII);
final HttpMessageParser<HttpResponse> parser = new DefaultHttpResponseParser(inbuffer);
parser.parse();
}
示例14: createResponseParser
import org.apache.http.io.HttpMessageParser; //导入依赖的package包/类
@Override
protected HttpMessageParser createResponseParser(final SessionInputBuffer buffer,
final HttpResponseFactory responseFactory, final HttpParams params) {
return new DefaultResponseParser(buffer, new IcyLineParser(), responseFactory, params);
}
示例15: createResponseParser
import org.apache.http.io.HttpMessageParser; //导入依赖的package包/类
/**
* Creates an instance of {@link HttpMessageParser} to be used for parsing
* HTTP responses received over this connection.
* <p>
* This method can be overridden in a super class in order to provide
* a different implementation of the {@link HttpMessageParser} interface or
* to pass a different implementation of the {@link LineParser} to the
* the {@link DefaultHttpResponseParser} constructor.
*
* @param buffer the session input buffer.
* @param responseFactory the HTTP response factory.
* @param params HTTP parameters.
* @return HTTP message parser.
*/
protected HttpMessageParser<HttpResponse> createResponseParser(
final SessionInputBuffer buffer,
final HttpResponseFactory responseFactory,
final HttpParams params) {
return new DefaultHttpResponseParser(buffer, null, responseFactory, params);
}