public class HttpsMapper extends Object implements IRequestMapperDelegate
IRequestMapper
that will issue a redirect to secured communication (over https) if the
page resolved by delegate is annotated with @RequireHttps
To setup it:
public class MyApplication extends WebApplication { public void init() { super.init(); getRootRequestMapperAsCompound().add(new MountedMapper("secured", HttpsPage.class)); mountPage(SomeOtherPage.class); // notice that in most cases this should be done as the // last mounting-related operation because it replaces the root mapper setRootRequestMapper(new HttpsMapper(getRootRequestMapper(), new HttpsConfig(80, 443))); } }any request to http://hostname:httpPort/secured will be redirected to https://hostname:httpsPort/secured
Modifier and Type | Class and Description |
---|---|
static class |
HttpsMapper.RedirectHandler
Handler that takes care of redirecting
|
Constructor and Description |
---|
HttpsMapper(IRequestMapper delegate,
HttpsConfig config)
Constructor
|
Modifier and Type | Method and Description |
---|---|
protected IRequestHandler |
createRedirectHandler(String url)
Creates the
IRequestHandler that will be responsible for the redirect |
protected String |
createRedirectUrl(IRequestHandler handler,
Request request,
Scheme scheme)
Constructs a redirect url that should switch the user to the specified
scheme |
int |
getCompatibilityScore(Request request)
Returns the score representing how compatible this request mapper is to processing the given
request.
|
HttpsConfig |
getConfig() |
IRequestMapper |
getDelegateMapper()
Returns the delegate
IRequestMapper . |
protected Scheme |
getDesiredSchemeFor(Class<? extends IRequestablePage> pageClass)
Determines which
Scheme should be used to access the page |
protected Scheme |
getDesiredSchemeFor(IRequestHandler handler)
Figures out which
Scheme should be used to access the request handler |
protected Scheme |
getSchemeOf(Request request)
Determines the
Scheme of the request |
Url |
mapHandler(IRequestHandler handler)
|
IRequestHandler |
mapRequest(Request request)
|
public HttpsMapper(IRequestMapper delegate, HttpsConfig config)
delegate
- config
- public IRequestMapper getDelegateMapper()
IRequestMapper
.getDelegateMapper
in interface IRequestMapperDelegate
IRequestMapper
.public final int getCompatibilityScore(Request request)
IRequestMapper
A good criteria for calculating the score is the number of matched url segments. For example
when there are two mappers for a mounted page, one mapped to /foo
another to
/foo/bar
and the incoming request URL is /foo/bar/baz, the mapping
to /foo/bar
should probably handle the request first as it has matching segments
count of 2 while the first one has only matching segments count of 1.
Note that the method can return value greater then zero even if the mapper does not recognize the request.
getCompatibilityScore
in interface IRequestMapper
public final IRequestHandler mapRequest(Request request)
IRequestMapper
mapRequest
in interface IRequestMapper
request
- provides access to request data (i.e. Url and Parameters)null
public final Url mapHandler(IRequestHandler handler)
IRequestMapper
mapHandler
in interface IRequestMapper
null
.protected IRequestHandler createRedirectHandler(String url)
IRequestHandler
that will be responsible for the redirecturl
- protected String createRedirectUrl(IRequestHandler handler, Request request, Scheme scheme)
scheme
handler
- request handler being accessedrequest
- current requestscheme
- desired scheme for the redirect urlprotected Scheme getDesiredSchemeFor(IRequestHandler handler)
Scheme
should be used to access the request handlerhandler
- request handlerScheme
protected Scheme getSchemeOf(Request request)
Scheme
of the requestrequest
- Scheme.HTTPS
or Scheme.HTTP
protected Scheme getDesiredSchemeFor(Class<? extends IRequestablePage> pageClass)
Scheme
should be used to access the pagepageClass
- type of pageScheme
public final HttpsConfig getConfig()
Copyright © 2006–2022 Apache Software Foundation. All rights reserved.