服装网站建设内容,wordpress媒体库只能列表,wordpress解压后怎么安装,专业的网站优化jetty代理jettySPDY是Google提出的一种新协议#xff0c;是针对网络的新协议。 SPDY与HTTP兼容#xff0c;但尝试通过压缩#xff0c;多路复用和优先级降低网页负载。准确地说#xff0c;快速的目标是#xff1a;#xff08; http://dev.chromium.org/spdy/spdy-whitepap… jetty代理jetty SPDY是Google提出的一种新协议是针对网络的新协议。 SPDY与HTTP兼容但尝试通过压缩多路复用和优先级降低网页负载。准确地说快速的目标是 http://dev.chromium.org/spdy/spdy-whitepaper 。 SPDY项目为Web定义并实现了一个应用程序层协议可大大减少延迟。 SPDY的高级目标是 旨在将页面加载时间减少50。 我们的初步结果已经接近这个目标见下文。 以最小化部署复杂性。 SPDY使用TCP作为基础传输层因此不需要更改现有的网络基础结构。 为了避免网站作者对内容进行任何更改。 支持SPDY的唯一更改是在客户端用户代理和Web服务器应用程序中。 将对探索协议感兴趣的志趣相投的各方聚集在一起以解决延迟问题。 我们希望与开源社区和行业专家合作开发此新协议 一些特定的技术目标是 允许多个并发HTTP请求在单个TCP会话中运行。 通过压缩头并消除不必要的头来减少HTTP当前使用的带宽。 定义易于实施且服务器效率高的协议。 我们希望通过减少边缘情况并定义易于解析的消息格式来降低HTTP的复杂性。 使SSL成为基础传输协议以提高安全性和与现有网络基础结构的兼容性。 尽管SSL确实会带来延迟损失但我们认为网络的长期发展取决于安全的网络连接。 另外必须使用SSL以确保跨现有代理的通信不中断。 为了使服务器能够启动与客户端的通信并在可能的情况下将数据推送到客户端。 安装专家 在本文中我们不会过多地研究此协议的技术实现但将向您展示如何自己开始使用SPDY并对其进行试验。 为此我们将使用在最新版本 http://wiki.eclipse.org/Jetty/Feature/SPDY 中提供SPDY实现的Jetty。 因此让我们开始吧。 对于此示例我们将让Maven处理依赖关系。 我们将使用以下POM。 project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdsmartjava.jetty.spdy/groupIdartifactIdSPDY-Example/artifactIdversion0.0.1-SNAPSHOT/versiondependenciesdependencygroupIdorg.eclipse.jetty.aggregate/groupIdartifactIdjetty-all-server/artifactIdversion8.1.2.v20120308/versiontypejar/typescopecompile/scopeexclusionsexclusionartifactIdmail/artifactIdgroupIdjavax.mail/groupId/exclusion/exclusions/dependencydependencygroupIdorg.eclipse.jetty.spdy/groupIdartifactIdspdy-jetty/artifactIdversion8.1.2.v20120308/version/dependencydependencygroupIdorg.eclipse.jetty.spdy/groupIdartifactIdspdy-core/artifactIdversion8.1.2.v20120308/version/dependencydependencygroupIdorg.eclipse.jetty.spdy/groupIdartifactIdspdy-jetty-http/artifactIdversion8.1.2.v20120308/version/dependencydependencygroupIdorg.eclipse.jetty.npn/groupIdartifactIdnpn-api/artifactIdversion8.1.2.v20120308/versionscopeprovided/scope/dependency/dependencies
/projectNTP TLS扩展 通过此POM将加载正确的库因此我们可以开始在Jetty中使用特定的SPDY类。 但是在真正使用SPDY之前我们还需要配置Java以使用TLS协议的扩展TLS下一协议协商或简称NPN。 可以在googles技术说明 http://technotes.googlecode.com/git/nextprotoneg.html 上找到此扩展程序的详细信息但总而言之可以解决此问题。 通过TLS与服务器建立连接时如果我们想使用不同于HTTP的协议该怎么办 我们不知道服务器是否支持该协议并且由于SPDY专注于速度因此我们不希望增加往返行程的延迟。 即使有几种不同的解决方案但大多数解决方案都具有不可预测性额外的往返次数或破坏现有代理的影响有关更多信息请参阅 http://www.ietf.org/proceedings/80/slides/tls-1.pdf 。 Google提出的解决方案是使用TLS的扩展机制来确定要使用的协议。 这称为“下一协议协商”或简称NPN。 使用此扩展在TLS握手期间将执行以下步骤 客户端显示对此扩展程序的支持 服务器响应此支持并包括支持的协议列表 客户端发送他要使用的协议而不必由服务器提供。 这导致以下TLS握手 客户端服务器 ClientHelloNP扩展——– ServerHelloNP扩展和协议列表 证书* ServerKeyExchange * 证书申请* ——– ServerHelloDone 证书* ClientKeyExchange 证书验证* [ChangeCipherSpec] NextProtocol 成品——– [ChangeCipherSpec] ——–已完成 应用数据——-应用数据 有关TLS / SSL握手的更多信息请参阅我以前的文章该文章有关如何分析Java SSL错误 http : //www.smartjava.org/content/how-analyze-java-ssl-errors 。 因此我们需要NPN来快速确定我们要使用的协议。 由于这不是标准的TLS因此我们需要配置Java以使用NPN。 标准Java还不支持NPN因此我们不能在标准JVM上运行SPDY。 为了解决这个问题Jetty创建了一个可以与OpenJDK 7一起使用的NPN实现有关更多详细信息请参见http://wiki.eclipse.org/Jetty/Feature/NPN 。 您可以从此处下载此实现 http : //repo2.maven.org/maven2/org/mortbay/jetty/npn/npn-boot/ 您必须像这样将其添加到启动类路径中 java -Xbootclasspath/p:path_to_npn_boot_jar ...在SPDY中包装HTTP请求 现在您可以开始使用Jetty的SPDY。 Jetty以两种不同方式支持此功能。 您可以使用它来将SPDY透明地转换为HTTP然后再次返回也可以使用它直接对话SPDY。 让我们创建一个简单的服务器配置使用启用SPDY的连接托管一些静态内容。 为此我们将使用以下Jetty配置 import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.spdy.http.HTTPSPDYServerConnector;
import org.eclipse.jetty.util.ssl.SslContextFactory;public class SPDYServerLauncher {public static void main(String[] args) throws Exception {// the server to startServer server new Server();// the ssl context to useSslContextFactory sslFactory new SslContextFactory();sslFactory.setKeyStorePath(src/main/resources/spdy.keystore);sslFactory.setKeyStorePassword(secret);sslFactory.setProtocol(TLSv1);// simple connector to add to serve content using spdyConnector connector new HTTPSPDYServerConnector(sslFactory);connector.setPort(8443);// add connector to the serverserver.addConnector(connector);// add a handler to serve contentContextHandler handler new ContextHandler();handler.setContextPath(/content);handler.setResourceBase(src/main/resources/webcontent);handler.setHandler(new ResourceHandler());server.setHandler(handler);server.start();server.join();}
} 由于Jetty还具有非常灵活的XML配置语言因此您可以使用以下XML配置执行相同的操作。 Configure idServer classorg.eclipse.jetty.server.ServerNew idsslContextFactory classorg.eclipse.jetty.util.ssl.SslContextFactorySet namekeyStorePathsrc/main/resources/spdy.keystore/SetSet namekeyStorePasswordsecret/SetSet nameprotocolTLSv1/Set/NewCall nameaddConnectorArgNew classorg.eclipse.jetty.spdy.http.HTTPSPDYServerConnectorArgRef idsslContextFactory //ArgSet namePort8443/Set/New/Arg/Call// Use standard XML configuration for the other handlers and other// stuff you want to add/Configure 如您所见我们指定了SSL上下文。 这是必需的因为SPDY可在TLS上运行。 当我们运行此配置时Jetty将开始在端口8443上侦听SPDY连接。 并非所有浏览器都支持SPDY我已经使用最新的chrome浏览器测试了此示例。 如果浏览到https// localhost8443 / dummy.html 我创建用来测试的文件则将看到该文件的内容就像您使用HTTPS请求该文件一样。 那么这里发生了什么 首先让我们看一下Chrome提供的SPDY会话视图以确定我们是否真的在使用SPDY。 如果您导航到以下网址chrome// net-internals /eventsq typeSPDY_SESSION20isactive。 您会看到类似下图的内容。 在此视图中您可以看到所有当前的SPDY会话。 如果一切配置正确您还可以看到连接到本地主机的SPDY会话。 额外检查以查看是否一切正常以启用NPN扩展的调试功能。 您可以通过在用于启动服务器的Java代码中添加以下行来完成此操作 NextProtoNego。 调试 true ; 直接使用SPDY协议 现在我们已经可以使用HTTP over SPDY了让我们看一下Jetty提供的另一个选项它允许我们直接发送和接收SPDY消息。 对于此示例我们将创建一个客户端每5秒向服务器发送一条消息。 服务器以每秒接收的消息数发送响应到连接的客户端。 首先我们创建服务器代码。 import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.spdy.SPDYServerConnector;
import org.eclipse.jetty.spdy.api.DataInfo;
import org.eclipse.jetty.spdy.api.ReplyInfo;
import org.eclipse.jetty.spdy.api.Stream;
import org.eclipse.jetty.spdy.api.StreamFrameListener;
import org.eclipse.jetty.spdy.api.StringDataInfo;
import org.eclipse.jetty.spdy.api.SynInfo;
import org.eclipse.jetty.spdy.api.server.ServerSessionFrameListener;public class SPDYListener {public static void main(String[] args) throws Exception {// Frame listener that handles the communication over speedy ServerSessionFrameListener frameListener new ServerSessionFrameListener.Adapter() {/*** As soon as we receive a syninfo we return the handler for the stream on * this session*/Overridepublic StreamFrameListener onSyn(final Stream stream, SynInfo synInfo) {// Send a reply to this messagestream.reply(new ReplyInfo(false));// and start a timer that sends a request to this stream every 5 secondsScheduledExecutorService executor Executors.newSingleThreadScheduledExecutor();Runnable periodicTask new Runnable() {private int i 0;public void run() {// send a request and dont close the streamstream.data(new StringDataInfo(Data from the server i, false));}};executor.scheduleAtFixedRate(periodicTask, 0, 1, TimeUnit.SECONDS);// Next create an adapter to further handle the client input from specific stream.return new StreamFrameListener.Adapter() {/*** Were only interested in the data, not the headers in this* example*/public void onData(Stream stream, DataInfo dataInfo) {String clientData dataInfo.asString(UTF-8, true);System.out.println(Received the following client data: clientData);}};}};// Wire up and start the connectororg.eclipse.jetty.server.Server server new Server();SPDYServerConnector connector new SPDYServerConnector(frameListener);connector.setPort(8181);server.addConnector(connector);server.start();server.join();}
} 客户端代码如下所示 import java.net.InetSocketAddress;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;import org.eclipse.jetty.spdy.SPDYClient;
import org.eclipse.jetty.spdy.api.DataInfo;
import org.eclipse.jetty.spdy.api.SPDY;
import org.eclipse.jetty.spdy.api.Session;
import org.eclipse.jetty.spdy.api.Stream;
import org.eclipse.jetty.spdy.api.StreamFrameListener;
import org.eclipse.jetty.spdy.api.StringDataInfo;
import org.eclipse.jetty.spdy.api.SynInfo;/*** Calls the server every couple of seconds.* * author jos*/
public class SPDYCaller {public static void main(String[] args) throws Exception {// this listener receives data from the server. It then prints out the dataStreamFrameListener streamListener new StreamFrameListener.Adapter() {public void onData(Stream stream, DataInfo dataInfo) {// Data received from serverString content dataInfo.asString(UTF-8, true);System.out.println(SPDY content: content);}};// Create clientSPDYClient.Factory clientFactory new SPDYClient.Factory();clientFactory.start();SPDYClient client clientFactory.newSPDYClient(SPDY.V2);// Create a session to the server running on localhost port 8181Session session client.connect(new InetSocketAddress(localhost, 8181), null).get(5, TimeUnit.SECONDS);// Start a new session, and configure the stream listenerfinal Stream stream session.syn(new SynInfo(false), streamListener).get(5, TimeUnit.SECONDS);//start a timer that sends a request to this stream every secondScheduledExecutorService executor Executors.newSingleThreadScheduledExecutor();Runnable periodicTask new Runnable() {private int i 0;public void run() {// send a request, dont close the streamstream.data(new StringDataInfo(Data from the client i, false));}};executor.scheduleAtFixedRate(periodicTask, 0, 1, TimeUnit.SECONDS);}
} 这将在客户端和服务器上显示以下输出 客户 .. SPDY内容来自服务器的数据3 SPDY内容来自服务器的数据4 SPDY内容来自服务器的数据5 SPDY内容来自服务器的数据6 .. 服务器 … 收到以下客户端数据来自客户端的数据2 收到以下客户端数据来自客户端的数据3 收到以下客户端数据来自客户端的数据4 收到以下客户端数据来自客户端的数据5 … 从内联注释中代码本身应该易于理解。 唯一要记住的是当您想通过一个流发送多条数据消息时要确保将StringDataInfo的构造函数的第二个参数设置为false。 如果设置为true则在发送数据后将关闭流。 stream.data(new StringDataInfo(Data from the client i, false)); 这只是显示了一个简单的用例说明如何直接使用SPDY协议。 可以在Jetty Wiki和SPDY API文档中找到更多信息和示例。 参考 Smart Java博客上的JCG合作伙伴 Jos Dirksen的如何将SPDY与Jetty一起使用 。 翻译自: https://www.javacodegeeks.com/2012/04/how-to-use-spdy-with-jetty.htmljetty代理jetty