Source:
<code>protected DefaultHttpClient httpClient(final String repositoryURL) { if ( clients.size() > 0 ) { for ( final Iterator<String> it = clients.keySet().iterator(); it.hasNext(); ) { final String base = it.next(); if ( repositoryURL.startsWith(base) ) { return clients.get(base); } } } if ( defaultClient != null ) { return defaultClient; } final String baseURL; if ( repositoryURL.indexOf("/rest/") > 0 ) { <START> baseURL = repositoryURL.substring(0, repositoryURL.indexOf("/rest/") + 6); <END> } else if ( repositoryURL.indexOf("/",8) > 0 ) { baseURL = repositoryURL.substring(0, repositoryURL.indexOf("/",8) + 1); } else { baseURL = repositoryURL; } final PoolingClientConnectionManager connMann = new PoolingClientConnectionManager(); connMann.setMaxTotal(MAX_VALUE); connMann.setDefaultMaxPerRoute(MAX_VALUE); final DefaultHttpClient httpClient = new DefaultHttpClient(connMann); httpClient.setRedirectStrategy(new DefaultRedirectStrategy()); httpClient.setHttpRequestRetryHandler(new StandardHttpRequestRetryHandler(0, false)); if (!isBlank(fedoraUsername) && !isBlank(fedoraPassword)) { LOGGER.debug("Adding BASIC credentials to client for repo requests."); final URI fedoraUri = URI.create(baseURL); final CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(fedoraUri.getHost(), fedoraUri.getPort()), new UsernamePasswordCredentials(fedoraUsername, fedoraPassword)); httpClient.setCredentialsProvider(credsProvider); } clients.put(baseURL, httpClient); return httpClient; }</code><technical_language>Instead of magic number "6", length of a variable holds "/rest/"</technical_language>

Target:
protected DefaultHttpClient httpClient(final String repositoryURL) { if ( clients.size() > 0 ) { for ( final Iterator<String> it = clients.keySet().iterator(); it.hasNext(); ) { final String base = it.next(); if ( repositoryURL.startsWith(base) ) { return clients.get(base); } } } if ( defaultClient != null ) { return defaultClient; } final String baseURL; if ( repositoryURL.indexOf(REST_PREFIX) > 0 ) { baseURL = repositoryURL.substring(0, repositoryURL.indexOf(REST_PREFIX) + REST_PREFIX.length()); } else if ( repositoryURL.indexOf("/",FCREPO_PREFIX.length()) > 0 ) { baseURL = repositoryURL.substring(0, repositoryURL.indexOf("/",FCREPO_PREFIX.length()) + 1); } else { baseURL = repositoryURL; } final PoolingClientConnectionManager connMann = new PoolingClientConnectionManager(); connMann.setMaxTotal(MAX_VALUE); connMann.setDefaultMaxPerRoute(MAX_VALUE); final DefaultHttpClient httpClient = new DefaultHttpClient(connMann); httpClient.setRedirectStrategy(new DefaultRedirectStrategy()); httpClient.setHttpRequestRetryHandler(new StandardHttpRequestRetryHandler(0, false)); if (!isBlank(fedoraUsername) && !isBlank(fedoraPassword)) { LOGGER.debug("Adding BASIC credentials to client for repo requests."); final URI fedoraUri = URI.create(baseURL); final CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(fedoraUri.getHost(), fedoraUri.getPort()), new UsernamePasswordCredentials(fedoraUsername, fedoraPassword)); httpClient.setCredentialsProvider(credsProvider); } clients.put(baseURL, httpClient); return httpClient; }