Search in sources :

Example 36 with Response

use of javax.sip.message.Response in project Openfire by igniterealtime.

the class SipManager method sendNotImplemented.

/**
     * Sends a NOT_IMPLEMENTED response through the specified transaction.
     *
     * @param serverTransaction the transaction to send the response through.
     * @param request           the request that is being answered.
     */
void sendNotImplemented(ServerTransaction serverTransaction, Request request) {
    Response notImplemented;
    try {
        notImplemented = messageFactory.createResponse(Response.NOT_IMPLEMENTED, request);
        attachToTag(notImplemented, serverTransaction.getDialog());
    } catch (ParseException ex) {
        fireCommunicationsError(new CommunicationsException("Failed to create a NOT_IMPLEMENTED response to a " + request.getMethod() + " request!", ex));
        return;
    }
    try {
        serverTransaction.sendResponse(notImplemented);
    } catch (SipException ex) {
        fireCommunicationsError(new CommunicationsException("Failed to create a NOT_IMPLEMENTED response to a " + request.getMethod() + " request!", ex));
    }
}
Also used : Response(javax.sip.message.Response) ParseException(java.text.ParseException) CommunicationsException(org.jivesoftware.openfire.sip.tester.comm.CommunicationsException)

Example 37 with Response

use of javax.sip.message.Response in project Openfire by igniterealtime.

the class SimpleListener method processResponse.

public void processResponse(ResponseEvent responseEvent) {
    if (responseEvent.getClientTransaction() != null) {
        Log.debug("SimpleListener for " + myUsername + ":  Getting client transaction...");
        ClientTransaction clientTransaction = responseEvent.getClientTransaction();
        Dialog clientDialog = clientTransaction.getDialog();
        getSession().printDialog(clientDialog);
    }
    Log.debug("SimpleListener for " + myUsername + ":  Received a response event:  " + responseEvent.getResponse().toString());
    //		String   fromAddr = "";
    String toAddr = "";
    Response response = responseEvent.getResponse();
    //		}
    if (response.getHeader(ToHeader.NAME) != null) {
        ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
        URI toUri = toHeader.getAddress().getURI();
        if (toUri instanceof SipUri)
            toAddr = ((SipUri) toUri).getUser() + "@" + ((SipUri) toUri).getHost();
        else
            toAddr = toUri.toString();
    }
    if (response.getHeader(CSeqHeader.NAME) != null) {
        String method = ((CSeqHeader) response.getHeader(CSeqHeader.NAME)).getMethod();
        if (method.equals(Request.REGISTER)) {
            if (response.getStatusCode() / 100 == 2) {
                int expires = 0;
                if (response.getHeader(ContactHeader.NAME) != null) {
                    expires = ((ContactHeader) response.getHeader(ContactHeader.NAME)).getExpires();
                } else if (response.getHeader(ExpiresHeader.NAME) != null) {
                    expires = ((ExpiresHeader) response.getHeader(ExpiresHeader.NAME)).getExpires();
                }
                if (expires > 0) {
                    Log.debug("SimpleListener(" + myUsername + ").processResponse:  " + getSession().getRegistration().getUsername() + " log in successful!");
                    getSession().sipUserLoggedIn();
                } else {
                    if (getSession().getLoginStatus().equals(TransportLoginStatus.LOGGING_OUT)) {
                        Log.debug("SimpleListener(" + myUsername + ").processResponse:  " + getSession().getRegistration().getUsername() + " log out successful!");
                        getSession().sipUserLoggedOut();
                        getSession().removeStack();
                    }
                }
            }
        }
        if (method.equals(Request.SUBSCRIBE)) {
            if (response.getStatusCode() / 100 == 2) {
                Log.debug("SimpleListener for " + myUsername + ":  Handling SUBSCRIBE acknowledgement!!");
                int expires = 0;
                if (response.getHeader(ContactHeader.NAME) != null) {
                    expires = ((ContactHeader) response.getHeader(ContactHeader.NAME)).getExpires();
                }
                if (response.getHeader(ExpiresHeader.NAME) != null) {
                    expires = ((ExpiresHeader) response.getHeader(ExpiresHeader.NAME)).getExpires();
                }
                if (expires > 0) {
                    // Confirm subscription of roster item
                    getSession().contactSubscribed(toAddr);
                } else {
                    // Confirm unsubscription of roster item
                    getSession().contactUnsubscribed(toAddr);
                }
                Log.debug("SimpleListener for " + myUsername + ":  Handled SUBSCRIBE acknowledgement!!");
            }
        }
    }
}
Also used : Response(javax.sip.message.Response) CSeqHeader(javax.sip.header.CSeqHeader) Dialog(javax.sip.Dialog) ClientTransaction(javax.sip.ClientTransaction) ToHeader(javax.sip.header.ToHeader) ExpiresHeader(javax.sip.header.ExpiresHeader) SipUri(gov.nist.javax.sip.address.SipUri) URI(javax.sip.address.URI) SipURI(javax.sip.address.SipURI)

Example 38 with Response

use of javax.sip.message.Response in project XobotOS by xamarin.

the class SipHelper method sendInviteOk.

/**
     * @param event the INVITE request event
     */
public ServerTransaction sendInviteOk(RequestEvent event, SipProfile localProfile, String sessionDescription, ServerTransaction inviteTransaction, String externalIp, int externalPort) throws SipException {
    try {
        Request request = event.getRequest();
        Response response = mMessageFactory.createResponse(Response.OK, request);
        response.addHeader(createContactHeader(localProfile, externalIp, externalPort));
        response.setContent(sessionDescription, mHeaderFactory.createContentTypeHeader("application", "sdp"));
        if (inviteTransaction == null) {
            inviteTransaction = getServerTransaction(event);
        }
        if (inviteTransaction.getState() != TransactionState.COMPLETED) {
            if (DEBUG)
                Log.d(TAG, "send OK: " + response);
            inviteTransaction.sendResponse(response);
        }
        return inviteTransaction;
    } catch (ParseException e) {
        throw new SipException("sendInviteOk()", e);
    }
}
Also used : Response(javax.sip.message.Response) Request(javax.sip.message.Request) ParseException(java.text.ParseException) SipException(javax.sip.SipException)

Example 39 with Response

use of javax.sip.message.Response in project XobotOS by xamarin.

the class SipHelper method sendInviteAck.

/**
     * @param event the INVITE ACK request event
     */
public void sendInviteAck(ResponseEvent event, Dialog dialog) throws SipException {
    Response response = event.getResponse();
    long cseq = ((CSeqHeader) response.getHeader(CSeqHeader.NAME)).getSeqNumber();
    Request ack = dialog.createAck(cseq);
    if (DEBUG)
        Log.d(TAG, "send ACK: " + ack);
    dialog.sendAck(ack);
}
Also used : Response(javax.sip.message.Response) CSeqHeader(javax.sip.header.CSeqHeader) Request(javax.sip.message.Request)

Example 40 with Response

use of javax.sip.message.Response in project XobotOS by xamarin.

the class SipSessionGroup method expectResponse.

/**
     * @return true if the event is a response event and the CSeqHeader method
     * match the given arguments; false otherwise
     */
private static boolean expectResponse(String expectedMethod, EventObject evt) {
    if (evt instanceof ResponseEvent) {
        ResponseEvent event = (ResponseEvent) evt;
        Response response = event.getResponse();
        return expectedMethod.equalsIgnoreCase(getCseqMethod(response));
    }
    return false;
}
Also used : Response(javax.sip.message.Response) SIPResponse(gov.nist.javax.sip.message.SIPResponse) ResponseEvent(javax.sip.ResponseEvent)

Aggregations

Response (javax.sip.message.Response)77 ParseException (java.text.ParseException)42 SipException (javax.sip.SipException)41 InvalidArgumentException (javax.sip.InvalidArgumentException)32 Request (javax.sip.message.Request)28 ServerTransaction (javax.sip.ServerTransaction)22 TransactionUnavailableException (javax.sip.TransactionUnavailableException)20 Dialog (javax.sip.Dialog)18 ToHeader (javax.sip.header.ToHeader)17 Test (org.junit.Test)17 ListeningPoint (javax.sip.ListeningPoint)16 ContactHeader (javax.sip.header.ContactHeader)16 SipURI (javax.sip.address.SipURI)13 SIPResponse (gov.nist.javax.sip.message.SIPResponse)12 ClientTransaction (javax.sip.ClientTransaction)12 SipProvider (javax.sip.SipProvider)11 TransactionDoesNotExistException (javax.sip.TransactionDoesNotExistException)11 ViaHeader (javax.sip.header.ViaHeader)11 FromHeader (javax.sip.header.FromHeader)10 CSeqHeader (javax.sip.header.CSeqHeader)9