It's all about the answers!

Ask a question

Session data crossover problem with plain java web app, all users see the same person who is logged in first, any ideas?


Raheem Alhamdani (2816) | asked Feb 22 '18, 12:53 p.m.
edited Feb 26 '18, 9:56 a.m.

Created a web application using the plain java API, then installed it on WebSphere (not sure if this a good practice), now all other users see who ever logged in first. the intended purpose is to create an application that takes a work item and change the estimates on all its children.

this is the form

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
 pageEncoding="ISO-8859-1"%>
<@page">%@page import="rtcWiz.LoggerTester"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login Test Page</title>
</head>
<body>

 <br>
 <form action="testRes.jsp" method="post" accept-charset="UTF-8">
  RepositoryURI:<br> <input type="text"     value="https://some-server" name="RepositoryURI"> <br>
  <br> UserId:  <br> <input type="text"   value="userID" name="UserId"><br>
  <br> Password:<br> <input type="password" value="userPassword" name="Password"><br>
  <input type="Submit" value="Log me in">
  <br>
 </form>

 <br>
 <br>
 <br>

</body>
</html>

here the form response

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<@page">%@page import="rtcWiz.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Login Test Page</title>
    </head>
<body>

    <%
      String[] htmlArgs = new String[3];
      htmlArgs[0] = request.getParameter("RepositoryURI");
      htmlArgs[1] = request.getParameter("UserId");
      htmlArgs[2] = request.getParameter("Password");
    %>
   
   
    <!-- Create Work Items -->
    <%
      LoggerTester Lt = new LoggerTester();
      Lt.run(htmlArgs[0] ,htmlArgs[1], htmlArgs[2]);
     %>
     <h3>Welcome</h3>
    <br>You are logged in as :  <%= LoggerTester.getRepo().loggedInContributor().getName() %>

</body>
</html>

<code>

package rtcWiz;


import org.eclipse.core.runtime.IProgressMonitor;

import com.ibm.team.repository.client.ITeamRepository;
import com.ibm.team.repository.client.TeamPlatform;
import com.ibm.team.repository.common.TeamRepositoryException;

/**
 * Plain Java Snippet: Connecting to a repository
 */
public class LoggerTester {

 private static String REPOSITORY_ADDRESS;
 private static String USER_AND_PASSWORD;
 private static String USER_ID;
 private static ITeamRepository repo;

 public static ITeamRepository getRepo() {
  return repo;
 }

 public static void setRepo(ITeamRepository repo) {
  LoggerTester.repo = repo;
 }

 public void run(String url, String user, String pass) {
  REPOSITORY_ADDRESS = url;
  USER_AND_PASSWORD = pass;
  USER_ID = user;
  
  TeamPlatform.startup();
  try {
   IProgressMonitor monitor = new SysoutProgressMonitor();
   login(monitor);
  } catch (TeamRepositoryException e) {
   // System.out.println("Unable to login: " + e.getMessage());
  } finally {
   TeamPlatform.shutdown();
  }
 }

 public static ITeamRepository login(IProgressMonitor monitor) throws TeamRepositoryException {
  ITeamRepository repository = TeamPlatform.getTeamRepositoryService().getTeamRepository(REPOSITORY_ADDRESS);
  
  repository.registerLoginHandler(new ITeamRepository.ILoginHandler() {
   
   public ILoginInfo challenge(ITeamRepository repository) {
    return new ILoginInfo() {
     public String getUserId() {
      return USER_ID;
     }

     public String getPassword() {
      return USER_AND_PASSWORD;
     }
    };
   }
  });
  monitor.subTask("Contacting to " + repository.getRepositoryURI() + "...");
  repository.login(monitor);
  monitor.subTask("Connected");
  setRepo(repository);
  return repository;
 }
}

</code>

One answer



permanent link
Donald Nong (14.5k614) | answered Mar 12 '18, 11:08 p.m.

If I'm not mistaken, you just developed a client application but happened to deploy it to a server. The client application simply does not handle multiple sessions, and that's why you see whoever is the first to log in.

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.