use of org.apache.solr.client.solrj.impl.BinaryRequestWriter in project lucene-solr by apache.
the class SolrExampleStreamingBinaryTest method createNewSolrClient.
@Override
public SolrClient createNewSolrClient() {
ConcurrentUpdateSolrClient client = (ConcurrentUpdateSolrClient) super.createNewSolrClient();
client.setParser(new BinaryResponseParser());
client.setRequestWriter(new BinaryRequestWriter());
return client;
}
use of org.apache.solr.client.solrj.impl.BinaryRequestWriter in project lucene-solr by apache.
the class SolrExampleBinaryTest method createNewSolrClient.
@Override
public SolrClient createNewSolrClient() {
try {
// setup the server...
String url = jetty.getBaseUrl().toString() + "/collection1";
HttpSolrClient client = getHttpSolrClient(url);
client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
client.setUseMultiPartPost(random().nextBoolean());
// where the magic happens
client.setParser(new BinaryResponseParser());
client.setRequestWriter(new BinaryRequestWriter());
return client;
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
use of org.apache.solr.client.solrj.impl.BinaryRequestWriter in project lucene-solr by apache.
the class TestBatchUpdate method testWithBinaryBean.
@Test
public void testWithBinaryBean() throws Exception {
HttpSolrClient client = (HttpSolrClient) getSolrClient();
client.setRequestWriter(new BinaryRequestWriter());
// delete everything!
client.deleteByQuery("*:*");
final int[] counter = new int[1];
counter[0] = 0;
client.addBeans(new Iterator<Bean>() {
@Override
public boolean hasNext() {
return counter[0] < numdocs;
}
@Override
public Bean next() {
Bean bean = new Bean();
bean.id = "" + (++counter[0]);
bean.cat = "foocat";
return bean;
}
@Override
public void remove() {
//do nothing
}
});
client.commit();
SolrQuery query = new SolrQuery("*:*");
QueryResponse response = client.query(query);
assertEquals(0, response.getStatus());
assertEquals(numdocs, response.getResults().getNumFound());
}
use of org.apache.solr.client.solrj.impl.BinaryRequestWriter in project lucene-solr by apache.
the class TestBatchUpdate method testWithBinary.
@Test
public void testWithBinary() throws Exception {
HttpSolrClient client = (HttpSolrClient) getSolrClient();
client.setRequestWriter(new BinaryRequestWriter());
// delete everything!
client.deleteByQuery("*:*");
doIt(client);
}
use of org.apache.solr.client.solrj.impl.BinaryRequestWriter in project ranger by apache.
the class DbToSolrMigrationUtil method createSolrClient.
private SolrClient createSolrClient() throws Exception {
SolrClient solrClient = null;
registerSolrClientJAAS();
String zkHosts = PropertiesUtil.getProperty(SOLR_ZK_HOSTS);
if (zkHosts == null) {
zkHosts = PropertiesUtil.getProperty("ranger.audit.solr.zookeeper");
}
if (zkHosts == null) {
zkHosts = PropertiesUtil.getProperty("ranger.solr.zookeeper");
}
String solrURL = PropertiesUtil.getProperty(SOLR_URLS_PROP);
if (solrURL == null) {
// Try with url
solrURL = PropertiesUtil.getProperty("ranger.audit.solr.url");
}
if (solrURL == null) {
// Let's try older property name
solrURL = PropertiesUtil.getProperty("ranger.solr.url");
}
if (zkHosts != null && !"".equals(zkHosts.trim()) && !"none".equalsIgnoreCase(zkHosts.trim())) {
zkHosts = zkHosts.trim();
String collectionName = PropertiesUtil.getProperty(SOLR_COLLECTION_NAME);
if (collectionName == null || "none".equalsIgnoreCase(collectionName)) {
collectionName = DEFAULT_COLLECTION_NAME;
}
logger.info("Solr zkHosts=" + zkHosts + ", collectionName=" + collectionName);
try {
// Instantiate
Krb5HttpClientBuilder krbBuild = new Krb5HttpClientBuilder();
SolrHttpClientBuilder kb = krbBuild.getBuilder();
HttpClientUtil.setHttpClientBuilder(kb);
final List<String> zkhosts = new ArrayList<String>(Arrays.asList(zkHosts.split(",")));
CloudSolrClient solrCloudClient = new CloudSolrClient.Builder(zkhosts, null).build();
solrCloudClient.setDefaultCollection(collectionName);
return solrCloudClient;
} catch (Exception e) {
logger.error("Can't connect to Solr server. ZooKeepers=" + zkHosts + ", collection=" + collectionName, e);
throw e;
}
} else {
if (solrURL == null || solrURL.isEmpty() || "none".equalsIgnoreCase(solrURL)) {
logger.error("Solr ZKHosts and URL for Audit are empty. Please set property " + SOLR_ZK_HOSTS + " or " + SOLR_URLS_PROP);
} else {
try {
Krb5HttpClientBuilder krbBuild = new Krb5HttpClientBuilder();
SolrHttpClientBuilder kb = krbBuild.getBuilder();
HttpClientUtil.setHttpClientBuilder(kb);
HttpSolrClient.Builder builder = new HttpSolrClient.Builder();
builder.withBaseSolrUrl(solrURL);
builder.allowCompression(true);
builder.withConnectionTimeout(1000);
HttpSolrClient httpSolrClient = builder.build();
httpSolrClient.setRequestWriter(new BinaryRequestWriter());
solrClient = httpSolrClient;
} catch (Exception e) {
logger.error("Can't connect to Solr server. URL=" + solrURL, e);
throw e;
}
}
}
return solrClient;
}
Aggregations