Search in sources :

Example 1 with HopImpl

use of gov.nist.javax.sip.stack.HopImpl in project XobotOS by xamarin.

the class SipProviderImpl method sendResponse.

/*
     * (non-Javadoc)
     *
     * @see javax.sip.SipProvider#sendResponse(javax.sip.message.Response)
     */
public void sendResponse(Response response) throws SipException {
    if (!sipStack.isAlive())
        throw new SipException("Stack is stopped");
    SIPResponse sipResponse = (SIPResponse) response;
    Via via = sipResponse.getTopmostVia();
    if (via == null)
        throw new SipException("No via header in response!");
    SIPServerTransaction st = (SIPServerTransaction) sipStack.findTransaction((SIPMessage) response, true);
    if (st != null && st.getState() != TransactionState.TERMINATED && this.isAutomaticDialogSupportEnabled()) {
        throw new SipException("Transaction exists -- cannot send response statelessly");
    }
    String transport = via.getTransport();
    // check to see if Via has "received paramaeter". If so
    // set the host to the via parameter. Else set it to the
    // Via host.
    String host = via.getReceived();
    if (host == null)
        host = via.getHost();
    // Symmetric nat support
    int port = via.getRPort();
    if (port == -1) {
        port = via.getPort();
        if (port == -1) {
            if (transport.equalsIgnoreCase("TLS"))
                port = 5061;
            else
                port = 5060;
        }
    }
    // for correct management of IPv6 addresses.
    if (host.indexOf(":") > 0)
        if (host.indexOf("[") < 0)
            host = "[" + host + "]";
    Hop hop = sipStack.getAddressResolver().resolveAddress(new HopImpl(host, port, transport));
    try {
        ListeningPointImpl listeningPoint = (ListeningPointImpl) this.getListeningPoint(transport);
        if (listeningPoint == null)
            throw new SipException("whoopsa daisy! no listening point found for transport " + transport);
        MessageChannel messageChannel = sipStack.createRawMessageChannel(this.getListeningPoint(hop.getTransport()).getIPAddress(), listeningPoint.port, hop);
        messageChannel.sendMessage(sipResponse);
    } catch (IOException ex) {
        throw new SipException(ex.getMessage());
    }
}
Also used : SIPResponse(gov.nist.javax.sip.message.SIPResponse) MessageChannel(gov.nist.javax.sip.stack.MessageChannel) Hop(javax.sip.address.Hop) SIPMessage(gov.nist.javax.sip.message.SIPMessage) IOException(java.io.IOException) SipException(javax.sip.SipException) SIPServerTransaction(gov.nist.javax.sip.stack.SIPServerTransaction) ListeningPoint(javax.sip.ListeningPoint) HopImpl(gov.nist.javax.sip.stack.HopImpl) Via(gov.nist.javax.sip.header.Via)

Aggregations

Via (gov.nist.javax.sip.header.Via)1 SIPMessage (gov.nist.javax.sip.message.SIPMessage)1 SIPResponse (gov.nist.javax.sip.message.SIPResponse)1 HopImpl (gov.nist.javax.sip.stack.HopImpl)1 MessageChannel (gov.nist.javax.sip.stack.MessageChannel)1 SIPServerTransaction (gov.nist.javax.sip.stack.SIPServerTransaction)1 IOException (java.io.IOException)1 ListeningPoint (javax.sip.ListeningPoint)1 SipException (javax.sip.SipException)1 Hop (javax.sip.address.Hop)1