@Override
    public Object getAttribute(ObjectName name, String attribute) throws MBeanException, AttributeNotFoundException, InstanceNotFoundException, ReflectionException, IOException {
        final String sourceMethod = "getAttribute";
        checkConnection();
        if (name == null)
            throw new RuntimeOperationsException(new IllegalArgumentException(RESTClientMessagesUtil.getMessage(RESTClientMessagesUtil.OBJECT_NAME_NULL)));
        else if (name.isPattern())
            throw new InstanceNotFoundException(RESTClientMessagesUtil.getMessage(RESTClientMessagesUtil.OBJECT_NAME_PATTERN, name));
        else if (attribute == null)
            throw new RuntimeOperationsException(new IllegalArgumentException(RESTClientMessagesUtil.getMessage(RESTClientMessagesUtil.ATTRIBUTE_NAME_NULL)));

        URL attributeURL;

        try {
            // Get URL for attribute
            attributeURL = getAttributeURL(name, attribute);

        } catch (IntrospectionException intro) {
            throw getRequestErrorException(sourceMethod, intro);
        } catch (IOException io) {
            throw getRequestErrorException(sourceMethod, io);
        }

        HttpsURLConnection connection;
        try {
            connection = getConnection(attributeURL, HttpMethod.GET); // Get connection to server
        } catch (IOException io) {
            throw getRequestErrorException(sourceMethod, io, attributeURL);
        }

        // Check response code from server
        int responseCode = 0;
        try {
            responseCode = connection.getResponseCode();
        } catch (ConnectException ce) {
            recoverConnection(ce);
            // Server is down; not a client bug
            throw ce;
        }

        switch (responseCode) {
            case HttpURLConnection.HTTP_OK:
                JSONConverter converter = JSONConverter.getConverter();
                try {
                    // Process and return server response, which should be a POJO
                    return converter.readPOJO(connection.getInputStream());
                } catch (ClassNotFoundException cnf) {
                    // Not a REST connector bug per se; not need to log this case
                    throw new IOException(RESTClientMessagesUtil.getMessage(RESTClientMessagesUtil.SERVER_RESULT_EXCEPTION), cnf);
                } catch (Exception e) {
                    throw getResponseErrorException(sourceMethod, e, attributeURL);
                } finally {
                    JSONConverter.returnConverter(converter);
                }
            case HttpURLConnection.HTTP_BAD_REQUEST:
            case HttpURLConnection.HTTP_INTERNAL_ERROR:
                try {
                    // Server response should be a serialized Throwable
                    throw getServerThrowable(sourceMethod, connection);
                } catch (MBeanException me) {
                    throw me;
                } catch (AttributeNotFoundException anf) {
                    throw anf;
                } catch (InstanceNotFoundException inf) {
                    throw inf;
                } catch (ReflectionException re) {
                    throw re;
                } catch (IOException io) {
                    throw io;
                } catch (Throwable t) {
                    throw new IOException(RESTClientMessagesUtil.getMessage(RESTClientMessagesUtil.UNEXPECTED_SERVER_THROWABLE), t);
                }
            case HttpURLConnection.HTTP_UNAUTHORIZED:
            case HttpURLConnection.HTTP_FORBIDDEN:
                throw getBadCredentialsException(responseCode, connection);
            case HttpURLConnection.HTTP_GONE:
            case HttpURLConnection.HTTP_NOT_FOUND:
                IOException ioe = getResponseCodeErrorException(sourceMethod, responseCode, connection);
                recoverConnection(ioe);
                throw ioe;
            default:
                throw getResponseCodeErrorException(sourceMethod, responseCode, connection);
        }
    }
@ Override public Object getAttribute ( ObjectName name , String attribute ) throws MBeanException , AttributeNotFoundException , InstanceNotFoundException , ReflectionException , IOException { final String sourceMethod = "getAttribute" ; checkConnection ( ) ; if ( name == null ) throw new RuntimeOperationsException ( new IllegalArgumentException ( RESTClientMessagesUtil . getMessage ( RESTClientMessagesUtil . OBJECT_NAME_NULL ) ) ) ; else if ( name . isPattern ( ) ) throw new InstanceNotFoundException ( RESTClientMessagesUtil . getMessage ( RESTClientMessagesUtil . OBJECT_NAME_PATTERN , name ) ) ; else if ( attribute == null ) throw new RuntimeOperationsException ( new IllegalArgumentException ( RESTClientMessagesUtil . getMessage ( RESTClientMessagesUtil . ATTRIBUTE_NAME_NULL ) ) ) ; URL attributeURL ; try { attributeURL = getAttributeURL ( name , attribute ) ; } catch ( IntrospectionException intro ) { throw getRequestErrorException ( sourceMethod , intro ) ; } catch ( IOException io ) { throw getRequestErrorException ( sourceMethod , io ) ; } HttpsURLConnection connection ; try { connection = getConnection ( attributeURL , HttpMethod . GET ) ; } catch ( IOException io ) { throw getRequestErrorException ( sourceMethod , io , attributeURL ) ; } int responseCode = 0 ; try { responseCode = connection . getResponseCode ( ) ; } catch ( ConnectException ce ) { recoverConnection ( ce ) ; throw ce ; } switch ( responseCode ) { case HttpURLConnection . HTTP_OK : JSONConverter converter = JSONConverter . getConverter ( ) ; try { return converter . readPOJO ( connection . getInputStream ( ) ) ; } catch ( ClassNotFoundException cnf ) { throw new IOException ( RESTClientMessagesUtil . getMessage ( RESTClientMessagesUtil . SERVER_RESULT_EXCEPTION ) , cnf ) ; } catch ( Exception e ) { throw getResponseErrorException ( sourceMethod , e , attributeURL ) ; } finally { JSONConverter . returnConverter ( converter ) ; } case HttpURLConnection . HTTP_BAD_REQUEST : case HttpURLConnection . HTTP_INTERNAL_ERROR : try { throw getServerThrowable ( sourceMethod , connection ) ; } catch ( MBeanException me ) { throw me ; } catch ( AttributeNotFoundException anf ) { throw anf ; } catch ( InstanceNotFoundException inf ) { throw inf ; } catch ( ReflectionException re ) { throw re ; } catch ( IOException io ) { throw io ; } catch ( Throwable t ) { throw new IOException ( RESTClientMessagesUtil . getMessage ( RESTClientMessagesUtil . UNEXPECTED_SERVER_THROWABLE ) , t ) ; } case HttpURLConnection . HTTP_UNAUTHORIZED : case HttpURLConnection . HTTP_FORBIDDEN : throw getBadCredentialsException ( responseCode , connection ) ; case HttpURLConnection . HTTP_GONE : case HttpURLConnection . HTTP_NOT_FOUND : IOException ioe = getResponseCodeErrorException ( sourceMethod , responseCode , connection ) ; recoverConnection ( ioe ) ; throw ioe ; default : throw getResponseCodeErrorException ( sourceMethod , responseCode , connection ) ; } }
{@inheritDoc}