@Override
    public int executeCommand(final ServerDetails serverDetails, final IndexCommand command) throws IndexingException {
        LOGGER.trace("executeCommand() called...");

        // Sanity check...
        Validate.notNull(serverDetails, "Indexing server connection details must be set before calling this method.");
        Validate.notNull(command.getCommand(), "You must set a valid index command to execute");
        Validate.notNull(httpClient, "You must set httpClient before executing commands");

        HttpResponse httpResponse = null;

        try {
            // Create the HTTP method to use...
            final HttpUriRequest httpRequest = (command.getPostData() == null)
                    ? createGetMethod(serverDetails, command)
                    : createPostMethod(serverDetails, command);

            LOGGER.debug("Executing a {} index command...", command.getCommand());

            // Execute the command...
            httpResponse = httpClient.execute(httpRequest);

            LOGGER.debug("Successfully executed the index command, HTTP status - {}...", httpResponse.getStatusLine().getStatusCode());

            // Get the response...
            final ByteArrayOutputStream baos = new ByteArrayOutputStream();
            httpResponse.getEntity().writeTo(baos);
            final String response = baos.toString("UTF-8");

            if(!response.contains("INDEXID")) {
                throw new IndexingException(response.trim());
            }

            // Get the index queue id...
            final Matcher matcher = pattern.matcher(response);
            if(matcher.matches()) {
                return NumberUtils.toInt(matcher.group(1));
            }

            throw new IndexingException("Unable to get index queue id from response: [" + response + ']');
        }
        catch(final IOException ioe) {
            throw new IndexingException("Unable to execute the Index command", ioe);
        }
        catch(final URISyntaxException urise) {
            throw new IndexingException("Unable to construct the Index command URI.", urise);
        }
        finally {
            try {
                if(httpResponse != null) {
                    // Release the HTTP connection...
                    EntityUtils.consume(httpResponse.getEntity());
                }
            }
            catch(final IOException ioe) {
                LOGGER.error("Unable to consume any remaining content from the IndexCommand response.", ioe);
            }
        }
    }
@ Override public int executeCommand ( final ServerDetails serverDetails , final IndexCommand command ) throws IndexingException { LOGGER . trace ( "executeCommand() called..." ) ; Validate . notNull ( serverDetails , "Indexing server connection details must be set before calling this method." ) ; Validate . notNull ( command . getCommand ( ) , "You must set a valid index command to execute" ) ; Validate . notNull ( httpClient , "You must set httpClient before executing commands" ) ; HttpResponse httpResponse = null ; try { final HttpUriRequest httpRequest = ( command . getPostData ( ) == null ) ? createGetMethod ( serverDetails , command ) : createPostMethod ( serverDetails , command ) ; LOGGER . debug ( "Executing a {} index command..." , command . getCommand ( ) ) ; httpResponse = httpClient . execute ( httpRequest ) ; LOGGER . debug ( "Successfully executed the index command, HTTP status - {}..." , httpResponse . getStatusLine ( ) . getStatusCode ( ) ) ; final ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; httpResponse . getEntity ( ) . writeTo ( baos ) ; final String response = baos . toString ( "UTF-8" ) ; if ( ! response . contains ( "INDEXID" ) ) { throw new IndexingException ( response . trim ( ) ) ; } final Matcher matcher = pattern . matcher ( response ) ; if ( matcher . matches ( ) ) { return NumberUtils . toInt ( matcher . group ( 1 ) ) ; } throw new IndexingException ( "Unable to get index queue id from response: [" + response + ']' ) ; } catch ( final IOException ioe ) { throw new IndexingException ( "Unable to execute the Index command" , ioe ) ; } catch ( final URISyntaxException urise ) { throw new IndexingException ( "Unable to construct the Index command URI." , urise ) ; } finally { try { if ( httpResponse != null ) { EntityUtils . consume ( httpResponse . getEntity ( ) ) ; } } catch ( final IOException ioe ) { LOGGER . error ( "Unable to consume any remaining content from the IndexCommand response." , ioe ) ; } } }
Executes an index command

@param serverDetails The connection details of the indexing server.
@param command The index command to execute
@return the index queue id for the command
@throws com.autonomy.nonaci.indexing.IndexingException if an error response was detected, or if something went
wrong while executing the command