本文整理匯總了Java中org.apache.http.impl.DefaultHttpResponseFactory類的典型用法代碼示例。如果您正苦於以下問題:Java DefaultHttpResponseFactory類的具體用法?Java DefaultHttpResponseFactory怎麽用?Java DefaultHttpResponseFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DefaultHttpResponseFactory類屬於org.apache.http.impl包,在下文中一共展示了DefaultHttpResponseFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: QSystemHtmlInstance
import org.apache.http.impl.DefaultHttpResponseFactory; //導入依賴的package包/類
private QSystemHtmlInstance() {
this.params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000).
setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024).
setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false).
setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true).
setParameter(CoreProtocolPNames.ORIGIN_SERVER, "QSystemReportHttpServer/1.1");
// Set up the HTTP protocol processor
final BasicHttpProcessor httpproc = new BasicHttpProcessor();
httpproc.addInterceptor(new ResponseDate());
httpproc.addInterceptor(new ResponseServer());
httpproc.addInterceptor(new ResponseContent());
httpproc.addInterceptor(new ResponseConnControl());
// Set up request handlers
final HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
reqistry.register("*", new HttpQSystemReportsHandler());
// Set up the HTTP service
this.httpService = new HttpService(
httpproc,
new DefaultConnectionReuseStrategy(),
new DefaultHttpResponseFactory(), reqistry, this.params);
}
示例2: RequestListenerThread
import org.apache.http.impl.DefaultHttpResponseFactory; //導入依賴的package包/類
public RequestListenerThread(Context context) throws IOException, BindException {
serversocket = new ServerSocket(PORT);
params = new BasicHttpParams();
params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000).setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true).setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");
// Set up the HTTP protocol processor
BasicHttpProcessor httpProcessor = new BasicHttpProcessor();
httpProcessor.addInterceptor(new ResponseDate());
httpProcessor.addInterceptor(new ResponseServer());
httpProcessor.addInterceptor(new ResponseContent());
httpProcessor.addInterceptor(new ResponseConnControl());
// Set up the HTTP service
this.httpService = new YaaccHttpService(httpProcessor, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory(), context);
}
示例3: RequestListenerThread
import org.apache.http.impl.DefaultHttpResponseFactory; //導入依賴的package包/類
public RequestListenerThread(int port, final String docroot) throws IOException {
this.serversocket = new ServerSocket(port);
this.params = new SyncBasicHttpParams();
this.params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000).setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024).setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false).setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true).setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");
// Set up the HTTP protocol processor
HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpResponseInterceptor[]{
new ResponseDate(),
new ResponseServer(),
new ResponseContent(),
new ResponseConnControl()
});
// Set up request handlers
HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
reqistry.register("*", new HttpFileHandler());
// Set up the HTTP service
this.httpService = new HttpService(
httpproc,
new DefaultConnectionReuseStrategy(),
new DefaultHttpResponseFactory(),
reqistry,
this.params);
}
示例4: HttpServerConnectionUpnpStream
import org.apache.http.impl.DefaultHttpResponseFactory; //導入依賴的package包/類
protected HttpServerConnectionUpnpStream(ProtocolFactory protocolFactory,
HttpServerConnection connection,
final HttpParams params) {
super(protocolFactory);
this.connection = connection;
this.params = params;
// The Date header is recommended in UDA, need to document the requirement in StreamServer interface?
httpProcessor.addInterceptor(new ResponseDate());
// The Server header is only required for Control so callers have to add it to UPnPMessage
// httpProcessor.addInterceptor(new ResponseServer());
httpProcessor.addInterceptor(new ResponseContent());
httpProcessor.addInterceptor(new ResponseConnControl());
httpService =
new UpnpHttpService(
httpProcessor,
new DefaultConnectionReuseStrategy(),
new DefaultHttpResponseFactory()
);
httpService.setParams(params);
}
示例5: ListenerThread
import org.apache.http.impl.DefaultHttpResponseFactory; //導入依賴的package包/類
public ListenerThread(InetAddress address, int port, HttpParams params,
HttpRequestHandlerRegistry handlerRegistry) throws IOException {
this.params = params;
this.serverSocket = new ServerSocket(port, 0, address);
BasicHttpProcessor httpproc = new BasicHttpProcessor();
httpproc.addInterceptor(new ResponseDate());
httpproc.addInterceptor(new ResponseServer());
httpproc.addInterceptor(new ResponseContent());
httpproc.addInterceptor(new ResponseConnControl());
this.httpService = new HttpService(httpproc,
new DefaultConnectionReuseStrategy(),
new DefaultHttpResponseFactory());
this.httpService.setParams(params);
this.httpService.setHandlerResolver(handlerRegistry);
}
示例6: handleResponseTest
import org.apache.http.impl.DefaultHttpResponseFactory; //導入依賴的package包/類
/**
*
*/
@Test
public void handleResponseTest() throws Exception {
ResponseHandler handler = new ResponseHandler();
HttpResponseFactory factory = new DefaultHttpResponseFactory();
HttpResponse responseSent = factory.newHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK,
"reason"), null);
HttpResponse response = handler.handleResponse(responseSent);
Assert.assertEquals(handler.getStatus(), HttpStatus.SC_OK);
Assert.assertFalse(handler.hasContent());
// response with content.
BasicHttpEntity entity = new BasicHttpEntity();
InputStream inputStream = new ByteArrayInputStream("new content".getBytes());
entity.setContent(inputStream);
entity.setContentLength("new content".length()); // sets the length
response.setEntity(entity);
response = handler.handleResponse(responseSent);
Assert.assertEquals("new content", handler.getResponseContent());
}
示例7: put
import org.apache.http.impl.DefaultHttpResponseFactory; //導入依賴的package包/類
public HttpResponse put(Map<String, InputStream> uriAndStreamMap, Map<String, String> headers) throws MultipleBintrayCallException {
List<Future<String>> executions = new ArrayList<>();
List<BintrayCallException> errors = new ArrayList<>();
List<RequestRunner> runners = createPutRequestRunners(uriAndStreamMap, headers, errors);
try {
executions = executorService.invokeAll(runners);
} catch (InterruptedException e) {
BintrayCallException bce = new BintrayCallException(409, e.getMessage(), (e.getCause() == null) ? ""
: e.getCause().toString() + " : " + e.getCause().getMessage());
log.error(bce.toString());
log.debug("{}", e.getMessage(), e);
errors.add(bce);
}
collectResults(executions, errors);
//Return ok or throw errors
if (errors.isEmpty()) {
String entity = "Operation Successful";
HttpResponse response = DefaultHttpResponseFactory.INSTANCE.newHttpResponse(
new ProtocolVersion("HTTP", 1, 1), HttpStatus.SC_CREATED, new HttpClientContext());
response.setEntity(new StringEntity(entity, Charset.forName("UTF-8")));
return response;
} else {
throw new MultipleBintrayCallException(errors);
}
}
示例8: RequestListenerThread
import org.apache.http.impl.DefaultHttpResponseFactory; //導入依賴的package包/類
public RequestListenerThread(int port, final String docroot) throws IOException {
this.serversocket = new ServerSocket(port);
this.params = new BasicHttpParams();
this.params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 1000).setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false).setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
.setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");
// Set up the HTTP protocol processor
HttpProcessor httpproc = new BasicHttpProcessor();
// Set up request handlers
HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
reqistry.register("*", new HttpFileHandler(docroot));
// Set up the HTTP service
this.httpService = new HttpService(httpproc, new NoConnectionReuseStrategy(), new DefaultHttpResponseFactory());
this.httpService.setParams(this.params);
this.httpService.setHandlerResolver(reqistry);
}
示例9: RequestListenerThread
import org.apache.http.impl.DefaultHttpResponseFactory; //導入依賴的package包/類
public RequestListenerThread(int port, final String docroot) throws IOException {
this.serversocket = new ServerSocket(port);
this.params = new SyncBasicHttpParams();
this.params
.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
.setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
.setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");
// Set up the HTTP protocol processor
HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpResponseInterceptor[] {
new ResponseDate(),
new ResponseServer(),
new ResponseContent(),
new ResponseConnControl()
});
// Set up request handlers
HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
reqistry.register("*", new HttpFileHandler(docroot));
// Set up the HTTP service
this.httpService = new HttpService(
httpproc,
new DefaultConnectionReuseStrategy(),
new DefaultHttpResponseFactory(),
reqistry,
this.params);
}
示例10: ListenerThread
import org.apache.http.impl.DefaultHttpResponseFactory; //導入依賴的package包/類
public ListenerThread(final ApiServer requestHandler, final int port) {
try {
_serverSocket = new ServerSocket(port);
} catch (final IOException ioex) {
s_logger.error("error initializing api server", ioex);
return;
}
_params = new BasicHttpParams();
_params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 30000)
.setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
.setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");
// Set up the HTTP protocol processor
final BasicHttpProcessor httpproc = new BasicHttpProcessor();
httpproc.addInterceptor(new ResponseDate());
httpproc.addInterceptor(new ResponseServer());
httpproc.addInterceptor(new ResponseContent());
httpproc.addInterceptor(new ResponseConnControl());
// Set up request handlers
final HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
reqistry.register("*", requestHandler);
// Set up the HTTP service
_httpService = new HttpService(httpproc, new NoConnectionReuseStrategy(), new DefaultHttpResponseFactory());
_httpService.setParams(_params);
_httpService.setHandlerResolver(reqistry);
}
示例11: ListenerThread
import org.apache.http.impl.DefaultHttpResponseFactory; //導入依賴的package包/類
public ListenerThread(final HttpRequestHandler requestHandler, final int port) {
_executor = Executors.newCachedThreadPool(new NamedThreadFactory("Cluster-Listener"));
try {
_serverSocket = new ServerSocket(port);
} catch (final IOException ioex) {
s_logger.error("error initializing cluster service servlet container", ioex);
return;
}
_params = new BasicHttpParams();
_params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
.setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
.setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");
// Set up the HTTP protocol processor
final BasicHttpProcessor httpproc = new BasicHttpProcessor();
httpproc.addInterceptor(new ResponseDate());
httpproc.addInterceptor(new ResponseServer());
httpproc.addInterceptor(new ResponseContent());
httpproc.addInterceptor(new ResponseConnControl());
// Set up request handlers
final HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
reqistry.register("/clusterservice", requestHandler);
// Set up the HTTP service
_httpService = new HttpService(httpproc, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory());
_httpService.setParams(_params);
_httpService.setHandlerResolver(reqistry);
}
示例12: sendAndReturn
import org.apache.http.impl.DefaultHttpResponseFactory; //導入依賴的package包/類
@Override
protected String sendAndReturn(HttpUriRequest request) throws IOException{
HttpResponseFactory factory = new DefaultHttpResponseFactory();
HttpResponse response = factory.newHttpResponse(
new BasicStatusLine(HttpVersion.HTTP_1_1, this.status, null),null);
StringBuilder sb = new StringBuilder();
sb.append(String.format("%s = %s;", "METHOD", request.getMethod()));
sb.append(String.format("%s = %s;", "URI", request.getURI()));
if (request.getAllHeaders().length > 0){
sb.append("HEADER_EXISTS");
}
for (Header h : request.getAllHeaders()){
sb.append(String.format("%s = %s;", h.getName(), h.getValue()));
}
if (request instanceof HttpEntityEnclosingRequestBase){
HttpEntity entity = ((HttpEntityEnclosingRequestBase)request).getEntity();
if (entity != null){
sb.append("BODY_EXISTS");
sb.append(String.format("%s = %s;", "BODY", EntityUtils.toString(entity)));
}
}
response.setEntity(new StringEntity(sb.toString()));
return parseResponse(response);
}
示例13: setNextHttpResponse
import org.apache.http.impl.DefaultHttpResponseFactory; //導入依賴的package包/類
private void setNextHttpResponse(int code, Optional<String> message) throws IOException {
DefaultHttpResponseFactory responseFactory = new DefaultHttpResponseFactory();
HttpResponse httpResponse = responseFactory.newHttpResponse(
new BasicStatusLine(HttpVersion.HTTP_1_1, code, null), null);
if (message.isPresent()) httpResponse.setEntity(new StringEntity(message.get()));
when(httpClient.execute(any())).thenReturn(httpResponse);
}
示例14: RequestListener
import org.apache.http.impl.DefaultHttpResponseFactory; //導入依賴的package包/類
protected RequestListener() throws Exception {
mHttpService = new org.apache.http.protocol.HttpService(
mHttpProcessor,
new DefaultConnectionReuseStrategy(),
new DefaultHttpResponseFactory());
mHttpService.setHandlerResolver(mRegistry);
mHttpService.setParams(mParams);
}
示例15: DefaultHttpResponseParserFactory
import org.apache.http.impl.DefaultHttpResponseFactory; //導入依賴的package包/類
public DefaultHttpResponseParserFactory(
final LineParser lineParser,
final HttpResponseFactory responseFactory) {
super();
this.lineParser = lineParser != null ? lineParser : BasicLineParser.INSTANCE;
this.responseFactory = responseFactory != null ? responseFactory
: DefaultHttpResponseFactory.INSTANCE;
}