Java Code Examples for org.apache.catalina.connector.Connector#setMaxPostSize()

The following examples show how to use org.apache.catalina.connector.Connector#setMaxPostSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestSwallowAbortedUploads.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
private synchronized void init(int status, boolean swallow)
        throws Exception {

    Tomcat tomcat = getTomcatInstance();
    context = tomcat.addContext("", TEMP_DIR);
    AbortedPOSTServlet servlet = new AbortedPOSTServlet(status);
    Tomcat.addServlet(context, servletName, servlet);
    context.addServletMappingDecoded(URI, servletName);
    context.setSwallowAbortedUploads(swallow);

    tomcat.start();

    Connector c = tomcat.getConnector();
    c.setMaxPostSize(2 * hugeSize);
    c.setProperty("maxSwallowSize", Integer.toString(hugeSize));

    setPort(c.getLocalPort());
}
 
Example 2
Source File: ConnectorConf.java    From nano-framework with Apache License 2.0 6 votes vote down vote up
public Connector init() {
    final Connector connector = new Connector(protocal);
    connector.setPort(port);
    connector.setAsyncTimeout(connectionTimeout);
    connector.setRedirectPort(redirectPort);
    connector.setAttribute("executor", executor);
    connector.setEnableLookups(enableLookups);
    connector.setAttribute("acceptCount", acceptCount);
    connector.setMaxPostSize(maxPostSize);
    connector.setAttribute("compression", compression);
    connector.setAttribute("disableUploadTimeout", disableUploadTimeout);
    connector.setAttribute("noCompressionUserAgents", noCompressionUserAgents);
    connector.setAttribute("acceptorThreadCount", acceptorThreadCount);
    connector.setAttribute("compressableMimeType", compressableMimeType);
    connector.setURIEncoding(URIEncoding);
    return connector;
}
 
Example 3
Source File: TestSwallowAbortedUploads.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
private synchronized void init(boolean limited, boolean swallow)
        throws Exception {

    Tomcat tomcat = getTomcatInstance();
    context = tomcat.addContext("", TEMP_DIR);
    Wrapper w;
    w = Tomcat.addServlet(context, servletName,
                          new AbortedUploadServlet());
    // Tomcat.addServlet does not respect annotations, so we have
    // to set our own MultipartConfigElement.
    // Choose upload file size limit.
    if (limited) {
        w.setMultipartConfigElement(new MultipartConfigElement("",
                limitSize, -1, -1));
    } else {
        w.setMultipartConfigElement(new MultipartConfigElement(""));
    }
    context.addServletMappingDecoded(URI, servletName);
    context.setSwallowAbortedUploads(swallow);

    Connector c = tomcat.getConnector();
    c.setMaxPostSize(2 * hugeSize);
    c.setProperty("maxSwallowSize", Integer.toString(hugeSize));

    tomcat.start();
    setPort(c.getLocalPort());
}
 
Example 4
Source File: TomcatServer.java    From onetwo with Apache License 2.0 4 votes vote down vote up
public void initialize() {
		try {
			JFishTomcat tomcat = new JFishTomcat();
			if(serverConfig.getTomcatContextClassName()!=null){
				tomcat.setContextClass((Class<StandardContext>)ReflectUtils.loadClass(serverConfig.getTomcatContextClassName(), true));
			}
			int port = serverConfig.getPort();
			tomcat.setPort(port);
//			tomcat.setBaseDir(webConfig.getServerBaseDir());
			String baseDir = null;
			if(!Utils.isBlank(serverConfig.getServerBaseDir())){
				baseDir = serverConfig.getServerBaseDir();
			}else{
				baseDir = System.getProperty("java.io.tmpdir");
				logger.info("set serverBaseDir as java.io.tmpdir : {} ", baseDir);
			}
			tomcat.setBaseDir(baseDir);
			
			// This magic line makes Tomcat look for WAR files in catalinaHome/webapps
			// and automatically deploy them
//			tomcat.getHost().addLifecycleListener(new HostConfig());
			appBaseFile = new File(baseDir+"/tomcat.webapps."+this.serverConfig.getPort());
			if(!appBaseFile.exists()){
				appBaseFile.mkdirs();
			}
			appBaseFile.deleteOnExit();
			tomcat.getHost().setAppBase(appBaseFile.getAbsolutePath());
			Connector connector = tomcat.getConnector();
			connector.setURIEncoding("UTF-8");
			connector.setRedirectPort(serverConfig.getRedirectPort());
			connector.setMaxPostSize(serverConfig.getMaxPostSize());
			
			ProtocolHandler protocol = connector.getProtocolHandler();
			if(protocol instanceof AbstractHttp11Protocol){
				/*****
				 * <Connector port="8080" protocol="HTTP/1.1" 
					   connectionTimeout="20000" 
   						redirectPort="8181" compression="500" 
  						compressableMimeType="text/html,text/xml,text/plain,application/octet-stream" />
				 */
				AbstractHttp11Protocol<?> hp = (AbstractHttp11Protocol<?>) protocol;
				hp.setCompression("on");
				hp.setCompressableMimeTypes("text/html,text/xml,text/plain,application/octet-stream");
			}
			
			
			StandardServer server = (StandardServer) tomcat.getServer();
			AprLifecycleListener listener = new AprLifecycleListener();
			server.addLifecycleListener(listener);

			/*tomcat.addUser("adminuser", "adminuser");
			tomcat.addRole("adminuser", "admin");
			tomcat.addRole("adminuser", "admin");*/
			
			this.tomcat = tomcat;
		} catch (Exception e) {
			throw new RuntimeException("web server initialize error , check it. " + e.getMessage(), e);
		}
		
		/*Runtime.getRuntime().addShutdownHook(new Thread(){

			@Override
			public void run() {
				appBaseFile.delete();
			}
			
		});*/
	}
 
Example 5
Source File: ServingLayer.java    From oryx with Apache License 2.0 4 votes vote down vote up
private Connector makeConnector() {
  Connector connector = new Connector(Http11Nio2Protocol.class.getName());

  if (keystoreFile == null) {

    // HTTP connector
    connector.setPort(port);
    connector.setSecure(false);
    connector.setScheme("http");

  } else {

    // HTTPS connector
    connector.setPort(securePort);
    connector.setSecure(true);
    connector.setScheme("https");
    connector.setAttribute("SSLEnabled", "true");
    SSLHostConfig sslHostConfig = new SSLHostConfig();
    SSLHostConfigCertificate cert =
        new SSLHostConfigCertificate(sslHostConfig, SSLHostConfigCertificate.Type.RSA);
    cert.setCertificateKeystoreFile(keystoreFile.toAbsolutePath().toString());
    cert.setCertificateKeystorePassword(keystorePassword);
    cert.setCertificateKeyAlias(keyAlias);
    sslHostConfig.addCertificate(cert);
    connector.addSslHostConfig(sslHostConfig);
  }

  connector.addUpgradeProtocol(new Http2Protocol());

  // Keep quiet about the server type
  connector.setXpoweredBy(false);

  // Basic tuning params:
  connector.setAttribute("maxThreads", 400);
  connector.setAttribute("acceptCount", 50);
  //connector.setAttribute("connectionTimeout", 2000);
  connector.setAttribute("maxKeepAliveRequests", 100);

  // Avoid running out of ephemeral ports under heavy load?
  connector.setAttribute("socket.soReuseAddress", true);

  connector.setMaxPostSize(0);
  connector.setAttribute("disableUploadTimeout", false);

  // Allow long URLs
  connector.setAttribute("maxHttpHeaderSize", 65536);

  // Enable response compression
  connector.setAttribute("compression", "on");
  // Defaults are text/html,text/xml,text/plain,text/css
  connector.setAttribute("compressableMimeType", "text/html,text/xml,text/plain,text/css,text/csv,application/json");

  return connector;
}
 
Example 6
Source File: Runner.java    From myrrix-recommender with Apache License 2.0 4 votes vote down vote up
private Connector makeConnector() throws IOException {
  Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
  File keystoreFile = config.getKeystoreFile();
  String keystorePassword = config.getKeystorePassword();
  if (keystoreFile == null && keystorePassword == null) {
    // HTTP connector
    connector.setPort(config.getPort());
    connector.setSecure(false);
    connector.setScheme("http");

  } else {

    if (keystoreFile == null || !keystoreFile.exists()) {
      log.info("Keystore file not found; trying to load remote keystore file if applicable");
      ResourceRetriever resourceRetriever =
          ClassUtils.loadInstanceOf("net.myrrix.online.io.DelegateResourceRetriever", ResourceRetriever.class);
      resourceRetriever.init(config.getBucket());
      keystoreFile = resourceRetriever.getKeystoreFile(config.getInstanceID());
      if (keystoreFile == null) {
        throw new FileNotFoundException();
      }
    }

    // HTTPS connector
    connector.setPort(config.getSecurePort());
    connector.setSecure(true);
    connector.setScheme("https");
    connector.setAttribute("SSLEnabled", "true");
    String protocol = chooseSSLProtocol("TLSv1.1", "TLSv1");
    if (protocol != null) {
      connector.setAttribute("sslProtocol", protocol);
    }
    if (keystoreFile != null) {
      connector.setAttribute("keystoreFile", keystoreFile.getAbsoluteFile());
    }
    connector.setAttribute("keystorePass", keystorePassword);
  }

  // Keep quiet about the server type
  connector.setXpoweredBy(false);
  connector.setAttribute("server", "Myrrix");

  // Basic tuning params:
  connector.setAttribute("maxThreads", 400);
  connector.setAttribute("acceptCount", 50);
  //connector.setAttribute("connectionTimeout", 2000);
  connector.setAttribute("maxKeepAliveRequests", 100);

  // Avoid running out of ephemeral ports under heavy load?
  connector.setAttribute("socket.soReuseAddress", true);
  
  connector.setMaxPostSize(0);
  connector.setAttribute("disableUploadTimeout", false);

  return connector;
}