Skip to content

Bulletproof AbstractProxyServlet#destory() to make it easier to write #9938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.eclipse.jetty.io.ClientConnector;
import org.eclipse.jetty.util.HttpCookieStore;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.slf4j.Logger;
Expand Down Expand Up @@ -145,11 +146,13 @@ public void destroy()
{
try
{
_client.stop();
LifeCycle.stop(_client);
}
catch (Exception x)
{
if (_log.isDebugEnabled())
if (_log == null)
x.printStackTrace();
else if (_log.isDebugEnabled())
_log.debug("Failed to stop client", x);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//

package org.eclipse.jetty.proxy;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.client.api.Response.CompleteListener;
import org.junit.jupiter.api.Test;

public class AbstractProxyServletTest
{

@Test
public void testNewDestroy() throws Exception
{
new AbstractProxyServlet()
{
private static final long serialVersionUID = 1L;

@Override
protected CompleteListener newProxyResponseListener(HttpServletRequest clientRequest, HttpServletResponse proxyResponse)
{
return null;
}
}.destroy();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.Utf8StringBuilder;
import org.eclipse.jetty.util.ajax.JSON;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -159,9 +160,15 @@ private void startClient() throws Exception
@AfterEach
public void dispose() throws Exception
{
client.stop();
proxy.stop();
server.stop();
LifeCycle.stop(client);
LifeCycle.stop(proxy);
LifeCycle.stop(proxy);
}

@Test
public void testNewDestroy() throws Exception
{
new AsyncMiddleManServlet().destroy();
}

@Test
Expand Down