Package org.asteriskjava.manager.response

Examples of org.asteriskjava.manager.response.ManagerResponse


    }

    private void populateRoom(MeetMeRoomImpl room)
    {
        final CommandAction meetMeListAction;
        final ManagerResponse response;
        final List<String> lines;
        final Collection<Integer> userNumbers = new ArrayList<Integer>(); // list of user numbers in the room

        meetMeListAction = new CommandAction(MEETME_LIST_COMMAND + " " + room.getRoomNumber());
        try
        {
            response = server.sendAction(meetMeListAction);
        }
        catch (ManagerCommunicationException e)
        {
            logger.error("Unable to send \"" + MEETME_LIST_COMMAND + "\" command", e);
            return;
        }
        if (response instanceof ManagerError)
        {
            logger.error("Unable to send \"" + MEETME_LIST_COMMAND + "\" command: " + response.getMessage());
            return;
        }
        if (!(response instanceof CommandResponse))
        {
            logger.error("Response to \"" + MEETME_LIST_COMMAND + "\" command is not a CommandResponse but "
                    + response.getClass());
            return;
        }

        lines = ((CommandResponse) response).getResult();
        for (String line : lines)
View Full Code Here


    }

    ManagerResponse sendAction(ManagerAction action) throws ManagerCommunicationException
    {
        ManagerConnection connection;
        ManagerResponse response;

        connection = get();
        try
        {
            response = connection.sendAction(action);
View Full Code Here

     */
    protected synchronized void doLogin(long timeout, String eventMask) throws IOException, AuthenticationFailedException,
            TimeoutException
    {
        ChallengeAction challengeAction;
        ManagerResponse challengeResponse;
        String challenge;
        String key;
        LoginAction loginAction;
        ManagerResponse loginResponse;

        if (socket == null)
        {
            connect();
        }

        synchronized (protocolIdentifier)
        {
            if (protocolIdentifier.value == null)
            {
                try
                {
                    protocolIdentifier.wait(timeout);
                }
                catch (InterruptedException e) // NOPMD
                {
                    Thread.currentThread().interrupt();
                }
            }

            if (protocolIdentifier.value == null)
            {
                disconnect();
                if (reader != null && reader.getTerminationException() != null)
                {
                    throw reader.getTerminationException();
                }
                else
                {
                    throw new TimeoutException("Timeout waiting for protocol identifier");
                }
            }
        }

        challengeAction = new ChallengeAction("MD5");
        try
        {
            challengeResponse = sendAction(challengeAction);
        }
        catch (Exception e)
        {
            disconnect();
            throw new AuthenticationFailedException("Unable to send challenge action", e);
        }

        if (challengeResponse instanceof ChallengeResponse)
        {
            challenge = ((ChallengeResponse) challengeResponse).getChallenge();
        }
        else
        {
            disconnect();
            throw new AuthenticationFailedException("Unable to get challenge from Asterisk. ChallengeAction returned: "
                    + challengeResponse.getMessage());
        }

        try
        {
            MessageDigest md;

            md = MessageDigest.getInstance("MD5");
            if (challenge != null)
            {
                md.update(challenge.getBytes());
            }
            if (password != null)
            {
                md.update(password.getBytes());
            }
            key = ManagerUtil.toHexString(md.digest());
        }
        catch (NoSuchAlgorithmException ex)
        {
            disconnect();
            throw new AuthenticationFailedException("Unable to create login key using MD5 Message Digest", ex);
        }

        loginAction = new LoginAction(username, "MD5", key, eventMask);
        try
        {
            loginResponse = sendAction(loginAction);
        }
        catch (Exception e)
        {
            disconnect();
            throw new AuthenticationFailedException("Unable to send login action", e);
        }

        if (loginResponse instanceof ManagerError)
        {
            disconnect();
            throw new AuthenticationFailedException(loginResponse.getMessage());
        }

        logger.info("Successfully logged in");

        version = determineVersion();
View Full Code Here

//            return AsteriskVersion.ASTERISK_1_6;
//        }

        while (attempts++ < MAX_VERSION_ATTEMPTS)
        {
            final ManagerResponse showVersionFilesResponse;
            final List<String> showVersionFilesResult;

            // increase timeout as output is quite large
            showVersionFilesResponse = sendAction(new CommandAction("show version files pbx.c"), defaultResponseTimeout * 2);
            if (!(showVersionFilesResponse instanceof CommandResponse))
            {
                // return early in case of permission problems
                // org.asteriskjava.manager.response.ManagerError:
                // actionId='null'; message='Permission denied'; response='Error';
                // uniqueId='null'; systemHashcode=15231583
                break;
            }

            showVersionFilesResult = ((CommandResponse) showVersionFilesResponse).getResult();
            if (showVersionFilesResult != null && showVersionFilesResult.size() > 0)
            {
                final String line1 = showVersionFilesResult.get(0);

                if (line1.startsWith("File"))
                {
                    final String rawVersion;

                    rawVersion = getRawVersion();
                    if (rawVersion != null && rawVersion.startsWith("Asterisk 1.4"))
                    {
                        return AsteriskVersion.ASTERISK_1_4;
                    }
                    return AsteriskVersion.ASTERISK_1_2;
                }
                else if (line1.contains("No such command"))
                {
                    final ManagerResponse coreShowVersionResponse = sendAction(new CommandAction("core show version"), defaultResponseTimeout * 2);

                    if (coreShowVersionResponse != null && coreShowVersionResponse instanceof CommandResponse)
                    {
                        final List<String> coreShowVersionResult = ((CommandResponse) coreShowVersionResponse).getResult();

View Full Code Here

        return AsteriskVersion.ASTERISK_1_6;
    }

    protected String getRawVersion()
    {
        final ManagerResponse showVersionResponse;

        try
        {
            showVersionResponse = sendAction(new CommandAction("show version"), defaultResponseTimeout * 2);
        }
View Full Code Here

            {
                c.sendAction(new PingAction(), null);
            }
            else
            {
                final ManagerResponse response;

                response = c.sendAction(new PingAction(), timeout);
                logger.debug("Ping response '" + response + "' for " + c.toString());
            }
        }
View Full Code Here

        sendPauseAction(new QueuePauseAction(location, paused));
    }

    private void sendPauseAction(QueuePauseAction action) throws ManagerCommunicationException, NoSuchInterfaceException
    {
        final ManagerResponse response = server.sendAction(action);

        if (response instanceof ManagerError)
        {
            //Message: Interface not found
            if (action.getQueue() != null)
            {
                //Message: Interface not found
                throw new NoSuchInterfaceException("Unable to change paused state for '" + action.getInterface() + "' on '" +
                        action.getQueue() + "': " + response.getMessage());
            }
            else
            {
                throw new NoSuchInterfaceException("Unable to change paused state for '" + action.getInterface() +
                        "' on all queues: " + response.getMessage());
            }
        }
    }
View Full Code Here

        if (penalty < 0)
        {
            throw new IllegalArgumentException("Penalty must not be negative");
        }

        final ManagerResponse response = server.sendAction(
                new QueuePenaltyAction(location, penalty, queue.getName()));
        if (response instanceof ManagerError)
        {
            throw new InvalidPenaltyException("Unable to set penalty for '" + location + "' on '" +
                    queue.getName() + "': " + response.getMessage());
        }
    }
View Full Code Here

                            logger.debug("buildEvent returned null");
                        }
                    }
                    else if (buffer.containsKey("response"))
                    {
                        ManagerResponse response = buildResponse(buffer);
                        // TODO tracing
                        //logger.debug("attempting to build response");
                        if (response != null)
                        {
                            dispatcher.dispatchResponse(response);
View Full Code Here

            {
                expectedResponseClasses.remove(internalActionId);
            }
        }

        final ManagerResponse response = responseBuilder.buildResponse(responseClass, buffer);

        if (response != null)
        {
            response.setDateReceived(DateUtil.getDate());
        }

        return response;
    }
View Full Code Here

TOP

Related Classes of org.asteriskjava.manager.response.ManagerResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.