org.sonatype.tests.http.server.jetty.impl
Class JettyServerProvider

java.lang.Object
  extended by org.sonatype.tests.http.server.jetty.impl.JettyServerProvider
All Implemented Interfaces:
ServerProvider
Direct Known Subclasses:
JettyProxyProvider

public class JettyServerProvider
extends Object
implements ServerProvider

Author:
Benjamin Hanzelmann

Nested Class Summary
static class JettyServerProvider.CertificateHolder
           
static class JettyServerProvider.CustomTrustManager
           
 
Field Summary
protected  int port
           
protected  org.eclipse.jetty.server.Server server
           
protected  boolean ssl
           
 
Constructor Summary
JettyServerProvider()
           
 
Method Summary
 void addAuthentication(String pathSpec, String authName)
          Add authentication handler to the given pathspec.
 void addBehaviour(String pathspec, Behaviour... behaviour)
          Add the given chain of Behaviour to execute for the given pathspec.
 void addCertificate(String alias, JettyServerProvider.CertificateHolder certHolder)
          Adds the given certificate to the keystore for use with AUTH-CERT.
 void addDefaultServices()
           
 void addServlet(TestServlet servlet)
           
 void addUser(String user, Object password)
          Add the given user to the LoginService.
protected  org.eclipse.jetty.server.Connector connector()
           
 org.eclipse.jetty.server.Server createServer()
           
 int getPort()
           
 org.eclipse.jetty.security.ConstraintSecurityHandler getSecurityHandler()
           
 void getServer()
           
 URL getUrl()
           
 org.eclipse.jetty.servlet.ServletContextHandler getWebappContext()
           
 void initServer()
          Configure the underlying server instance.
protected  void initWebappContext(org.eclipse.jetty.server.Server s)
           
 void setPort(int port)
          Set to -1 to auto-choose a free port.
 void setSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler securityHandler)
           
 void setSSL(String keystore, String password)
           
 void setWebappContext(org.eclipse.jetty.servlet.ServletContextHandler webappContext)
           
protected  org.eclipse.jetty.server.Connector sslConnector()
           
 void start()
           
 void stop()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

server

protected org.eclipse.jetty.server.Server server

port

protected int port

ssl

protected boolean ssl
Constructor Detail

JettyServerProvider

public JettyServerProvider()
                    throws Exception
Throws:
Exception
Method Detail

setSSL

public void setSSL(String keystore,
                   String password)
Specified by:
setSSL in interface ServerProvider
Parameters:
keystore - The keystore to use. (generated with e.g. 'keytool -keystore keystore -alias jetty -genkey -keyalg DSA')

setPort

public void setPort(int port)
Description copied from interface: ServerProvider
Set to -1 to auto-choose a free port.

Specified by:
setPort in interface ServerProvider

initServer

public void initServer()
                throws Exception
Description copied from interface: ServerProvider
Configure the underlying server instance.

Specified by:
initServer in interface ServerProvider
Throws:
Exception

getServer

public void getServer()
               throws Exception
Throws:
Exception

createServer

public org.eclipse.jetty.server.Server createServer()
                                             throws URISyntaxException
Throws:
URISyntaxException

addAuthentication

public void addAuthentication(String pathSpec,
                              String authName)
Description copied from interface: ServerProvider
Add authentication handler to the given pathspec.

Specified by:
addAuthentication in interface ServerProvider
Parameters:
pathSpec - e.g. "/path/*"
authName - e.g. BASIC, DIGEST

addUser

public void addUser(String user,
                    Object password)
Add the given user to the LoginService. If the password object is a JettyServerProvider.CertificateHolder, addCertificate(String, CertificateHolder) is called. For any other class, the String representation of the object is used as a password.

Specified by:
addUser in interface ServerProvider
Parameters:
user - the username, may not be null.
password - The password to use, may not be null.

addCertificate

public void addCertificate(String alias,
                           JettyServerProvider.CertificateHolder certHolder)
                    throws Exception
Adds the given certificate to the keystore for use with AUTH-CERT.

Parameters:
alias - The alias to use for the key in the keystore.
certHolder - The key and certificate to use.
Throws:
Exception

addDefaultServices

public void addDefaultServices()

addServlet

public void addServlet(TestServlet servlet)

initWebappContext

protected void initWebappContext(org.eclipse.jetty.server.Server s)
                          throws URISyntaxException
Throws:
URISyntaxException

connector

protected org.eclipse.jetty.server.Connector connector()

sslConnector

protected org.eclipse.jetty.server.Connector sslConnector()

start

public void start()
           throws Exception
Specified by:
start in interface ServerProvider
Throws:
Exception

addBehaviour

public void addBehaviour(String pathspec,
                         Behaviour... behaviour)
Description copied from interface: ServerProvider
Add the given chain of Behaviour to execute for the given pathspec.

Specified by:
addBehaviour in interface ServerProvider
Parameters:
pathspec - e.g. "/path/*"

stop

public void stop()
          throws Exception
Specified by:
stop in interface ServerProvider
Throws:
Exception

getUrl

public URL getUrl()
           throws MalformedURLException
Specified by:
getUrl in interface ServerProvider
Returns:
the URL for the server
Throws:
MalformedURLException

getWebappContext

public org.eclipse.jetty.servlet.ServletContextHandler getWebappContext()

setWebappContext

public void setWebappContext(org.eclipse.jetty.servlet.ServletContextHandler webappContext)

getPort

public int getPort()
Specified by:
getPort in interface ServerProvider

getSecurityHandler

public org.eclipse.jetty.security.ConstraintSecurityHandler getSecurityHandler()

setSecurityHandler

public void setSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler securityHandler)


Copyright © 2010-2012 Sonatype, Inc.. All Rights Reserved.