当前位置: 首页>>代码示例>>Java>>正文


Java NetworkListener.getCompressionConfig方法代码示例

本文整理汇总了Java中org.glassfish.grizzly.http.server.NetworkListener.getCompressionConfig方法的典型用法代码示例。如果您正苦于以下问题:Java NetworkListener.getCompressionConfig方法的具体用法?Java NetworkListener.getCompressionConfig怎么用?Java NetworkListener.getCompressionConfig使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.glassfish.grizzly.http.server.NetworkListener的用法示例。


在下文中一共展示了NetworkListener.getCompressionConfig方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: Server

import org.glassfish.grizzly.http.server.NetworkListener; //导入方法依赖的package包/类
public Server(PropertiesConfiguration properties) throws IOException {
	m_properties = properties;
	m_httpServer = new HttpServer();
	
	int port = properties.getInt(PROPERTY_PORT, DEFAULT_PORT);
	String host = properties.getString(PROPERTY_HOST, DEFAULT_HOST);
	final NetworkListener networkListener = new NetworkListener(
			NET_LISTENER_NAME,
			host,
			port);

	// Enable SSL on the listener
	networkListener.setSecure(true);
	networkListener.setSSLEngineConfig(makeSSLConfig(m_properties));

	CompressionConfig compressionConfig =
	        networkListener.getCompressionConfig();
	compressionConfig.setCompressionMode(CompressionConfig.CompressionMode.ON); // the mode
	compressionConfig.setCompressionMinSize(100); // the min amount of bytes to compress
	compressionConfig.setCompressableMimeTypes("text/plain", "text/html", "application/x-protobuf", "application/pdf"); // the mime types to compress
	
	m_httpServer.addListener(networkListener);
	

	// Create a concurrent, nonblocking, asynchronous, batching JPA-based store for persistence
	// of request data. Async is OK, as persistence failures do not need to be handled by the client.
	m_store = new JPABatchStore(ConfigurationConverter.getMap(m_properties));
	m_batchPersister = new AsyncConcurrentBatchingProcessor<PersistEntityEvent>(
			m_store,
			PersistEntityEvent::new,
			PersistEntityEvent::translate
			);

	final ServerConfiguration config = m_httpServer.getServerConfiguration();

	config.setMaxPostSize(MAX_POST_SIZE);
	AsyncPostHandler.ErrorHandler errorHandler = 
			(ByteBuffer postBytes, Response resp, Throwable t) -> {
				LogManager.getLogger(this).warn("Invalid submission.", t);
				resp.sendError(300);
				resp.finish();
			};

	AsyncPostHandler certHandler = 
			new AsyncPostHandler(new CertificateHandler(m_batchPersister, CERT_TEMPLATE_PATH, errorHandler),
					errorHandler);
	
	
	AsyncPostHandler versionHandler =
			new AsyncPostHandler(new VersionCheckHandler(m_batchPersister, properties), errorHandler);
	config.addHttpHandler(certHandler, PATH_SUBMIT);
	config.addHttpHandler(versionHandler, PATH_VERSION_CHECK);
	
}
 
开发者ID:davruet,项目名称:shenanigans.io,代码行数:55,代码来源:Server.java

示例2: createListeners

import org.glassfish.grizzly.http.server.NetworkListener; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static List<NetworkListener> createListeners(List<Connector> connectors, CompressionConfig compression) {
    List<NetworkListener> listeners = Lists.newArrayList();

    for (Connector connector : connectors) {
        final String host = (connector.getHost() == null) ? Connector.DEFAULT_NETWORK_HOST
                : connector.getHost();
        final int port = (connector.getPort() == -1) ? 80 : connector.getPort();
        final NetworkListener listener = new NetworkListener(
                StringUtils.defaultString(connector.getName(), DEFAULT_NETWORK_LISTENER_NAME),
                host,
                port);
        listener.setSecure(connector.isSecureEnabled());
        SSLEngineConfigurator sslEngineConfigurator = createSslEngineConfigurator(connector);
        if (sslEngineConfigurator != null) {
            listener.setSSLEngineConfig(sslEngineConfigurator);

            if (connector.isSecureEnabled() && !connector.isAjpEnabled()) {
                listener.registerAddOn(new Http2AddOn());
                listener.registerAddOn(new SpdyAddOn());
            }
        }

        if (connector.isAjpEnabled()) {
            listener.registerAddOn(new AjpAddOn());
        }

        CompressionConfig compressionConfig = listener.getCompressionConfig();
        CompressionConfig compressionCfg = createCompressionConfig(null, (Map) connector.getRawProperties());

        if (compression != null) {

            if (compressionCfg.getCompressionMode() == null) {
                compressionCfg.setCompressionMode(compression.getCompressionMode());
            }

            if (compressionCfg.getCompressionMode() != CompressionConfig.CompressionMode.OFF) {
                if (compressionCfg.getCompressionMinSize() < 512) {
                    compressionCfg.setCompressionMinSize(compression.getCompressionMinSize());
                }

                Set<String> mimeTypes = compressionCfg.getCompressibleMimeTypes();
                Set<String> newTypes = Sets.newConcurrentHashSet(compression.getCompressibleMimeTypes());
                newTypes.addAll(mimeTypes);
                compressionCfg.setCompressibleMimeTypes(newTypes);

                Set<String> agents = compressionCfg.getNoCompressionUserAgents();
                Set<String> newAgents = Sets.newConcurrentHashSet(compression.getNoCompressionUserAgents());
                newAgents.addAll(agents);
                compressionCfg.setNoCompressionUserAgents(newAgents);
            }
        }

        if (compressionCfg != null) {
            compressionConfig.set(compressionCfg);
        }
        listener.setMaxHttpHeaderSize(98304);
        listeners.add(listener);
    }

    return listeners;
}
 
开发者ID:icode,项目名称:ameba-container-grizzly,代码行数:63,代码来源:GrizzlyServerUtil.java

示例3: createServer

import org.glassfish.grizzly.http.server.NetworkListener; //导入方法依赖的package包/类
private HttpServer createServer(URI uri, ResourceConfig configuration) {
		GrizzlyHttpContainer handler = ContainerFactory.createContainer(GrizzlyHttpContainer.class, configuration);
		boolean secure = false;
		SSLEngineConfigurator sslEngineConfigurator = null;
		boolean start = false;

		final String host = (uri.getHost() == null) ? NetworkListener.DEFAULT_NETWORK_HOST
				: uri.getHost();
		final int port = (uri.getPort() == -1) ? 80 : uri.getPort();
		final HttpServer server = new HttpServer();
		final NetworkListener listener = new NetworkListener("grizzly", host, port);
		listener.setSecure(secure);
		if (sslEngineConfigurator != null) {
			listener.setSSLEngineConfig(sslEngineConfigurator);
		}

		// insert
//		listener.

		CompressionConfig cg = listener.getCompressionConfig();
		cg.setCompressionMode(CompressionConfig.CompressionMode.ON);
//		cg.setCompressableMimeTypes("text","application/json");
		// end insert

		server.addListener(listener);

		// Map the path to the processor.
		final ServerConfiguration config = server.getServerConfiguration();
		if (handler != null) {
			config.addHttpHandler(handler, uri.getPath());
		}

		config.setPassTraceRequest(true);

		if (start) {
			try {
				// Start the server.
				server.start();
			} catch (IOException ex) {
				throw new ProcessingException("IOException thrown when trying to start grizzly server", ex);
			}
		}

		return server;
	}
 
开发者ID:jakobwenzel,项目名称:rallye-server,代码行数:46,代码来源:RallyeServer.java


注:本文中的org.glassfish.grizzly.http.server.NetworkListener.getCompressionConfig方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。