Skip to content

Commit

Permalink
detect site by header
Browse files Browse the repository at this point in the history
  • Loading branch information
madness-inc committed Dec 16, 2021
1 parent a3f5809 commit 77d342a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Expand Up @@ -78,13 +78,18 @@ public void setClean() {
}

public SessionData serialize() throws IOException {
return serialize(null);
}

public SessionData serialize(String alternativeSiteName) throws IOException {
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos)) {
setClean();
writeObjectData(oos);
oos.flush();
bos.flush();
return new SessionData(getId(), Utils.getSiteName(this), bos.toByteArray());
String siteName = null == alternativeSiteName ? Utils.getSiteName(this) : alternativeSiteName;
return new SessionData(getId(), siteName, bos.toByteArray());
}
}

Expand Down
Expand Up @@ -80,7 +80,11 @@ public HazelcastSession createSession(String sessionId) {
return (HazelcastSession) super.createSession(sessionId);
}

public boolean commit(Session session) throws IOException {
boolean commit(Session session) throws IOException {
return commit(session, null);
}

boolean commit(Session session, String alternativeSiteName) throws IOException {
HazelcastSession hzSession = HazelcastSession.class.cast(session);
long start = System.currentTimeMillis();
SessionData currentSessionData = null;
Expand Down
Expand Up @@ -35,8 +35,8 @@
public class HazelcastSessionTrackerValve extends ValveBase {

private final Log log = Utils.getLog(HazelcastSessionTrackerValve.class);

protected Pattern filter = Pattern.compile("^(/template/.*)|((/health)(\\?.*)?)$");
protected String siteNameHeader = "x-appng-site";

@Override
public void invoke(Request request, Response response) throws IOException, ServletException {
Expand All @@ -47,7 +47,7 @@ public void invoke(Request request, Response response) throws IOException, Servl
if (commitRequired(request.getDecodedRequestURI()) && null != session) {
long start = System.currentTimeMillis();
HazelcastManager manager = (HazelcastManager) request.getContext().getManager();
boolean committed = manager.commit(session);
boolean committed = manager.commit(session, request.getHeader(siteNameHeader));
if (log.isDebugEnabled()) {
log.debug(String.format("Handling session %s for %s took %dms (committed: %s)", session.getId(),
request.getServletPath(), System.currentTimeMillis() - start, committed));
Expand All @@ -60,6 +60,14 @@ protected boolean commitRequired(String uri) {
return null == filter || !filter.matcher(uri).matches();
}

public String getSiteNameHeader() {
return siteNameHeader;
}

public void setSiteNameHeader(String siteNameHeader) {
this.siteNameHeader = siteNameHeader;
}

public String getFilter() {
return null == filter ? null : filter.toString();
}
Expand Down

0 comments on commit 77d342a

Please sign in to comment.