Search in sources :

Example 11 with From

use of gov.nist.javax.sip.header.From in project XobotOS by xamarin.

the class SIPDialog method createRequest.

/**
     * The method that actually does the work of creating a request.
     * 
     * @param method
     * @param response
     * @return
     * @throws SipException
     */
private Request createRequest(String method, SIPResponse sipResponse) throws SipException {
    if (method == null || sipResponse == null)
        throw new NullPointerException("null argument");
    if (method.equals(Request.CANCEL))
        throw new SipException("Dialog.createRequest(): Invalid request");
    if (this.getState() == null || (this.getState().getValue() == TERMINATED_STATE && !method.equalsIgnoreCase(Request.BYE)) || (this.isServer() && this.getState().getValue() == EARLY_STATE && method.equalsIgnoreCase(Request.BYE)))
        throw new SipException("Dialog  " + getDialogId() + " not yet established or terminated " + this.getState());
    SipUri sipUri = null;
    if (this.getRemoteTarget() != null)
        sipUri = (SipUri) this.getRemoteTarget().getURI().clone();
    else {
        sipUri = (SipUri) this.getRemoteParty().getURI().clone();
        sipUri.clearUriParms();
    }
    CSeq cseq = new CSeq();
    try {
        cseq.setMethod(method);
        cseq.setSeqNumber(this.getLocalSeqNumber());
    } catch (Exception ex) {
        if (sipStack.isLoggingEnabled())
            sipStack.getStackLogger().logError("Unexpected error");
        InternalErrorHandler.handleException(ex);
    }
    /*
         * Add a via header for the outbound request based on the transport of the message
         * processor.
         */
    ListeningPointImpl lp = (ListeningPointImpl) this.sipProvider.getListeningPoint(sipResponse.getTopmostVia().getTransport());
    if (lp == null) {
        if (sipStack.isLoggingEnabled())
            sipStack.getStackLogger().logError("Cannot find listening point for transport " + sipResponse.getTopmostVia().getTransport());
        throw new SipException("Cannot find listening point for transport " + sipResponse.getTopmostVia().getTransport());
    }
    Via via = lp.getViaHeader();
    From from = new From();
    from.setAddress(this.localParty);
    To to = new To();
    to.setAddress(this.remoteParty);
    SIPRequest sipRequest = sipResponse.createRequest(sipUri, via, cseq, from, to);
    if (SIPRequest.isTargetRefresh(method)) {
        ContactHeader contactHeader = ((ListeningPointImpl) this.sipProvider.getListeningPoint(lp.getTransport())).createContactHeader();
        ((SipURI) contactHeader.getAddress().getURI()).setSecure(this.isSecure());
        sipRequest.setHeader(contactHeader);
    }
    try {
        /*
             * Guess of local sequence number - this is being re-set when the request is actually
             * dispatched
             */
        cseq = (CSeq) sipRequest.getCSeq();
        cseq.setSeqNumber(this.localSequenceNumber + 1);
    } catch (InvalidArgumentException ex) {
        InternalErrorHandler.handleException(ex);
    }
    if (method.equals(Request.SUBSCRIBE)) {
        if (eventHeader != null)
            sipRequest.addHeader(eventHeader);
    }
    try {
        if (this.getLocalTag() != null) {
            from.setTag(this.getLocalTag());
        } else {
            from.removeTag();
        }
        if (this.getRemoteTag() != null) {
            to.setTag(this.getRemoteTag());
        } else {
            to.removeTag();
        }
    } catch (ParseException ex) {
        InternalErrorHandler.handleException(ex);
    }
    // get the route list from the dialog.
    this.updateRequest(sipRequest);
    return sipRequest;
}
Also used : ContactHeader(javax.sip.header.ContactHeader) ListeningPointImpl(gov.nist.javax.sip.ListeningPointImpl) CSeq(gov.nist.javax.sip.header.CSeq) From(gov.nist.javax.sip.header.From) SipUri(gov.nist.javax.sip.address.SipUri) SipURI(javax.sip.address.SipURI) SIPRequest(gov.nist.javax.sip.message.SIPRequest) DialogDoesNotExistException(javax.sip.DialogDoesNotExistException) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) ObjectInUseException(javax.sip.ObjectInUseException) SipException(javax.sip.SipException) IOException(java.io.IOException) TransactionDoesNotExistException(javax.sip.TransactionDoesNotExistException) Via(gov.nist.javax.sip.header.Via) InvalidArgumentException(javax.sip.InvalidArgumentException) To(gov.nist.javax.sip.header.To) ParseException(java.text.ParseException) SipException(javax.sip.SipException)

Aggregations

From (gov.nist.javax.sip.header.From)11 To (gov.nist.javax.sip.header.To)9 CSeq (gov.nist.javax.sip.header.CSeq)6 CallID (gov.nist.javax.sip.header.CallID)5 MaxForwards (gov.nist.javax.sip.header.MaxForwards)5 ContentLength (gov.nist.javax.sip.header.ContentLength)4 InReplyTo (gov.nist.javax.sip.header.InReplyTo)4 SIPHeader (gov.nist.javax.sip.header.SIPHeader)4 Via (gov.nist.javax.sip.header.Via)4 ParseException (java.text.ParseException)4 InvalidArgumentException (javax.sip.InvalidArgumentException)4 SIPRequest (gov.nist.javax.sip.message.SIPRequest)3 IOException (java.io.IOException)3 DialogDoesNotExistException (javax.sip.DialogDoesNotExistException)3 ObjectInUseException (javax.sip.ObjectInUseException)3 SipException (javax.sip.SipException)3 TransactionDoesNotExistException (javax.sip.TransactionDoesNotExistException)3 ListeningPointImpl (gov.nist.javax.sip.ListeningPointImpl)2 SIPHeaderList (gov.nist.javax.sip.header.SIPHeaderList)2 SipURI (javax.sip.address.SipURI)2