    protected void doInvite(SipServletRequest invite) throws ServletException,
            IOException {
        log("doInvite");
        invite.createResponse(SipServletResponse.SC_RINGING).send();
        ServletContext servletContext = getServletContext();
        SdpParser sdpParser = (SdpParser)servletContext.getAttribute(
                SdpParser.class.getName());
        Charset charset = Charset.forName("UTF-8");
        Object contentObject = invite.getContent();
        String sdp;
        if (contentObject instanceof String)
            sdp = (String)contentObject;
        else
        {
            byte[] content = (byte[])contentObject;
            sdp = new String(content, charset);
        }
        RtpConnection rtpConnection = sdpParser.getRtpConnection(sdp);
        if (rtpConnection == null)
        {
            invite.createResponse(SipServletResponse.SC_NOT_ACCEPTABLE).send();
            return;
        }
        int audioPayloadType;
        List<Integer> payloadTypes = rtpConnection.getPayloadTypes();
        if (payloadTypes.contains(0))
            audioPayloadType = 0;
        else if (payloadTypes.contains(8))
            audioPayloadType = 8;
        else
        {
            invite.createResponse(SipServletResponse.SC_NOT_ACCEPTABLE).send();
            return;
        }
        if (!payloadTypes.contains(DTMF_PAYLOAD_TYPE))
        {
            invite.createResponse(SipServletResponse.SC_NOT_ACCEPTABLE).send();
            return;
        }
        int port = rtpConnection.getPort();
        DtmfSession dtmfSession = new DtmfSession(DTMF_PAYLOAD_TYPE,
                rtpConnection.getHost(), port, audioPayloadType);
        try
        {
            dtmfSession.init();
        }
        catch (Exception e)
        {
            Log.warn("cannot initialize dtmf session on port " + port, e);
            SipServletResponse resp = invite.createResponse(
                    SipServletResponse.SC_SERVER_INTERNAL_ERROR);
            resp.send();
            return;
        }
        invite.getApplicationSession(true).setAttribute(
                DtmfSession.class.getName(), dtmfSession);
        SipServletResponse resp =
            invite.createResponse(SipServletResponse.SC_OK);
        String sdpAnswer = "v=0\r\n"
            + "o=user1 123 456 IN IP4 192.168.2.149\r\n"
            + "s=-\r\n"
            + "c=IN IP4 192.168.2.149\r\n"
            + "t=0 0\r\n"
            + "m=audio " + dtmfSession.getLocalPort() + " RTP/AVP "
                + audioPayloadType + " " + DTMF_PAYLOAD_TYPE + "\r\n"
            + "a=rtpmap:0 PCMU/8000\r\n"
            + "a=rtpmap:" + DTMF_PAYLOAD_TYPE + " telephone-event/8000\r\n"
            + "a=fmtp:" + DTMF_PAYLOAD_TYPE + " 0-15\r\n";
        resp.setContent(sdpAnswer.getBytes(charset), "application/sdp");
        resp.send();
    }

    protected void doInvite(SipServletRequest invite) throws ServletException,
            IOException {
        log("doInvite");
        invite.createResponse(SipServletResponse.SC_RINGING).send();
        ServletContext servletContext = getServletContext();
        SdpParser sdpParser = (SdpParser)servletContext.getAttribute(
                SdpParser.class.getName());
        Charset charset = Charset.forName("UTF-8");
        Object contentObject = invite.getContent();
        String sdp;
        if (contentObject instanceof String)
            sdp = (String)contentObject;
        else
        {
            byte[] content = (byte[])contentObject;
            sdp = new String(content, charset);
        }
        RtpConnection rtpConnection = sdpParser.getRtpConnection(sdp);
        if (rtpConnection == null)
        {
            invite.createResponse(SipServletResponse.SC_NOT_ACCEPTABLE).send();
            return;
        }
        int audioPayloadType;
        List<Integer> payloadTypes = rtpConnection.getPayloadTypes();
        if (payloadTypes.contains(0))
            audioPayloadType = 0;
        else if (payloadTypes.contains(8))
            audioPayloadType = 8;
        else
        {
            invite.createResponse(SipServletResponse.SC_NOT_ACCEPTABLE).send();
            return;
        }
        if (!payloadTypes.contains(DTMF_PAYLOAD_TYPE))
        {
            invite.createResponse(SipServletResponse.SC_NOT_ACCEPTABLE).send();
            return;
        }
        int port = rtpConnection.getPort();
        DtmfSession dtmfSession = new DtmfSession(DTMF_PAYLOAD_TYPE,
                rtpConnection.getHost(), port, audioPayloadType);
        try
        {
            dtmfSession.init();
        }
        catch (Exception e)
        {
            Log.warn("cannot initialize dtmf session on port " + port, e);
            SipServletResponse resp = invite.createResponse(
                    SipServletResponse.SC_SERVER_INTERNAL_ERROR);
            resp.send();
            return;
        }
        invite.getApplicationSession(true).setAttribute(
                DtmfSession.class.getName(), dtmfSession);
        SipServletResponse resp =
            invite.createResponse(SipServletResponse.SC_OK);
        String sdpAnswer = "v=0\r\n"
            + "o=user1 123 456 IN IP4 127.0.0.1\r\n"
            + "s=-\r\n"
            + "c=IN IP4 127.0.0.1\r\n"
            + "t=0 0\r\n"
            + "m=audio " + dtmfSession.getLocalPort() + " RTP/AVP "
                + audioPayloadType + " " + DTMF_PAYLOAD_TYPE + "\r\n"
            + "a=rtpmap:0 PCMU/8000\r\n"
            + "a=rtpmap:" + DTMF_PAYLOAD_TYPE + " telephone-event/8000\r\n"
            + "a=fmtp:" + DTMF_PAYLOAD_TYPE + " 0-15\r\n";
        resp.setContent(sdpAnswer.getBytes(charset), "application/sdp");
        resp.send();
    }
