Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.englishtown.vertx.solr.impl;
  
 
 import java.net.URI;
Default implementation of com.englishtown.vertx.solr.VertxSolrClient
 
 public class DefaultVertxSolrClient implements VertxSolrClient {
 
     private static final String DEFAULT_PATH = "/select";
     protected String baseUrl;
     protected HttpClient httpClient;
 
     @Inject
     public DefaultVertxSolrClient(Vertx vertxString baseUrlHttpClientOptions options) {
 
         if (baseUrl == null) {
             throw new IllegalArgumentException("The base URL cannot be null");
         }
         if (baseUrl.indexOf('?') >= 0) {
             throw new IllegalArgumentException("The base URL must not contain parameters: "
                     + baseUrl);
         }
         if (baseUrl.endsWith("/")) {
             baseUrl = baseUrl.substring(0, baseUrl.length() - 1);
         }
 
         this. = baseUrl;
         this. = vertx.createHttpClient(options);
 
     }
 
     @Override
     public void setInvariantParams(SolrParams params) {
         if (params != null) {
             .add(params);
         }
     }
 
     @Override
     public void request(SolrRequest requestHandler<AsyncResult<JsonObject>> resultHandler) {
 
         if (request.getMethod() != ..) {
             throw new IllegalStateException("Only GET operations are currently supported");
         }
 
         String path = request.getPath();
         if (path == null || !path.startsWith("/")) {
             path = ;
         }
 
         ModifiableSolrParams params = new ModifiableSolrParams(request.getParams());
         params.set(."json");
 
         if ( != null) {
             params.add();
         }
 
         // Remove credentials so they don't appear in the http request query string
         String authUser = params.get(.);
         String authPassword = params.get(.);
         params.remove(.);
         params.remove(.);
 
         URI uri = URI.create( + path + ClientUtils.toQueryString(paramsfalse));
         int port = uri.getPort() > 0 ? uri.getPort() : ("https".equals(uri.getScheme()) ? 443 : 80);
 
         HttpClientRequest httpRequest = .request(.porturi.getHost(), uri.getPath() + "?" + uri.getQuery());
 
         if ((authUser != null && !authUser.isEmpty()) && (authPassword != null && !authPassword.isEmpty())) {
             String authHeader = authUser + ":" + authPassword;
             String encodedHeader = new String(Base64.getEncoder().encode(authHeader.getBytes()));
             httpRequest.putHeader("Authorization""Basic " + encodedHeader);
         }
 
         httpRequest
                 .exceptionHandler(t -> resultHandler.handle(Future.failedFuture(t)))
                 .handler(response -> {
                     if (response.statusCode() != 200) {
                         resultHandler.handle(Future.failedFuture(new SolrServerException("Received http response status " + response.statusCode())));
                         return;
                    }
                    String contentType = response.headers().get(.);
                    if (contentType == null || !contentType.startsWith("application/json")) {
                        resultHandler.handle(Future.failedFuture(new SolrServerException("Recieved content type " + contentType)));
                        return;
                    }
                    response.bodyHandler(body -> {
                        JsonObject json = new JsonObject(body.toString());
                        resultHandler.handle(Future.succeededFuture(json));
                    });
                })
                .setTimeout(30000)
                .end();
    }
    @Override
    public void stop() {
        if ( != null) {
            .close();
        }
    }
New to GrepCode? Check out our FAQ X