Class JettyHttpServer

java.lang.Object
org.oddjob.jetty.JettyHttpServer
All Implemented Interfaces:
Service, Stoppable

public class JettyHttpServer extends Object implements Service
Author:
rob

Description

An HTTP server.

This is a wrapper around the Jetty Server. The handlers property must be used to configure the server to do anything useful. By default a simple welcome message is returned for all requests.

Common handlers to use are:

Example

Using Basic Authentication.
<oddjob id="oddjob">

    <job>

        <web:server id="server" port="${server.port}" xmlns:web="oddjob:web">

            <handler>

                <bean class="org.eclipse.jetty.security.ConstraintSecurityHandler">

                    <loginService>

                        <bean class="org.eclipse.jetty.security.HashLoginService" name="FooRealm" config="${oddjob.dir}/realm.txt" hotReload="false"/>

                    </loginService>

                    <constraintMappings>

                        <list>

                            <values>

                                <bean class="org.eclipse.jetty.security.ConstraintMapping" pathSpec="/*">

                                    <constraint>

                                        <bean class="org.eclipse.jetty.util.security.Constraint" name="auth" authenticate="true">

                                            <roles>

                                                <value value="**"/>

                                            </roles>

                                        </bean>

                                    </constraint>

                                </bean>

                            </values>

                        </list>

                    </constraintMappings>

                    <authenticator>

                        <bean class="org.eclipse.jetty.security.authentication.BasicAuthenticator"/>

                    </authenticator>

                    <handler>

                        <bean class="org.oddjob.jetty.EchoRequestHandler"/>

                    </handler>

                </bean>

            </handler>

        </web:server>

    </job>

</oddjob>
  • Constructor Details

    • JettyHttpServer

      public JettyHttpServer()
  • Method Details

    • start

      public void start() throws Exception
      Description copied from interface: Service
      Start the service.
      Specified by:
      start in interface Service
      Throws:
      Exception - If the service can't be started.
    • stop

      public void stop() throws FailedToStopException
      Description copied from interface: Stoppable
      Stop executing. This method should not return until the Stoppable has actually stopped.
      Specified by:
      stop in interface Stoppable
      Throws:
      FailedToStopException
    • getName

      public String getName()
    • setName

      public void setName(String name)
    • getPort

      public int getPort()
    • setPort

      public void setPort(int port)
    • getHandler

      public org.eclipse.jetty.server.Handler getHandler()
    • setHandler

      public void setHandler(org.eclipse.jetty.server.Handler handler)
    • getBeans

      public Object getBeans(int index)
    • setBeans

      public void setBeans(int index, Object bean)
    • setModifiers

      public void setModifiers(int index, JettyServerModifier modifier)
    • toString

      public String toString()
      Overrides:
      toString in class Object