Package com.pugh.sockso.web

Examples of com.pugh.sockso.web.BadRequestException


     */
   
    public static void checkFeatureEnabled( final Properties p, final String property ) throws BadRequestException {

        if ( !isFeatureEnabled(p,property) )
            throw new BadRequestException( "feature not enabled", 403 );

    }
View Full Code Here


                    action.handleRequest();
                }
               
                catch ( final Exception e ) {
                    log.debug( "API Exception: " +e.getMessage() );
                    throw new BadRequestException( e.getMessage() );
                }
               
                return;
               
            }

        }

        throw new BadRequestException( "Unknown API Action" );

    }
View Full Code Here

            st = db.prepare( sql );
            st.setInt( 1, artistId );
            rs = st.executeQuery();

            if ( !rs.next() )
                throw new BadRequestException( "unknown artist", 404 );

            return rs.getString( "name" );

        }
View Full Code Here

            getResponse().sendData( in );
           
        }

        catch ( final FileNotFoundException e ) {
            throw new BadRequestException( locale.getString("www.error.fileNotFound"), 404 );
        }
       
        finally {
            Utils.close( in );
        }
View Full Code Here

     */

    public void handleRequest() throws Exception {
       
        if ( !getUser().isAdmin() ) {
            throw new BadRequestException(
                getLocale().getString("www.error.notAnAdmin")
            );
        }

        handleAdminRequest();
View Full Code Here

        final int trackId = Integer.parseInt( req.getUrlParam( 1 ) );

        final Track track = Track.find( getDatabase(), trackId );

        if ( track == null ) {
            throw new BadRequestException( "Invalid track ID", 404 );
        }

        final MusicStream stream = getStream( track );

        playTrack( track, stream );
View Full Code Here

        final Pattern pattern = Pattern.compile("bytes=(\\d+)-(\\d+)?");
        final Matcher matcher = pattern.matcher(rangeHeader);

        if ( !matcher.matches() ) {
            log.error("Bad \"Range\" header: " + rangeHeader);
            throw new BadRequestException("Invalid range", 416);
        }

        try {
           
            long beginPos = Long.parseLong(matcher.group(1));
            long endPos = -1;

            String endMatch = matcher.group(2);

            if ( endMatch != null ) {
                endPos = Long.parseLong(endMatch);
            }

            final long trackLength = new File(track.getPath()).length();

            if ( endPos < 0 ) {
                endPos = trackLength - 1;
            }

            if ( beginPos < 0 || beginPos >= trackLength
                 || endPos >= trackLength || endPos <= beginPos ) {
                log.error("Bad \"Range\" values: " + beginPos + "-" + endPos);
                throw new BadRequestException("Invalid range", 416);
            }

            return new Range(beginPos, endPos);

        } catch (NumberFormatException e) {
            log.error("Bad \"Range\" header", e);
            throw new BadRequestException("Invalid range", 416);
        }

    }
View Full Code Here

            // make sure we've a directory to put the track in
            final Database db = getDatabase();
            final File dir = new File( Utils.getUploadsPath(db,p) + "/"+artist+" - "+album );
            if ( !dir.exists() )
                if ( !dir.mkdir() )
                    throw new BadRequestException( locale.getString("www.error.cantCreateTrackFolder"), 500 );

            // write the track to disk
            final File tempFile = file.getTemporaryFile();
            final File newFile = new File( getNewUploadFilename(dir,track,Utils.getExt(file.getFilename())) );
View Full Code Here

        final Request req = getRequest();
        final Locale locale = getLocale();
        final UploadFile file = req.getFile( "musicFile" );

        if ( file == null )
            throw new BadRequestException( locale.getString("www.error.noFileUploaded") );

        // check mime type to see if it looks ok
        final String contentType = file.getContentType();
        log.debug( "File content type: " + contentType );
        if ( !Files.isValidMimeType(contentType) )
            throw new BadRequestException( locale.getString("www.error.unsupportedAudioFormat") );
       
        // check required fields
        final Database db = getDatabase();
        final Validater v = new Validater( db );
        final String artist = req.getArgument( "artist" );
        final String album = req.getArgument( "album" );
        final String track = req.getArgument( "title" );
        if ( !v.checkRequiredFields( new String[] { artist, album, track }) )
            throw new BadRequestException( locale.getString("www.error.missingField") );

    }
View Full Code Here

            );
            if ( !file.exists() )
                return file.getAbsolutePath();
        }
       
        throw new BadRequestException( locale.getString("www.error.couldNotCreateUniqueFilename"), 500 );

    }
View Full Code Here

TOP

Related Classes of com.pugh.sockso.web.BadRequestException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.