Search in sources :

Example 11 with CommunicationsException

use of org.jivesoftware.openfire.sip.tester.comm.CommunicationsException in project Openfire by igniterealtime.

the class SipManager method start.

/**
     * Creates and initializes JAIN SIP objects (factories, stack, listening
     * point and provider). Once this method is called the application is ready
     * to handle (incoming and outgoing) sip messages.
     *
     * @throws CommunicationsException if an axception should occur during the initialization
     *                                 process
     */
public void start() throws CommunicationsException {
    initProperties();
    SIPConfig.setSystemProperties();
    this.sipFactory = SipFactory.getInstance();
    sipFactory.setPathName(sipStackPath);
    try {
        addressFactory = sipFactory.createAddressFactory();
        headerFactory = sipFactory.createHeaderFactory();
        messageFactory = sipFactory.createMessageFactory();
    } catch (PeerUnavailableException ex) {
        Log.error("start", ex);
        throw new CommunicationsException("Could not create factories!", ex);
    }
    try {
        sipStack = sipFactory.createSipStack(System.getProperties());
        ((SipCommRouter) sipStack.getRouter()).setOutboundProxy(SIPConfig.getOutboundProxy());
    } catch (PeerUnavailableException ex) {
        Log.error("start", ex);
        throw new CommunicationsException("Cannot connect!\n" + "Cannot reach proxy.\nCheck your connection." + "(Syntax:<proxy_address:port/transport>)", ex);
    }
    try {
        boolean successfullyBound = false;
        while (!successfullyBound) {
            try {
                publicIpAddress = new InetSocketAddress(localAddress, localPort);
                listeningPoint = sipStack.createListeningPoint(localPort, transport);
            } catch (InvalidArgumentException ex) {
                // choose another port between 1024 and 65000
                localPort = (int) ((65000 - 1024) * Math.random()) + 1024;
                try {
                    Thread.sleep(1000);
                } catch (Exception e) {
                // Do Nothing
                }
                continue;
            }
            successfullyBound = true;
        }
    } catch (TransportNotSupportedException ex) {
        throw new CommunicationsException("Transport " + transport + " is not suppported by the stack!\n Try specifying another" + " transport in Mais property files.\n", ex);
    }
    try {
        sipProvider = sipStack.createSipProvider(listeningPoint);
    } catch (ObjectInUseException ex) {
        Log.error("start", ex);
        throw new CommunicationsException("Could not create factories!\n", ex);
    }
    try {
        sipProvider.addSipListener(this);
    } catch (TooManyListenersException exc) {
        throw new CommunicationsException("Could not register SipManager as a sip listener!", exc);
    }
    sipSecurityManager.setHeaderFactory(headerFactory);
    sipSecurityManager.setTransactionCreator(sipProvider);
    sipSecurityManager.setSipManCallback(this);
    // Make sure prebuilt headers are nulled so that they get reinited
    // if this is a restart
    contactHeader = null;
    fromHeader = null;
    viaHeaders = null;
    maxForwardsHeader = null;
    isStarted = true;
}
Also used : TooManyListenersException(java.util.TooManyListenersException) InetSocketAddress(java.net.InetSocketAddress) CommunicationsException(org.jivesoftware.openfire.sip.tester.comm.CommunicationsException) TooManyListenersException(java.util.TooManyListenersException) UnknownHostException(java.net.UnknownHostException) CommunicationsException(org.jivesoftware.openfire.sip.tester.comm.CommunicationsException) ParseException(java.text.ParseException)

Example 12 with CommunicationsException

use of org.jivesoftware.openfire.sip.tester.comm.CommunicationsException in project Openfire by igniterealtime.

the class SipManager method attachToTag.

/**
     * Generates a ToTag (the containingDialog's hashCode())and attaches it to
     * response's ToHeader.
     *
     * @param response         the response that is to get the ToTag.
     * @param containingDialog the Dialog instance that is to extract a unique Tag value
     *                         (containingDialog.hashCode())
     */
public void attachToTag(Response response, Dialog containingDialog) {
    ToHeader to = (ToHeader) response.getHeader(ToHeader.NAME);
    if (to == null) {
        fireCommunicationsError(new CommunicationsException("No TO header found in, attaching a to tag is therefore impossible"));
    }
    try {
        if (to.getTag() == null || to.getTag().trim().length() == 0) {
            int toTag = containingDialog != null ? containingDialog.hashCode() : (int) System.currentTimeMillis();
            to.setTag(Integer.toString(toTag));
        }
    } catch (ParseException ex) {
        fireCommunicationsError(new CommunicationsException("Failed to attach a TO tag to an outgoing response"));
    }
}
Also used : ParseException(java.text.ParseException) CommunicationsException(org.jivesoftware.openfire.sip.tester.comm.CommunicationsException)

Aggregations

CommunicationsException (org.jivesoftware.openfire.sip.tester.comm.CommunicationsException)12 ParseException (java.text.ParseException)10 UnknownHostException (java.net.UnknownHostException)4 InetAddress (java.net.InetAddress)3 InetSocketAddress (java.net.InetSocketAddress)3 TooManyListenersException (java.util.TooManyListenersException)3 Address (javax.sip.address.Address)3 SipURI (javax.sip.address.SipURI)3 Request (javax.sip.message.Request)2 Response (javax.sip.message.Response)2 SipSecurityException (org.jivesoftware.openfire.sip.tester.security.SipSecurityException)2 ArrayList (java.util.ArrayList)1 UserCredentials (org.jivesoftware.openfire.sip.tester.security.UserCredentials)1