Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Httpclient4.4 of principle (Http execution context)     - Justniffer installed on Ubuntu 15.04 (Linux)

- Use ldap implement Windows Remote Desktop Ubuntu Linux (Linux)

- Linux console password solution (Programming)

- Java garbage collection (Programming)

- Linux firewall settings instance (Linux)

- Linux use chattr and lsattr commands to manage file and directory attributes (Linux)

- Java to create a table in the database SYBase (Database)

- Method under Linux GCC Compiler shared library function export control (Programming)

- How to deploy Python Web application: Heroku deployment process complete records (Server)

- Hadoop upload files error solved (Server)

- Linux host system monitoring implement the cgi (Server)

- Crawl use Wireshark packet on remote Linux (Linux)

- Ubuntu install Liferea news subscription software (Linux)

- Linux foundation tutorial: how to modify the host name on CentOS or RHEL 7 (Linux)

- Hadoop2.0 configuration yarn success (Server)

- PULL operation mechanism parsing XML Comments (Programming)

- Migu online music player for Linux (Linux)

- Linux serial debugging tools xgcom install (Linux)

- Linux common network tools: ping host sweep (Linux)

- Export error: ORA-04063: package body dmsys dbms dm model exp has error (Database)

  Httpclient4.4 of principle (Http execution context)
  Add Date : 2018-11-21      
  HTTP was originally designed to be stateless. However, the real applications often through several logically related request / response maintain state information. In order for an application to maintain a processing state, HttpClient allow HTTP requests within the context of this particular execution, called HTTP context. If the same context between consecutive requests reuse, a plurality of logically successive requests associated logic can participate in a conversation. HTTP context functions similarly to java.util.Map < String, Object>, it is merely a collection of values ​​arbitrarily named. Applications can fill the context of the implementation of property before the request, the request can be executed after completion of checking context.

HttpContext can contain any object, therefore, it may not be thread safe. It recommended that each thread of execution to maintain their own context.

In the course of HTTP request execution, HttpClient adds the following attributes to the execution context:

HttpConnection: it represents the actual connection to the target server.
HttpHost: It represents the connection target.
HttpRoute: It represents a complete connection routes.
HttpRequest: It represents a real HTTP requests. In the context of the last representatives of the HttpRequest object is always an accurate status of the message is sent to the target server. The default HTTP1.0 and HTTP1.1 use relative request URI, however, the request is sent by the agent in a non-tunnel mode, then it is an absolute URI.
HttpResponse: it represents the current HTTP response.
java.lang.Boolean: It represents a notation indicating whether the current request has been completely transferred to the connection target.
RequestConfig: It represents the configuration of the current request.
java.util.List: It represents a collection of requests received in the course of implementation of all the redirection address.
We can use HttpClientContext adapter class to simplify the interaction between the state and the context:

HttpContext context = < ...>
HttpClientContext clientContext = HttpClientContext.adapt (context);
HttpHost target = clientContext.getTargetHost ();
HttpRequest request = clientContext.getRequest ();
HttpResponse response = clientContext.getResponse ();
RequestConfig config = clientContext.getRequestConfig ();

Represent a logical sequence of multiple requests related to the session should be performed in the same HttpContext entity, ensure that the session context and status information between requests automatic transmission (an example of convergence above example):

CloseableHttpClient httpclient = HttpClients.createDefault ();
RequestConfig requestConfig = RequestConfig.custom ().
    setSocketTimeout (1000) .setConnectTimeout (1000) .build ();
HttpGet httpget1 = new HttpGet ( "http: // localhost / 1");
httpget1.setConfig (requestConfig);
// Context defined in the previous example
CloseableHttpResponse response1 = httpclient.execute (httpget1, context);
try {
    HttpEntity entity1 = response1.getEntity ();
} Finally {
    response1.close ();
HttpGet httpget2 = new HttpGet ( "http: // localhost / 2");
CloseableHttpResponse response2 = httpclient.execute (httpget2, context);
try {
    HttpEntity entity2 = response2.getEntity ();
} Finally {
    response2.close ();
- Let OpenCV face detection score output codes (Programming)
- Spark build standalone version cluster (Server)
- Grep how to find files based on file contents in UNIX (Linux)
- Android Notification (Programming)
- Joseph Central Java implementation (Programming)
- Struts2 form of non-use component tags (Programming)
- Oracle study notes view (Database)
- OpenStack / Dev stack with neutron on Ubuntu 14.04 (Server)
- Java memory mechanism Description (Programming)
- Linux System Getting Started Learning: Fix ImportError: No module named scapy.all (Linux)
- Oracle 11G using DG Broker create DataGuard (Database)
- Timing Nginx logs cut and remove the log records of the specified number of days before (Server)
- MySQL IO SSD attempt at optimization (Database)
- Ubuntu manually set the DSL broadband connection (Linux)
- Let Markdown code syntax highlighting and support Django1.6 (Linux)
- GNU / Linux system, how to clean up memory space (Linux)
- Verify the character set on MyCAT (Database)
- Add your own kernel and ramfs based on an existing Linux LiveCD (Linux)
- Linux RPM default installation path (Linux)
- Linux file permissions to modify the command: chmod (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.