Search in sources :

Example 1 with ListeningPoint

use of javax.sip.ListeningPoint in project XobotOS by xamarin.

the class SipHelper method createViaHeaders.

private List<ViaHeader> createViaHeaders() throws ParseException, SipException {
    List<ViaHeader> viaHeaders = new ArrayList<ViaHeader>(1);
    ListeningPoint lp = getListeningPoint();
    ViaHeader viaHeader = mHeaderFactory.createViaHeader(lp.getIPAddress(), lp.getPort(), lp.getTransport(), null);
    viaHeader.setRPort();
    viaHeaders.add(viaHeader);
    return viaHeaders;
}
Also used : ViaHeader(javax.sip.header.ViaHeader) ArrayList(java.util.ArrayList) ListeningPoint(javax.sip.ListeningPoint)

Example 2 with ListeningPoint

use of javax.sip.ListeningPoint 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)

Example 3 with ListeningPoint

use of javax.sip.ListeningPoint in project XobotOS by xamarin.

the class SipStackImpl method createListeningPoint.

/*
	 * (non-Javadoc)
	 * 
	 * @see javax.sip.SipStack#createListeningPoint(java.lang.String, int,
	 * java.lang.String)
	 */
public synchronized ListeningPoint createListeningPoint(String address, int port, String transport) throws TransportNotSupportedException, InvalidArgumentException {
    if (isLoggingEnabled())
        getStackLogger().logDebug("createListeningPoint : address = " + address + " port = " + port + " transport = " + transport);
    if (address == null)
        throw new NullPointerException("Address for listening point is null!");
    if (transport == null)
        throw new NullPointerException("null transport");
    if (port <= 0)
        throw new InvalidArgumentException("bad port");
    if (!transport.equalsIgnoreCase("UDP") && !transport.equalsIgnoreCase("TLS") && !transport.equalsIgnoreCase("TCP") && !transport.equalsIgnoreCase("SCTP"))
        throw new TransportNotSupportedException("bad transport " + transport);
    /** Reusing an old stack instance */
    if (!this.isAlive()) {
        this.toExit = false;
        this.reInitialize();
    }
    String key = ListeningPointImpl.makeKey(address, port, transport);
    ListeningPointImpl lip = (ListeningPointImpl) listeningPoints.get(key);
    if (lip != null) {
        return lip;
    } else {
        try {
            InetAddress inetAddr = InetAddress.getByName(address);
            MessageProcessor messageProcessor = this.createMessageProcessor(inetAddr, port, transport);
            if (this.isLoggingEnabled()) {
                this.getStackLogger().logDebug("Created Message Processor: " + address + " port = " + port + " transport = " + transport);
            }
            lip = new ListeningPointImpl(this, port, transport);
            lip.messageProcessor = messageProcessor;
            messageProcessor.setListeningPoint(lip);
            this.listeningPoints.put(key, lip);
            // start processing messages.
            messageProcessor.start();
            return (ListeningPoint) lip;
        } catch (java.io.IOException ex) {
            if (isLoggingEnabled())
                getStackLogger().logError("Invalid argument address = " + address + " port = " + port + " transport = " + transport);
            throw new InvalidArgumentException(ex.getMessage(), ex);
        }
    }
}
Also used : TransportNotSupportedException(javax.sip.TransportNotSupportedException) InvalidArgumentException(javax.sip.InvalidArgumentException) MessageProcessor(gov.nist.javax.sip.stack.MessageProcessor) ListeningPoint(javax.sip.ListeningPoint) IOException(java.io.IOException) InetAddress(java.net.InetAddress)

Example 4 with ListeningPoint

use of javax.sip.ListeningPoint in project camel by apache.

the class SipPublisher method doStart.

@Override
protected void doStart() throws Exception {
    super.doStart();
    Properties properties = configuration.createInitialProperties();
    setSipStack(configuration.getSipFactory().createSipStack(properties));
    configuration.parseURI();
    if (sipPublishListener == null) {
        sipPublishListener = new SipPublishListener(this);
    }
    configuration.setListeningPoint(sipStack.createListeningPoint(configuration.getFromHost(), Integer.valueOf(configuration.getFromPort()).intValue(), configuration.getTransport()));
    boolean found = false;
    if (provider != null) {
        for (ListeningPoint listeningPoint : provider.getListeningPoints()) {
            if (listeningPoint.getIPAddress().equalsIgnoreCase(configuration.getListeningPoint().getIPAddress()) && (listeningPoint.getPort() == configuration.getListeningPoint().getPort())) {
                found = true;
            }
        }
    }
    if (!found) {
        provider = getSipStack().createSipProvider(configuration.getListeningPoint());
        provider.addSipListener(sipPublishListener);
        configuration.setCallIdHeader(provider.getNewCallId());
    }
}
Also used : SipPublishListener(org.apache.camel.component.sip.listener.SipPublishListener) ListeningPoint(javax.sip.ListeningPoint) Properties(java.util.Properties)

Example 5 with ListeningPoint

use of javax.sip.ListeningPoint in project camel by apache.

the class SipSubscriber method doStart.

@Override
protected void doStart() throws Exception {
    super.doStart();
    Properties properties = configuration.createInitialProperties();
    sipStack = configuration.getSipFactory().createSipStack(properties);
    configuration.parseURI();
    sipSubscriptionListener = new SipSubscriptionListener(this);
    ListeningPoint listeningPoint = sipStack.createListeningPoint(configuration.getFromHost(), Integer.valueOf(configuration.getFromPort()).intValue(), configuration.getTransport());
    configuration.setListeningPoint(listeningPoint);
    provider = sipStack.createSipProvider(configuration.getListeningPoint());
    provider.addSipListener(sipSubscriptionListener);
    if (configuration.getCallIdHeader() == null) {
        configuration.setCallIdHeader(provider.getNewCallId());
    }
    // Create the Subscription request to register with the presence agent and receive notifications.
    configuration.setCallIdHeader(provider.getNewCallId());
    Request request = configuration.createSipRequest(1, Request.SUBSCRIBE, configuration.getEventHeaderName());
    // Create the subscriber transaction from request.
    ClientTransaction subscriberTransactionId = provider.getNewClientTransaction(request);
    // Add an Event header for the subscription.
    request.addHeader(configuration.getEventHeader());
    subscriberDialog = subscriberTransactionId.getDialog();
    // Send the outgoing subscription request.
    subscriberTransactionId.sendRequest();
}
Also used : ClientTransaction(javax.sip.ClientTransaction) SipSubscriptionListener(org.apache.camel.component.sip.listener.SipSubscriptionListener) Request(javax.sip.message.Request) ListeningPoint(javax.sip.ListeningPoint) Properties(java.util.Properties)

Aggregations

ListeningPoint (javax.sip.ListeningPoint)5 IOException (java.io.IOException)2 Properties (java.util.Properties)2 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 MessageProcessor (gov.nist.javax.sip.stack.MessageProcessor)1 SIPServerTransaction (gov.nist.javax.sip.stack.SIPServerTransaction)1 InetAddress (java.net.InetAddress)1 ArrayList (java.util.ArrayList)1 ClientTransaction (javax.sip.ClientTransaction)1 InvalidArgumentException (javax.sip.InvalidArgumentException)1 SipException (javax.sip.SipException)1 TransportNotSupportedException (javax.sip.TransportNotSupportedException)1 Hop (javax.sip.address.Hop)1 ViaHeader (javax.sip.header.ViaHeader)1 Request (javax.sip.message.Request)1 SipPublishListener (org.apache.camel.component.sip.listener.SipPublishListener)1