|
|
@ -30,6 +30,7 @@ import org.apache.commons.lang.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.context.annotation.DependsOn; |
|
|
|
import org.springframework.context.annotation.DependsOn; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import org.springframework.web.bind.ServletRequestUtils; |
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.PostConstruct; |
|
|
|
import javax.annotation.PostConstruct; |
|
|
|
import javax.servlet.http.Cookie; |
|
|
|
import javax.servlet.http.Cookie; |
|
|
@ -70,7 +71,7 @@ public class PlayerService { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Equivalent to <code>getPlayer(request, response, true)</code> . |
|
|
|
* Equivalent to <code>getPlayer(request, response, true)</code> . |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Player getPlayer(HttpServletRequest request, HttpServletResponse response) { |
|
|
|
public Player getPlayer(HttpServletRequest request, HttpServletResponse response) throws Exception { |
|
|
|
return getPlayer(request, response, true, false); |
|
|
|
return getPlayer(request, response, true, false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -85,14 +86,14 @@ public class PlayerService { |
|
|
|
* @return The player associated with the given HTTP request. |
|
|
|
* @return The player associated with the given HTTP request. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public synchronized Player getPlayer(HttpServletRequest request, HttpServletResponse response, |
|
|
|
public synchronized Player getPlayer(HttpServletRequest request, HttpServletResponse response, |
|
|
|
boolean remoteControlEnabled, boolean isStreamRequest) { |
|
|
|
boolean remoteControlEnabled, boolean isStreamRequest) throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
// Find by 'player' request parameter.
|
|
|
|
// Find by 'player' request parameter.
|
|
|
|
Player player = getPlayerById(request.getParameter("player")); |
|
|
|
Player player = getPlayerById(ServletRequestUtils.getIntParameter(request, "player")); |
|
|
|
|
|
|
|
|
|
|
|
// Find in session context.
|
|
|
|
// Find in session context.
|
|
|
|
if (player == null && remoteControlEnabled) { |
|
|
|
if (player == null && remoteControlEnabled) { |
|
|
|
String playerId = (String) request.getSession().getAttribute("player"); |
|
|
|
Integer playerId = (Integer) request.getSession().getAttribute("player"); |
|
|
|
if (playerId != null) { |
|
|
|
if (playerId != null) { |
|
|
|
player = getPlayerById(playerId); |
|
|
|
player = getPlayerById(playerId); |
|
|
|
} |
|
|
|
} |
|
|
@ -148,7 +149,7 @@ public class PlayerService { |
|
|
|
// Set cookie in response.
|
|
|
|
// Set cookie in response.
|
|
|
|
if (response != null) { |
|
|
|
if (response != null) { |
|
|
|
String cookieName = COOKIE_NAME + "-" + StringUtil.utf8HexEncode(username); |
|
|
|
String cookieName = COOKIE_NAME + "-" + StringUtil.utf8HexEncode(username); |
|
|
|
Cookie cookie = new Cookie(cookieName, player.getId()); |
|
|
|
Cookie cookie = new Cookie(cookieName, String.valueOf(player.getId())); |
|
|
|
cookie.setMaxAge(COOKIE_EXPIRY); |
|
|
|
cookie.setMaxAge(COOKIE_EXPIRY); |
|
|
|
String path = request.getContextPath(); |
|
|
|
String path = request.getContextPath(); |
|
|
|
if (StringUtils.isEmpty(path)) { |
|
|
|
if (StringUtils.isEmpty(path)) { |
|
|
@ -181,8 +182,8 @@ public class PlayerService { |
|
|
|
* @param id The unique player ID. |
|
|
|
* @param id The unique player ID. |
|
|
|
* @return The player with the given ID, or <code>null</code> if no such player exists. |
|
|
|
* @return The player with the given ID, or <code>null</code> if no such player exists. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Player getPlayerById(String id) { |
|
|
|
public Player getPlayerById(Integer id) { |
|
|
|
if (StringUtils.isBlank(id)) { |
|
|
|
if (id == null) { |
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return playerDao.getPlayerById(id); |
|
|
|
return playerDao.getPlayerById(id); |
|
|
@ -234,7 +235,7 @@ public class PlayerService { |
|
|
|
* @param username The name of the current user. |
|
|
|
* @param username The name of the current user. |
|
|
|
* @return The player ID embedded in the cookie, or <code>null</code> if cookie is not present. |
|
|
|
* @return The player ID embedded in the cookie, or <code>null</code> if cookie is not present. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private String getPlayerIdFromCookie(HttpServletRequest request, String username) { |
|
|
|
private Integer getPlayerIdFromCookie(HttpServletRequest request, String username) { |
|
|
|
Cookie[] cookies = request.getCookies(); |
|
|
|
Cookie[] cookies = request.getCookies(); |
|
|
|
if (cookies == null) { |
|
|
|
if (cookies == null) { |
|
|
|
return null; |
|
|
|
return null; |
|
|
@ -242,7 +243,11 @@ public class PlayerService { |
|
|
|
String cookieName = COOKIE_NAME + "-" + StringUtil.utf8HexEncode(username); |
|
|
|
String cookieName = COOKIE_NAME + "-" + StringUtil.utf8HexEncode(username); |
|
|
|
for (Cookie cookie : cookies) { |
|
|
|
for (Cookie cookie : cookies) { |
|
|
|
if (cookieName.equals(cookie.getName())) { |
|
|
|
if (cookieName.equals(cookie.getName())) { |
|
|
|
return StringUtils.trimToNull(cookie.getValue()); |
|
|
|
try { |
|
|
|
|
|
|
|
return Integer.valueOf(cookie.getValue()); |
|
|
|
|
|
|
|
} catch (NumberFormatException e) { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return null; |
|
|
|
return null; |
|
|
@ -274,7 +279,7 @@ public class PlayerService { |
|
|
|
* |
|
|
|
* |
|
|
|
* @param id The unique player ID. |
|
|
|
* @param id The unique player ID. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public synchronized void removePlayerById(String id) { |
|
|
|
public synchronized void removePlayerById(int id) { |
|
|
|
playerDao.deletePlayer(id); |
|
|
|
playerDao.deletePlayer(id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -284,7 +289,7 @@ public class PlayerService { |
|
|
|
* @param playerId The ID of the player to clone. |
|
|
|
* @param playerId The ID of the player to clone. |
|
|
|
* @return The cloned player. |
|
|
|
* @return The cloned player. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Player clonePlayer(String playerId) { |
|
|
|
public Player clonePlayer(int playerId) { |
|
|
|
Player player = getPlayerById(playerId); |
|
|
|
Player player = getPlayerById(playerId); |
|
|
|
if (player.getName() != null) { |
|
|
|
if (player.getName() != null) { |
|
|
|
player.setName(player.getName() + " (copy)"); |
|
|
|
player.setName(player.getName() + " (copy)"); |
|
|
@ -309,9 +314,10 @@ public class PlayerService { |
|
|
|
defaultActiveTranscodings.add(transcoding); |
|
|
|
defaultActiveTranscodings.add(transcoding); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (player != null) { |
|
|
|
transcodingService.setTranscodingsForPlayer(player, defaultActiveTranscodings); |
|
|
|
transcodingService.setTranscodingsForPlayer(player, defaultActiveTranscodings); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Returns a player associated to the special "guest" user, creating it if necessary. |
|
|
|
* Returns a player associated to the special "guest" user, creating it if necessary. |
|
|
|