Java Code Examples for org.apache.catalina.Wrapper#setMultipartConfigElement()

The following examples show how to use org.apache.catalina.Wrapper#setMultipartConfigElement() . 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: TestStandardContext.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
private synchronized void init() throws Exception {
    if (init) return;

    Tomcat tomcat = getTomcatInstance();
    context = tomcat.addContext("", TEMP_DIR);
    Tomcat.addServlet(context, "regular", new Bug49711Servlet());
    Wrapper w = Tomcat.addServlet(context, "multipart", new Bug49711Servlet_multipart());

    // Tomcat.addServlet does not respect annotations, so we have
    // to set our own MultipartConfigElement.
    w.setMultipartConfigElement(new MultipartConfigElement(""));

    context.addServletMappingDecoded("/regular", "regular");
    context.addServletMappingDecoded("/multipart", "multipart");
    tomcat.start();

    setPort(tomcat.getConnector().getLocalPort());

    init = true;
}
 
Example 2
Source File: TestStandardContext.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
private synchronized void init() throws Exception {
    if (init) return;

    Tomcat tomcat = getTomcatInstance();
    context = tomcat.addContext("", TEMP_DIR);
    Tomcat.addServlet(context, "regular", new Bug49711Servlet());
    Wrapper w = Tomcat.addServlet(context, "multipart", new Bug49711Servlet_multipart());

    // Tomcat.addServlet does not respect annotations, so we have
    // to set our own MultipartConfigElement.
    w.setMultipartConfigElement(new MultipartConfigElement(""));

    context.addServletMapping("/regular", "regular");
    context.addServletMapping("/multipart", "multipart");
    tomcat.start();

    setPort(tomcat.getConnector().getLocalPort());

    init = true;
}
 
Example 3
Source File: TestStandardContext.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
private synchronized void init() throws Exception {
    if (init) return;

    Tomcat tomcat = getTomcatInstance();
    context = tomcat.addContext("", TEMP_DIR);
    Tomcat.addServlet(context, "regular", new Bug49711Servlet());
    Wrapper w = Tomcat.addServlet(context, "multipart", new Bug49711Servlet_multipart());

    // Tomcat.addServlet does not respect annotations, so we have
    // to set our own MultipartConfigElement.
    w.setMultipartConfigElement(new MultipartConfigElement(""));

    context.addServletMapping("/regular", "regular");
    context.addServletMapping("/multipart", "multipart");
    tomcat.start();

    setPort(tomcat.getConnector().getLocalPort());

    init = true;
}
 
Example 4
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 5
Source File: TestSwallowAbortedUploads.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
private synchronized void init(boolean limited, boolean swallow)
        throws Exception {
    if (init)
        return;

    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.addServletMapping(URI, servletName);
    context.setSwallowAbortedUploads(swallow);

    tomcat.start();
    setPort(tomcat.getConnector().getLocalPort());

    init = true;
}
 
Example 6
Source File: TestSwallowAbortedUploads.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
private synchronized void init(boolean limited, boolean swallow)
        throws Exception {
    if (init)
        return;

    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.addServletMapping(URI, servletName);
    context.setSwallowAbortedUploads(swallow);

    tomcat.start();
    setPort(tomcat.getConnector().getLocalPort());

    init = true;
}
 
Example 7
Source File: ServingLayer.java    From oryx with Apache License 2.0 4 votes vote down vote up
private void makeContext(Tomcat tomcat, Path noSuchBaseDir) throws IOException {
  Path contextPath = noSuchBaseDir.resolve("context");
  Files.createDirectories(contextPath);

  context = tomcat.addContext(contextPathURIBase, contextPath.toAbsolutePath().toString());

  context.setWebappVersion("3.1");
  context.setName("Oryx");

  context.addWelcomeFile("index.html");
  addErrorPages(context);

  // OryxApplication only needs one config value, so just pass it
  context.addParameter(OryxApplication.class.getName() + ".packages", appResourcesPackages);
  // ModelManagerListener will need whole config
  String serializedConfig = ConfigUtils.serialize(config);
  context.addParameter(ConfigUtils.class.getName() + ".serialized", serializedConfig);

  Wrapper wrapper =
      Tomcat.addServlet(context, "Jersey", "org.glassfish.jersey.servlet.ServletContainer");
  wrapper.addInitParameter("javax.ws.rs.Application", OryxApplication.class.getName());
  //wrapper.addInitParameter(OryxApplication.class.getName() + ".packages", appResourcesPackage);
  wrapper.addMapping("/*");
  wrapper.setLoadOnStartup(1);
  wrapper.setMultipartConfigElement(new MultipartConfigElement(""));

  if (!doNotInitTopics) { // Only for tests
    context.addApplicationListener(ModelManagerListener.class.getName());
  }

  // Better way to configure JASPIC?
  AuthConfigFactory.setFactory(new AuthConfigFactoryImpl());

  boolean needHTTPS = keystoreFile != null;
  boolean needAuthentication = userName != null;

  if (needHTTPS || needAuthentication) {

    SecurityCollection securityCollection = new SecurityCollection();
    securityCollection.addPattern("/*");
    SecurityConstraint securityConstraint = new SecurityConstraint();
    securityConstraint.addCollection(securityCollection);

    if (needHTTPS) {
      securityConstraint.setUserConstraint("CONFIDENTIAL");
    }

    if (needAuthentication) {

      LoginConfig loginConfig = new LoginConfig();
      loginConfig.setAuthMethod("DIGEST");
      loginConfig.setRealmName(InMemoryRealm.NAME);
      context.setLoginConfig(loginConfig);

      securityConstraint.addAuthRole(InMemoryRealm.AUTH_ROLE);

      context.addSecurityRole(InMemoryRealm.AUTH_ROLE);
      DigestAuthenticator authenticator = new DigestAuthenticator();
      authenticator.setNonceValidity(10 * 1000L); // Shorten from 5 minutes to 10 seconds
      authenticator.setNonceCacheSize(20000); // Increase from 1000 to 20000
      context.getPipeline().addValve(authenticator);
    }

    context.addConstraint(securityConstraint);
  }

  context.setCookies(false);
}
 
Example 8
Source File: Runner.java    From myrrix-recommender with Apache License 2.0 4 votes vote down vote up
@Override
public Boolean call() throws IOException {

  MemoryHandler.setSensibleLogFormat();
  java.util.logging.Logger.getLogger("").addHandler(new MemoryHandler());

  Tomcat tomcat = new Tomcat();
  Connector connector = makeConnector();
  configureTomcat(tomcat, connector);
  configureEngine(tomcat.getEngine());
  configureServer(tomcat.getServer());
  configureHost(tomcat.getHost());
  Context context = makeContext(tomcat, noSuchBaseDir, connector.getPort());
  
  if (config.getHostRequestLimit() != null) {
    addFilter(context, new DoSFilter(), "/*", 
              Collections.singletonMap(DoSFilter.MAX_ACCESS_PER_HOST_PER_MIN_KEY, 
                                       config.getHostRequestLimit().toString()));
  }

  addServlet(context, new RecommendServlet(), "/recommend/*");
  addServlet(context, new RecommendToManyServlet(), "/recommendToMany/*");
  addServlet(context, new RecommendToAnonymousServlet(), "/recommendToAnonymous/*");
  addServlet(context, new SimilarityServlet(), "/similarity/*");
  addServlet(context, new SimilarityToItemServlet(), "/similarityToItem/*");
  addServlet(context, new EstimateServlet(), "/estimate/*");
  addServlet(context, new EstimateForAnonymousServlet(), "/estimateForAnonymous/*");    
  addServlet(context, new BecauseServlet(), "/because/*");
  addServlet(context, new ReadyServlet(), "/ready/*");
  addServlet(context, new AllUserIDsServlet(), "/user/allIDs/*");
  addServlet(context, new AllItemIDsServlet(), "/item/allIDs/*");
  addServlet(context, new UserClusterServlet(), "/user/clusters/*");
  addServlet(context, new ItemClusterServlet(), "/item/clusters/*");
  addServlet(context, new MostPopularItemsServlet(), "/mostPopularItems/*");

  if (!config.isReadOnly()) {
    addServlet(context, new PreferenceServlet(), "/pref/*");
    addServlet(context, new TagUserServlet(), "/tag/user/*");
    addServlet(context, new TagItemServlet(), "/tag/item/*");
    Wrapper ingestWrapper = addServlet(context, new IngestServlet(), "/ingest/*");
    ingestWrapper.setMultipartConfigElement(new MultipartConfigElement("/tmp"));
    addServlet(context, new RefreshServlet(), "/refresh/*");
  }

  addServlet(context, new index_jspx(), "/index.jspx");
  addServlet(context, new status_jspx(), "/status.jspx");
  addServlet(context, new error_jspx(), "/error.jspx");
  addServlet(context, new som_jspx(), "/som.jspx");
  addServlet(context, new LogServlet(), "/log.txt");

  try {
    tomcat.start();
  } catch (LifecycleException le) {
    throw new IOException(le);
  }
  this.tomcat = tomcat;
  return Boolean.TRUE;
}