use of org.apache.commons.codec.net.URLCodec in project alfresco-repository by Alfresco.
the class SOLRAdminClient method executeCommand.
/* (non-Javadoc)
* @see org.alfresco.repo.search.impl.solr.SolrAdminClient#executeCommand(java.lang.String, org.alfresco.repo.search.impl.solr.SolrAdminClient.HANDLER, org.alfresco.repo.search.impl.solr.SolrAdminClient.COMMAND, java.util.Map)
*/
@Override
public JSONAPIResult executeCommand(String core, JSONAPIResultFactory.HANDLER handler, JSONAPIResultFactory.COMMAND command, Map<String, String> parameters) {
StoreRef store = StoreRef.STORE_REF_WORKSPACE_SPACESSTORE;
SolrStoreMappingWrapper mapping = SolrClientUtil.extractMapping(store, mappingLookup, shardRegistry, useDynamicShardRegistration, beanFactory);
HttpClient httpClient = mapping.getHttpClientAndBaseUrl().getFirst();
StringBuilder url = new StringBuilder();
url.append(baseUrl);
if (!url.toString().endsWith("/")) {
url.append("/");
}
url.append(core + "/" + handler.toString().toLowerCase());
URLCodec encoder = new URLCodec();
url.append("?command=" + command.toString().toLowerCase());
parameters.forEach((key, value) -> {
try {
url.append("&" + key + "=" + encoder.encode(value));
} catch (EncoderException e) {
throw new RuntimeException(e);
}
});
url.append("&alfresco.shards=");
if (mapping.isSharded()) {
url.append(mapping.getShards());
} else {
String solrurl = httpClient.getHostConfiguration().getHostURL() + mapping.getHttpClientAndBaseUrl().getSecond();
url.append(solrurl);
}
try {
JSONAPIResult response = new SolrCommandBackupResult(getOperation(httpClient, url.toString()));
if (response.getStatus() != 0) {
solrTracker.setSolrActive(false);
}
return response;
} catch (IOException e) {
throw new LuceneQueryParserException("action", e);
}
}
use of org.apache.commons.codec.net.URLCodec in project alfresco-repository by Alfresco.
the class SolrQueryHTTPClient method buildPivotParameters.
protected void buildPivotParameters(SearchParameters searchParameters, URLCodec encoder, StringBuilder url) throws UnsupportedEncodingException {
if (searchParameters.getPivots() != null && !searchParameters.getPivots().isEmpty()) {
url.append("&facet=").append(encoder.encode("true", "UTF-8"));
for (List<String> pivotKeys : searchParameters.getPivots()) {
List<String> pivotsList = new ArrayList<>();
pivotsList.addAll(pivotKeys);
url.append("&facet.pivot=");
StringBuilder prefix = new StringBuilder("{! ");
if (searchParameters.getStats() != null && !searchParameters.getStats().isEmpty()) {
for (StatsRequestParameters aStat : searchParameters.getStats()) {
if (pivotKeys.contains(aStat.getLabel())) {
prefix.append("stats=" + aStat.getLabel() + " ");
pivotsList.remove(aStat.getLabel());
// only do it once
break;
}
}
}
if (searchParameters.getRanges() != null && !searchParameters.getRanges().isEmpty()) {
for (RangeParameters aRange : searchParameters.getRanges()) {
Optional<String> found = pivotKeys.stream().filter(aKey -> aKey.equals(aRange.getLabel())).findFirst();
if (found.isPresent()) {
prefix.append("range=" + found.get() + " ");
pivotsList.remove(found.get());
// only do it once
break;
}
}
}
if (// We have add something
prefix.length() > 3) {
url.append(encoder.encode(prefix.toString().trim(), "UTF-8"));
url.append(encoder.encode("}", "UTF-8"));
}
url.append(encoder.encode(String.join(",", pivotsList), "UTF-8"));
}
}
}
use of org.apache.commons.codec.net.URLCodec in project alfresco-repository by Alfresco.
the class SolrQueryHTTPClient method buildStatsUrl.
protected String buildStatsUrl(StatsParameters searchParameters, String baseUrl, Locale locale, SolrStoreMappingWrapper mapping) throws UnsupportedEncodingException {
URLCodec encoder = new URLCodec();
StringBuilder url = new StringBuilder();
String languageUrlFragment = SolrClientUtil.extractLanguageFragment(languageMappings, searchParameters.getLanguage());
url.append(baseUrl);
url.append("/").append(languageUrlFragment);
url.append("?wt=").append(encoder.encode("json", "UTF-8"));
url.append("&locale=").append(encoder.encode(locale.toString(), "UTF-8"));
url.append(buildSortParameters(searchParameters, encoder));
url.append("&stats=true");
url.append("&rows=0");
if (!StringUtils.isBlank(searchParameters.getFilterQuery())) {
url.append("?fq=").append(encoder.encode(searchParameters.getFilterQuery(), "UTF-8"));
}
for (Entry<String, String> entry : searchParameters.getStatsParameters().entrySet()) {
url.append("&stats.").append(entry.getKey()).append("=").append(encoder.encode(entry.getValue(), "UTF-8"));
}
if ((mapping != null) && ((searchParameters.getStores().size() > 1) || (mapping.isSharded()))) {
url.append("&shards=");
buildShards(url, searchParameters.getStores());
}
return url.toString();
}
use of org.apache.commons.codec.net.URLCodec in project alfresco-repository by Alfresco.
the class ExplicitSolrStoreMappingWrapper method getShards2.
private String getShards2() {
try {
URLCodec encoder = new URLCodec();
StringBuilder builder = new StringBuilder();
for (int shard = 0; shard < wrapped.getNumShards(); shard++) {
int position = random.nextInt(wrapped.getReplicationFactor());
List<Integer> nodeInstances = policy.getNodeInstancesForShardId(shard);
Integer nodeId = nodeInstances.get(position);
if (builder.length() > 0) {
builder.append(',');
}
HttpClientAndBaseUrl httpClientAndBaseUrl = httpClientsAndBaseURLs.toArray(new HttpClientAndBaseUrl[0])[nodeId - 1];
builder.append(encoder.encode(httpClientAndBaseUrl.getProtocol() + "://", "UTF-8"));
builder.append(encoder.encode(httpClientAndBaseUrl.getHost(), "UTF-8"));
builder.append(':');
builder.append(encoder.encode("" + httpClientAndBaseUrl.getPort(), "UTF-8"));
if (httpClientAndBaseUrl.getBaseUrl().startsWith("/")) {
builder.append(encoder.encode(httpClientAndBaseUrl.getBaseUrl(), "UTF-8"));
} else {
builder.append(encoder.encode("/" + httpClientAndBaseUrl.getBaseUrl(), "UTF-8"));
}
if (isSharded())
builder.append('-').append(shard);
}
return builder.toString();
} catch (UnsupportedEncodingException e) {
throw new LuceneQueryParserException("", e);
}
}
Aggregations