use new...(), not build...()
This commit is contained in:
parent
dfd3abd4a9
commit
2778869d14
2 changed files with 24 additions and 24 deletions
|
@ -28,12 +28,12 @@ public class WebApplication extends BaseApplication {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Codec<Session> buildSessionCodec(HttpServerContext httpServerContext) {
|
protected Codec<Session> newSessionCodec(HttpServerContext httpServerContext) {
|
||||||
return new FileJsonSessionCodec(sessionName, this, 1024, Duration.ofDays(1),
|
return new FileJsonSessionCodec(sessionName, this, 1024, Duration.ofDays(1),
|
||||||
Paths.get("/var/tmp/session"));
|
Paths.get("/var/tmp/session"));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HttpHandler buildIncomingSessionHandler(HttpServerContext httpServerContext) {
|
protected HttpHandler newIncomingSessionHandler(HttpServerContext httpServerContext) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Codec<Session> sessionCodec = httpServerContext.getAttributes().get(Codec.class, "sessioncodec");
|
Codec<Session> sessionCodec = httpServerContext.getAttributes().get(Codec.class, "sessioncodec");
|
||||||
return new IncomingSessionHandler(
|
return new IncomingSessionHandler(
|
||||||
|
@ -47,7 +47,7 @@ public class WebApplication extends BaseApplication {
|
||||||
() -> RandomUtil.randomString(16));
|
() -> RandomUtil.randomString(16));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected OutgoingSessionHandler buildOutgoingSessionHandler(HttpServerContext httpServerContext) {
|
protected OutgoingSessionHandler newOutgoingSessionHandler(HttpServerContext httpServerContext) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Codec<Session> sessionCodec = httpServerContext.getAttributes().get(Codec.class, "sessioncodec");
|
Codec<Session> sessionCodec = httpServerContext.getAttributes().get(Codec.class, "sessioncodec");
|
||||||
return new OutgoingSessionHandler(
|
return new OutgoingSessionHandler(
|
||||||
|
|
|
@ -70,10 +70,10 @@ public class BaseApplication implements Application {
|
||||||
this.executor.setRejectedExecutionHandler((runnable, threadPoolExecutor) ->
|
this.executor.setRejectedExecutionHandler((runnable, threadPoolExecutor) ->
|
||||||
logger.log(Level.SEVERE, "rejected " + runnable + " for thread pool executor = " + threadPoolExecutor));
|
logger.log(Level.SEVERE, "rejected " + runnable + " for thread pool executor = " + threadPoolExecutor));
|
||||||
this.sessionName = getSettings().get("session.name", "SESS");
|
this.sessionName = getSettings().get("session.name", "SESS");
|
||||||
this.httpRequestValidator = buildRequestValidator();
|
this.httpRequestValidator = newRequestValidator();
|
||||||
this.incomingCookieHandler = buildIncomingCookieHandler();
|
this.incomingCookieHandler = newIncomingCookieHandler();
|
||||||
this.outgoingCookieHandler = buildOutgoingCookieHandler();
|
this.outgoingCookieHandler = newOutgoingCookieHandler();
|
||||||
this.httpResponseRenderer = buildResponseRenderer();
|
this.httpResponseRenderer = newResponseRenderer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BaseApplicationBuilder builder() {
|
public static BaseApplicationBuilder builder() {
|
||||||
|
@ -155,7 +155,6 @@ public class BaseApplication implements Application {
|
||||||
HttpResponseBuilder httpResponseBuilder,
|
HttpResponseBuilder httpResponseBuilder,
|
||||||
HttpResponseStatus httpResponseStatus) {
|
HttpResponseStatus httpResponseStatus) {
|
||||||
HttpServerContext httpServerContext = createContext(null, httpRequestBuilder, httpResponseBuilder);
|
HttpServerContext httpServerContext = createContext(null, httpRequestBuilder, httpResponseBuilder);
|
||||||
httpServerContext.getAttributes().put("responsebuilder", httpResponseBuilder);
|
|
||||||
RouterCallable routerCallable = new RouterCallable() {
|
RouterCallable routerCallable = new RouterCallable() {
|
||||||
@Override
|
@Override
|
||||||
public Boolean call() {
|
public Boolean call() {
|
||||||
|
@ -180,32 +179,36 @@ public class BaseApplication implements Application {
|
||||||
HttpServerContext httpServerContext = new BaseHttpServerContext(this, domain, requestBuilder, responseBuilder);
|
HttpServerContext httpServerContext = new BaseHttpServerContext(this, domain, requestBuilder, responseBuilder);
|
||||||
httpServerContext.getAttributes().put("requestbuilder", requestBuilder);
|
httpServerContext.getAttributes().put("requestbuilder", requestBuilder);
|
||||||
httpServerContext.getAttributes().put("responsebuilder", responseBuilder);
|
httpServerContext.getAttributes().put("responsebuilder", responseBuilder);
|
||||||
this.sessionCodec = buildSessionCodec(httpServerContext);
|
this.sessionCodec = newSessionCodec(httpServerContext);
|
||||||
if (sessionCodec != null) {
|
if (sessionCodec != null) {
|
||||||
httpServerContext.getAttributes().put("sessioncodec", sessionCodec);
|
httpServerContext.getAttributes().put("sessioncodec", sessionCodec);
|
||||||
}
|
}
|
||||||
this.incomingSessionHandler = buildIncomingSessionHandler(httpServerContext);
|
this.incomingSessionHandler = newIncomingSessionHandler(httpServerContext);
|
||||||
this.outgoingSessionHandler = buildOutgoingSessionHandler(httpServerContext);
|
this.outgoingSessionHandler = newOutgoingSessionHandler(httpServerContext);
|
||||||
return httpServerContext;
|
return httpServerContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HttpRequestValidator buildRequestValidator() {
|
protected HttpRequestValidator newRequestValidator() {
|
||||||
return new HttpRequestValidator();
|
return new HttpRequestValidator();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HttpHandler buildIncomingCookieHandler() {
|
protected HttpHandler newIncomingCookieHandler() {
|
||||||
return new IncomingCookieHandler();
|
return new IncomingCookieHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HttpHandler buildOutgoingCookieHandler() {
|
protected HttpHandler newOutgoingCookieHandler() {
|
||||||
return new OutgoingCookieHandler();
|
return new OutgoingCookieHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Codec<Session> buildSessionCodec(HttpServerContext httpServerContext) {
|
protected HttpResponseRenderer newResponseRenderer() {
|
||||||
|
return new HttpResponseRenderer();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Codec<Session> newSessionCodec(HttpServerContext httpServerContext) {
|
||||||
return new MemoryPropertiesSessionCodec(sessionName,this, 1024, Duration.ofDays(1));
|
return new MemoryPropertiesSessionCodec(sessionName,this, 1024, Duration.ofDays(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HttpHandler buildIncomingSessionHandler(HttpServerContext httpServerContext) {
|
protected HttpHandler newIncomingSessionHandler(HttpServerContext httpServerContext) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Codec<Session> sessionCodec = httpServerContext.getAttributes().get(Codec.class, "sessioncodec");
|
Codec<Session> sessionCodec = httpServerContext.getAttributes().get(Codec.class, "sessioncodec");
|
||||||
return new IncomingSessionHandler(
|
return new IncomingSessionHandler(
|
||||||
|
@ -219,7 +222,7 @@ public class BaseApplication implements Application {
|
||||||
() -> RandomUtil.randomString(16));
|
() -> RandomUtil.randomString(16));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HttpHandler buildOutgoingSessionHandler(HttpServerContext httpServerContext) {
|
protected HttpHandler newOutgoingSessionHandler(HttpServerContext httpServerContext) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Codec<Session> sessionCodec = httpServerContext.getAttributes().get(Codec.class, "sessioncodec");
|
Codec<Session> sessionCodec = httpServerContext.getAttributes().get(Codec.class, "sessioncodec");
|
||||||
return new OutgoingSessionHandler(
|
return new OutgoingSessionHandler(
|
||||||
|
@ -237,10 +240,6 @@ public class BaseApplication implements Application {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HttpResponseRenderer buildResponseRenderer() {
|
|
||||||
return new HttpResponseRenderer();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreated(Session session) {
|
public void onCreated(Session session) {
|
||||||
logger.log(Level.FINE, "session name = " + sessionName + " created = " + session);
|
logger.log(Level.FINE, "session name = " + sessionName + " created = " + session);
|
||||||
|
@ -253,6 +252,7 @@ public class BaseApplication implements Application {
|
||||||
builder.applicationModuleList.forEach(module -> module.onClose(this, session));
|
builder.applicationModuleList.forEach(module -> module.onClose(this, session));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void onOpen(HttpServerContext httpServerContext) {
|
public void onOpen(HttpServerContext httpServerContext) {
|
||||||
try {
|
try {
|
||||||
if (httpRequestValidator != null) {
|
if (httpRequestValidator != null) {
|
||||||
|
@ -275,9 +275,10 @@ public class BaseApplication implements Application {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void onClose(HttpServerContext httpServerContext) {
|
public void onClose(HttpServerContext httpServerContext) {
|
||||||
try {
|
try {
|
||||||
// call modules before session/cookie setdown
|
// call modules before session/cookie
|
||||||
builder.applicationModuleList.forEach(module -> module.onClose(this, httpServerContext));
|
builder.applicationModuleList.forEach(module -> module.onClose(this, httpServerContext));
|
||||||
if (builder.sessionsEnabled && outgoingSessionHandler != null) {
|
if (builder.sessionsEnabled && outgoingSessionHandler != null) {
|
||||||
outgoingSessionHandler.handle(httpServerContext);
|
outgoingSessionHandler.handle(httpServerContext);
|
||||||
|
@ -320,7 +321,7 @@ public class BaseApplication implements Application {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
logger.log(Level.INFO, "application closing down");
|
logger.log(Level.INFO, "application closing");
|
||||||
// stop dispatching and stop dispatched requests
|
// stop dispatching and stop dispatched requests
|
||||||
executor.shutdown();
|
executor.shutdown();
|
||||||
try {
|
try {
|
||||||
|
@ -358,5 +359,4 @@ public class BaseApplication implements Application {
|
||||||
}
|
}
|
||||||
logger.log(Level.INFO, "application closed");
|
logger.log(Level.INFO, "application closed");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue