Search in sources :

Example 1 with CommunicationsException

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

the class RegisterProcessing method register.

synchronized void register(String registrarAddress, int registrarPort, String registrarTransport, int expires) throws CommunicationsException {
    try {
        isUnregistering = false;
        // From
        FromHeader fromHeader = sipManCallback.getFromHeader(true);
        Address fromAddress = fromHeader.getAddress();
        sipManCallback.fireRegistering(fromAddress.toString());
        // Request URI
        SipURI requestURI = null;
        try {
            requestURI = sipManCallback.addressFactory.createSipURI(null, registrarAddress);
        } catch (ParseException ex) {
            throw new CommunicationsException("Bad registrar address:" + registrarAddress, ex);
        } catch (NullPointerException ex) {
            // Do not throw an exc, we should rather silently notify the
            // user
            // throw new CommunicationsException("A registrar address was
            // not specified!", ex);
            sipManCallback.fireUnregistered(fromAddress.getURI().toString() + " (registrar not specified)");
            return;
        }
        requestURI.setPort(registrarPort);
        try {
            requestURI.setTransportParam(registrarTransport);
        } catch (ParseException ex) {
            throw new CommunicationsException(registrarTransport + " is not a valid transport!", ex);
        }
        // Call ID Header
        CallIdHeader callIdHeader = sipManCallback.sipProvider.getNewCallId();
        // CSeq Header
        CSeqHeader cSeqHeader = null;
        try {
            cSeqHeader = sipManCallback.headerFactory.createCSeqHeader(1, Request.REGISTER);
        } catch (ParseException ex) {
            // Should never happen
            Log.error("register", ex);
        } catch (InvalidArgumentException ex) {
            // Should never happen
            Log.error("register", ex);
        }
        // To Header
        ToHeader toHeader = null;
        try {
            toHeader = sipManCallback.headerFactory.createToHeader(fromAddress, null);
        } catch (ParseException ex) {
            // throw was missing - reported by Eero Vaarnas
            throw new CommunicationsException("Could not create a To header " + "for address:" + fromHeader.getAddress(), ex);
        }
        // User Agent Header
        UserAgentHeader uaHeader = null;
        ArrayList<String> userAgentList = new ArrayList<String>();
        userAgentList.add(SIPConfig.getStackName());
        try {
            uaHeader = sipManCallback.headerFactory.createUserAgentHeader(userAgentList);
        } catch (ParseException ex) {
            // throw was missing - reported by Eero Vaarnas
            throw new CommunicationsException("Could not create a To header " + "for address:" + fromHeader.getAddress(), ex);
        }
        // Via Headers
        ArrayList viaHeaders = sipManCallback.getLocalViaHeaders();
        // MaxForwardsHeader
        MaxForwardsHeader maxForwardsHeader = sipManCallback.getMaxForwardsHeader();
        // Request
        Request request = null;
        try {
            request = sipManCallback.messageFactory.createRequest(requestURI, Request.REGISTER, callIdHeader, cSeqHeader, fromHeader, toHeader, viaHeaders, maxForwardsHeader);
            request.setHeader(uaHeader);
        } catch (ParseException ex) {
            // throw was missing - reported by Eero Vaarnas
            throw new CommunicationsException("Could not create the register request!", ex);
        }
        // Expires Header
        ExpiresHeader expHeader = null;
        for (int retry = 0; retry < 2; retry++) {
            try {
                expHeader = sipManCallback.headerFactory.createExpiresHeader(expires);
            } catch (InvalidArgumentException ex) {
                if (retry == 0) {
                    expires = 3600;
                    continue;
                }
                throw new CommunicationsException("Invalid registrations expiration parameter - " + expires, ex);
            }
        }
        request.addHeader(expHeader);
        // Contact Header should contain IP - bug report - Eero Vaarnas
        ContactHeader contactHeader = sipManCallback.getRegistrationContactHeader();
        request.addHeader(contactHeader);
        // Transaction
        ClientTransaction regTrans = null;
        try {
            regTrans = sipManCallback.sipProvider.getNewClientTransaction(request);
        } catch (TransactionUnavailableException ex) {
            // throw was missing - reported by Eero Vaarnas
            throw new CommunicationsException("Could not create a register transaction!\n" + "Check that the Registrar address is correct!");
        }
        try {
            regTrans.sendRequest();
        }// we sometimes get a null pointer exception here so catch them all
         catch (Exception ex) {
            // throw was missing - reported by Eero Vaarnas
            throw new CommunicationsException("Could not send out the register request!", ex);
        }
        this.registerRequest = request;
    } catch (Exception e) {
        Log.error("register", e);
    }
}
Also used : Address(javax.sip.address.Address) ArrayList(java.util.ArrayList) Request(javax.sip.message.Request) SipURI(javax.sip.address.SipURI) SipSecurityException(org.jivesoftware.openfire.sip.tester.security.SipSecurityException) CommunicationsException(org.jivesoftware.openfire.sip.tester.comm.CommunicationsException) ParseException(java.text.ParseException) ParseException(java.text.ParseException) CommunicationsException(org.jivesoftware.openfire.sip.tester.comm.CommunicationsException)

Example 2 with CommunicationsException

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

the class SipManager method processResponse.

// -------------------- PROCESS RESPONSE
public void processResponse(ResponseEvent responseReceivedEvent) {
    Log.debug("RESPONSE [" + responseReceivedEvent.getResponse().getStatusCode() + "]");
    ClientTransaction clientTransaction = responseReceivedEvent.getClientTransaction();
    if (clientTransaction == null) {
        return;
    }
    Response response = responseReceivedEvent.getResponse();
    String method = ((CSeqHeader) response.getHeader(CSeqHeader.NAME)).getMethod();
    // OK
    if (response.getStatusCode() == Response.OK) {
        // REGISTER
        if (method.equals(Request.REGISTER)) {
            registerProcessing.processOK(clientTransaction, response);
        }
    } else // NOT_FOUND
    if (response.getStatusCode() == Response.NOT_FOUND) {
        if (method.equals(Request.REGISTER)) {
            try {
                unregister();
                registrationFailed(RegistrationEvent.Type.NotFound);
            } catch (CommunicationsException e) {
                Log.error("NOT FOUND", e);
            }
            Log.debug("REGISTER NOT FOUND");
        }
    } else // NOT_IMPLEMENTED
    if (response.getStatusCode() == Response.NOT_IMPLEMENTED) {
        if (method.equals(Request.REGISTER)) {
            // Fixed typo issues - Reported by pizarro
            registerProcessing.processNotImplemented(clientTransaction, response);
        }
    } else // 401 UNAUTHORIZED
    if (response.getStatusCode() == Response.UNAUTHORIZED || response.getStatusCode() == Response.PROXY_AUTHENTICATION_REQUIRED) {
        if (method.equals(Request.REGISTER)) {
            CSeqHeader cseq = (CSeqHeader) response.getHeader(CSeqHeader.NAME);
            if (cseq.getSequenceNumber() < 2)
                registerProcessing.processAuthenticationChallenge(clientTransaction, response);
            else
                registrationFailed(RegistrationEvent.Type.WrongPass);
        }
    } else // 403 Wrong Authorization user for this account
    if (response.getStatusCode() == Response.FORBIDDEN) {
        registrationFailed(RegistrationEvent.Type.Forbidden);
    }
}
Also used : Response(javax.sip.message.Response) CommunicationsException(org.jivesoftware.openfire.sip.tester.comm.CommunicationsException)

Example 3 with CommunicationsException

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

the class SipManager method stop.

/**
     * Unregisters listening points, deletes sip providers, and generally
     * prepares the stack for a re-start(). This method is meant to be used when
     * properties are changed and should be reread by the stack.
     *
     * @throws CommunicationsException CommunicationsException
     */
public synchronized void stop() throws CommunicationsException {
    if (sipStack == null)
        return;
    // Delete SipProvider
    int tries;
    for (tries = 0; tries < SipManager.RETRY_OBJECT_DELETES; tries++) {
        try {
            sipStack.deleteSipProvider(sipProvider);
        } catch (ObjectInUseException ex) {
            SipManager.sleep(SipManager.RETRY_OBJECT_DELETES_AFTER);
            continue;
        }
        break;
    }
    if (sipStack == null)
        return;
    if (tries >= SipManager.RETRY_OBJECT_DELETES)
        throw new CommunicationsException("Failed to delete the sipProvider!");
    if (sipStack == null)
        return;
    // Delete RI ListeningPoint
    for (tries = 0; tries < SipManager.RETRY_OBJECT_DELETES; tries++) {
        try {
            sipStack.deleteListeningPoint(listeningPoint);
        } catch (ObjectInUseException ex) {
            // Log.debug("Retrying delete of riListeningPoint!");
            SipManager.sleep(SipManager.RETRY_OBJECT_DELETES_AFTER);
            continue;
        }
        break;
    }
    if (sipStack != null) {
        for (Iterator<SipProvider> it = sipStack.getSipProviders(); it.hasNext(); ) {
            SipProvider element = it.next();
            try {
                sipStack.deleteSipProvider(element);
            } catch (Exception e) {
            // Do nothing
            }
        }
    }
    if (tries >= SipManager.RETRY_OBJECT_DELETES)
        throw new CommunicationsException("Failed to delete a listeningPoint!");
    listeningPoint = null;
    addressFactory = null;
    messageFactory = null;
    headerFactory = null;
    sipStack = null;
    registrarAddress = null;
    viaHeaders = null;
    contactHeader = null;
    fromHeader = null;
}
Also used : 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 4 with CommunicationsException

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

the class SipManager method getFromHeader.

public FromHeader getFromHeader(boolean isNew) throws CommunicationsException {
    if (fromHeader != null && !isNew) {
        return fromHeader;
    }
    try {
        SipURI fromURI = (SipURI) addressFactory.createURI(currentlyUsedURI);
        fromURI.setTransportParam(listeningPoint.getTransport());
        fromURI.setPort(listeningPoint.getPort());
        Address fromAddress = addressFactory.createAddress(fromURI);
        if (displayName != null && displayName.trim().length() > 0) {
            fromAddress.setDisplayName(displayName);
        } else {
            fromAddress.setDisplayName(// UserCredentials.getUser());
            UserCredentials.getUserDisplay());
        // JOptionPane.showMessageDialog(null,currentlyUsedURI);
        }
        fromHeader = headerFactory.createFromHeader(fromAddress, Integer.toString(hashCode()));
    } catch (ParseException ex) {
        throw new CommunicationsException("A ParseException occurred while creating From Header!", ex);
    }
    return fromHeader;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) InetAddress(java.net.InetAddress) Address(javax.sip.address.Address) ParseException(java.text.ParseException) SipURI(javax.sip.address.SipURI) CommunicationsException(org.jivesoftware.openfire.sip.tester.comm.CommunicationsException)

Example 5 with CommunicationsException

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

the class RegisterProcessing method unregister.

/**
     * Synchronize because of timer tasks
     *
     * @throws CommunicationsException
     */
synchronized void unregister() throws CommunicationsException {
    try {
        Log.debug("UNREGISTER");
        cancelPendingRegistrations();
        isRegistered = false;
        isUnregistering = true;
        Request registerRequest = getRegisterRequest();
        if (this.registerRequest == null) {
            throw new CommunicationsException("Couldn't find the initial register request");
        }
        Request unregisterRequest = (Request) registerRequest.clone();
        try {
            unregisterRequest.getExpires().setExpires(0);
            CSeqHeader cSeqHeader = (CSeqHeader) unregisterRequest.getHeader(CSeqHeader.NAME);
            // [issue 1] - increment registration cseq number
            // reported by - Roberto Tealdi <roby.tea@tin.it>
            cSeqHeader.setSequenceNumber(cSeqHeader.getSequenceNumber() + 1);
        } catch (InvalidArgumentException ex) {
            // Shouldn't happen
            throw new CommunicationsException("Unable to set Expires Header", ex);
        }
        ClientTransaction unregisterTransaction = null;
        try {
            unregisterTransaction = sipManCallback.sipProvider.getNewClientTransaction(unregisterRequest);
        } catch (TransactionUnavailableException ex) {
            throw new CommunicationsException("Unable to create a unregister transaction", ex);
        }
        try {
            sipManCallback.fireUnregistering(sipManCallback.currentlyUsedURI);
            unregisterTransaction.sendRequest();
        } catch (SipException ex) {
            throw new CommunicationsException("Failed to send unregister request", ex);
        }
    } catch (Exception e) {
        Log.error("unregister", e);
    }
}
Also used : Request(javax.sip.message.Request) CommunicationsException(org.jivesoftware.openfire.sip.tester.comm.CommunicationsException) SipSecurityException(org.jivesoftware.openfire.sip.tester.security.SipSecurityException) CommunicationsException(org.jivesoftware.openfire.sip.tester.comm.CommunicationsException) ParseException(java.text.ParseException)

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