{
- /**
- * Indicates whether the results are a preview from an unfinished search.
- * @return {@code true} if the results are a preview, {@code false} if not.
- */
- public boolean isPreview();
-
- /**
- * Returns a collection of field names from the results.
- * @return A collection of field names.
- *
- * Note that any given result will contain a subset of these fields.
- */
- public Collection getFields();
-}
+/*
+ * Copyright 2012 Splunk, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"): you may
+ * not use this file except in compliance with the License. You may obtain
+ * a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.splunk;
+
+import java.util.Collection;
+
+/**
+ * The {@code SearchResults} interface represents Splunk search results.
+ */
+public interface SearchResults extends Iterable {
+ /**
+ * Indicates whether the results are a preview from an unfinished search.
+ * @return {@code true} if the results are a preview, {@code false} if not.
+ */
+ public boolean isPreview();
+
+ /**
+ * Returns a collection of field names from the results.
+ * @return A collection of field names.
+ *
+ * Note that any given result will contain a subset of these fields.
+ */
+ public Collection getFields();
+}
diff --git a/splunk/src/main/java/com/splunk/Service.java b/splunk/src/main/java/com/splunk/Service.java
index 3af59b62..c8087070 100644
--- a/splunk/src/main/java/com/splunk/Service.java
+++ b/splunk/src/main/java/com/splunk/Service.java
@@ -1,1481 +1,1477 @@
-/*
- * Copyright 2012 Splunk, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"): you may
- * not use this file except in compliance with the License. You may obtain
- * a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- */
-
-package com.splunk;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.net.*;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-/**
- * The {@code Service} class represents a Splunk service instance at a given
- * address (host:port), accessed using the {@code http} or {@code https}
- * protocol scheme.
- *
- * A {@code Service} instance also captures an optional namespace context
- * consisting of an optional owner name (or "-" wildcard) and optional app name
- * (or "-" wildcard).
- *
- * To access {@code Service} members, the {@code Service} instance must be
- * authenticated by presenting credentials using the {@code login} method, or
- * by constructing the {@code Service} instance using the {@code connect}
- * method, which both creates and authenticates the instance.
- */
-public class Service extends BaseService {
- /** The current app context. */
- protected String app = null;
-
- /** The current session token. */
- protected String token = null;
-
- /** The current owner context. A value of "nobody" means that all users
- * have access to the resource.
- */
- protected String owner = null;
-
- /** The Splunk account username, which is used to authenticate the Splunk
- * instance. */
- protected String username = null;
-
- /** The password, which is used to authenticate the Splunk instance. */
- protected String password = null;
-
- /** The default simple receiver endpoint. */
- protected String simpleReceiverEndPoint = "/services/receivers/simple";
-
- /** The default password endpoint, can change over Splunk versions. */
- protected String passwordEndPoint = "admin/passwords";
-
- /** The version of this Splunk instance, once logged in. */
- public String version = null;
-
- /** The type of this Splunk instance, once logged in. */
- public String instanceType = null;
-
- /** The default host name, which is used when a host name is not provided.*/
- public static String DEFAULT_HOST = "localhost";
-
- /** The default port number, which is used when a port number is not
- * provided. */
- public static int DEFAULT_PORT = 8089;
-
- /** The default scheme, which is used when a scheme is not provided. */
- public static String DEFAULT_SCHEME = "https";
-
- /** Flag to notify SDK to try for re-login if the session has expired API call*/
- protected boolean autologin = false;
-
- /**
- * Creates a new {@code Service} instance using a host.
- *
- * @param host The host name.
- */
- public Service(String host) {
- super(host);
- }
-
- /**
- * Creates a new {@code Service} instance using a host and port.
- *
- * @param host The host name.
- * @param port The port number.
- */
- public Service(String host, int port) {
- super(host, port);
- }
-
- /**
- * Creates a new {@code Service} instance using a host, port, and
- * scheme for accessing the service ({@code http} or {@code https}).
- *
- * @param host The host name.
- * @param port The port number.
- * @param scheme The scheme ({@code http} or {@code https}).
- */
- public Service(String host, int port, String scheme) {
- super(host, port, scheme);
- }
-
- /**
- * Constructs a new {@code Service} instance using the given host,
- * port, and scheme, and instructing it to use the specified HTTPS handler.
- *
- * @param host The host name of the service.
- * @param port The port number of the service.
- * @param scheme Scheme for accessing the service ({@code http} or
- * {@code https}).
- * @param httpsHandler The URLStreamHandler instance
- */
- public Service(String host, int port, String scheme,
- URLStreamHandler httpsHandler) {
- this.host = host;
- this.port = port;
- this.scheme = scheme;
- this.httpsHandler = httpsHandler;
- }
-
- /**
- * Creates a new {@code Service} instance using a collection of arguments.
- *
- * @param args The {@code ServiceArgs} to initialize the service.
- */
- // NOTE: This overload exists primarily to provide better documentation
- // for the "args" parameter.
- @SuppressWarnings("deprecation")
- public Service(ServiceArgs args) {
- super();
- // NOTE: Must read the deprecated fields for backward compatibility.
- // (Consider the case where the fields are initialized directly,
- // rather than using the new setters.)
- // NOTE: Must also read the underlying dictionary for forward compatibility.
- // (Consider the case where the user calls Map.put() directly,
- // rather than using the new setters.)
- this.app = Args.get(args, "app", args.app != null ? args.app : null);
- this.host = Args.get(args, "host", args.host != null ? args.host : DEFAULT_HOST);
- this.owner = Args.get(args, "owner", args.owner != null ? args.owner : null);
- this.port = Args.get(args, "port", args.port != null ? args.port : DEFAULT_PORT);
- this.scheme = Args.get(args, "scheme", args.scheme != null ? args.scheme : DEFAULT_SCHEME);
- this.token = Args.get(args, "token", args.token != null ? args.token : null);
- this.username = (String)args.get("username");
- this.password = (String)args.get("password");
- this.autologin = Args.get(args, "autologin", false);
- this.httpsHandler = Args.get(args, "httpsHandler", null);
- this.setSslSecurityProtocol(Args.get(args, "SSLSecurityProtocol", Service.getSslSecurityProtocol()));
- this.addCookie((String)args.get("cookie"));
- this.setCustomHeaders((Map) args.get("customHeaders"));
- }
-
- /**
- * Creates a new {@code Service} instance using a map of arguments.
- *
- * @param args A {@code Map} of arguments to initialize the service.
- */
- public Service(Map args) {
- super();
- this.app = Args.get(args, "app", null);
- this.host = Args.get(args, "host", DEFAULT_HOST);
- this.owner = Args.get(args, "owner", null);
- this.port = Args.get(args, "port", DEFAULT_PORT);
- this.scheme = Args.get(args, "scheme", DEFAULT_SCHEME);
- this.token = Args.get(args, "token", null);
- this.username = (String)args.get("username");
- this.password = (String)args.get("password");
- this.autologin = Args.get(args, "autologin", false);
- this.httpsHandler = Args.get(args, "httpsHandler", null);
- this.setSslSecurityProtocol(Args.get(args, "SSLSecurityProtocol", Service.getSslSecurityProtocol()));
- this.addCookie((String)args.get("cookie"));
- this.connectTimeout = Args.get(args, "connectTimeout", null);
- this.readTimeout = Args.get(args, "readTimeout", null);
- }
-
- /**
- * Establishes a connection to a Splunk service using a map of arguments.
- * This member creates a new {@code Service} instance and authenticates
- * the session using credentials passed in from the {@code args} map.
- *
- * @param args The {@code args} map.
- * @return A new {@code Service} instance.
- */
- public static Service connect(Map args) {
- Service service = new Service(args);
- if (args.containsKey("username")) {
- service.login();
- }
- return service;
- }
-
- /**
- * Runs an export search (using the {@code search/jobs/export} endpoint),
- * and streams results back in an input stream.
- *
- * @param search The search query to run.
- * @return The {@code InputStream} object that contains the search results.
- */
- public InputStream export(String search) {
- return export(search, null);
- }
-
- /**
- * Runs an export search with arguments (using the {@code search/jobs/export}
- * endpoint), and streams results back in an input stream.
- *
- * @param search The search query to run.
- * @param args Additional search arguments.
- * For a list of possible parameters, see
- * Saved search parameters on
- * dev.splunk.com.
- * @return The {@code InputStream} object that contains the search results.
- */
- public InputStream export(String search, Map args) {
- args = Args.create(args).add("search", search);
- // By default don't highlight search terms in the output.
- if (!args.containsKey("segmentation")) {
- args.put("segmentation", "none");
- }
- ResponseMessage response;
-
- if(enableV2SearchApi())
- response = post(JobCollection.REST_PATH_V2 + "/export", args);
- else {
- response = post(JobCollection.REST_PATH + "/export", args);
- }
- return new ExportResultsStream(response.getContent());
- }
-
- /**
- * Runs an export search with arguments (using the {@code search/jobs/export}
- * endpoint), and streams results back in an input stream.
- *
- * @param search The search query to run.
- * @param args Additional search arguments (see {@code JobExportArgs}).
- * @return The {@code InputStream} object that contains the search results.
- */
- // NOTE: This overload exists primarily to provide better documentation
- // for the "args" parameter.
- public InputStream export(String search, JobExportArgs args) {
- return export(search, (Map) args);
- }
-
- /**
- * Ensures that the given path is fully qualified, prepending a path
- * prefix if necessary. The path prefix is constructed using the current
- * owner and app context when available.
- *
- * @param path The path to verify.
- * @return A fully-qualified resource path.
- */
- String fullpath(String path) {
- return fullpath(path, null);
- }
-
- /**
- * Ensures that a given path is fully qualified, prepending a path
- * prefix if necessary. The path prefix is constructed using the
- * current owner and app context when available.
- *
- * @param path The path to verify.
- * @param namespace The namespace dictionary (app, owner, sharing).
- * @return A fully-qualified resource path.
- */
- public String fullpath(String path, Args namespace) {
-
- // if already fully qualified (i.e. root begins with /) then return
- // the already qualified path.
- if (path.startsWith("/"))
- return path;
-
- // if no namespace at all, and no service instance of app, and no
- // sharing, return base service endpoint + path.
- if (namespace == null && app == null) {
- return "/services/" + path;
- }
-
- // base namespace values
- String localApp = app;
- String localOwner = owner;
- String localSharing = "";
-
- // override with invocation namespace if set.
- if (namespace != null) {
- // URL encode the owner and app.
- if (namespace.containsKey("app")) {
- try {
- localApp = URLEncoder.encode((String)namespace.get("app"), "UTF-8");
- } catch (UnsupportedEncodingException e) {
- // This is unreachable, since UTF-8 is always supported.
- assert false;
- }
- }
- if (namespace.containsKey("owner")) {
- try {
- localOwner = URLEncoder.encode((String)namespace.get("owner"), "UTF-8");
- } catch (UnsupportedEncodingException e) {
- // This is unreachable, since UTF-8 is always supported.
- assert false;
- }
- }
- if (namespace.containsKey("sharing")) {
- localSharing = (String)namespace.get("sharing");
- }
- }
-
- // sharing, if set calls for special mapping, override here.
- // "user" --> {user}/{app}
- // "app" --> nobody/{app}
- // "global" --> nobody/{app}
- // "system" --> nobody/system
- if (localSharing.equals("app") || localSharing.equals("global"))
- localOwner = "nobody";
- else if (localSharing.equals("system")) {
- localApp = "system";
- localOwner = "nobody";
- }
-
- return String.format("/servicesNS/%s/%s/%s",
- localOwner == null ? "-" : localOwner,
- localApp == null ? "-" : localApp,
- path);
- }
-
- /**
- * Returns the app context for this {@code Service} instance.
- * A {@code null} value indicates no app context, and a value of
- * {@code "-"} indicates an app wildcard.
- *
- * @return The app context.
- */
- public String getApp() {
- return this.app;
- }
-
- /**
- * Returns the collection of applications.
- *
- * @return The application collection.
- */
- public EntityCollection getApplications() {
- return new EntityCollection(
- this, "/services/apps/local", Application.class);
- }
-
- /**
- * Returns the collection of configurations.
- *
- * @return The configurations collection.
- */
- public ConfCollection getConfs() {
- return getConfs(null);
- }
-
- /**
- * Returns the collection of configurations.
- *
- * @param args Collection arguments that specify the number of entities to
- * return and how to sort them. See {@link CollectionArgs}.
- * @return The configurations collection.
- */
- public ConfCollection getConfs(Args args) {
- return new ConfCollection(this, args);
- }
-
- /**
- * Returns an array of system capabilities.
- *
- * @return An array of capabilities.
- */
- public String[] getCapabilities() {
- Entity caps = new Entity(this, "authorization/capabilities");
- return caps.getStringArray("capabilities");
- }
-
- /**
- * Returns the collection of data models.
- * @return DataModelCollection instance
- */
- public DataModelCollection getDataModels() {
- return new DataModelCollection(this);
- }
-
- /**
- * Returns the configuration and status of a deployment client.
- *
- * @return The configuration and status.
- */
- public DeploymentClient getDeploymentClient() {
- return new DeploymentClient(this);
- }
-
- /**
- * Returns the configuration of all deployment servers.
- *
- * @return The configuration of deployment servers.
- */
- public EntityCollection getDeploymentServers() {
- return getDeploymentServers(null);
- }
-
- /**
- * Returns the collection of deployment servers.
- *
- * @param args Collection arguments that specify the number of entities to
- * return and how to sort them. See {@link CollectionArgs}.
- * @return The configuration of deployment servers.
- */
- public EntityCollection getDeploymentServers(Args args) {
- String path;
- if (versionIsEarlierThan("6.0.0")) {
- path = "deployment/server";
- } else {
- path = ""; // TODO: Find out what this should be and fix it.
- }
- return new EntityCollection(
- this, "deployment/server", DeploymentServer.class, args);
- }
-
- /**
- * Returns a collection of class configurations for a deployment server.
- *
- * @return A collection of class configurations.
- */
- public EntityCollection getDeploymentServerClasses(){
- return getDeploymentServerClasses(null);
- }
-
- /**
- * Returns a collection of class configurations for a deployment server.
- *
- * @param args Collection arguments that specify the number of entities to
- * return and how to sort them. See {@link CollectionArgs}.
- * @return A collection of server class configurations.
- */
- public EntityCollection getDeploymentServerClasses(
- Args args) {
- String path;
- if (versionIsEarlierThan("6.0.0")) {
- path = "deployment/serverclass";
- } else {
- path = "deployment/server/serverclasses";
- }
- return new EntityCollection(
- this, path, DeploymentServerClass.class, args);
- }
-
- /**
- * Returns a collection of multi-tenant configurations.
- *
- * @return A collection of multi-tenant configurations.
- */
- public EntityCollection getDeploymentTenants() {
- return getDeploymentTenants(null);
- }
-
- /**
- * Returns a collection of multi-tenant configurations.
- *
- * @param args Collection arguments that specify the number of entities to
- * return and how to sort them. See {@link CollectionArgs}.
- * @return A collection of multi-tenant configurations.
- */
- public EntityCollection getDeploymentTenants(Args args) {
- return new EntityCollection