Search in sources :

Example 1 with ServerHeader

use of javax.sip.header.ServerHeader in project XobotOS by xamarin.

the class DialogFilter method sendLoopDetectedResponse.

/**
     * Send back a LOOP Detected Response.
     * 
     * @param sipRequest
     * @param transaction
     * 
     */
private void sendLoopDetectedResponse(SIPRequest sipRequest, SIPServerTransaction transaction) {
    SIPResponse sipResponse = sipRequest.createResponse(Response.LOOP_DETECTED);
    ServerHeader serverHeader = MessageFactoryImpl.getDefaultServerHeader();
    if (serverHeader != null) {
        sipResponse.setHeader(serverHeader);
    }
    try {
        sipStack.addTransactionPendingAck(transaction);
        transaction.sendResponse(sipResponse);
        transaction.releaseSem();
    } catch (Exception ex) {
        sipStack.getStackLogger().logError("Problem sending error response", ex);
        transaction.releaseSem();
        sipStack.removeTransaction(transaction);
    }
}
Also used : SIPResponse(gov.nist.javax.sip.message.SIPResponse) ServerHeader(javax.sip.header.ServerHeader) InvalidArgumentException(javax.sip.InvalidArgumentException) SipException(javax.sip.SipException) IOException(java.io.IOException) ObjectInUseException(javax.sip.ObjectInUseException)

Example 2 with ServerHeader

use of javax.sip.header.ServerHeader in project XobotOS by xamarin.

the class DialogFilter method sendRequestPendingResponse.

/**
     * Send back a Request Pending response.
     * 
     * @param sipRequest
     * @param transaction
     */
private void sendRequestPendingResponse(SIPRequest sipRequest, SIPServerTransaction transaction) {
    SIPResponse sipResponse = sipRequest.createResponse(Response.REQUEST_PENDING);
    ServerHeader serverHeader = MessageFactoryImpl.getDefaultServerHeader();
    if (serverHeader != null) {
        sipResponse.setHeader(serverHeader);
    }
    try {
        RetryAfter retryAfter = new RetryAfter();
        retryAfter.setRetryAfter(1);
        sipResponse.setHeader(retryAfter);
        if (sipRequest.getMethod().equals(Request.INVITE)) {
            sipStack.addTransactionPendingAck(transaction);
        }
        transaction.sendResponse(sipResponse);
        transaction.releaseSem();
    } catch (Exception ex) {
        sipStack.getStackLogger().logError("Problem sending error response", ex);
        transaction.releaseSem();
        sipStack.removeTransaction(transaction);
    }
}
Also used : SIPResponse(gov.nist.javax.sip.message.SIPResponse) RetryAfter(gov.nist.javax.sip.header.RetryAfter) ServerHeader(javax.sip.header.ServerHeader) InvalidArgumentException(javax.sip.InvalidArgumentException) SipException(javax.sip.SipException) IOException(java.io.IOException) ObjectInUseException(javax.sip.ObjectInUseException)

Example 3 with ServerHeader

use of javax.sip.header.ServerHeader in project XobotOS by xamarin.

the class DialogFilter method sendBadRequestResponse.

/**
     * Send a BAD REQUEST response.
     * 
     * @param sipRequest
     * @param transaction
     * @param reasonPhrase
     */
private void sendBadRequestResponse(SIPRequest sipRequest, SIPServerTransaction transaction, String reasonPhrase) {
    SIPResponse sipResponse = sipRequest.createResponse(Response.BAD_REQUEST);
    if (reasonPhrase != null)
        sipResponse.setReasonPhrase(reasonPhrase);
    ServerHeader serverHeader = MessageFactoryImpl.getDefaultServerHeader();
    if (serverHeader != null) {
        sipResponse.setHeader(serverHeader);
    }
    try {
        if (sipRequest.getMethod().equals(Request.INVITE)) {
            sipStack.addTransactionPendingAck(transaction);
        }
        transaction.sendResponse(sipResponse);
        transaction.releaseSem();
    } catch (Exception ex) {
        sipStack.getStackLogger().logError("Problem sending error response", ex);
        transaction.releaseSem();
        sipStack.removeTransaction(transaction);
    }
}
Also used : SIPResponse(gov.nist.javax.sip.message.SIPResponse) ServerHeader(javax.sip.header.ServerHeader) InvalidArgumentException(javax.sip.InvalidArgumentException) SipException(javax.sip.SipException) IOException(java.io.IOException) ObjectInUseException(javax.sip.ObjectInUseException)

Example 4 with ServerHeader

use of javax.sip.header.ServerHeader in project XobotOS by xamarin.

the class DialogFilter method sendServerInternalErrorResponse.

/**
     * Send back an error Response.
     * 
     * @param sipRequest
     * @param transaction
     */
private void sendServerInternalErrorResponse(SIPRequest sipRequest, SIPServerTransaction transaction) {
    if (sipStack.isLoggingEnabled())
        sipStack.getStackLogger().logDebug("Sending 500 response for out of sequence message");
    SIPResponse sipResponse = sipRequest.createResponse(Response.SERVER_INTERNAL_ERROR);
    sipResponse.setReasonPhrase("Request out of order");
    if (MessageFactoryImpl.getDefaultServerHeader() != null) {
        ServerHeader serverHeader = MessageFactoryImpl.getDefaultServerHeader();
        sipResponse.setHeader(serverHeader);
    }
    try {
        RetryAfter retryAfter = new RetryAfter();
        retryAfter.setRetryAfter(10);
        sipResponse.setHeader(retryAfter);
        sipStack.addTransactionPendingAck(transaction);
        transaction.sendResponse(sipResponse);
        transaction.releaseSem();
    } catch (Exception ex) {
        sipStack.getStackLogger().logError("Problem sending response", ex);
        transaction.releaseSem();
        sipStack.removeTransaction(transaction);
    }
}
Also used : SIPResponse(gov.nist.javax.sip.message.SIPResponse) RetryAfter(gov.nist.javax.sip.header.RetryAfter) ServerHeader(javax.sip.header.ServerHeader) InvalidArgumentException(javax.sip.InvalidArgumentException) SipException(javax.sip.SipException) IOException(java.io.IOException) ObjectInUseException(javax.sip.ObjectInUseException)

Example 5 with ServerHeader

use of javax.sip.header.ServerHeader in project XobotOS by xamarin.

the class MessageChannel method createBadReqRes.

/**
     * Creates a response to a bad request (ie one that causes a ParseException)
     * 
     * @param badReq
     * @return message bytes, null if unable to formulate response
     */
protected final String createBadReqRes(String badReq, ParseException pe) {
    StringBuffer buf = new StringBuffer(512);
    buf.append("SIP/2.0 400 Bad Request (" + pe.getLocalizedMessage() + ')');
    // We need the following headers: all Vias, CSeq, Call-ID, From, To
    if (!copyViaHeaders(badReq, buf))
        return null;
    if (!copyHeader(CSeqHeader.NAME, badReq, buf))
        return null;
    if (!copyHeader(CallIdHeader.NAME, badReq, buf))
        return null;
    if (!copyHeader(FromHeader.NAME, badReq, buf))
        return null;
    if (!copyHeader(ToHeader.NAME, badReq, buf))
        return null;
    // Should add a to-tag if not already present...
    int toStart = buf.indexOf(ToHeader.NAME);
    if (toStart != -1 && buf.indexOf("tag", toStart) == -1) {
        buf.append(";tag=badreq");
    }
    // Let's add a Server header too..
    ServerHeader s = MessageFactoryImpl.getDefaultServerHeader();
    if (s != null) {
        buf.append("\r\n" + s.toString());
    }
    int clength = badReq.length();
    if (!(this instanceof UDPMessageChannel) || clength + buf.length() + ContentTypeHeader.NAME.length() + ": message/sipfrag\r\n".length() + ContentLengthHeader.NAME.length() < 1300) {
        /*
             * Check to see we are within one UDP packet.
             */
        ContentTypeHeader cth = new ContentType("message", "sipfrag");
        buf.append("\r\n" + cth.toString());
        ContentLength clengthHeader = new ContentLength(clength);
        buf.append("\r\n" + clengthHeader.toString());
        buf.append("\r\n\r\n" + badReq);
    } else {
        ContentLength clengthHeader = new ContentLength(0);
        buf.append("\r\n" + clengthHeader.toString());
    }
    return buf.toString();
}
Also used : ContentType(gov.nist.javax.sip.header.ContentType) ContentTypeHeader(javax.sip.header.ContentTypeHeader) ServerHeader(javax.sip.header.ServerHeader) ContentLength(gov.nist.javax.sip.header.ContentLength)

Aggregations

ServerHeader (javax.sip.header.ServerHeader)7 SIPResponse (gov.nist.javax.sip.message.SIPResponse)5 IOException (java.io.IOException)5 InvalidArgumentException (javax.sip.InvalidArgumentException)5 ObjectInUseException (javax.sip.ObjectInUseException)5 SipException (javax.sip.SipException)5 ContentLength (gov.nist.javax.sip.header.ContentLength)2 ContentType (gov.nist.javax.sip.header.ContentType)2 RetryAfter (gov.nist.javax.sip.header.RetryAfter)2 CSeq (gov.nist.javax.sip.header.CSeq)1 ContactList (gov.nist.javax.sip.header.ContactList)1 From (gov.nist.javax.sip.header.From)1 MaxForwards (gov.nist.javax.sip.header.MaxForwards)1 ReasonList (gov.nist.javax.sip.header.ReasonList)1 RecordRouteList (gov.nist.javax.sip.header.RecordRouteList)1 RequireList (gov.nist.javax.sip.header.RequireList)1 SIPHeader (gov.nist.javax.sip.header.SIPHeader)1 To (gov.nist.javax.sip.header.To)1 ViaList (gov.nist.javax.sip.header.ViaList)1 SessionExpires (gov.nist.javax.sip.header.extensions.SessionExpires)1