Merge branch 'jetty-9.3.x' into jetty-9.3.x-845
This commit is contained in:
commit
33ca8cf695
|
@ -38,6 +38,12 @@ import org.eclipse.jetty.util.Attributes;
|
|||
*/
|
||||
public interface Authentication
|
||||
{
|
||||
/**
|
||||
* Constant used to indicate that any realm will match.
|
||||
* @see #matches(String, URI, String)
|
||||
*/
|
||||
public static final String ANY_REALM = "<<ANY_REALM>>";
|
||||
|
||||
/**
|
||||
* Matches {@link Authentication}s based on the given parameters
|
||||
* @param type the {@link Authentication} type such as "Basic" or "Digest"
|
||||
|
|
|
@ -52,7 +52,7 @@ public abstract class AbstractAuthentication implements Authentication
|
|||
if (!getType().equalsIgnoreCase(type))
|
||||
return false;
|
||||
|
||||
if (!this.realm.equals(realm))
|
||||
if (!this.realm.equals(ANY_REALM) && !this.realm.equals(realm))
|
||||
return false;
|
||||
|
||||
return matchesURI(this.uri, uri);
|
||||
|
|
|
@ -119,6 +119,14 @@ public class HttpClientAuthenticationTest extends AbstractHttpClientServerTest
|
|||
test_Authentication(new BasicAuthentication(uri, realm, "basic", "basic"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_BasicAnyRealm() throws Exception
|
||||
{
|
||||
startBasic(new EmptyServerHandler());
|
||||
URI uri = URI.create(scheme + "://localhost:" + connector.getLocalPort());
|
||||
test_Authentication(new BasicAuthentication(uri, Authentication.ANY_REALM, "basic", "basic"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_DigestAuthentication() throws Exception
|
||||
{
|
||||
|
|
|
@ -30,8 +30,10 @@ import javax.management.MBeanRegistrationException;
|
|||
import javax.management.MBeanServer;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||
import org.eclipse.jetty.util.component.Container;
|
||||
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
||||
import org.eclipse.jetty.util.component.Destroyable;
|
||||
import org.eclipse.jetty.util.component.Dumpable;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
@ -39,7 +41,8 @@ import org.eclipse.jetty.util.log.Logger;
|
|||
/**
|
||||
* Container class for the MBean instances
|
||||
*/
|
||||
public class MBeanContainer implements Container.InheritedListener, Dumpable
|
||||
@ManagedObject("The component that registers beans as MBeans")
|
||||
public class MBeanContainer implements Container.InheritedListener, Dumpable, Destroyable
|
||||
{
|
||||
private final static Logger LOG = Log.getLogger(MBeanContainer.class.getName());
|
||||
private final static ConcurrentMap<String, AtomicInteger> __unique = new ConcurrentHashMap<>();
|
||||
|
@ -254,6 +257,7 @@ public class MBeanContainer implements Container.InheritedListener, Dumpable
|
|||
return ContainerLifeCycle.dump(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy()
|
||||
{
|
||||
_beans.values().stream()
|
||||
|
|
|
@ -0,0 +1,116 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
//
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
//
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
//
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
//
|
||||
|
||||
package org.eclipse.jetty.jmx;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.management.MBeanServer;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
||||
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MBeanContainerLifeCycleTest
|
||||
{
|
||||
private ContainerLifeCycle container;
|
||||
private MBeanServer mbeanServer;
|
||||
|
||||
@Before
|
||||
public void prepare() throws Exception
|
||||
{
|
||||
container = new ContainerLifeCycle();
|
||||
mbeanServer = ManagementFactory.getPlatformMBeanServer();
|
||||
MBeanContainer mbeanContainer = new MBeanContainer(mbeanServer);
|
||||
container.addBean(mbeanContainer);
|
||||
container.start();
|
||||
}
|
||||
|
||||
@After
|
||||
public void dispose() throws Exception
|
||||
{
|
||||
container.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddBeanRegistersMBeanRemoveBeanUnregistersMBean() throws Exception
|
||||
{
|
||||
// Adding a bean to the container should register the MBean.
|
||||
QueuedThreadPool bean = new QueuedThreadPool();
|
||||
container.addBean(bean);
|
||||
|
||||
String pkg = bean.getClass().getPackage().getName();
|
||||
Set<ObjectName> objectNames = mbeanServer.queryNames(ObjectName.getInstance(pkg + ":*"), null);
|
||||
Assert.assertEquals(1, objectNames.size());
|
||||
|
||||
// Removing the bean should unregister the MBean.
|
||||
container.removeBean(bean);
|
||||
objectNames = mbeanServer.queryNames(ObjectName.getInstance(pkg + ":*"), null);
|
||||
Assert.assertEquals(0, objectNames.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoppingContainerDoesNotUnregistersMBeans() throws Exception
|
||||
{
|
||||
QueuedThreadPool bean = new QueuedThreadPool();
|
||||
container.addBean(bean, true);
|
||||
|
||||
String pkg = bean.getClass().getPackage().getName();
|
||||
Set<ObjectName> objectNames = mbeanServer.queryNames(ObjectName.getInstance(pkg + ":*"), null);
|
||||
Assert.assertEquals(1, objectNames.size());
|
||||
|
||||
container.stop();
|
||||
|
||||
objectNames = mbeanServer.queryNames(ObjectName.getInstance(pkg + ":*"), null);
|
||||
Assert.assertEquals(1, objectNames.size());
|
||||
|
||||
// Remove the MBeans to start clean on the next test.
|
||||
objectNames.forEach(objectName ->
|
||||
{
|
||||
try
|
||||
{
|
||||
mbeanServer.unregisterMBean(objectName);
|
||||
}
|
||||
catch (Throwable ignored)
|
||||
{
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDestroyingContainerUnregistersMBeans() throws Exception
|
||||
{
|
||||
QueuedThreadPool bean = new QueuedThreadPool();
|
||||
container.addBean(bean, true);
|
||||
|
||||
String pkg = bean.getClass().getPackage().getName();
|
||||
Set<ObjectName> objectNames = mbeanServer.queryNames(ObjectName.getInstance(pkg + ":*"), null);
|
||||
Assert.assertEquals(1, objectNames.size());
|
||||
|
||||
container.stop();
|
||||
container.destroy();
|
||||
|
||||
objectNames = mbeanServer.queryNames(ObjectName.getInstance(pkg + ":*"), null);
|
||||
Assert.assertEquals(0, objectNames.size());
|
||||
}
|
||||
}
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
package org.eclipse.jetty.util.component;
|
||||
|
||||
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||
import org.eclipse.jetty.util.annotation.ManagedOperation;
|
||||
|
||||
/**
|
||||
* <p>A Destroyable is an object which can be destroyed.</p>
|
||||
|
@ -25,7 +27,9 @@ package org.eclipse.jetty.util.component;
|
|||
* resources over multiple start/stop cycles. A call to destroy will release all
|
||||
* resources and will prevent any further start/stop cycles from being successful.</p>
|
||||
*/
|
||||
@ManagedObject
|
||||
public interface Destroyable
|
||||
{
|
||||
@ManagedOperation(value = "Destroys this component", impact = "ACTION")
|
||||
void destroy();
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.jsr356;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.nio.ByteBuffer;
|
||||
|
@ -43,10 +45,9 @@ import org.junit.AfterClass;
|
|||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
|
||||
/**
|
||||
* This class tests receiving of messages by different types of {@link MessageHandler}
|
||||
*/
|
||||
|
@ -109,6 +110,7 @@ public class MessageReceivingTest {
|
|||
* @throws Exception on exception occur
|
||||
*/
|
||||
@Test
|
||||
@Ignore("flappy test")
|
||||
public void testWholeTextMessage() throws Exception {
|
||||
final TestEndpoint echoer = new TestEndpoint(new WholeStringCaptureHandler());
|
||||
Assert.assertThat(echoer, instanceOf(javax.websocket.Endpoint.class));
|
||||
|
|
Loading…
Reference in New Issue