List of usage examples for org.springframework.web.bind ServletRequestUtils getRequiredIntParameters
public static int[] getRequiredIntParameters(ServletRequest request, String name) throws ServletRequestBindingException
From source file:net.sourceforge.subsonic.controller.RESTController.java
public void createShare(HttpServletRequest request, HttpServletResponse response) throws Exception { request = wrapRequest(request);/*from ww w. ja v a 2s .co m*/ Player player = playerService.getPlayer(request, response); User user = securityService.getCurrentUser(request); if (!user.isShareRole()) { error(request, response, ErrorCode.NOT_AUTHORIZED, user.getUsername() + " is not authorized to share media."); return; } if (!settingsService.isUrlRedirectionEnabled()) { error(request, response, ErrorCode.GENERIC, "Sharing is only supported for *.subsonic.org domain names."); return; } XMLBuilder builder = createXMLBuilder(request, response, true); try { List<MediaFile> files = new ArrayList<MediaFile>(); for (int id : ServletRequestUtils.getRequiredIntParameters(request, "id")) { files.add(mediaFileService.getMediaFile(id)); } // TODO: Update api.jsp Share share = shareService.createShare(request, files); share.setDescription(request.getParameter("description")); long expires = ServletRequestUtils.getLongParameter(request, "expires", 0L); if (expires != 0) { share.setExpires(new Date(expires)); } shareService.updateShare(share); builder.add("shares", false); builder.add("share", createAttributesForShare(share), false); for (MediaFile mediaFile : shareService.getSharedFiles(share.getId())) { AttributeSet attributes = createAttributesForMediaFile(player, mediaFile); builder.add("entry", attributes, true); } builder.endAll(); response.getWriter().print(builder); } catch (ServletRequestBindingException x) { error(request, response, ErrorCode.MISSING_PARAMETER, getErrorMessage(x)); } catch (Exception x) { LOG.warn("Error in REST API.", x); error(request, response, ErrorCode.GENERIC, getErrorMessage(x)); } }