Java Code Examples for org.apache.solr.client.solrj.request.QueryRequest#setBasicAuthCredentials()

The following examples show how to use org.apache.solr.client.solrj.request.QueryRequest#setBasicAuthCredentials() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SolrUtil.java    From ranger with Apache License 2.0 6 votes vote down vote up
public QueryResponse runQuery(SolrClient solrClient, SolrQuery solrQuery) throws Throwable {
    if (solrQuery != null) {
        try {
            QueryRequest req = new QueryRequest(solrQuery, METHOD.POST);
            String username = PropertiesUtil.getProperty("ranger.solr.audit.user");
            String password = PropertiesUtil.getProperty("ranger.solr.audit.user.password");
            if (username != null && password != null) {
                req.setBasicAuthCredentials(username, password);
            }

            return req.process(solrClient);
        } catch (Throwable e) {
            logger.error("Error from Solr server. ", e);
            throw e;
        }
    }
    return null;
}
 
Example 2
Source File: SolrStream.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public TupleStreamParser constructParser(SolrClient server, SolrParams requestParams) throws IOException, SolrServerException {
  String p = requestParams.get("qt");
  if (p != null) {
    ModifiableSolrParams modifiableSolrParams = (ModifiableSolrParams) requestParams;
    modifiableSolrParams.remove("qt");
    //performance optimization - remove extra whitespace by default when streaming
    modifiableSolrParams.set("indent", modifiableSolrParams.get("indent", "off"));
  }

  String wt = requestParams.get(CommonParams.WT, "json");
  QueryRequest query = new QueryRequest(requestParams);
  query.setPath(p);
  query.setResponseParser(new InputStreamResponseParser(wt));
  query.setMethod(SolrRequest.METHOD.POST);

  if(user != null && password != null) {
    query.setBasicAuthCredentials(user, password);
  }

  NamedList<Object> genericResponse = server.request(query);
  InputStream stream = (InputStream) genericResponse.get("stream");
  this.closeableHttpResponse = (CloseableHttpResponse)genericResponse.get("closeableResponse");
  if (CommonParams.JAVABIN.equals(wt)) {
    return new JavabinTupleStreamParser(stream, true);
  } else {
    InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8);
    return new JSONTupleStream(reader);
  }
}
 
Example 3
Source File: ServiceSolrClient.java    From ranger with Apache License 2.0 5 votes vote down vote up
public List<String> getFieldList(String collection,
		List<String> ignoreFieldList) throws Exception {
	// TODO: Best is to get the collections based on the collection value
	// which could contain wild cards
	String queryStr = "";
	if (collection != null && !collection.isEmpty()) {
		queryStr += "/" + collection;
	}
	queryStr += "/schema/fields";
	SolrQuery query = new SolrQuery();
	query.setRequestHandler(queryStr);
	QueryRequest req = new QueryRequest(query);
	String decPassword = getDecryptedPassword();
	if (username != null && decPassword != null) {
	    req.setBasicAuthCredentials(username, decPassword);
	}
	QueryResponse response = req.process(solrClient);

	List<String> fieldList = new ArrayList<String>();
	if (response != null && response.getStatus() == 0) {
		@SuppressWarnings("unchecked")
		List<SimpleOrderedMap<String>> fields = (ArrayList<SimpleOrderedMap<String>>) response
				.getResponse().get("fields");
		for (SimpleOrderedMap<String> fmap : fields) {
			String fieldName = fmap.get("name");
			if (ignoreFieldList == null
					|| !ignoreFieldList.contains(fieldName)) {
				fieldList.add(fieldName);
			}
		}
	} else {
		LOG.error("Error getting fields for collection=" + collection
				+ ", response=" + response);
	}
	return fieldList;
}
 
Example 4
Source File: GetSolr.java    From nifi with Apache License 2.0 5 votes vote down vote up
private String getFieldNameOfUniqueKey() {
    final SolrQuery solrQuery = new SolrQuery();
    try {
        solrQuery.setRequestHandler("/schema/uniquekey");
        final QueryRequest req = new QueryRequest(solrQuery);
        if (isBasicAuthEnabled()) {
            req.setBasicAuthCredentials(getUsername(), getPassword());
        }

        return(req.process(getSolrClient()).getResponse().get("uniqueKey").toString());
    } catch (SolrServerException | IOException e) {
        getLogger().error("Solr query to retrieve uniqueKey-field failed due to {}", new Object[]{solrQuery.toString(), e}, e);
        throw new ProcessException(e);
    }
}
 
Example 5
Source File: SearchableImpl.java    From spring-content with Apache License 2.0 4 votes vote down vote up
QueryRequest solrAuthenticate(QueryRequest request) {
	request.setBasicAuthCredentials(solrProperties.getUser(),
			solrProperties.getPassword());
	return request;
}
 
Example 6
Source File: SolrSearchService.java    From spring-content with Apache License 2.0 4 votes vote down vote up
QueryRequest solrAuthenticate(QueryRequest request) {
	request.setBasicAuthCredentials(solrProperties.getUser(),
			solrProperties.getPassword());
	return request;
}