Search in sources :

Example 71 with HttpSolrClient

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);
    }
}
Also used : RestTestHarness(org.apache.solr.util.RestTestHarness) SolrClient(org.apache.solr.client.solrj.SolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient)

Example 72 with HttpSolrClient

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;
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) HttpPost(org.apache.http.client.methods.HttpPost) HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) HttpGet(org.apache.http.client.methods.HttpGet) ArrayList(java.util.ArrayList) URI(java.net.URI) HttpHead(org.apache.http.client.methods.HttpHead)

Example 73 with HttpSolrClient

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);
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) Header(org.apache.http.Header) HttpClient(org.apache.http.client.HttpClient) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) Test(org.junit.Test)

Example 74 with HttpSolrClient

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();
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) LBHttpSolrClient(org.apache.solr.client.solrj.impl.LBHttpSolrClient) SolrRequest(org.apache.solr.client.solrj.SolrRequest) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) Test(org.junit.Test)

Example 75 with HttpSolrClient

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;
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) LBHttpSolrClient(org.apache.solr.client.solrj.impl.LBHttpSolrClient) DelegationTokenRequest(org.apache.solr.client.solrj.request.DelegationTokenRequest) DelegationTokenResponse(org.apache.solr.client.solrj.response.DelegationTokenResponse) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Aggregations

HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)187 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)48 SolrClient (org.apache.solr.client.solrj.SolrClient)46 Test (org.junit.Test)46 SolrQuery (org.apache.solr.client.solrj.SolrQuery)38 ArrayList (java.util.ArrayList)35 Replica (org.apache.solr.common.cloud.Replica)34 SolrInputDocument (org.apache.solr.common.SolrInputDocument)31 IOException (java.io.IOException)26 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)25 Slice (org.apache.solr.common.cloud.Slice)25 QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)24 SolrException (org.apache.solr.common.SolrException)23 SolrServerException (org.apache.solr.client.solrj.SolrServerException)21 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)20 NamedList (org.apache.solr.common.util.NamedList)19 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)18 DocCollection (org.apache.solr.common.cloud.DocCollection)18 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)15 ZkCoreNodeProps (org.apache.solr.common.cloud.ZkCoreNodeProps)15