Design Patterns
----Proxy (
Agent
)
Mode
GOF
:Provides a proxy for other objects to control access to this object. Not like flyweight. Proxy is itself the meaning of the agent. The reason for access control for an object is to use it when we really need it, or some function of the object. In a forum system (such as the very famous "Tianya"), browsing the for
The graphical proxy settings of the new software manager are clear. Here we will introduce the network proxy settings of the terminal command line, so that you can perform apt-Get through the proxy.
Method 1:
If you only want to temporarily use the HTTP proxy, you can enter: Export http_proxy = "http: // username:
Winsock provides two methods for HTTP proxy to submit HTTP requests.1. Direct Request2. Connect to the remote server and submit an HTTP request like a common request.
Let's talk about the first method:Let's talk about the common process of submitting an HTTP request:
After connecting to the remote server directly, submit the HTTP header to the server when the connection is successful. Check the approximate format.
Get, HTTP, 1.1
Accept :*/*
Accept-lan
Java reflection and dynamic proxy, java reflection dynamic proxy
The two things that have been unclear are recorded today, java reflection and dynamic proxy
Java reflection: 1. The ability to analyze classes at runtime
2. view the object during running
3. array operation code
4. Use the Method object
In java. lang. the reflect package contains three classes: Fiel
1.Concept of forward proxy
Forward proxyIsOrigin server)To get content from the original server, the client sends a request to the proxy and specifies the target (original server ), then the proxy transfers the request to the original server and returns the obtained content to the client. The client must make some special settings to use the forward
1.1.view various information about the dynamic proxy classthrough the reflection mechanism can obtain Proxy creates a variety of information about the dynamic proxy class, including implemented interfaces, constructors, methods, and so on. Once you see this information, you can better understand why dynamic proxies are used. /*** @Title: proxytest.java* @Package
What is HTTP proxy: www for every person who is familiar with the internet, WWW connection request is the HTTP protocol used, so we browse the Web page, download data (also can use FTP protocol) is the use of HTTP proxy. It is usually bound to the proxy server on the 80, 3128, 8080 ports.
What is SOCKS Agent: Accordingly, the
The JDK dynamic proxy is introduced at 1.3, and its underlying need relies on a tool class Java.lang.reflect.Proxy and an interface Java.lang.reflect.InvocationHandler
JDK Dynamic proxy must be agent based on interface
code example:Jdkproxyutils.java
Package com.my.jdkproxy;
Import Java.lang.reflect.InvocationHandler;
Import Java.lang.reflect.Method;
Import Java.lang.reflect.Proxy;
Create JDK dynamic
To sum up is:1, the agent when the client knows the server, through the proxy to access the server, then the agent is the server2, reverse proxy when the client does not know the server side, the server knows the client, through the proxy to access the server, then the agent is the clientThe concept of a forward proxyThe forward agent, the legendary agent, works
1. Forward Proxy: The Agent object is the client;For example, some companies control the company computer can only access the local area network and a few external network URLs, then the company needs a proxy server, the employee computer request the network URL is sent through the proxy server (proxy server will check
1. Forward proxy
The forward proxy is located between the original server and the client, and its role is to send requests in place of the client, for example, to protect the client, or to flip the wall (the condition is that the proxy server must not be limited by GFW, currently, most VPs instances outside China are purchased. The process is as follows:
1.
Protocol and proxy, protocol proxy
======================================
Protocols and Proxies
======================================
[Agreement]
@ Protocol
[Role of the Protocol]: Specifies the interface method to be implemented. An agreement that must be followed by the entrusting party and the agent.
Delegate by (nt. delegate = self;) [Note: you can delegate yourself or other classes]
The
Forward proxy is a client and originalServerTo get content from the original server, the client sends a request to the proxy and specifies the target (original server ), then the proxy transfers the request to the original server and returns the obtained content to the client. The client must make some special settings to use the forward
provide the API to get the target object.Java code
Import Java.lang.reflect.Field;
Import Org.springframework.aop.framework.AdvisedSupport;
Import Org.springframework.aop.framework.AopProxy;
Import Org.springframework.aop.support.AopUtils;
Public class Aoptargetutils {
/**
* Get target object
* @param proxy Object
* @return
* @throws Exception
*/
public Static Object Gettarget (object
Last night a buddy needs to get the target object of the proxy object, find the document found no corresponding tool class, so I wrote a share to everyone. Can obtain the target object of the JDK dynamic Agent/cglib proxy object agent.Problem Description::I now have a tricky problem, to save the object through the spring managed service class, which is obtained through reflection, and it is experimentally d
1. Create tunnel on the server using SSHSSH 10080 -f-c-q-n [email protected]112.34. 113.35 -D: Let SSH on the specified port (1025-65536-----n:tells SSH That no command would be sent once the tunnel is up# the last specified is the SSH user and the currently established tunnel server IPRun in the background after execution, you can view the process through PS2. Configure SOCKS5 proxy locally via puttyOpen
Python crawler practice (iii) -------- sogou article (IP proxy pool and user proxy pool settings ---- scrapy ),
In learning the scrapy crawler framework, it will certainly involve setting the IP proxy pool and User-Agent pool to avoid anti-crawling of websites.
In the past two days, I watched a video about sogou's article crawling. I talked about ip
Concept:Static proxy: The source code is generated automatically by the programmer or a specific tool, and then compiled. Before the program runs, the. class file for the proxy classes already exists.Dynamic Agent: When the program is running, it is created dynamically using the reflection mechanism.The dynamic proxy of the JDK is very simple to use, when it has
A forward proxy is a server that is located between the client and the original server (Origin server), in order to obtain content from the original server, the client sends a request to the agent and specifies the target (the original server), and the agent forwards the request to the original server and returns the obtained content to the client. The client must make some special settings to use the forward proxy.Reverse
Squid cache (squid for short) is a popular free software (GNU General Public License) proxy server and Web Cache Server. Squid has a wide range of uses, from cache-related requests as front cache servers of web servers to improving the speed of web servers, to cache the World Wide Web for a group of people to share network resources, domain Name System and other network search, to help network security by filtering traffic, to the LAN through the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.