Top Description Inners Fields Constructors Methods
org.eclipse.jgit.junit.http

public Class AppServer

extends Object
Class Inheritance
Static Imports
org.junit.Assert.assertFalse, .Assert.assertTrue

Tiny web application server for unit testing.

Tests should start the server in their setUp() method and stop the server in their tearDown() method. Only while started the server's URL and/or port number can be obtained.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private static final String
authRole

Role for authentication.

private final HttpConfiguration
private final ServerConnector
private final ContextHandlerCollection
private List<File>
private static final String
keyPassword

SSL keystore password; must have at least 6 characters.

private final TestRequestLog
public static final String
password

Password for username in secured access areas.

public static final String
realm

Realm name for the secure access areas.

private final HttpConfiguration
private final ServerConnector
private final Server
public static final String
username

Username for secured access areas.

Constructor Summary

AccessConstructor and Description
public
AppServer()

Constructor for AppServer.

public
AppServer(int
the http port number; may be zero to allocate a port dynamically
port
)

Constructor for AppServer.

public
AppServer(int
for http, may be zero to allocate a port dynamically
port
,
int
for https,may be zero to allocate a port dynamically. If negative, the server will be set up without https support.
sslPort
)

Constructor for AppServer.

Method Summary

Modifier and TypeMethod and Description
public ServletContextHandler

Returns:

the context to add servlets into.
addContext
(String
path of the context; use "/" for the root context if binding to the root is desired.
path
)

Create a new servlet context within the server.

private void
private void
private void
auth(ServletContextHandler ctx, Authenticator authType, String... methods)

public ServletContextHandler

Returns:

servlet context handler
authBasic
(ServletContextHandler
servlet context handler
ctx
,
String...
the methods
methods
)

Configure basic authentication.

private ConstraintMapping
private SslContextFactory.Server
public int

Returns:

the local port number the server is listening on.
getPort
()

Get port.

public List<AccessEvent>

Returns:

all requests since the server was started.
getRequests
()

Get requests.

public List<AccessEvent>

Returns:

all requests which match the given path.
getRequests
(URIish
base URI used to access the server.
base
,
String
the path to locate requests for, relative to base.
path
)

Get requests.

public List<AccessEvent>

Returns:

all requests which match the given path.
getRequests
(String
the path to locate requests for.
path
)

Get requests.

public int

Returns:

the HTTPS port or -1 if not configured.
getSecurePort
()

Get secure port.

public URI

Returns:

URI to reference this server's root context.
getURI
()

Get the URI to reference this server.

private void
public void
setUp()

Start the server on a random local port.

public void
tearDown()

Shutdown the server.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

authRoleback to summary
private static final String authRole

Role for authentication.

configback to summary
private final HttpConfiguration config
connectorback to summary
private final ServerConnector connector
contextsback to summary
private final ContextHandlerCollection contexts
filesToDeleteback to summary
private List<File> filesToDelete
keyPasswordback to summary
private static final String keyPassword

SSL keystore password; must have at least 6 characters.

logback to summary
private final TestRequestLog log
passwordback to summary
public static final String password

Password for username in secured access areas.

realmback to summary
public static final String realm

Realm name for the secure access areas.

secureConfigback to summary
private final HttpConfiguration secureConfig
secureConnectorback to summary
private final ServerConnector secureConnector
serverback to summary
private final Server server
usernameback to summary
public static final String username

Username for secured access areas.

Constructor Detail

AppServerback to summary
public AppServer()

Constructor for AppServer.

AppServerback to summary
public AppServer(int port)

Constructor for AppServer.

Parameters
port:int

the http port number; may be zero to allocate a port dynamically

Since
4.2
AppServerback to summary
public AppServer(int port, int sslPort)

Constructor for AppServer.

Parameters
port:int

for http, may be zero to allocate a port dynamically

sslPort:int

for https,may be zero to allocate a port dynamically. If negative, the server will be set up without https support.

Since
4.9

Method Detail

addContextback to summary
public ServletContextHandler addContext(String path)

Create a new servlet context within the server.

This method should be invoked before the server is started, once for each context the caller wants to register.

Parameters
path:String

path of the context; use "/" for the root context if binding to the root is desired.

Returns:ServletContextHandler

the context to add servlets into.

Since
7.0
assertAlreadySetUpback to summary
private void assertAlreadySetUp()
assertNotYetSetUpback to summary
private void assertNotYetSetUp()
authback to summary
private void auth(ServletContextHandler ctx, Authenticator authType, String... methods)
authBasicback to summary
public ServletContextHandler authBasic(ServletContextHandler ctx, String... methods)

Configure basic authentication.

Parameters
ctx:ServletContextHandler

servlet context handler

methods:String[]

the methods

Returns:ServletContextHandler

servlet context handler

Since
7.0
createConstraintMappingback to summary
private ConstraintMapping createConstraintMapping()
createTestSslContextFactoryback to summary
private SslContextFactory.Server createTestSslContextFactory(String hostName, String ip)
getPortback to summary
public int getPort()

Get port.

Returns:int

the local port number the server is listening on.

getRequestsback to summary
public List<AccessEvent> getRequests()

Get requests.

Returns:List<AccessEvent>

all requests since the server was started.

getRequestsback to summary
public List<AccessEvent> getRequests(URIish base, String path)

Get requests.

Parameters
base:URIish

base URI used to access the server.

path:String

the path to locate requests for, relative to base.

Returns:List<AccessEvent>

all requests which match the given path.

getRequestsback to summary
public List<AccessEvent> getRequests(String path)

Get requests.

Parameters
path:String

the path to locate requests for.

Returns:List<AccessEvent>

all requests which match the given path.

getSecurePortback to summary
public int getSecurePort()

Get secure port.

Returns:int

the HTTPS port or -1 if not configured.

getURIback to summary
public URI getURI()

Get the URI to reference this server.

The returned URI includes the proper host name and port number, but does not contain a path.

Returns:URI

URI to reference this server's root context.

makePrivateback to summary
private void makePrivate(File file)
setUpback to summary
public void setUp() throws Exception

Start the server on a random local port.

Exceptions
Exception:
the server cannot be started, testing is not possible.
tearDownback to summary
public void tearDown() throws Exception

Shutdown the server.

Exceptions
Exception:
the server refuses to halt, or wasn't running.
org.eclipse.jgit.junit.http back to summary

pack-priv Class AppServer.TestMappedLoginService

extends AbstractLoginService
Class Inheritance

Field Summary

Modifier and TypeField and Description
private RolePrincipal
protected final Map<String, UserPrincipal>
Inherited from org.eclipse.jetty.security.AbstractLoginService:
_fullValidate_identityService_name

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected void
doStart()

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.doStart.

Starts the managed lifecycle beans in the order they were added.

protected List<RolePrincipal>
protected UserPrincipal
Inherited from org.eclipse.jetty.security.AbstractLoginService:
getIdentityServicegetNameisFullValidateloginlogoutsetFullValidatesetIdentityServicesetNametoStringvalidate

Field Detail

roleback to summary
private RolePrincipal role
usersback to summary
protected final Map<String, UserPrincipal> users

Constructor Detail

TestMappedLoginServiceback to summary
pack-priv TestMappedLoginService(String role)

Method Detail

doStartback to summary
protected void doStart() throws Exception

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.doStart.

Doc from org.eclipse.jetty.util.component.ContainerLifeCycle.doStart.

Starts the managed lifecycle beans in the order they were added.

Annotations
@Override
Exceptions
Exception:

Doc from org.eclipse.jetty.util.component.AbstractLifeCycle.doStart.

If there was a problem starting. Will cause a transition to FAILED state

loadRoleInfoback to summary
protected List<RolePrincipal> loadRoleInfo(UserPrincipal user)

Implements abstract org.eclipse.jetty.security.AbstractLoginService.loadRoleInfo.

Annotations
@Override
loadUserInfoback to summary
protected UserPrincipal loadUserInfo(String user)

Implements abstract org.eclipse.jetty.security.AbstractLoginService.loadUserInfo.

Annotations
@Override