Start RestController migration.

master
Rémi Cocula 8 years ago
parent f76470537f
commit e301f2363f
  1. 273
      libresonic-main/src/main/java/org/libresonic/player/controller/RESTController.java
  2. 1
      libresonic-main/src/main/resources/applicationContext-security.xml
  3. 33
      libresonic-main/src/main/resources/libresonic-servlet.xml
  4. 19
      libresonic-main/src/test/resources/libresonic-rest-api-soapui-project.xml

@ -19,124 +19,46 @@
*/ */
package org.libresonic.player.controller; package org.libresonic.player.controller;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
import org.libresonic.restapi.AlbumID3;
import org.libresonic.restapi.AlbumList;
import org.libresonic.restapi.AlbumList2;
import org.libresonic.restapi.AlbumWithSongsID3;
import org.libresonic.restapi.ArtistID3;
import org.libresonic.restapi.ArtistInfo;
import org.libresonic.restapi.ArtistInfo2;
import org.libresonic.restapi.ArtistWithAlbumsID3;
import org.libresonic.restapi.ArtistsID3;
import org.libresonic.restapi.Bookmarks;
import org.libresonic.restapi.ChatMessage;
import org.libresonic.restapi.ChatMessages;
import org.libresonic.restapi.Child;
import org.libresonic.restapi.Directory;
import org.libresonic.restapi.Genres;
import org.libresonic.restapi.Index;
import org.libresonic.restapi.IndexID3;
import org.libresonic.restapi.Indexes;
import org.libresonic.restapi.InternetRadioStation;
import org.libresonic.restapi.InternetRadioStations;
import org.libresonic.restapi.JukeboxPlaylist;
import org.libresonic.restapi.JukeboxStatus;
import org.libresonic.restapi.Lyrics;
import org.libresonic.restapi.MediaType;
import org.libresonic.restapi.MusicFolders;
import org.libresonic.restapi.NewestPodcasts;
import org.libresonic.restapi.NowPlaying;
import org.libresonic.restapi.NowPlayingEntry;
import org.libresonic.restapi.PlaylistWithSongs;
import org.libresonic.restapi.Playlists;
import org.libresonic.restapi.PodcastStatus;
import org.libresonic.restapi.Podcasts;
import org.libresonic.restapi.Response;
import org.libresonic.restapi.SearchResult2;
import org.libresonic.restapi.SearchResult3;
import org.libresonic.restapi.Shares;
import org.libresonic.restapi.SimilarSongs;
import org.libresonic.restapi.SimilarSongs2;
import org.libresonic.restapi.Songs;
import org.libresonic.restapi.Starred;
import org.libresonic.restapi.Starred2;
import org.libresonic.restapi.TopSongs;
import org.libresonic.restapi.Users;
import org.libresonic.restapi.Videos;
import org.libresonic.player.Logger; import org.libresonic.player.Logger;
import org.libresonic.player.ajax.ChatService; import org.libresonic.player.ajax.ChatService;
import org.libresonic.player.ajax.LyricsInfo; import org.libresonic.player.ajax.LyricsInfo;
import org.libresonic.player.ajax.LyricsService; import org.libresonic.player.ajax.LyricsService;
import org.libresonic.player.ajax.PlayQueueService; import org.libresonic.player.ajax.PlayQueueService;
import org.libresonic.player.command.UserSettingsCommand; import org.libresonic.player.command.UserSettingsCommand;
import org.libresonic.player.dao.AlbumDao; import org.libresonic.player.dao.*;
import org.libresonic.player.dao.ArtistDao; import org.libresonic.player.domain.*;
import org.libresonic.player.dao.BookmarkDao;
import org.libresonic.player.dao.MediaFileDao;
import org.libresonic.player.dao.PlayQueueDao;
import org.libresonic.player.domain.Album;
import org.libresonic.player.domain.Artist; import org.libresonic.player.domain.Artist;
import org.libresonic.player.domain.ArtistBio;
import org.libresonic.player.domain.Bookmark; import org.libresonic.player.domain.Bookmark;
import org.libresonic.player.domain.Genre; import org.libresonic.player.domain.Genre;
import org.libresonic.player.domain.InternetRadio;
import org.libresonic.player.domain.MediaFile;
import org.libresonic.player.domain.MusicFolder; import org.libresonic.player.domain.MusicFolder;
import org.libresonic.player.domain.MusicFolderContent;
import org.libresonic.player.domain.MusicIndex;
import org.libresonic.player.domain.PlayQueue; import org.libresonic.player.domain.PlayQueue;
import org.libresonic.player.domain.PlayStatus;
import org.libresonic.player.domain.Player;
import org.libresonic.player.domain.PlayerTechnology;
import org.libresonic.player.domain.Playlist; import org.libresonic.player.domain.Playlist;
import org.libresonic.player.domain.PodcastChannel; import org.libresonic.player.domain.PodcastChannel;
import org.libresonic.player.domain.PodcastEpisode; import org.libresonic.player.domain.PodcastEpisode;
import org.libresonic.player.domain.RandomSearchCriteria;
import org.libresonic.player.domain.SavedPlayQueue;
import org.libresonic.player.domain.SearchCriteria;
import org.libresonic.player.domain.SearchResult; import org.libresonic.player.domain.SearchResult;
import org.libresonic.player.domain.Share; import org.libresonic.player.domain.Share;
import org.libresonic.player.domain.TranscodeScheme;
import org.libresonic.player.domain.User; import org.libresonic.player.domain.User;
import org.libresonic.player.domain.UserSettings; import org.libresonic.player.service.*;
import org.libresonic.player.service.AudioScrobblerService;
import org.libresonic.player.service.JukeboxService;
import org.libresonic.player.service.LastFmService;
import org.libresonic.player.service.MediaFileService;
import org.libresonic.player.service.MusicIndexService;
import org.libresonic.player.service.PlayerService;
import org.libresonic.player.service.PlaylistService;
import org.libresonic.player.service.PodcastService;
import org.libresonic.player.service.RatingService;
import org.libresonic.player.service.SearchService;
import org.libresonic.player.service.SecurityService;
import org.libresonic.player.service.SettingsService;
import org.libresonic.player.service.ShareService;
import org.libresonic.player.service.StatusService;
import org.libresonic.player.service.TranscodingService;
import org.libresonic.player.util.Pair; import org.libresonic.player.util.Pair;
import org.libresonic.player.util.StringUtil; import org.libresonic.player.util.StringUtil;
import org.libresonic.player.util.Util; import org.libresonic.player.util.Util;
import org.libresonic.restapi.*;
import org.libresonic.restapi.Genres;
import org.libresonic.restapi.PodcastStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import static org.libresonic.player.security.RESTRequestParameterProcessingFilter.decrypt; import static org.libresonic.player.security.RESTRequestParameterProcessingFilter.decrypt;
import static org.springframework.web.bind.ServletRequestUtils.*; import static org.springframework.web.bind.ServletRequestUtils.*;
@ -150,44 +72,76 @@ import static org.springframework.web.bind.ServletRequestUtils.*;
* *
* @author Sindre Mehus * @author Sindre Mehus
*/ */
public class RESTController extends MultiActionController { @Controller
public class RESTController {
private static final Logger LOG = Logger.getLogger(RESTController.class); private static final Logger LOG = Logger.getLogger(RESTController.class);
@Autowired
private SettingsService settingsService; private SettingsService settingsService;
@Autowired
private SecurityService securityService; private SecurityService securityService;
@Autowired
private PlayerService playerService; private PlayerService playerService;
@Autowired
private MediaFileService mediaFileService; private MediaFileService mediaFileService;
@Autowired
private LastFmService lastFmService; private LastFmService lastFmService;
@Autowired
private MusicIndexService musicIndexService; private MusicIndexService musicIndexService;
@Autowired
private TranscodingService transcodingService; private TranscodingService transcodingService;
@Autowired
private DownloadController downloadController; private DownloadController downloadController;
@Autowired
private CoverArtController coverArtController; private CoverArtController coverArtController;
@Autowired
private AvatarController avatarController; private AvatarController avatarController;
@Autowired
private UserSettingsController userSettingsController; private UserSettingsController userSettingsController;
@Autowired
private LeftController leftController; private LeftController leftController;
@Autowired
private StatusService statusService; private StatusService statusService;
@Autowired
private StreamController streamController; private StreamController streamController;
@Autowired
private HLSController hlsController; private HLSController hlsController;
@Autowired
private ShareService shareService; private ShareService shareService;
@Autowired
private PlaylistService playlistService; private PlaylistService playlistService;
@Autowired
private ChatService chatService; private ChatService chatService;
@Autowired
private LyricsService lyricsService; private LyricsService lyricsService;
@Autowired
private PlayQueueService playQueueService; private PlayQueueService playQueueService;
@Autowired
private JukeboxService jukeboxService; private JukeboxService jukeboxService;
@Autowired
private AudioScrobblerService audioScrobblerService; private AudioScrobblerService audioScrobblerService;
@Autowired
private PodcastService podcastService; private PodcastService podcastService;
@Autowired
private RatingService ratingService; private RatingService ratingService;
@Autowired
private SearchService searchService; private SearchService searchService;
@Autowired
private MediaFileDao mediaFileDao; private MediaFileDao mediaFileDao;
@Autowired
private ArtistDao artistDao; private ArtistDao artistDao;
@Autowired
private AlbumDao albumDao; private AlbumDao albumDao;
@Autowired
private BookmarkDao bookmarkDao; private BookmarkDao bookmarkDao;
@Autowired
private PlayQueueDao playQueueDao; private PlayQueueDao playQueueDao;
private final Map<BookmarkKey, Bookmark> bookmarkCache = new ConcurrentHashMap<BookmarkKey, Bookmark>(); private final Map<BookmarkKey, Bookmark> bookmarkCache = new ConcurrentHashMap<BookmarkKey, Bookmark>();
private final JAXBWriter jaxbWriter = new JAXBWriter(); private final JAXBWriter jaxbWriter = new JAXBWriter();
@PostConstruct
public void init() { public void init() {
refreshBookmarkCache(); refreshBookmarkCache();
} }
@ -199,7 +153,7 @@ public class RESTController extends MultiActionController {
} }
} }
@SuppressWarnings("UnusedDeclaration") @RequestMapping(value = "/rest/ping", method = RequestMethod.GET)
public void ping(HttpServletRequest request, HttpServletResponse response) throws Exception { public void ping(HttpServletRequest request, HttpServletResponse response) throws Exception {
Response res = createResponse(); Response res = createResponse();
jaxbWriter.writeResponse(request, response, res); jaxbWriter.writeResponse(request, response, res);
@ -1066,7 +1020,7 @@ public class RESTController extends MultiActionController {
writeEmptyResponse(request, response); writeEmptyResponse(request, response);
} }
@SuppressWarnings("UnusedDeclaration") @RequestMapping(value = "/rest/getAlbumList", method = RequestMethod.GET)
public void getAlbumList(HttpServletRequest request, HttpServletResponse response) throws Exception { public void getAlbumList(HttpServletRequest request, HttpServletResponse response) throws Exception {
request = wrapRequest(request); request = wrapRequest(request);
Player player = playerService.getPlayer(request, response); Player player = playerService.getPlayer(request, response);
@ -2342,125 +2296,6 @@ public class RESTController extends MultiActionController {
return !players.isEmpty() ? players.get(0).getId() : null; return !players.isEmpty() ? players.get(0).getId() : null;
} }
public void setSettingsService(SettingsService settingsService) {
this.settingsService = settingsService;
}
public void setSecurityService(SecurityService securityService) {
this.securityService = securityService;
}
public void setPlayerService(PlayerService playerService) {
this.playerService = playerService;
}
public void setTranscodingService(TranscodingService transcodingService) {
this.transcodingService = transcodingService;
}
public void setDownloadController(DownloadController downloadController) {
this.downloadController = downloadController;
}
public void setCoverArtController(CoverArtController coverArtController) {
this.coverArtController = coverArtController;
}
public void setUserSettingsController(UserSettingsController userSettingsController) {
this.userSettingsController = userSettingsController;
}
public void setLeftController(LeftController leftController) {
this.leftController = leftController;
}
public void setStatusService(StatusService statusService) {
this.statusService = statusService;
}
public void setPlaylistService(PlaylistService playlistService) {
this.playlistService = playlistService;
}
public void setStreamController(StreamController streamController) {
this.streamController = streamController;
}
public void setHlsController(HLSController hlsController) {
this.hlsController = hlsController;
}
public void setChatService(ChatService chatService) {
this.chatService = chatService;
}
public void setLyricsService(LyricsService lyricsService) {
this.lyricsService = lyricsService;
}
public void setPlayQueueService(PlayQueueService playQueueService) {
this.playQueueService = playQueueService;
}
public void setJukeboxService(JukeboxService jukeboxService) {
this.jukeboxService = jukeboxService;
}
public void setAudioScrobblerService(AudioScrobblerService audioScrobblerService) {
this.audioScrobblerService = audioScrobblerService;
}
public void setPodcastService(PodcastService podcastService) {
this.podcastService = podcastService;
}
public void setRatingService(RatingService ratingService) {
this.ratingService = ratingService;
}
public void setSearchService(SearchService searchService) {
this.searchService = searchService;
}
public void setShareService(ShareService shareService) {
this.shareService = shareService;
}
public void setMediaFileService(MediaFileService mediaFileService) {
this.mediaFileService = mediaFileService;
}
public void setAvatarController(AvatarController avatarController) {
this.avatarController = avatarController;
}
public void setArtistDao(ArtistDao artistDao) {
this.artistDao = artistDao;
}
public void setAlbumDao(AlbumDao albumDao) {
this.albumDao = albumDao;
}
public void setMediaFileDao(MediaFileDao mediaFileDao) {
this.mediaFileDao = mediaFileDao;
}
public void setMusicIndexService(MusicIndexService musicIndexService) {
this.musicIndexService = musicIndexService;
}
public void setBookmarkDao(BookmarkDao bookmarkDao) {
this.bookmarkDao = bookmarkDao;
}
public void setLastFmService(LastFmService lastFmService) {
this.lastFmService = lastFmService;
}
public void setPlayQueueDao(PlayQueueDao playQueueDao) {
this.playQueueDao = playQueueDao;
}
public enum ErrorCode { public enum ErrorCode {

@ -24,6 +24,7 @@
<security:intercept-url pattern="/hls/**" access="permitAll" /> <security:intercept-url pattern="/hls/**" access="permitAll" />
<security:intercept-url pattern="/stream/**" access="permitAll" /> <security:intercept-url pattern="/stream/**" access="permitAll" />
<security:intercept-url pattern="/ws/**" access="permitAll" /> <security:intercept-url pattern="/ws/**" access="permitAll" />
<security:intercept-url pattern="/rest/**" access="permitAll" />
<security:intercept-url pattern="/share/**" access="permitAll" /> <security:intercept-url pattern="/share/**" access="permitAll" />
<security:intercept-url pattern="/style/**" access="permitAll" /> <security:intercept-url pattern="/style/**" access="permitAll" />
<security:intercept-url pattern="/icons/**" access="permitAll" /> <security:intercept-url pattern="/icons/**" access="permitAll" />

@ -26,38 +26,6 @@
<property name="mediaFileService" ref="mediaFileService"/> <property name="mediaFileService" ref="mediaFileService"/>
<property name="musicIndexService" ref="musicIndexService"/> <property name="musicIndexService" ref="musicIndexService"/>
</bean> </bean>
<bean id="restController" class="org.libresonic.player.controller.RESTController" init-method="init">
<property name="settingsService" ref="settingsService"/>
<property name="securityService" ref="securityService"/>
<property name="playerService" ref="playerService"/>
<property name="mediaFileService" ref="mediaFileService"/>
<property name="lastFmService" ref="lastFmService"/>
<property name="musicIndexService" ref="musicIndexService"/>
<property name="transcodingService" ref="transcodingService"/>
<property name="statusService" ref="statusService"/>
<property name="searchService" ref="searchService"/>
<property name="jukeboxService" ref="jukeboxService"/>
<property name="audioScrobblerService" ref="audioScrobblerService"/>
<property name="playlistService" ref="playlistService"/>
<property name="playQueueService" ref="ajaxPlayQueueService"/>
<property name="ratingService" ref="ratingService"/>
<property name="chatService" ref="ajaxChatService"/>
<property name="lyricsService" ref="ajaxLyricsService"/>
<property name="podcastService" ref="podcastService"/>
<property name="shareService" ref="shareService"/>
<property name="mediaFileDao" ref="mediaFileDao"/>
<property name="artistDao" ref="artistDao"/>
<property name="albumDao" ref="albumDao"/>
<property name="bookmarkDao" ref="bookmarkDao"/>
<property name="playQueueDao" ref="playQueueDao"/>
<property name="downloadController" ref="downloadController"/>
<property name="streamController" ref="streamController"/>
<property name="hlsController" ref="hlsController"/>
<property name="coverArtController" ref="coverArtController"/>
<property name="avatarController" ref="avatarController"/>
<property name="userSettingsController" ref="userSettingsController"/>
<property name="leftController" ref="leftController"/>
</bean>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="alwaysUseFullPath" value="true"/> <property name="alwaysUseFullPath" value="true"/>
@ -66,7 +34,6 @@
<prop key="/podcast/**">podcastController</prop> <prop key="/podcast/**">podcastController</prop>
<prop key="/wap/download.view">downloadController</prop> <prop key="/wap/download.view">downloadController</prop>
<prop key="/wap/**">wapController</prop> <prop key="/wap/**">wapController</prop>
<prop key="/rest/**">restController</prop>
</props> </props>
</property> </property>
</bean> </bean>

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save