Search in sources :

Example 1 with ContactHeader

use of javax.sip.header.ContactHeader in project Openfire by igniterealtime.

the class SimpleSession method prepareRequest.

/**
     * @param requestType Type of request
	 * @param destUri    The SipURI for the destination.  Leave <code>null</code> if a loopback request (e.g. REGISTER) is being made.
	 * @param toTag      The tag for to header.  Can leave null.
	 * @param requestUri The Request URI to set in the message.  Leave null if the default destination SipURI should be used.
     * @param callId     ID of call
     * @param seqNum     Sequence number
     * @return Prepared request
	 */
private Request prepareRequest(RequestType requestType, SipURI destUri, String toTag, SipURI requestUri, String callId, long seqNum) {
    Request request = null;
    String myXMPPUsername = this.jid.getNode();
    Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Preparing request packet of type '" + requestType + "'");
    try {
        // Prepare request packet first
        request = messageFactory.createRequest(null);
        request.setMethod(requestType.toString());
    } catch (Exception e) {
        Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Exception occured when preparing request.", e);
    }
    // Prepare "From" header
    Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Preparing \"From\" header...");
    String mySipUsername = registration.getUsername();
    try {
        SipURI fromUri = addressFactory.createSipURI(mySipUsername, sipHost);
        Address fromNameAddress = addressFactory.createAddress(fromUri);
        fromNameAddress.setDisplayName(mySipUsername);
        FromHeader fromHeader = headerFactory.createFromHeader(fromNameAddress, getTag());
        // Use "set" because this header is mandatory.
        request.setHeader(fromHeader);
    } catch (Exception e) {
        Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Exception occured when preparing FromHeader.", e);
        return null;
    }
    // Prepare "To" header
    Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Preparing \"To\" header...");
    try {
        if (destUri == null)
            destUri = addressFactory.createSipURI(mySipUsername, sipHost);
        Address toNameAddress = addressFactory.createAddress(destUri);
        ToHeader toHeader = headerFactory.createToHeader(toNameAddress, toTag);
        // Use "set" because this header is mandatory.
        request.setHeader(toHeader);
    } catch (Exception e) {
        Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Exception occured when preparing ToHeader.", e);
        return null;
    }
    // Prepare "Via" header
    Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Preparing \"Via\" header...");
    try {
        ViaHeader viaHeader = headerFactory.createViaHeader(InetAddress.getLocalHost().getHostAddress(), sipPort, ListeningPoint.UDP, null);
        // Use "set" because this header is mandatory.
        request.setHeader(viaHeader);
    } catch (Exception e) {
        Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Exception occured when preparing ViaHeader.", e);
        return null;
    }
    // Prepare "CallId" header
    Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Preparing \"CallId\" header...");
    CallIdHeader callIdHeader;
    try {
        if (callId != null)
            callIdHeader = headerFactory.createCallIdHeader(callId);
        else
            callIdHeader = udpSipProvider.getNewCallId();
        // Use "set" because this header is mandatory.
        request.setHeader(callIdHeader);
    } catch (Exception e) {
        Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Exception occured when preparing CallIdHeader.", e);
        return null;
    }
    // Prepare "CSeq" header
    Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Preparing \"CSeq\" header...");
    try {
        CSeqHeader cSeqHeader = headerFactory.createCSeqHeader(seqNum, requestType.toString());
        // Use "set" because this header is mandatory.
        request.setHeader(cSeqHeader);
    } catch (Exception e) {
        Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Exception occured when preparing CSeqHeader.", e);
        return null;
    }
    // Prepare "MaxForwards" header
    Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Preparing \"MaxForwards\" header...");
    try {
        MaxForwardsHeader maxForwardsHeader = headerFactory.createMaxForwardsHeader(70);
        // Use "set" because this header is mandatory.
        request.setHeader(maxForwardsHeader);
    } catch (Exception e) {
        Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Exception occured when preparing MaxForwardsHeader.", e);
        return null;
    }
    // Setting Request URI
    Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  setting request URI...");
    try {
        if (requestUri == null) {
            requestUri = (SipURI) destUri.clone();
            requestUri.setTransportParam(ListeningPoint.UDP);
        }
        request.setRequestURI(requestUri);
    } catch (Exception e) {
        Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Exception occured when setting request URI.", e);
        return null;
    }
    // Add "Contact" header
    Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Preparing \"Contact\" header...");
    try {
        SipURI contactURI = addressFactory.createSipURI(mySipUsername, InetAddress.getLocalHost().getHostAddress());
        contactURI.setPort(sipPort);
        Address contactAddress = addressFactory.createAddress(contactURI);
        contactAddress.setDisplayName(mySipUsername);
        ContactHeader contactHeader = headerFactory.createContactHeader(contactAddress);
        request.setHeader(contactHeader);
    } catch (Exception e) {
        Log.debug("SimpleSession(" + myXMPPUsername + ").prepareRequest:  Exception occured when adding ContactHeader.", e);
        return null;
    }
    return request;
}
Also used : CSeqHeader(javax.sip.header.CSeqHeader) MaxForwardsHeader(javax.sip.header.MaxForwardsHeader) ContactHeader(javax.sip.header.ContactHeader) InetAddress(java.net.InetAddress) Address(javax.sip.address.Address) ViaHeader(javax.sip.header.ViaHeader) FromHeader(javax.sip.header.FromHeader) Request(javax.sip.message.Request) ToHeader(javax.sip.header.ToHeader) CallIdHeader(javax.sip.header.CallIdHeader) SipURI(javax.sip.address.SipURI) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) NotFoundException(org.jivesoftware.util.NotFoundException) TooManyListenersException(java.util.TooManyListenersException) SipException(javax.sip.SipException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 2 with ContactHeader

use of javax.sip.header.ContactHeader in project Openfire by igniterealtime.

the class SimpleSession method sendResponse.

public ServerTransaction sendResponse(int status, Request request, ServerTransaction serverTransaction) {
    try {
        Log.debug("SimpleSession(" + jid.getNode() + ").sendResponse:  Starting response sending process.");
        if (serverTransaction == null)
            serverTransaction = udpSipProvider.getNewServerTransaction(request);
        Response response = messageFactory.createResponse(status, request);
        // Set "Exprires" header
        if (request.getHeader(ExpiresHeader.NAME) != null)
            response.setHeader(request.getHeader(ExpiresHeader.NAME));
        // Add "Contact" header
        Log.debug("SimpleSession(" + jid.getNode() + ").sendResponse:  Preparing \"Contact\" header...");
        try {
            SipURI contactURI = addressFactory.createSipURI(null, InetAddress.getLocalHost().getHostAddress());
            contactURI.setPort(sipPort);
            Address contactAddress = addressFactory.createAddress(contactURI);
            //				contactAddress.setDisplayName(mySipUsername);
            ContactHeader contactHeader = headerFactory.createContactHeader(contactAddress);
            response.addHeader(contactHeader);
        } catch (Exception e) {
            Log.debug("SimpleSession(" + jid.getNode() + ").sendResponse:  Exception occured when adding ContactHeader.", e);
        //				return false;	// We can continue with this though.
        }
        Log.debug("SimpleSession(" + jid.getNode() + ").sendResponse:  Sending response:  " + response.toString());
        serverTransaction.sendResponse(response);
        //			udpSipProvider.sendResponse(response);
        Log.debug("SimpleSession(" + jid.getNode() + ").sendResponse:  Response sent!");
        return serverTransaction;
    } catch (Exception ex) {
        Log.debug("SimpleSession(" + jid.getNode() + ").sendResponse:  ", ex);
    }
    return null;
}
Also used : Response(javax.sip.message.Response) ContactHeader(javax.sip.header.ContactHeader) InetAddress(java.net.InetAddress) Address(javax.sip.address.Address) SipURI(javax.sip.address.SipURI) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) NotFoundException(org.jivesoftware.util.NotFoundException) TooManyListenersException(java.util.TooManyListenersException) SipException(javax.sip.SipException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 3 with ContactHeader

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

the class SipHelper method createWildcardContactHeader.

private ContactHeader createWildcardContactHeader() {
    ContactHeader contactHeader = mHeaderFactory.createContactHeader();
    contactHeader.setWildCard();
    return contactHeader;
}
Also used : ContactHeader(javax.sip.header.ContactHeader)

Example 4 with ContactHeader

use of javax.sip.header.ContactHeader in project jain-sip.ha by RestComm.

the class SIPDialogCacheData method updateDialogMetaData.

/**
 * Update the haSipDialog passed in param with the dialogMetaData and app meta data
 * @param dialogMetaData
 * @param dialogAppData
 * @param haSipDialog
 * @throws ParseException
 * @throws PeerUnavailableException
 */
private void updateDialogMetaData(Map<String, Object> dialogMetaData, Object dialogAppData, HASipDialog haSipDialog, boolean recreation) throws ParseException, PeerUnavailableException {
    haSipDialog.setMetaDataToReplicate(dialogMetaData, recreation);
    haSipDialog.setApplicationDataToReplicate(dialogAppData);
    final String contactStringified = (String) dialogMetaData.get(AbstractHASipDialog.CONTACT_HEADER);
    if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
        clusteredlogger.logDebug("contactStringified " + contactStringified);
    }
    if (contactStringified != null) {
        Address contactAddress = SipFactory.getInstance().createAddressFactory().createAddress(contactStringified);
        ContactHeader contactHeader = SipFactory.getInstance().createHeaderFactory().createContactHeader(contactAddress);
        if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            clusteredlogger.logDebug("contactHeader " + contactHeader);
            clusteredlogger.logDebug("contactURI " + contactHeader.getAddress().getURI());
        }
        haSipDialog.setContactHeader(contactHeader);
    }
}
Also used : ContactHeader(javax.sip.header.ContactHeader) Address(javax.sip.address.Address)

Example 5 with ContactHeader

use of javax.sip.header.ContactHeader in project jain-sip.ha by RestComm.

the class SIPDialogCacheData method updateDialogMetaData.

/**
 * Update the haSipDialog passed in param with the dialogMetaData and app meta data
 * @param dialogMetaData
 * @param dialogAppData
 * @param haSipDialog
 * @throws ParseException
 * @throws PeerUnavailableException
 */
private void updateDialogMetaData(Map<String, Object> dialogMetaData, Object dialogAppData, HASipDialog haSipDialog, boolean recreation) throws ParseException, PeerUnavailableException {
    haSipDialog.setMetaDataToReplicate(dialogMetaData, recreation);
    haSipDialog.setApplicationDataToReplicate(dialogAppData);
    final String contactStringified = (String) dialogMetaData.get(AbstractHASipDialog.CONTACT_HEADER);
    if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
        clusteredlogger.logDebug("contactStringified " + contactStringified);
    }
    if (contactStringified != null) {
        Address contactAddress = SipFactory.getInstance().createAddressFactory().createAddress(contactStringified);
        ContactHeader contactHeader = SipFactory.getInstance().createHeaderFactory().createContactHeader(contactAddress);
        if (clusteredlogger.isLoggingEnabled(StackLogger.TRACE_DEBUG)) {
            clusteredlogger.logDebug("contactHeader " + contactHeader);
            clusteredlogger.logDebug("contactURI " + contactHeader.getAddress().getURI());
        }
        haSipDialog.setContactHeader(contactHeader);
    }
}
Also used : ContactHeader(javax.sip.header.ContactHeader) Address(javax.sip.address.Address)

Aggregations

ContactHeader (javax.sip.header.ContactHeader)30 ParseException (java.text.ParseException)20 SipURI (javax.sip.address.SipURI)19 InvalidArgumentException (javax.sip.InvalidArgumentException)18 SipException (javax.sip.SipException)18 Request (javax.sip.message.Request)18 Address (javax.sip.address.Address)17 ToHeader (javax.sip.header.ToHeader)16 ViaHeader (javax.sip.header.ViaHeader)16 FromHeader (javax.sip.header.FromHeader)15 CallIdHeader (javax.sip.header.CallIdHeader)13 MaxForwardsHeader (javax.sip.header.MaxForwardsHeader)13 Response (javax.sip.message.Response)12 TransactionUnavailableException (javax.sip.TransactionUnavailableException)11 CSeqHeader (javax.sip.header.CSeqHeader)11 ClientTransaction (javax.sip.ClientTransaction)10 ContentTypeHeader (javax.sip.header.ContentTypeHeader)9 ExpiresHeader (javax.sip.header.ExpiresHeader)9 Header (javax.sip.header.Header)9 ArrayList (java.util.ArrayList)8