ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/catalina/startup/EmbeddedTomcat.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/catalina/startup/EmbeddedTomcat.java
Status
scanned
Type
file
Name
EmbeddedTomcat.java
Extension
.java
Programming language
Java
Mime type
text/x-c
File type
C source, ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
4109 (4.0 KB)
MD5
0c8b6fce7a357e880b99837e468d5da6
SHA1
5d4cc53520b948b9242ed7873dc17a2aed626fdd
SHA256
e7c4c120522859c6350127ab7d33b6d7b91e2da186b5de541297b4c7a7b3059b
SHA512

      
    
SHA1_git
8363347de10b9dbfd61340e7100fd446c9ed4c91
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
EmbeddedTomcat.java | 4.0 KB |

/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.catalina.startup; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.LogManager; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.junit.Ignore; import org.apache.catalina.Context; import org.apache.catalina.connector.Connector; import org.apache.juli.logging.LogFactory; import org.apache.tomcat.util.modeler.Registry; import org.apache.tomcat.util.scan.StandardJarScanFilter; import org.apache.tomcat.util.scan.StandardJarScanner; @Ignore public class EmbeddedTomcat { private static void resetLogging() { final String loggingConfig = "handlers = java.util.logging.ConsoleHandler " + ".handlers = java.util.logging.ConsoleHandler " + "java.util.logging.ConsoleHandler.level = FINE " + "java.util.logging.ConsoleHandler.formatter = org.apache.juli.OneLineFormatter " + "java.util.logging.ConsoleHandler.encoding = UTF-8 "; try { InputStream is = new ByteArrayInputStream(loggingConfig.getBytes(StandardCharsets.UTF_8)); LogManager.getLogManager().readConfiguration(is); LogFactory.getLog(EmbeddedTomcat.class).info("Logger configured to System.out"); } catch (SecurityException | IOException e) { // Ignore, the VM default will be used } } public static void main(String... args) throws Exception { Registry.disableRegistry(); Tomcat tomcat = new Tomcat(); resetLogging(); tomcat.setPort(8080); Connector connector = tomcat.getConnector(); connector.setProperty("bindOnInit", "false"); // No file system docBase required Context ctx = tomcat.addContext("", null); skipTldsForResourceJars(ctx); CounterServlet counterServlet = new CounterServlet(); Tomcat.addServlet(ctx, "counterServlet", counterServlet); ctx.addServletMappingDecoded("/", "counterServlet"); //ctx.addApplicationListener(new WsContextListener()); tomcat.start(); Thread.sleep(60*1000); } public static void skipTldsForResourceJars(Context context) { StandardJarScanner scanner = (StandardJarScanner) context.getJarScanner(); StandardJarScanFilter filter = (StandardJarScanFilter) scanner.getJarScanFilter(); filter.setTldSkip(filter.getTldSkip() + ",resources*.jar"); } private static class CounterServlet extends HttpServlet { private static final long serialVersionUID = 1L; private AtomicInteger callCount = new AtomicInteger(0); @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.getSession(true); resp.setContentType("text/plain"); resp.getWriter().print("OK: " + req.getRequestURL() + "[" + callCount.incrementAndGet()+ "]"); } } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
28.74
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9