Example usage for io.netty.handler.codec.rtsp RtspMethods REDIRECT

List of usage examples for io.netty.handler.codec.rtsp RtspMethods REDIRECT

Introduction

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

Prototype

HttpMethod REDIRECT

To view the source code for io.netty.handler.codec.rtsp RtspMethods REDIRECT.

Click Source Link

Document

The REDIRECT request informs the client that it must connect to another server location.

Usage

From source file:sas.systems.imflux.session.rtsp.SimpleRtspSession.java

License:Apache License

/**
 * {@inheritDoc}/*from  w  w  w. j  a  va  2 s  .  co m*/
 */
@Override
public void requestReceived(Channel channel, HttpRequest request) {
    if (!request.getDecoderResult().isSuccess())
        return;

    LOG.debug("RTSP request received: {}", request);

    if (request.getMethod().equals(RtspMethods.OPTIONS)) {
        handleOptionsRequest(channel, request);
    }
    if (request.getMethod().equals(RtspMethods.DESCRIBE)) {
        if (this.requestListener.isEmpty()) {
            LOG.warn(
                    "No requestListener registered, sending NOT_IMPLEMENTED as response of a DESCRIBE request!");
            sendNotImplemented(channel, request);
        }
        // forward message (resource description is application specific)
        for (RtspRequestListener listener : this.requestListener) {
            listener.describeRequestReceived(request, RtspParticipant.newInstance(channel));
        }
    }
    if (request.getMethod().equals(RtspMethods.ANNOUNCE)) {
        if (this.requestListener.isEmpty()) {
            LOG.warn(
                    "No requestListener registered, sending NOT_IMPLEMENTED as response of an ANNOUNCE request!");
            sendNotImplemented(channel, request);
        }
        // forward message (resource description is again application specific)
        for (RtspRequestListener listener : this.requestListener) {
            listener.announceRequestReceived(request, RtspParticipant.newInstance(channel));
        }
    }
    if (request.getMethod().equals(RtspMethods.SETUP)) {
        handleSetupRequest(channel, request);
    }
    if (request.getMethod().equals(RtspMethods.PLAY)) {
        if (!automatedRtspHandling) {
            // forward message
            for (RtspRequestListener listener : this.requestListener) {
                listener.playRequestReceived(request, RtspParticipant.newInstance(channel));
            }
        } else {
            sendNotImplemented(channel, request);
        }
    }
    if (request.getMethod().equals(RtspMethods.PAUSE)) {
        if (!automatedRtspHandling) {
            // forward message
            for (RtspRequestListener listener : this.requestListener) {
                listener.pauseRequestReceived(request, RtspParticipant.newInstance(channel));
            }
        } else {
            sendNotImplemented(channel, request);
        }
    }
    if (request.getMethod().equals(RtspMethods.TEARDOWN)) {
        handleTeardownRequest(channel, request);
    }
    if (request.getMethod().equals(RtspMethods.GET_PARAMETER)) {
        if (this.requestListener.isEmpty()) {
            // RTSP assumes an empty body if content-length header is missing
            if (!request.headers().contains(RtspHeaders.Names.CONTENT_LENGTH)) {
                // assume this is a ping 
                HttpResponse response = new DefaultHttpResponse(rtspVersion, RtspResponseStatuses.OK);
                response.headers().add(RtspHeaders.Names.CSEQ, request.headers().get(RtspHeaders.Names.CSEQ));
                sendResponse(response, channel);
            }
            LOG.warn(
                    "No requestListener registered, sending NOT_IMPLEMENTED as response of a GET_PARAMETER request!");
            sendNotImplemented(channel, request);
        }
        // forward message (GET_PARAMETER is application specific)
        for (RtspRequestListener listener : this.requestListener) {
            listener.getParameterRequestReceived(request, RtspParticipant.newInstance(channel));
        }
    }
    if (request.getMethod().equals(RtspMethods.SET_PARAMETER)) {
        if (this.requestListener.isEmpty()) {
            LOG.warn(
                    "No requestListener registered, sending NOT_IMPLEMENTED as response of a SET_PARAMETER request!");
            sendNotImplemented(channel, request);
        }
        // forward message (SET_PARAMETER is application specific)
        for (RtspRequestListener listener : this.requestListener) {
            listener.setParameterRequestReceived(request, RtspParticipant.newInstance(channel));
        }
    }
    if (request.getMethod().equals(RtspMethods.REDIRECT)) {
        if (!automatedRtspHandling) {
            // forward message 
            for (RtspRequestListener listener : this.requestListener) {
                listener.redirectRequestReceived(request, RtspParticipant.newInstance(channel));
            }
        } else {
            sendNotImplemented(channel, request);
        }
    }
    if (request.getMethod().equals(RtspMethods.RECORD)) {
        if (!automatedRtspHandling) {
            // forward message 
            for (RtspRequestListener listener : this.requestListener) {
                listener.recordRequestReceived(request, RtspParticipant.newInstance(channel));
            }
        } else {
            sendNotImplemented(channel, request);
        }
    }
}