Example usage for io.netty.handler.codec.rtsp RtspResponseStatuses UNAUTHORIZED

List of usage examples for io.netty.handler.codec.rtsp RtspResponseStatuses UNAUTHORIZED

Introduction

In this page you can find the example usage for io.netty.handler.codec.rtsp RtspResponseStatuses UNAUTHORIZED.

Prototype

HttpResponseStatus UNAUTHORIZED

To view the source code for io.netty.handler.codec.rtsp RtspResponseStatuses UNAUTHORIZED.

Click Source Link

Document

401 Unauthorized

Usage

From source file:sas.systems.unveiled.server.RtspMessageHandler.java

License:Apache License

@Override
public void announceRequestReceived(HttpRequest message, RtspParticipant participant) {
    final String seq = message.headers().get(RtspHeaders.Names.CSEQ);
    final String contentType = message.headers().get(RtspHeaders.Names.CONTENT_TYPE);
    final String authorization = message.headers().get(RtspHeaders.Names.AUTHORIZATION);

    System.out.println(message);/* w  ww. j a  va  2s  .c o m*/

    if (authorization == null) {
        participant.sendMessage(createErrorResponse(RtspResponseStatuses.UNAUTHORIZED, message.headers()));
        return;
    } else {
        if (!isAuthorized(authorization)) {
            participant.sendMessage(createErrorResponse(RtspResponseStatuses.UNAUTHORIZED, message.headers()));
            return;
        }
    }

    if (message instanceof FullHttpRequest) {
        final FullHttpRequest fullResponse = (FullHttpRequest) message;
        final ByteBuf content = fullResponse.content();

        if (seq != null && contentType != null && contentType.contains("sdp") && content != null) {
            // parse announce content
            final String fileName = retrieveFileName(fullResponse.getUri());
            final SdpParser parser = new SdpParser(content);
            final String sessionId = participant.setup();

            // setup stream handler with content of announce request 
            final FileStreamHandler streamHandler = new FileStreamHandler(this.sm, participant);
            streamHandler.setFileName(fileName);
            streamHandler.setPayloadType(parser.getMediaType());
            streamHandler.setAuthor(retrieveUsername(authorization));
            streamHandler.setMediaType("video/mp4");

            // save session info
            this.sessions.put(sessionId, streamHandler);

            // send response
            try {
                int cseq = Integer.valueOf(seq);
                participant.sendMessage(createAnnounceResponse(cseq, sessionId));
                return;
            } catch (NumberFormatException e) {
                // send error message
                participant.sendMessage(
                        createErrorResponse(RtspResponseStatuses.HEADER_FIELD_NOT_VALID, message.headers()));
                return;
            }
        }
    }

    // otherwise send error message
    participant.sendMessage(createErrorResponse(RtspResponseStatuses.BAD_REQUEST, message.headers()));
}

From source file:sas.systems.unveiled.server.RtspMessageHandler.java

License:Apache License

@Override
public void setupRequestReceived(HttpRequest message, RtspParticipant participant) {
    final String seq = message.headers().get(RtspHeaders.Names.CSEQ);
    final String session = message.headers().get(RtspHeaders.Names.SESSION);
    final String authorization = message.headers().get(RtspHeaders.Names.AUTHORIZATION);
    final String transport = message.headers().get(RtspHeaders.Names.TRANSPORT);

    System.out.println(message);//from   w  w  w  . ja va 2  s .c o m

    // check authorization
    if (authorization == null) {
        participant.sendMessage(createErrorResponse(RtspResponseStatuses.UNAUTHORIZED, message.headers()));
        return;
    } else {
        if (!isAuthorized(authorization)) {
            participant.sendMessage(createErrorResponse(RtspResponseStatuses.UNAUTHORIZED, message.headers()));
            return;
        }
    }

    // extract transport information
    if (seq != null && session != null && transport != null) {
        int cseq = 0;
        try {
            cseq = Integer.valueOf(seq);
        } catch (NumberFormatException e) {
            participant.sendMessage(
                    createErrorResponse(RtspResponseStatuses.HEADER_FIELD_NOT_VALID, message.headers()));
            return;
        }
        FileStreamHandler handler = this.sessions.get(session);
        if (handler == null) {
            participant.sendMessage(
                    createErrorResponse(RtspResponseStatuses.SESSION_NOT_FOUND, message.headers()));
            return;
        }

        // parse transport header and validate entries
        final InetSocketAddress remote = (InetSocketAddress) participant.getRemoteAddress();
        final boolean validationError = parseTransportHeader(transport, handler.getParticipant(),
                remote.getHostName());
        if (!validationError) {
            participant.sendMessage(
                    createErrorResponse(RtspResponseStatuses.HEADER_FIELD_NOT_VALID, message.headers()));
            return;
        }

        participant.sendMessage(
                createSetupResponse(cseq, session, buildTransportString(transport, handler.getSsrc() + "")));
    }

    // send error message
    participant.sendMessage(createErrorResponse(RtspResponseStatuses.BAD_REQUEST, message.headers()));
}

From source file:sas.systems.unveiled.server.RtspMessageHandler.java

License:Apache License

@Override
public void teardownRequestReceived(HttpRequest message, RtspParticipant participant) {
    final String seq = message.headers().get(RtspHeaders.Names.CSEQ);
    final String session = message.headers().get(RtspHeaders.Names.SESSION);
    final String authorization = message.headers().get(RtspHeaders.Names.AUTHORIZATION);

    System.out.println(message);/*w  w  w . ja  v  a 2 s  .c o m*/

    // check authorization
    if (authorization == null) {
        participant.sendMessage(createErrorResponse(RtspResponseStatuses.UNAUTHORIZED, message.headers()));
        return;
    } else {
        if (!isAuthorized(authorization)) {
            participant.sendMessage(createErrorResponse(RtspResponseStatuses.UNAUTHORIZED, message.headers()));
            return;
        }
    }

    // extract transport information
    if (seq != null && session != null) {
        int cseq = 0;
        try {
            cseq = Integer.valueOf(seq);
        } catch (NumberFormatException e) {
            participant.sendMessage(
                    createErrorResponse(RtspResponseStatuses.HEADER_FIELD_NOT_VALID, message.headers()));
            return;
        }
        FileStreamHandler handler = this.sessions.get(session);
        if (handler == null) {
            participant.sendMessage(
                    createErrorResponse(RtspResponseStatuses.SESSION_NOT_FOUND, message.headers()));
            return;
        }

        // stop receiving data and close all resources
        handler.tieUp();

        // send response
        participant.sendMessage(createTeardownResponse(cseq, session));
    }
    participant.sendMessage(createErrorResponse(RtspResponseStatuses.BAD_REQUEST, message.headers()));
}

From source file:sas.systems.unveiled.server.RtspMessageHandler.java

License:Apache License

@Override
public void recordRequestReceived(HttpRequest message, RtspParticipant participant) {
    final String seq = message.headers().get(RtspHeaders.Names.CSEQ);
    final String session = message.headers().get(RtspHeaders.Names.SESSION);
    final String authorization = message.headers().get(RtspHeaders.Names.AUTHORIZATION);
    final String range = message.headers().get(RtspHeaders.Names.RANGE);

    System.out.println(message);//from  ww w  . j a va2 s. com

    // check authorization
    if (authorization == null) {
        participant.sendMessage(createErrorResponse(RtspResponseStatuses.UNAUTHORIZED, message.headers()));
        return;
    } else {
        if (!isAuthorized(authorization)) {
            participant.sendMessage(createErrorResponse(RtspResponseStatuses.UNAUTHORIZED, message.headers()));
            return;
        }
    }

    // extract transport information
    if (seq != null && session != null) {
        int cseq = 0;
        try {
            cseq = Integer.valueOf(seq);
        } catch (NumberFormatException e) {
            participant.sendMessage(
                    createErrorResponse(RtspResponseStatuses.HEADER_FIELD_NOT_VALID, message.headers()));
            return;
        }
        FileStreamHandler handler = this.sessions.get(session);
        if (handler == null) {
            participant.sendMessage(
                    createErrorResponse(RtspResponseStatuses.SESSION_NOT_FOUND, message.headers()));
            return;
        }

        if (range == null || range.startsWith("npt=0.0") || range.startsWith("npt=now")) {
            // start receiving data
            handler.initialize();

            // send response
            participant.sendMessage(createRecordResponse(cseq, session));
        }

        participant.sendMessage(
                createErrorResponse(RtspResponseStatuses.HEADER_FIELD_NOT_VALID, message.headers()));
    }
    participant.sendMessage(createErrorResponse(RtspResponseStatuses.BAD_REQUEST, message.headers()));
}