Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto E. Escobar2013-06-15 01:39:58 +0000
committerRoberto E. Escobar2013-06-15 01:41:35 +0000
commitf7cca63d005f1b881912c06035d512fda1c23aef (patch)
tree412b03ce7c93f89edf0a56b0bc4e2bf0779cc979 /plugins
parent4c7fa436c1f79c6a57a813193779ca9e1495fc78 (diff)
downloadorg.eclipse.osee-f7cca63d005f1b881912c06035d512fda1c23aef.tar.gz
org.eclipse.osee-f7cca63d005f1b881912c06035d512fda1c23aef.tar.xz
org.eclipse.osee-f7cca63d005f1b881912c06035d512fda1c23aef.zip
bug[ats_MT9SA]: Improve client loopback session lookup
Client loopback links were not working because server was limited to looping back to only its managed sessions instead of search through all available client sessions. Change-Id: If2bbee60835d1bf91afc5f6f1057fa7b685a6e9f
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/SessionManagerImpl.java20
-rw-r--r--plugins/org.eclipse.osee.framework.manager.servlet/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/SessionClientLoopbackServlet.java64
3 files changed, 54 insertions, 33 deletions
diff --git a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/SessionManagerImpl.java b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/SessionManagerImpl.java
index d08537ae5e5..a0d67b25144 100644
--- a/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/SessionManagerImpl.java
+++ b/plugins/org.eclipse.osee.framework.core.server/src/org/eclipse/osee/framework/core/server/internal/session/SessionManagerImpl.java
@@ -17,7 +17,6 @@ import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.Callable;
-
import org.eclipse.osee.cache.admin.Cache;
import org.eclipse.osee.framework.core.data.IUserToken;
import org.eclipse.osee.framework.core.data.OseeCredential;
@@ -133,7 +132,7 @@ public final class SessionManagerImpl implements ISessionManager {
} catch (Exception e) {
OseeExceptions.wrapAndThrow(e);
}
- if(all != null){
+ if (all != null) {
for (Session session : all) {
if (session.getClientAddress().equals(clientAddress)) {
sessions.add(session);
@@ -158,20 +157,17 @@ public final class SessionManagerImpl implements ISessionManager {
@Override
public Collection<ISession> getAllSessions(boolean includeNonServerManagedSessions) throws OseeCoreException {
Collection<ISession> toReturn = new HashSet<ISession>();
- Iterable<Session> all = null;
try {
- all = sessionCache.getAll();
- } catch (Exception e) {
- OseeExceptions.wrapAndThrow(e);
- }
- if(all != null){
+ Iterable<Session> all = sessionCache.getAll();
for (Session session : all) {
toReturn.add(session);
}
- if (includeNonServerManagedSessions) {
- ISessionCollector collector = new DefaultSessionCollector(serverId, sessionFactory, toReturn);
- sessionQuery.selectNonServerManagedSessions(collector);
- }
+ } catch (Exception e) {
+ OseeExceptions.wrapAndThrow(e);
+ }
+ if (includeNonServerManagedSessions) {
+ ISessionCollector collector = new DefaultSessionCollector(serverId, sessionFactory, toReturn);
+ sessionQuery.selectNonServerManagedSessions(collector);
}
return toReturn;
}
diff --git a/plugins/org.eclipse.osee.framework.manager.servlet/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.framework.manager.servlet/META-INF/MANIFEST.MF
index a869a228180..fd25335d306 100644
--- a/plugins/org.eclipse.osee.framework.manager.servlet/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.framework.manager.servlet/META-INF/MANIFEST.MF
@@ -39,4 +39,5 @@ Import-Package: org.eclipse.osee.event,
Service-Component: OSGI-INF/*.xml
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.eclipse.core.runtime,
- javax.servlet;bundle-version="2.5.0"
+ javax.servlet;bundle-version="2.5.0",
+ com.google.guava;bundle-version="12.0.0"
diff --git a/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/SessionClientLoopbackServlet.java b/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/SessionClientLoopbackServlet.java
index 3028bd21c61..c1ca5a9a616 100644
--- a/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/SessionClientLoopbackServlet.java
+++ b/plugins/org.eclipse.osee.framework.manager.servlet/src/org/eclipse/osee/framework/manager/servlet/SessionClientLoopbackServlet.java
@@ -19,7 +19,9 @@ import java.net.URLEncoder;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Comparator;
import java.util.Enumeration;
+import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.osee.framework.core.data.OseeServerContext;
@@ -29,6 +31,10 @@ import org.eclipse.osee.framework.core.server.ISessionManager;
import org.eclipse.osee.framework.core.server.UnsecuredOseeHttpServlet;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.logger.Log;
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Ordering;
/**
* @author Roberto E. Escobar
@@ -152,36 +158,54 @@ public class SessionClientLoopbackServlet extends UnsecuredOseeHttpServlet {
private int getSessionPort(HttpServletRequest request) throws UnknownHostException, OseeCoreException {
String remoteAddress = getNormalizedAddress(request.getRemoteAddr());
- String sessionId = request.getParameter("sessionId");
+ final String sessionId = request.getParameter("sessionId");
+
+ Iterable<? extends ISession> filteredByAddress = getSessionsByClientAddress(remoteAddress);
ISession sessionData = null;
if (Strings.isValid(sessionId)) {
- sessionData = sessionManager.getSessionById(sessionId);
- if (sessionData != null) {
- if (!sessionData.getClientAddress().equals(remoteAddress) || !isSessionValid(sessionData)) {
- sessionData = null;
+ Optional<? extends ISession> data = Iterables.tryFind(filteredByAddress, new Predicate<ISession>() {
+ @Override
+ public boolean apply(ISession session) {
+ return sessionId.equals(session.getGuid());
+ }
+ });
+ if (data.isPresent()) {
+ if (isSessionValid(data.get())) {
+ sessionData = data.get();
}
}
}
-
if (sessionData == null) {
- Collection<ISession> sessions = sessionManager.getSessionByClientAddress(remoteAddress);
- if (!sessions.isEmpty()) {
- for (ISession session : sessions) {
- if (sessionData == null) {
- if (isSessionValid(session)) {
- sessionData = session;
- }
- } else {
- if (sessionData.getLastInteractionDate().getTime() < session.getLastInteractionDate().getTime()) {
- if (isSessionValid(session)) {
- sessionData = session;
- }
- }
- }
+ List<? extends ISession> sortedByLastInteractionDate = sortByLastInteractionDate(filteredByAddress);
+ for (ISession session : sortedByLastInteractionDate) {
+ if (isSessionValid(session)) {
+ sessionData = session;
+ break;
}
}
}
return sessionData != null ? sessionData.getClientPort() : -1;
}
+
+ private Iterable<? extends ISession> getSessionsByClientAddress(final String remoteAddress) throws OseeCoreException {
+ Collection<? extends ISession> allSessions = sessionManager.getAllSessions(true);
+ return Iterables.filter(allSessions, new Predicate<ISession>() {
+ @Override
+ public boolean apply(ISession session) {
+ return remoteAddress.equals(session.getClientAddress());
+ }
+ });
+ }
+
+ private List<? extends ISession> sortByLastInteractionDate(Iterable<? extends ISession> sessions) {
+ Ordering<ISession> ordered = Ordering.from(new Comparator<ISession>() {
+ @Override
+ public int compare(ISession arg1, ISession arg2) {
+ return Long.valueOf(arg1.getLastInteractionDate().getTime()).compareTo(
+ Long.valueOf(arg2.getLastInteractionDate().getTime()));
+ }
+ });
+ return ordered.reverse().sortedCopy(sessions);
+ }
}

Back to the top