This commit is contained in:
2024-11-30 19:03:49 +08:00
commit 1e6763c160
3806 changed files with 737676 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,40 @@
/*
* 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.tomcat.unittest;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
public class TesterCounter {
private static final Log log = LogFactory.getLog(TesterCounter.class);
static {
log.info("TestCounter loaded by " + TesterCounter.class.getClassLoader() +
" in thread " + Thread.currentThread().getName());
}
private int count = 0;
public void increment() {
count++;
}
public int getCount() {
return count;
}
}

View File

@@ -0,0 +1,37 @@
/*
* 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.tomcat.unittest;
public class TesterData {
public static String string(char c, int count) {
StringBuilder sb = new StringBuilder(count);
for (int i = 0; i < count; i++) {
sb.append(c);
}
return sb.toString();
}
public static String string(String str, int count) {
StringBuilder sb = new StringBuilder(str.length() * count);
for (int i = 0; i < count; i++) {
sb.append(str);
}
return sb.toString();
}
}

View File

@@ -0,0 +1,377 @@
/*
* 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.tomcat.unittest;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.util.concurrent.ExecutorService;
import java.util.regex.Pattern;
import javax.management.ObjectName;
import org.apache.catalina.AccessLog;
import org.apache.catalina.Cluster;
import org.apache.catalina.Container;
import org.apache.catalina.ContainerListener;
import org.apache.catalina.Host;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.LifecycleState;
import org.apache.catalina.Pipeline;
import org.apache.catalina.Realm;
import org.apache.catalina.connector.Request;
import org.apache.catalina.connector.Response;
import org.apache.juli.logging.Log;
public class TesterHost implements Host {
@Override
public Log getLogger() {
return null;
}
@Override
public String getLogName() {
return null;
}
@Override
public ObjectName getObjectName() {
return null;
}
@Override
public String getDomain() {
return null;
}
@Override
public String getMBeanKeyProperties() {
return null;
}
@Override
public Pipeline getPipeline() {
return null;
}
@Override
public Cluster getCluster() {
return null;
}
@Override
public void setCluster(Cluster cluster) {
// NO-OP
}
@Override
public int getBackgroundProcessorDelay() {
return 0;
}
@Override
public void setBackgroundProcessorDelay(int delay) {
// NO-OP
}
private String name = "TestHost";
@Override
public String getName() {
return name;
}
@Override
public void setName(String name) {
this.name = name;
}
@Override
public Container getParent() {
return null;
}
@Override
public void setParent(Container container) {
// NO-OP
}
@Override
public ClassLoader getParentClassLoader() {
return null;
}
@Override
public void setParentClassLoader(ClassLoader parent) {
// NO-OP
}
@Override
public Realm getRealm() {
return null;
}
@Override
public void setRealm(Realm realm) {
// NO-OP
}
@Override
public void backgroundProcess() {
// NO-OP
}
@Override
public void addChild(Container child) {
// NO-OP
}
@Override
public void addContainerListener(ContainerListener listener) {
// NO-OP
}
@Override
public void addPropertyChangeListener(PropertyChangeListener listener) {
// NO-OP
}
@Override
public Container findChild(String name) {
return null;
}
@Override
public Container[] findChildren() {
return null;
}
@Override
public ContainerListener[] findContainerListeners() {
return null;
}
@Override
public void removeChild(Container child) {
// NO-OP
}
@Override
public void removeContainerListener(ContainerListener listener) {
// NO-OP
}
@Override
public void removePropertyChangeListener(PropertyChangeListener listener) {
// NO-OP
}
@Override
public void fireContainerEvent(String type, Object data) {
// NO-OP
}
@Override
public void logAccess(Request request, Response response, long time, boolean useDefault) {
// NO-OP
}
@Override
public AccessLog getAccessLog() {
return null;
}
@Override
public int getStartStopThreads() {
return 0;
}
@Override
public void setStartStopThreads(int startStopThreads) {
// NO-OP
}
@Override
public File getCatalinaBase() {
return null;
}
@Override
public File getCatalinaHome() {
return null;
}
@Override
public void addLifecycleListener(LifecycleListener listener) {
// NO-OP
}
@Override
public LifecycleListener[] findLifecycleListeners() {
return null;
}
@Override
public void removeLifecycleListener(LifecycleListener listener) {
// NO-OP
}
@Override
public void init() throws LifecycleException {
// NO-OP
}
@Override
public void start() throws LifecycleException {
// NO-OP
}
@Override
public void stop() throws LifecycleException {
// NO-OP
}
@Override
public void destroy() throws LifecycleException {
// NO-OP
}
@Override
public LifecycleState getState() {
return null;
}
@Override
public String getStateName() {
return null;
}
@Override
public String getXmlBase() {
return null;
}
@Override
public void setXmlBase(String xmlBase) {
// NO-OP
}
@Override
public File getConfigBaseFile() {
return null;
}
@Override
public String getAppBase() {
return null;
}
@Override
public File getAppBaseFile() {
return null;
}
@Override
public void setAppBase(String appBase) {
// NO-OP
}
@Override
public boolean getAutoDeploy() {
return false;
}
@Override
public void setAutoDeploy(boolean autoDeploy) {
// NO-OP
}
@Override
public String getConfigClass() {
return null;
}
@Override
public void setConfigClass(String configClass) {
// NO-OP
}
@Override
public boolean getDeployOnStartup() {
return false;
}
@Override
public void setDeployOnStartup(boolean deployOnStartup) {
// NO-OP
}
@Override
public String getDeployIgnore() {
return null;
}
@Override
public Pattern getDeployIgnorePattern() {
return null;
}
@Override
public void setDeployIgnore(String deployIgnore) {
// NO-OP
}
@Override
public ExecutorService getStartStopExecutor() {
return null;
}
@Override
public boolean getCreateDirs() {
return false;
}
@Override
public void setCreateDirs(boolean createDirs) {
// NO-OP
}
@Override
public boolean getUndeployOldVersions() {
return false;
}
@Override
public void setUndeployOldVersions(boolean undeployOldVersions) {
// NO-OP
}
@Override
public void addAlias(String alias) {
// NO-OP
}
@Override
public String[] findAliases() {
return null;
}
@Override
public void removeAlias(String alias) {
// NO-OP
}
}

View File

@@ -0,0 +1,54 @@
/*
* 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.tomcat.unittest;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
public class TesterLeakingServlet1 extends HttpServlet {
private static final Log log = LogFactory.getLog(TesterLeakingServlet1.class);
private static final long serialVersionUID = 1L;
private static ThreadLocal<TesterCounter> myThreadLocal = new ThreadLocal<>();
@Override
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
TesterCounter counter = myThreadLocal.get();
if (counter == null) {
log.info("Adding thread local to thread " + Thread.currentThread().getName());
counter = new TesterCounter();
myThreadLocal.set(counter);
}
counter.increment();
response.getWriter().println(
"The current thread served this servlet "
+ counter.getCount() + " times");
}
}

View File

@@ -0,0 +1,58 @@
/*
* 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.tomcat.unittest;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
public class TesterLeakingServlet2 extends HttpServlet {
private static final long serialVersionUID = 1L;
private static final Log log = LogFactory.getLog(TesterLeakingServlet2.class);
@Override
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
List<TesterCounter> counterList = TesterThreadScopedHolder.getFromHolder();
TesterCounter counter;
if (counterList == null) {
log.info("Adding thread local to thread " + Thread.currentThread().getName());
counter = new TesterCounter();
TesterThreadScopedHolder.saveInHolder(Arrays.asList(counter));
} else {
counter = counterList.get(0);
}
counter.increment();
response.getWriter().println(
"The current thread served this servlet "
+ counter.getCount() + " times");
}
}

View File

@@ -0,0 +1,90 @@
/*
* 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.tomcat.unittest;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Filter;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.LogRecord;
public class TesterLogValidationFilter implements Filter {
private final Level targetLevel;
private final String targetMessage;
private final String targetThrowableString;
private final AtomicInteger messageCount = new AtomicInteger(0);
public TesterLogValidationFilter(Level targetLevel, String targetMessage,
String targetThrowableString) {
this.targetLevel = targetLevel;
this.targetMessage = targetMessage;
this.targetThrowableString = targetThrowableString;
}
public int getMessageCount() {
return messageCount.get();
}
@Override
public boolean isLoggable(LogRecord record) {
if (targetLevel != null) {
Level level = record.getLevel();
if (targetLevel != level) {
return true;
}
}
if (targetMessage != null) {
String msg = record.getMessage();
if (msg == null || !msg.contains(targetMessage)) {
return true;
}
}
if (targetThrowableString != null) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
record.getThrown().printStackTrace(pw);
pw.close();
String throwableString = sw.toString();
if (!throwableString.contains(targetThrowableString)) {
return true;
}
}
messageCount.incrementAndGet();
return true;
}
public static TesterLogValidationFilter add(Level targetLevel, String targetMessage,
String targetThrowableString, String loggerName) {
TesterLogValidationFilter f = new TesterLogValidationFilter(targetLevel, targetMessage,
targetThrowableString);
LogManager.getLogManager().getLogger(loggerName).setFilter(f);
return f;
}
}

View File

@@ -0,0 +1,141 @@
/*
* 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.tomcat.unittest;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.ServletContext;
import javax.servlet.SessionTrackingMode;
import org.apache.catalina.Context;
import org.apache.catalina.connector.Request;
import org.apache.catalina.session.StandardSession;
public class TesterRequest extends Request {
private final TesterContext context;
private final TesterServletContext servletContext;
public TesterRequest() {
this(false);
}
public TesterRequest(boolean withSession) {
context = new TesterContext();
servletContext = new TesterServletContext();
context.setServletContext(servletContext);
if (withSession) {
Set<SessionTrackingMode> modes = new HashSet<>();
modes.add(SessionTrackingMode.URL);
modes.add(SessionTrackingMode.COOKIE);
servletContext.setSessionTrackingModes(modes);
session = new StandardSession(null);
session.setId("1234", false);
session.setValid(true);
}
}
@Override
public String getScheme() {
return "http";
}
@Override
public String getServerName() {
return "localhost";
}
@Override
public int getServerPort() {
return 8080;
}
@Override
public String getRequestURI() {
return "/level1/level2/foo.html";
}
@Override
public String getDecodedRequestURI() {
// Decoding not required
return getRequestURI();
}
@Override
public Context getContext() {
return context;
}
@Override
public ServletContext getServletContext() {
return servletContext;
}
private String method;
public void setMethod(String method) {
this.method = method;
}
@Override
public String getMethod() {
return method;
}
private final Map<String,List<String>> headers = new HashMap<>();
public void addHeader(String name, String value) {
List<String> values = headers.get(name);
if (values == null) {
values = new ArrayList<>();
headers.put(name, values);
}
values.add(value);
}
@Override
public String getHeader(String name) {
List<String> values = headers.get(name);
if (values == null || values.size() == 0) {
return null;
}
return values.get(0);
}
@Override
public Enumeration<String> getHeaders(String name) {
List<String> values = headers.get(name);
if (values == null || values.size() == 0) {
return Collections.emptyEnumeration();
}
return Collections.enumeration(headers.get(name));
}
@Override
public Enumeration<String> getHeaderNames() {
return Collections.enumeration(headers.keySet());
}
}

View File

@@ -0,0 +1,73 @@
/*
* 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.tomcat.unittest;
import java.io.IOException;
import org.apache.catalina.connector.Response;
/**
* Minimal changes to Response to enable tests that use this class to operate
* correctly.
*/
public class TesterResponse extends Response {
@Override
public boolean isCommitted() {
return false;
}
@Override
public void sendError(int status, String message) throws IOException {
// NO-OP by default.
/*
System.out.println("TesterResponse.sendError(" + status + ", \"" +
message + "\")");
*/
}
@Override
public void resetBuffer(boolean resetWriterStreamFlags) {
// NO-OP by default.
// There is no buffer created for this test object since no test depends
// on one being present or on this method resetting it.
}
@Override
public org.apache.coyote.Response getCoyoteResponse() {
// Lazy init
if (super.getCoyoteResponse() == null) {
this.coyoteResponse = new org.apache.coyote.Response();
}
return super.getCoyoteResponse();
}
@Override
public void setSuspended(boolean suspended) {
// NO-OP by default.
// There is no buffer created for this test object since no test depends
// on one being present or on this method suspending it.
}
@Override
public void reset() {
// Minimal implementation for tests that avoids using OutputBuffer
if (super.getCoyoteResponse() != null) {
super.getCoyoteResponse().reset();
}
}
}

View File

@@ -0,0 +1,345 @@
/*
* 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.tomcat.unittest;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collections;
import java.util.Enumeration;
import java.util.EventListener;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import javax.servlet.Filter;
import javax.servlet.FilterRegistration;
import javax.servlet.RequestDispatcher;
import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import javax.servlet.ServletRegistration.Dynamic;
import javax.servlet.SessionCookieConfig;
import javax.servlet.SessionTrackingMode;
import javax.servlet.descriptor.JspConfigDescriptor;
import org.apache.catalina.core.ApplicationFilterRegistration;
import org.apache.tomcat.util.descriptor.web.FilterDef;
public class TesterServletContext implements ServletContext {
/**
* {@inheritDoc}
* <p>
* This test implementation is hard coded to return an empty String.
*/
@Override
public String getContextPath() {
return "";
}
/**
* {@inheritDoc}
* <p>
* This test implementation is hard coded to return an empty Set.
*/
@Override
public Set<String> getResourcePaths(String path) {
return Collections.emptySet();
}
/**
* {@inheritDoc}
* <p>
* This test implementation is hard coded to return the class loader that
* loaded this class.
*/
@Override
public ClassLoader getClassLoader() {
return getClass().getClassLoader();
}
@Override
public ServletContext getContext(String uripath) {
throw new RuntimeException("Not implemented");
}
@Override
public int getMajorVersion() {
throw new RuntimeException("Not implemented");
}
@Override
public int getMinorVersion() {
throw new RuntimeException("Not implemented");
}
@Override
public String getMimeType(String file) {
throw new RuntimeException("Not implemented");
}
@Override
public URL getResource(String path) throws MalformedURLException {
return null;
}
@Override
public InputStream getResourceAsStream(String path) {
throw new RuntimeException("Not implemented");
}
@Override
public RequestDispatcher getRequestDispatcher(String path) {
throw new RuntimeException("Not implemented");
}
@Override
public RequestDispatcher getNamedDispatcher(String name) {
throw new RuntimeException("Not implemented");
}
@Override
public Servlet getServlet(String name) throws ServletException {
throw new RuntimeException("Not implemented");
}
@Override
public Enumeration<Servlet> getServlets() {
throw new RuntimeException("Not implemented");
}
@Override
public Enumeration<String> getServletNames() {
throw new RuntimeException("Not implemented");
}
@Override
public void log(String msg) {
// NOOP
}
@Override
public void log(Exception exception, String msg) {
// NOOP
}
@Override
public void log(String message, Throwable throwable) {
// NOOP
}
@Override
public String getRealPath(String path) {
throw new RuntimeException("Not implemented");
}
@Override
public String getServerInfo() {
throw new RuntimeException("Not implemented");
}
@Override
public String getInitParameter(String name) {
return null;
}
@Override
public Enumeration<String> getInitParameterNames() {
throw new RuntimeException("Not implemented");
}
@Override
public Object getAttribute(String name) {
// Used by websockets
return null;
}
@Override
public Enumeration<String> getAttributeNames() {
throw new RuntimeException("Not implemented");
}
@Override
public void setAttribute(String name, Object object) {
throw new RuntimeException("Not implemented");
}
@Override
public void removeAttribute(String name) {
throw new RuntimeException("Not implemented");
}
@Override
public String getServletContextName() {
throw new RuntimeException("Not implemented");
}
@Override
public int getEffectiveMajorVersion() {
throw new RuntimeException("Not implemented");
}
@Override
public int getEffectiveMinorVersion() {
throw new RuntimeException("Not implemented");
}
@Override
public boolean setInitParameter(String name, String value) {
throw new RuntimeException("Not implemented");
}
@Override
public Dynamic addServlet(String servletName, String className) {
throw new RuntimeException("Not implemented");
}
@Override
public Dynamic addServlet(String servletName, Servlet servlet) {
throw new RuntimeException("Not implemented");
}
@Override
public Dynamic addServlet(String servletName,
Class<? extends Servlet> servletClass) {
throw new RuntimeException("Not implemented");
}
@Override
public <T extends Servlet> T createServlet(Class<T> c)
throws ServletException {
throw new RuntimeException("Not implemented");
}
@Override
public ServletRegistration getServletRegistration(String servletName) {
throw new RuntimeException("Not implemented");
}
@Override
public Map<String, ? extends ServletRegistration> getServletRegistrations() {
throw new RuntimeException("Not implemented");
}
@Override
public javax.servlet.FilterRegistration.Dynamic addFilter(
String filterName, String className) {
throw new RuntimeException("Not implemented");
}
@Override
public javax.servlet.FilterRegistration.Dynamic addFilter(
String filterName, Filter filter) {
return new ApplicationFilterRegistration(
new FilterDef(), new TesterContext());
}
@Override
public javax.servlet.FilterRegistration.Dynamic addFilter(
String filterName, Class<? extends Filter> filterClass) {
return new ApplicationFilterRegistration(
new FilterDef(), new TesterContext());
}
@Override
public <T extends Filter> T createFilter(Class<T> c)
throws ServletException {
throw new RuntimeException("Not implemented");
}
@Override
public FilterRegistration getFilterRegistration(String filterName) {
throw new RuntimeException("Not implemented");
}
@Override
public Map<String, ? extends FilterRegistration> getFilterRegistrations() {
throw new RuntimeException("Not implemented");
}
private SessionCookieConfig sessionCookieConfig = new TesterSessionCookieConfig();
@Override
public SessionCookieConfig getSessionCookieConfig() {
return sessionCookieConfig;
}
private final Set<SessionTrackingMode> sessionTrackingModes = new HashSet<>();
@Override
public void setSessionTrackingModes(
Set<SessionTrackingMode> sessionTrackingModes) {
this.sessionTrackingModes.clear();
this.sessionTrackingModes.addAll(sessionTrackingModes);
}
@Override
public Set<SessionTrackingMode> getDefaultSessionTrackingModes() {
throw new RuntimeException("Not implemented");
}
@Override
public Set<SessionTrackingMode> getEffectiveSessionTrackingModes() {
return sessionTrackingModes;
}
@Override
public void addListener(String className) {
throw new RuntimeException("Not implemented");
}
@Override
public <T extends EventListener> void addListener(T t) {
throw new RuntimeException("Not implemented");
}
@Override
public void addListener(Class<? extends EventListener> listenerClass) {
throw new RuntimeException("Not implemented");
}
@Override
public <T extends EventListener> T createListener(Class<T> c)
throws ServletException {
throw new RuntimeException("Not implemented");
}
@Override
public JspConfigDescriptor getJspConfigDescriptor() {
throw new RuntimeException("Not implemented");
}
@Override
public void declareRoles(String... roleNames) {
throw new RuntimeException("Not implemented");
}
/**
* {@inheritDoc}
* <p>
* This test implementation is hard coded to return <code>localhost</code>.
*/
@Override
public String getVirtualServerName() {
return "localhost";
}
}

View File

@@ -0,0 +1,93 @@
/*
* 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.tomcat.unittest;
import javax.servlet.SessionCookieConfig;
public class TesterSessionCookieConfig implements SessionCookieConfig {
private String name;
@Override
public void setName(String name) {
this.name = name;
}
@Override
public String getName() {
return name;
}
@Override
public void setDomain(String domain) {
throw new UnsupportedOperationException();
}
@Override
public String getDomain() {
throw new UnsupportedOperationException();
}
@Override
public void setPath(String path) {
throw new UnsupportedOperationException();
}
@Override
public String getPath() {
throw new UnsupportedOperationException();
}
@Override
public void setComment(String comment) {
throw new UnsupportedOperationException();
}
@Override
public String getComment() {
throw new UnsupportedOperationException();
}
@Override
public void setHttpOnly(boolean httpOnly) {
throw new UnsupportedOperationException();
}
@Override
public boolean isHttpOnly() {
throw new UnsupportedOperationException();
}
@Override
public void setSecure(boolean secure) {
throw new UnsupportedOperationException();
}
@Override
public boolean isSecure() {
throw new UnsupportedOperationException();
}
@Override
public void setMaxAge(int MaxAge) {
throw new UnsupportedOperationException();
}
@Override
public int getMaxAge() {
throw new UnsupportedOperationException();
}
}

View File

@@ -0,0 +1,32 @@
/*
* 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.tomcat.unittest;
import java.util.List;
public class TesterThreadScopedHolder {
private static final ThreadLocal<List<TesterCounter>> threadLocal =
new ThreadLocal<>();
public static void saveInHolder(List<TesterCounter> o) {
threadLocal.set(o);
}
public static List<TesterCounter> getFromHolder() {
return threadLocal.get();
}
}

View File

@@ -0,0 +1,23 @@
/*
* 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.tomcat.unittest.tags;
import javax.servlet.jsp.tagext.BodyTagSupport;
public class Bug53545 extends BodyTagSupport {
private static final long serialVersionUID = 1L;
}