use of org.apache.solr.client.solrj.impl.HttpSolrClient in project lucene-solr by apache.
the class TestConfigReload method setupHarnesses.
private void setupHarnesses() {
for (final SolrClient client : clients) {
RestTestHarness harness = new RestTestHarness(() -> ((HttpSolrClient) client).getBaseURL());
restTestHarnesses.add(harness);
}
}
use of org.apache.solr.client.solrj.impl.HttpSolrClient in project lucene-solr by apache.
the class CacheHeaderTestBase method getUpdateMethod.
protected HttpRequestBase getUpdateMethod(String method, String... params) throws URISyntaxException {
HttpSolrClient client = (HttpSolrClient) getSolrClient();
HttpRequestBase m = null;
ArrayList<BasicNameValuePair> qparams = new ArrayList<>();
for (int i = 0; i < params.length / 2; i++) {
qparams.add(new BasicNameValuePair(params[i * 2], params[i * 2 + 1]));
}
URI uri = URI.create(client.getBaseURL() + "/update?" + URLEncodedUtils.format(qparams, StandardCharsets.UTF_8));
if ("GET".equals(method)) {
m = new HttpGet(uri);
} else if ("POST".equals(method)) {
m = new HttpPost(uri);
} else if ("HEAD".equals(method)) {
m = new HttpHead(uri);
}
return m;
}
use of org.apache.solr.client.solrj.impl.HttpSolrClient in project lucene-solr by apache.
the class ResponseHeaderTest method testHttpResponse.
@Test
public void testHttpResponse() throws SolrServerException, IOException {
HttpSolrClient client = (HttpSolrClient) getSolrClient();
HttpClient httpClient = client.getHttpClient();
URI uri = URI.create(client.getBaseURL() + "/withHeaders?q=*:*");
HttpGet httpGet = new HttpGet(uri);
HttpResponse response = httpClient.execute(httpGet);
Header[] headers = response.getAllHeaders();
boolean containsWarningHeader = false;
for (Header header : headers) {
if ("Warning".equals(header.getName())) {
containsWarningHeader = true;
assertEquals("This is a test warning", header.getValue());
break;
}
}
assertTrue("Expected header not found", containsWarningHeader);
}
use of org.apache.solr.client.solrj.impl.HttpSolrClient in project lucene-solr by apache.
the class TestDelegationWithHadoopAuth method testDelegationTokenSolrClient.
/**
* Test HttpSolrServer's delegation token support
*/
@Test
public void testDelegationTokenSolrClient() throws Exception {
// Get token
String token = getDelegationToken(null, USER_1, primarySolrClient);
assertNotNull(token);
SolrRequest request = getAdminRequest(new ModifiableSolrParams());
// test without token
HttpSolrClient ss = new HttpSolrClient.Builder(primarySolrClient.getBaseURL().toString()).withResponseParser(primarySolrClient.getParser()).build();
try {
doSolrRequest(ss, request, ErrorCode.UNAUTHORIZED.code);
} finally {
ss.close();
}
ss = new HttpSolrClient.Builder(primarySolrClient.getBaseURL().toString()).withKerberosDelegationToken(token).withResponseParser(primarySolrClient.getParser()).build();
try {
// test with token via property
doSolrRequest(ss, request, HttpStatus.SC_OK);
// test with param -- should throw an exception
ModifiableSolrParams tokenParam = new ModifiableSolrParams();
tokenParam.set("delegation", "invalidToken");
try {
doSolrRequest(ss, getAdminRequest(tokenParam), ErrorCode.FORBIDDEN.code);
Assert.fail("Expected exception");
} catch (IllegalArgumentException ex) {
}
} finally {
ss.close();
}
}
use of org.apache.solr.client.solrj.impl.HttpSolrClient in project lucene-solr by apache.
the class TestDelegationWithHadoopAuth method renewDelegationToken.
private long renewDelegationToken(final String token, final int expectedStatusCode, final String user, HttpSolrClient client) throws Exception {
DelegationTokenRequest.Renew renew = new DelegationTokenRequest.Renew(token) {
@Override
public SolrParams getParams() {
ModifiableSolrParams params = new ModifiableSolrParams(super.getParams());
params.set(PseudoAuthenticator.USER_NAME, user);
return params;
}
@Override
public Set<String> getQueryParams() {
Set<String> queryParams = super.getQueryParams();
queryParams.add(PseudoAuthenticator.USER_NAME);
return queryParams;
}
};
try {
DelegationTokenResponse.Renew renewResponse = renew.process(client);
assertEquals(HttpStatus.SC_OK, expectedStatusCode);
return renewResponse.getExpirationTime();
} catch (HttpSolrClient.RemoteSolrException ex) {
assertEquals(expectedStatusCode, ex.code());
return -1;
}
}
Aggregations