Java Code Examples for org.apache.solr.client.solrj.SolrRequest#METHOD

The following examples show how to use org.apache.solr.client.solrj.SolrRequest#METHOD . 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: SimScenario.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(SimScenario scenario) throws Exception {
  String path = params.get("path", "/");
  SolrRequest.METHOD m = SolrRequest.METHOD.valueOf(params.get("httpMethod", "GET"));
  params.remove("httpMethod");
  String streamBody = params.get("stream.body");
  params.remove("stream.body");
  GenericSolrRequest req = new GenericSolrRequest(m, path, params);
  if (streamBody != null) {
    req.setContentWriter(new RequestWriter.StringPayloadContentWriter(streamBody, "application/json"));
  }
  SolrResponse rsp = scenario.cluster.request(req);
  @SuppressWarnings({"unchecked"})
  List<SolrResponse> responses = (List<SolrResponse>) scenario.context.computeIfAbsent(RESPONSES_CTX_PROP, Utils.NEW_ARRAYLIST_FUN);
  responses.add(rsp);
}
 
Example 2
Source File: TestCollectionAPIs.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
static ZkNodeProps compareOutput(final ApiBag apiBag, final String path, final SolrRequest.METHOD method,
                          final String payload, final CoreContainer cc, String expectedOutputMapJson) throws Exception {
  Pair<SolrQueryRequest, SolrQueryResponse> ctx = makeCall(apiBag, path, method, payload, cc);
  ZkNodeProps output = (ZkNodeProps) ctx.second().getValues().get(ZkNodeProps.class.getName());
  @SuppressWarnings({"rawtypes"})
  Map expected = (Map) fromJSONString(expectedOutputMapJson);
  assertMapEqual(expected, output);
  return output;
}
 
Example 3
Source File: TestApiFramework.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private SolrQueryResponse invoke(PluginBag<SolrRequestHandler> reqHandlers, String path,
                                 String fullPath, SolrRequest.METHOD method,
                                 CoreContainer mockCC) {
  HashMap<String, String> parts = new HashMap<>();
  boolean containerHandlerLookup = mockCC.getRequestHandlers() == reqHandlers;
  path = path == null ? fullPath : path;
  Api api = null;
  if (containerHandlerLookup) {
    api = V2HttpCall.getApiInfo(reqHandlers, path, "GET", fullPath, parts);
  } else {
    api = V2HttpCall.getApiInfo(mockCC.getRequestHandlers(), fullPath, "GET", fullPath, parts);
    if (api == null) api = new CompositeApi(null);
    if (api instanceof CompositeApi) {
      CompositeApi compositeApi = (CompositeApi) api;
      api = V2HttpCall.getApiInfo(reqHandlers, path, "GET", fullPath, parts);
      compositeApi.add(api);
      api = compositeApi;
    }
  }

  SolrQueryResponse rsp = new SolrQueryResponse();
  LocalSolrQueryRequest req = new LocalSolrQueryRequest(null, new MapSolrParams(new HashMap<>())) {
    @Override
    public List<CommandOperation> getCommands(boolean validateInput) {
      return Collections.emptyList();
    }
  };

  api.call(req, rsp);
  return rsp;

}
 
Example 4
Source File: CloudTestUtils.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"rawtypes"})
public static SolrRequest create(SolrRequest.METHOD m, String subPath, String message, SolrParams params) {
  final boolean useV1 = LuceneTestCase.random().nextBoolean();
  String path = useV1 ? "/admin/autoscaling" : "/cluster/autoscaling";
  if (null != subPath) {
    assert subPath.startsWith("/");
    path += subPath;
  }
  return useV1
      ? new AutoScalingRequest(m, path, message).withParams(params)
      : new V2Request.Builder(path).withMethod(m).withParams(params).withPayload(message).build();

}
 
Example 5
Source File: TestCollectionAPIs.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public static Pair<SolrQueryRequest, SolrQueryResponse> makeCall(final ApiBag apiBag, String path,
                                                                 final SolrRequest.METHOD method,
                                                                 final String payload, final CoreContainer cc) throws Exception {
  SolrParams queryParams = new MultiMapSolrParams(Collections.emptyMap());
  if (path.indexOf('?') > 0) {
    String queryStr = path.substring(path.indexOf('?') + 1);
    path = path.substring(0, path.indexOf('?'));
    queryParams = SolrRequestParsers.parseQueryString(queryStr);
  }
  final HashMap<String, String> parts = new HashMap<>();
  Api api = apiBag.lookup(path, method.toString(), parts);
  if (api == null) throw new RuntimeException("No handler at path :" + path);
  SolrQueryResponse rsp = new SolrQueryResponse();
  LocalSolrQueryRequest req = new LocalSolrQueryRequest(null, queryParams) {
    @Override
    public List<CommandOperation> getCommands(boolean validateInput) {
      if (payload == null) return Collections.emptyList();
      return ApiBag.getCommandOperations(new ContentStreamBase.StringStream(payload), api.getCommandSchema(), true);
    }

    @Override
    public Map<String, String> getPathTemplateValues() {
      return parts;
    }

    @Override
    public String getHttpMethod() {
      return method.toString();
    }
  };
  try {
    api.call(req, rsp);
  } catch (ApiBag.ExceptionWithErrObject e) {
    throw new RuntimeException(e.getMessage() + Utils.toJSONString(e.getErrs()), e);

  }
  return new Pair<>(req, rsp);
}
 
Example 6
Source File: ApiBag.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public synchronized Api unregister(SolrRequest.METHOD method, String path) {
  List<String> l = PathTrie.getPathSegments(path);
  List<String> introspectPath = new ArrayList<>(l);
  introspectPath.add("_introspect");
  getRegistry(method.toString()).remove(introspectPath);
  return getRegistry(method.toString()).remove(l);
}
 
Example 7
Source File: CoreApiMapping.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked"})
Meta(EndPoint endPoint, SolrRequest.METHOD method, CoreAdminAction action, String commandName,
     @SuppressWarnings({"rawtypes"})Map paramstoAttr) {
  this.commandName = commandName;
  this.endPoint = endPoint;
  this.method = method;
  this.paramstoAttr = paramstoAttr == null ? Collections.EMPTY_MAP : Collections.unmodifiableMap(paramstoAttr);
  this.action = action;
}
 
Example 8
Source File: DelegatingCloudManager.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public byte[] httpRequest(String url, SolrRequest.METHOD method, Map<String, String> headers, String payload, int timeout, boolean followRedirects) throws IOException {
  return delegate.httpRequest(url, method, headers, payload, timeout, followRedirects);
}
 
Example 9
Source File: SimCloudManager.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
/**
 * HTTP requests are not supported by this implementation.
 */
@Override
public byte[] httpRequest(String url, SolrRequest.METHOD method, Map<String, String> headers, String payload, int timeout, boolean followRedirects) throws IOException {
  throw new UnsupportedOperationException("general HTTP requests are not supported yet");
}
 
Example 10
Source File: TestCollectionAPIs.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
static void assertErrorContains(final ApiBag apiBag, final String path, final SolrRequest.METHOD method,
    final String payload, final CoreContainer cc, String expectedErrorMsg) throws Exception {
  RuntimeException e = expectThrows(RuntimeException.class, () -> makeCall(apiBag, path, method, payload, cc));
  assertTrue("Expected exception with error message '" + expectedErrorMsg + "' but got: " + e.getMessage(),
      e.getMessage().contains(expectedErrorMsg));
}
 
Example 11
Source File: CollectionApiMapping.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public SolrRequest.METHOD getHttpMethod() {
  return method;
}
 
Example 12
Source File: CollectionApiMapping.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
ConfigSetMeta(ConfigSetEndPoint endPoint, SolrRequest.METHOD method, String cmdName, ConfigSetAction action) {
  this.cmdName = cmdName;
  this.endPoint = endPoint;
  this.method = method;
  this.action = action;
}
 
Example 13
Source File: CollectionApiMapping.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public SolrRequest.METHOD getHttpMethod() {
  return method;
}
 
Example 14
Source File: CollectionApiMapping.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
Meta(EndPoint endPoint, SolrRequest.METHOD method, CollectionAction action,
     String commandName,
     @SuppressWarnings({"rawtypes"})Map paramsToAttrs) {
  this(endPoint, method, action, commandName, paramsToAttrs, Collections.emptyMap());
}
 
Example 15
Source File: CollectionApiMapping.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
public SolrRequest.METHOD getMethod() {
  return method;
}
 
Example 16
Source File: CoreApiMapping.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@Override
public SolrRequest.METHOD getHttpMethod() {
  return method;
}
 
Example 17
Source File: CollectionApiMapping.java    From lucene-solr with Apache License 2.0 2 votes vote down vote up
/**
 * the http method supported by this command
 */
SolrRequest.METHOD getHttpMethod();
 
Example 18
Source File: CloudTestUtils.java    From lucene-solr with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a request using a randomized root path (V1 vs V2)
 *
 * @param m HTTP Method to use
 * @param subPath optional sub-path under <code>"$ROOT/autoscaling"</code>. may be null, 
 *        otherwise must start with "/"
 * @param message JSON payload, may be null
 */
@SuppressWarnings({"rawtypes"})
public static SolrRequest create(SolrRequest.METHOD m, String subPath, String message) {
  return create(m,subPath,message,null);

}
 
Example 19
Source File: CustomContainerPlugins.java    From lucene-solr with Apache License 2.0 2 votes vote down vote up
public SolrRequest.METHOD getMethod(){
  return api.getEndPoint().method()[0];

}
 
Example 20
Source File: SolrCloudManager.java    From lucene-solr with Apache License 2.0 votes vote down vote up
byte[] httpRequest(String url, SolrRequest.METHOD method, Map<String, String> headers, String payload, int timeout, boolean followRedirects) throws IOException;