- * You also can specify additional roles that have been created.
+ * You also can specify additional roles that have been created.
*
* @param importedRole A role from which to import attributes.
*/
diff --git a/splunk/com/splunk/SSLSecurityProtocol.java b/splunk/src/main/java/com/splunk/SSLSecurityProtocol.java
similarity index 100%
rename from splunk/com/splunk/SSLSecurityProtocol.java
rename to splunk/src/main/java/com/splunk/SSLSecurityProtocol.java
diff --git a/splunk/com/splunk/SavedSearch.java b/splunk/src/main/java/com/splunk/SavedSearch.java
similarity index 97%
rename from splunk/com/splunk/SavedSearch.java
rename to splunk/src/main/java/com/splunk/SavedSearch.java
index adf87fcb..b01fe17d 100644
--- a/splunk/com/splunk/SavedSearch.java
+++ b/splunk/src/main/java/com/splunk/SavedSearch.java
@@ -58,6 +58,7 @@ public void acknowledge() {
* Runs the saved search.
*
* @return The search job.
+ * @throws InterruptedException The InterruptedException instance
*/
public Job dispatch() throws InterruptedException {
return dispatch(null);
@@ -67,24 +68,23 @@ public Job dispatch() throws InterruptedException {
* Runs the saved search using dispatch arguments.
*
* @param args Dispatch arguments: args) {
+ ResponseMessage response = service.get(actionPath("history"), args);
+ return parseHistoryResponse(response);
+ }
+
+ /**
+ * Parses response message from history action path
+ *
+ * @param response
+ * @return result An array of Job
+ */
+ private Job[] parseHistoryResponse(final ResponseMessage response) {
AtomFeed feed;
try {
feed = AtomFeed.parseStream(response.getContent());
@@ -169,7 +192,7 @@ public String getActionEmailCc() {
*
* Generally, this command is a template search pipeline that is realized
* with values from the saved search. To reference saved search field
- * values, wrap them in "$". For example, use "$name$" to reference the
+ * values, wrap them in "$". For example, use "$name$" to reference the
* saved search name, or use "$search$" to reference the search query.
*
* @return The search command (or pipeline).
@@ -629,7 +652,7 @@ public String getActionSummaryIndexName() {
*
* Generally, this command is a template search pipeline that is realized
* with values from the saved search. To reference saved search field
- * values, wrap them in "$". For example, use "$name$" to reference the
+ * values, wrap them in "$". For example, use "$name$" to reference the
* saved search name, or use "$search$" to reference the search query.
*
* @return The search command (or pipeline).
@@ -905,7 +928,7 @@ public int getDispatchMaxCount() {
public int getDispatchMaxTime() {
return getInteger("dispatch.max_time");
}
-
+
/**
* Returns how frequently Splunk runs the MapReduce reduce phase
* on accumulated map values.
@@ -927,7 +950,7 @@ public int getDispatchReduceFrequency() {
public boolean getDispatchRtBackfill() {
return getDispatchRealTimeBackfill();
}
-
+
/**
* Indicates whether to back fill the real-time window for this search.
* This attribute only applies to real-time searches.
@@ -1163,6 +1186,30 @@ public boolean isVisible() {
return getBoolean("is_visible");
}
+ /**
+ * Indicates whether embedding is enabled for the search.
+ *
+ * @return {@code true} if the search is enabled for the search, {@code false} if not.
+ */
+ public boolean isEmbedEnabled() {
+ if (service.versionIsEarlierThan("6.2.0")){
+ throw new UnsupportedOperationException();
+ }
+ return getBoolean("embed.enabled");
+ }
+
+ /**
+ * Returns the authorization token for embedding the search.
+ *
+ * @return The authorization token for embedding the search.
+ */
+ public String getEmbedToken() {
+ if (service.versionIsEarlierThan("6.2.0")) {
+ throw new UnsupportedOperationException();
+ }
+ return getString("embed.token", null);
+ }
+
/**
* Sets the password to use when authenticating with the SMTP server.
* Normally this value will be set when editing the email settings, however
@@ -1210,7 +1257,7 @@ public void setActionEmailCc(String cc) {
*
* Generally, this command is a template search pipeline that is realized
* with values from the saved search. To reference saved search field
- * values, wrap them in "$". For example, use "$name$" to reference the
+ * values, wrap them in "$". For example, use "$name$" to reference the
* saved search name, or use "$search$" to reference the search query.
*
* @param command The search command (or pipeline).
@@ -1522,7 +1569,7 @@ public void setActionPopulateLookupTtl(String ttl) {
*
* Generally, this command is a template search pipeline that is realized
* with values from the saved search. To reference saved search field
- * values, wrap them in "$". For example, use "$name$" to reference the
+ * values, wrap them in "$". For example, use "$name$" to reference the
* saved search name, or use "$search$" to reference the search query.
*
* @param command The search command (or pipeline).
@@ -1589,7 +1636,7 @@ public void setActionRssTtl(String ttl) {
*
* Generally, this command is a template search pipeline that is realized
* with values from the saved search. To reference saved search field
- * values, wrap them in "$". For example, use "$name$" to reference the
+ * values, wrap them in "$". For example, use "$name$" to reference the
* saved search name, or use "$search$" to reference the search query.
*
* @param command The search command (or pipeline).
@@ -1677,7 +1724,7 @@ public void setActionSummaryIndexName(String name) {
*
* Generally, this command is a template search pipeline that is realized
* with values from the saved search. To reference saved search field
- * values, wrap them in "$". For example, use "$name$" to reference the
+ * values, wrap them in "$". For example, use "$name$" to reference the
* saved search name, or use "$search$" to reference the search query.
*
* @param command The search command (or pipeline).
@@ -1807,7 +1854,7 @@ public void setAlertSuppress(boolean suppress) {
/**
* Specifies a list of fields to use for alert suppression. This attribute
- * is required when alert supression and per-result alerting are enabled.
+ * is required when alert suppression and per-result alerting are enabled.
* @see #setAlertSuppress
* @see #isDigestMode
*
@@ -1929,7 +1976,7 @@ public void setDisabled(boolean disabled) {
public void setDispatchBuckets(String buckets) {
setDispatchBuckets(Integer.parseInt(buckets));
}
-
+
/**
* Sets the maximum number of timeline buckets.
*
@@ -2136,7 +2183,7 @@ public void setRequestUiDispatchView(String view) {
public void setRestartOnSearchpeerAdd(boolean restart) {
setRestartOnSearchPeerAdd(restart);
}
-
+
/**
* Sets whether a real-time search managed by the scheduler is
* restarted when a search peer becomes available for this saved search.
diff --git a/splunk/com/splunk/SavedSearchCollection.java b/splunk/src/main/java/com/splunk/SavedSearchCollection.java
similarity index 100%
rename from splunk/com/splunk/SavedSearchCollection.java
rename to splunk/src/main/java/com/splunk/SavedSearchCollection.java
diff --git a/splunk/com/splunk/SavedSearchCollectionArgs.java b/splunk/src/main/java/com/splunk/SavedSearchCollectionArgs.java
similarity index 100%
rename from splunk/com/splunk/SavedSearchCollectionArgs.java
rename to splunk/src/main/java/com/splunk/SavedSearchCollectionArgs.java
diff --git a/splunk/com/splunk/SavedSearchDispatchArgs.java b/splunk/src/main/java/com/splunk/SavedSearchDispatchArgs.java
similarity index 100%
rename from splunk/com/splunk/SavedSearchDispatchArgs.java
rename to splunk/src/main/java/com/splunk/SavedSearchDispatchArgs.java
diff --git a/splunk/com/splunk/ScriptInput.java b/splunk/src/main/java/com/splunk/ScriptInput.java
similarity index 100%
rename from splunk/com/splunk/ScriptInput.java
rename to splunk/src/main/java/com/splunk/ScriptInput.java
diff --git a/splunk/com/splunk/SearchResults.java b/splunk/src/main/java/com/splunk/SearchResults.java
similarity index 100%
rename from splunk/com/splunk/SearchResults.java
rename to splunk/src/main/java/com/splunk/SearchResults.java
diff --git a/splunk/com/splunk/Service.java b/splunk/src/main/java/com/splunk/Service.java
similarity index 89%
rename from splunk/com/splunk/Service.java
rename to splunk/src/main/java/com/splunk/Service.java
index 9001cfc9..57609010 100644
--- a/splunk/com/splunk/Service.java
+++ b/splunk/src/main/java/com/splunk/Service.java
@@ -19,9 +19,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
-import java.net.Socket;
-import java.net.URLEncoder;
-import java.net.URLStreamHandler;
+import java.net.*;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
/**
@@ -58,7 +58,7 @@ public class Service extends BaseService {
protected String password = null;
/** The default simple receiver endpoint. */
- protected String simpleReceiverEndPoint = "receivers/simple";
+ protected String simpleReceiverEndPoint = "/services/receivers/simple";
/** The default password endpoint, can change over Splunk versions. */
protected String passwordEndPoint = "admin/passwords";
@@ -66,6 +66,9 @@ public class Service extends BaseService {
/** 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";
@@ -115,6 +118,7 @@ public Service(String host, int port, String scheme) {
* @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) {
@@ -151,6 +155,7 @@ public Service(ServiceArgs args) {
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"));
}
/**
@@ -171,6 +176,8 @@ public Service(Map args) {
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);
}
/**
@@ -219,7 +226,13 @@ public InputStream export(String search, Map args) {
if (!args.containsKey("segmentation")) {
args.put("segmentation", "none");
}
- ResponseMessage response = get(JobCollection.REST_PATH + "/export", args);
+ 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());
}
@@ -371,6 +384,7 @@ public String[] getCapabilities() {
/**
* Returns the collection of data models.
+ * @return DataModelCollection instance
*/
public DataModelCollection getDataModels() {
return new DataModelCollection(this);
@@ -580,6 +594,35 @@ public ServiceInfo getInfo() {
return new ServiceInfo(this);
}
+ /**
+ * Returns list of all applicable Cluster Master Hosts for the SearchHead Service.
+ *
+ * @return List of Cluster Master Host(s).
+ */
+ public List getClusterMasters(){
+ Entity caps = new Entity(this, "cluster/config");
+ List hosts = new ArrayList();
+ try {
+ String clusterMasterURIs = caps.getString("master_uri");
+ URL clusterMasterUrl;
+ //for multi-cluster environment, there might be more than cluster master for the searchHead
+ if(clusterMasterURIs.contains(",")){
+ String[] masterURIs = clusterMasterURIs.split(",");
+ for(String uri : masterURIs){
+ clusterMasterUrl = new URL(uri);
+ hosts.add(clusterMasterUrl.getHost());
+ }
+ }else {
+ clusterMasterUrl = new URL(clusterMasterURIs);
+ hosts.add(clusterMasterUrl.getHost());
+ }
+ return hosts;
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+ return hosts;
+ }
+
/**
* Returns a collection of configured inputs.
*
@@ -1009,6 +1052,16 @@ public SavedSearchCollection getSavedSearches(Args args) {
return new SavedSearchCollection(this, args);
}
+ /**
+ * Returns a Saved Search by the provided title key.
+ *
+ * @param title The title for a job.
+ * @return A SavedSearch.
+ */
+ public SavedSearch getSavedSearch(String title) {
+ return new SavedSearch(this, JobCollection.REST_PATH + "/" + title);
+ }
+
/**
* Returns service configuration information for an instance of Splunk.
*
@@ -1091,7 +1144,7 @@ public UserCollection getUsers(Args args) {
* @return The current {@code Service} instance.
*/
public Service login() {
- if (!this.cookieStore.isEmpty() && (this.username == null || this.password == null)) {
+ if (this.cookieStore.hasSplunkAuthCookie() && (this.username == null || this.password == null)) {
return this;
}
else if (this.username == null || this.password == null) {
@@ -1126,6 +1179,7 @@ public Service login(String username, String password) {
.getTextContent();
this.token = "Splunk " + sessionKey;
this.version = this.getInfo().getVersion();
+ this.instanceType = this.getInfo().getInstanceType();
if (versionCompare("4.3") >= 0)
this.passwordEndPoint = "storage/passwords";
@@ -1209,7 +1263,7 @@ public InputStream oneshotSearch(String query, Args args) {
* @param port The port to open. This port must already have been
* created as an allowable TCP input to the service.
* @return The socket.
- * @throws java.io.IOException
+ * @throws java.io.IOException The IOException instance
*/
public Socket open(int port) throws IOException {
return new Socket(this.host, port);
@@ -1236,12 +1290,16 @@ public ResponseMessage parse(String query) {
*/
public ResponseMessage parse(String query, Map args) {
args = Args.create(args).add("q", query);
- return get("search/parser", args);
+
+ if(enableV2SearchApi())
+ return post("search/v2/parser", args);
+ else
+ return get("search/parser", args);
}
/**
* Restarts the service. The service will be unavailable until it has
- * sucessfully restarted.
+ * successfully restarted.
*
* @return The restart response message.
*/
@@ -1287,7 +1345,7 @@ public Job search(String query, Map args) {
*/
@Override public ResponseMessage send(String path, RequestMessage request) {
// cookieStore is a protected member of HttpService
- if (token != null && cookieStore.isEmpty()) {
+ if (token != null && !cookieStore.hasSplunkAuthCookie() ) {
request.getHeader().put("Authorization", token);
}
return super.send(fullpath(path), request);
@@ -1305,6 +1363,38 @@ public void setToken(String value) {
this.token = value;
}
+ /**
+ * Provides a session token having Splunk added before token.
+ * This method is specifically used when user just have token value.
+ *
+ * @param value The token value
+ */
+ public void setSplunkToken(String value) {
+ this.token = value.contains("Splunk") ? value : "Splunk " + value;
+ }
+
+ /**
+ * Provides a session token having Bearer added before token.
+ * This method is specifically used when user just have token value.
+ *
+ * @param value The token value
+ */
+ public void setBearerToken(String value) {
+ this.token = value.contains("Splunk") || value.contains("Bearer") ? value : "Bearer " + value;
+ }
+
+
+ public boolean enableV2SearchApi(){
+ if(null == this.instanceType){
+ this.instanceType = this.getInfo().getInstanceType();
+ }
+ if(this.instanceType.equalsIgnoreCase("cloud")) {
+ return versionIsAtLeast("9.0.2209");
+ }else{
+ return versionIsAtLeast("9.0.2");
+ }
+ }
+
/**
* Returns true if this Splunk instance's version is no earlier than
* the version specified in {@code version}.
@@ -1353,6 +1443,9 @@ boolean versionIsEarlierThan(String version) {
* or 1 if this version is greater than the given version.
*/
public int versionCompare(String otherVersion) {
+ if(null == this.version){
+ this.version = this.getInfo().getVersion();
+ }
String[] components1 = this.version.split("\\.");
String[] components2 = otherVersion.split("\\.");
int numComponents = Math.max(components1.length, components2.length);
diff --git a/splunk/com/splunk/ServiceArgs.java b/splunk/src/main/java/com/splunk/ServiceArgs.java
similarity index 94%
rename from splunk/com/splunk/ServiceArgs.java
rename to splunk/src/main/java/com/splunk/ServiceArgs.java
index 38670741..bf8f7f03 100644
--- a/splunk/com/splunk/ServiceArgs.java
+++ b/splunk/src/main/java/com/splunk/ServiceArgs.java
@@ -17,6 +17,7 @@
package com.splunk;
import java.net.URLStreamHandler;
+import java.util.Map;
/**
* The {@code ServiceArgs} class contains a collection of arguments that are
@@ -164,4 +165,12 @@ public void setUsername(String username) {
public void setCookie(String cookie) {
this.put("cookie", cookie);
}
+
+ /**
+ * @param httpHeaders
+ * A map of customHeaders.
+ */
+ public void setHttpHeaders(Map httpHeaders) {
+ this.put("customHeaders", httpHeaders);
+ }
}
diff --git a/splunk/com/splunk/ServiceInfo.java b/splunk/src/main/java/com/splunk/ServiceInfo.java
similarity index 96%
rename from splunk/com/splunk/ServiceInfo.java
rename to splunk/src/main/java/com/splunk/ServiceInfo.java
index 45d74ccb..16ec8aaa 100644
--- a/splunk/com/splunk/ServiceInfo.java
+++ b/splunk/src/main/java/com/splunk/ServiceInfo.java
@@ -34,8 +34,8 @@ public class ServiceInfo extends Entity {
*
* @return The build number.
*/
- public int getBuild() {
- return getInteger("build");
+ public String getBuild() {
+ return getString("build");
}
/**
@@ -155,6 +155,8 @@ public String getVersion() {
return getString("version");
}
+ public String getInstanceType() {return getString("instance_type", "");}
+
/**
* Indicates whether this Splunk instance is running under a free license.
*
diff --git a/splunk/com/splunk/Settings.java b/splunk/src/main/java/com/splunk/Settings.java
similarity index 100%
rename from splunk/com/splunk/Settings.java
rename to splunk/src/main/java/com/splunk/Settings.java
diff --git a/splunk/com/splunk/SimpleCookieStore.java b/splunk/src/main/java/com/splunk/SimpleCookieStore.java
similarity index 86%
rename from splunk/com/splunk/SimpleCookieStore.java
rename to splunk/src/main/java/com/splunk/SimpleCookieStore.java
index 274b1f94..4fd60664 100644
--- a/splunk/com/splunk/SimpleCookieStore.java
+++ b/splunk/src/main/java/com/splunk/SimpleCookieStore.java
@@ -28,6 +28,8 @@
*/
class SimpleCookieStore {
+ public static final String SPLUNK_AUTH_COOKIE = "splunkd_";
+
private Map cookieJar = new HashMap();
/**
* Adds cookies from a "Set-Cookie" header to the cookie store.
@@ -46,7 +48,7 @@ public void add(String setCookieHeader) {
/**
* Returns a string to be set as a "Cookie" header
*
- * @return Cookie String in the format "Key=Value; Key=Value; ect"
+ * @return Cookie String in the format "Key=Value; Key=Value; etc"
*/
public String getCookies() {
StringBuilder cookieStringBuilder = new StringBuilder();
@@ -69,6 +71,18 @@ public Boolean isEmpty() {
return cookieJar.isEmpty();
}
+ public boolean hasSplunkAuthCookie(){
+ if(cookieJar.isEmpty()){
+ return false;
+ }
+ for(String cookie : cookieJar.keySet()){
+ if(cookie.startsWith(SPLUNK_AUTH_COOKIE)){
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
* Removes all cookies from SimpleCookieStore
*/
diff --git a/splunk/com/splunk/SortDirection.java b/splunk/src/main/java/com/splunk/SortDirection.java
similarity index 100%
rename from splunk/com/splunk/SortDirection.java
rename to splunk/src/main/java/com/splunk/SortDirection.java
diff --git a/splunk/com/splunk/SplunkException.java b/splunk/src/main/java/com/splunk/SplunkException.java
similarity index 100%
rename from splunk/com/splunk/SplunkException.java
rename to splunk/src/main/java/com/splunk/SplunkException.java
diff --git a/splunk/com/splunk/StatsFunction.java b/splunk/src/main/java/com/splunk/StatsFunction.java
similarity index 100%
rename from splunk/com/splunk/StatsFunction.java
rename to splunk/src/main/java/com/splunk/StatsFunction.java
diff --git a/splunk/com/splunk/StreamIterableBase.java b/splunk/src/main/java/com/splunk/StreamIterableBase.java
similarity index 95%
rename from splunk/com/splunk/StreamIterableBase.java
rename to splunk/src/main/java/com/splunk/StreamIterableBase.java
index 8f69e8f1..8c423d3d 100644
--- a/splunk/com/splunk/StreamIterableBase.java
+++ b/splunk/src/main/java/com/splunk/StreamIterableBase.java
@@ -61,7 +61,7 @@ public void remove() {
/**
* Get the next element.
* @return null if the end is reached.
- * @throws IOException
+ * @throws IOException The IOException instance
*/
abstract T getNextElement() throws IOException;
diff --git a/splunk/com/splunk/StringComparison.java b/splunk/src/main/java/com/splunk/StringComparison.java
similarity index 100%
rename from splunk/com/splunk/StringComparison.java
rename to splunk/src/main/java/com/splunk/StringComparison.java
diff --git a/splunk/com/splunk/StringPivotColumnSplit.java b/splunk/src/main/java/com/splunk/StringPivotColumnSplit.java
similarity index 100%
rename from splunk/com/splunk/StringPivotColumnSplit.java
rename to splunk/src/main/java/com/splunk/StringPivotColumnSplit.java
diff --git a/splunk/com/splunk/StringPivotFilter.java b/splunk/src/main/java/com/splunk/StringPivotFilter.java
similarity index 86%
rename from splunk/com/splunk/StringPivotFilter.java
rename to splunk/src/main/java/com/splunk/StringPivotFilter.java
index cb1eab86..ca6769ee 100644
--- a/splunk/com/splunk/StringPivotFilter.java
+++ b/splunk/src/main/java/com/splunk/StringPivotFilter.java
@@ -43,9 +43,11 @@ JsonElement toJson() {
addCommonFields(root);
- root.add("comparator", new JsonPrimitive(this.comparison.toString()));
- root.add("compareTo", new JsonPrimitive(this.comparisonValue));
+ JsonObject filterRule = new JsonObject();
+ filterRule.add("comparator", new JsonPrimitive(this.comparison.toString()));
+ filterRule.add("compareTo", new JsonPrimitive(this.comparisonValue));
+ root.add("rule", filterRule);
return root;
}
}
diff --git a/splunk/com/splunk/StringPivotRowSplit.java b/splunk/src/main/java/com/splunk/StringPivotRowSplit.java
similarity index 100%
rename from splunk/com/splunk/StringPivotRowSplit.java
rename to splunk/src/main/java/com/splunk/StringPivotRowSplit.java
diff --git a/splunk/com/splunk/TcpConnections.java b/splunk/src/main/java/com/splunk/TcpConnections.java
similarity index 100%
rename from splunk/com/splunk/TcpConnections.java
rename to splunk/src/main/java/com/splunk/TcpConnections.java
diff --git a/splunk/com/splunk/TcpInput.java b/splunk/src/main/java/com/splunk/TcpInput.java
similarity index 97%
rename from splunk/com/splunk/TcpInput.java
rename to splunk/src/main/java/com/splunk/TcpInput.java
index 57e434e4..29faa6b5 100644
--- a/splunk/com/splunk/TcpInput.java
+++ b/splunk/src/main/java/com/splunk/TcpInput.java
@@ -39,6 +39,8 @@ public class TcpInput extends PortInput {
/**
* Returns a socket attached to this raw TCP input.
+ * @return Socket instance
+ * @throws IOException The IOException instance
*/
public Socket attach() throws IOException {
return new Socket(this.service.getHost(), this.getPort());
@@ -54,7 +56,9 @@ public Socket attach() throws IOException {
* How to
* get data into Splunk on
* dev.splunk.com.
+ * target="_blank">dev.splunk.com.
+ * @param behavior The ReceiverBehavior instance
+ * @throws IOException The IOException instance
*/
public void attachWith(ReceiverBehavior behavior) throws IOException {
Socket socket = null;
@@ -249,6 +253,7 @@ public void setIndex(String index) {
* @see #attachWith
*
* @param eventBody A string that contains the event.
+ * @throws IOException The IOException instance
*/
public void submit(String eventBody) throws IOException {
Socket socket = null;
diff --git a/splunk/com/splunk/TcpSplunkInput.java b/splunk/src/main/java/com/splunk/TcpSplunkInput.java
similarity index 100%
rename from splunk/com/splunk/TcpSplunkInput.java
rename to splunk/src/main/java/com/splunk/TcpSplunkInput.java
diff --git a/splunk/com/splunk/TimestampBinning.java b/splunk/src/main/java/com/splunk/TimestampBinning.java
similarity index 100%
rename from splunk/com/splunk/TimestampBinning.java
rename to splunk/src/main/java/com/splunk/TimestampBinning.java
diff --git a/splunk/com/splunk/TimestampPivotColumnSplit.java b/splunk/src/main/java/com/splunk/TimestampPivotColumnSplit.java
similarity index 100%
rename from splunk/com/splunk/TimestampPivotColumnSplit.java
rename to splunk/src/main/java/com/splunk/TimestampPivotColumnSplit.java
diff --git a/splunk/com/splunk/TimestampPivotRowSplit.java b/splunk/src/main/java/com/splunk/TimestampPivotRowSplit.java
similarity index 100%
rename from splunk/com/splunk/TimestampPivotRowSplit.java
rename to splunk/src/main/java/com/splunk/TimestampPivotRowSplit.java
diff --git a/splunk/com/splunk/UdpConnections.java b/splunk/src/main/java/com/splunk/UdpConnections.java
similarity index 100%
rename from splunk/com/splunk/UdpConnections.java
rename to splunk/src/main/java/com/splunk/UdpConnections.java
diff --git a/splunk/com/splunk/UdpInput.java b/splunk/src/main/java/com/splunk/UdpInput.java
similarity index 99%
rename from splunk/com/splunk/UdpInput.java
rename to splunk/src/main/java/com/splunk/UdpInput.java
index a68bf5a8..baa6ff7d 100644
--- a/splunk/com/splunk/UdpInput.java
+++ b/splunk/src/main/java/com/splunk/UdpInput.java
@@ -257,6 +257,7 @@ public void setSourceType(String sourcetype) {
* Send a string to this UDP input.
*
* @param eventBody The text to send.
+ * @throws IOException The IOException instance
*/
public void submit(String eventBody) throws IOException {
DatagramSocket socket = new DatagramSocket();
diff --git a/splunk/com/splunk/Upload.java b/splunk/src/main/java/com/splunk/Upload.java
similarity index 100%
rename from splunk/com/splunk/Upload.java
rename to splunk/src/main/java/com/splunk/Upload.java
diff --git a/splunk/com/splunk/User.java b/splunk/src/main/java/com/splunk/User.java
similarity index 100%
rename from splunk/com/splunk/User.java
rename to splunk/src/main/java/com/splunk/User.java
diff --git a/splunk/com/splunk/UserCollection.java b/splunk/src/main/java/com/splunk/UserCollection.java
similarity index 100%
rename from splunk/com/splunk/UserCollection.java
rename to splunk/src/main/java/com/splunk/UserCollection.java
diff --git a/splunk/com/splunk/Util.java b/splunk/src/main/java/com/splunk/Util.java
similarity index 100%
rename from splunk/com/splunk/Util.java
rename to splunk/src/main/java/com/splunk/Util.java
diff --git a/splunk/com/splunk/Value.java b/splunk/src/main/java/com/splunk/Value.java
similarity index 92%
rename from splunk/com/splunk/Value.java
rename to splunk/src/main/java/com/splunk/Value.java
index 9c7694ce..812bfcad 100644
--- a/splunk/com/splunk/Value.java
+++ b/splunk/src/main/java/com/splunk/Value.java
@@ -80,9 +80,9 @@ else if (value.endsWith("GB"))
* @param value Value to convert.
* @return Date value.
*/
- static Date toDate(String value) {
+ static synchronized Date toDate(String value) {
if (dateFormat == null) {
- dateFormat = new SimpleDateFormat[4];
+ dateFormat = new SimpleDateFormat[6];
dateFormat[0] = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
dateFormat[0].setLenient(true);
dateFormat[1] = new SimpleDateFormat("E MMM d HH:mm:ss z y");
@@ -91,6 +91,10 @@ static Date toDate(String value) {
dateFormat[2].setLenient(true);
dateFormat[3] = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
dateFormat[3].setLenient(true);
+ dateFormat[4] = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
+ dateFormat[4].setLenient(true);
+ dateFormat[5] = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
+ dateFormat[5].setLenient(true);
}
if (datePattern == null) {
String pattern = "(.*)\\.\\d+([\\-+]\\d+):(\\d+)";
@@ -98,9 +102,6 @@ static Date toDate(String value) {
}
for (SimpleDateFormat simpleDateFormat: dateFormat) {
- // Must first remove the colon (':') from the timezone
- // field, or SimpleDataFormat will not parse correctly.
- // Eg: 2010-01-01T12:00:00+01:00 => 2010-01-01T12:00:00+0100
try {
Matcher matcher = datePattern.matcher(value);
diff --git a/splunk/com/splunk/WindowsActiveDirectoryInput.java b/splunk/src/main/java/com/splunk/WindowsActiveDirectoryInput.java
similarity index 100%
rename from splunk/com/splunk/WindowsActiveDirectoryInput.java
rename to splunk/src/main/java/com/splunk/WindowsActiveDirectoryInput.java
diff --git a/splunk/com/splunk/WindowsEventLogInput.java b/splunk/src/main/java/com/splunk/WindowsEventLogInput.java
similarity index 100%
rename from splunk/com/splunk/WindowsEventLogInput.java
rename to splunk/src/main/java/com/splunk/WindowsEventLogInput.java
diff --git a/splunk/com/splunk/WindowsPerfmonInput.java b/splunk/src/main/java/com/splunk/WindowsPerfmonInput.java
similarity index 100%
rename from splunk/com/splunk/WindowsPerfmonInput.java
rename to splunk/src/main/java/com/splunk/WindowsPerfmonInput.java
diff --git a/splunk/com/splunk/WindowsRegistryInput.java b/splunk/src/main/java/com/splunk/WindowsRegistryInput.java
similarity index 100%
rename from splunk/com/splunk/WindowsRegistryInput.java
rename to splunk/src/main/java/com/splunk/WindowsRegistryInput.java
diff --git a/splunk/com/splunk/WindowsWmiInput.java b/splunk/src/main/java/com/splunk/WindowsWmiInput.java
similarity index 100%
rename from splunk/com/splunk/WindowsWmiInput.java
rename to splunk/src/main/java/com/splunk/WindowsWmiInput.java
diff --git a/splunk/com/splunk/Xml.java b/splunk/src/main/java/com/splunk/Xml.java
similarity index 87%
rename from splunk/com/splunk/Xml.java
rename to splunk/src/main/java/com/splunk/Xml.java
index 516e5f20..ef582f72 100644
--- a/splunk/com/splunk/Xml.java
+++ b/splunk/src/main/java/com/splunk/Xml.java
@@ -52,6 +52,10 @@ public static Document parse(InputStream input, boolean silent) {
try {
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
+ factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
+ factory.setExpandEntityReferences(false);
+ factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
+ factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
factory.setNamespaceAware(false);
DocumentBuilder builder = factory.newDocumentBuilder();
if (silent)
diff --git a/splunk/com/splunk/modularinput/Argument.java b/splunk/src/main/java/com/splunk/modularinput/Argument.java
similarity index 100%
rename from splunk/com/splunk/modularinput/Argument.java
rename to splunk/src/main/java/com/splunk/modularinput/Argument.java
diff --git a/splunk/com/splunk/modularinput/Event.java b/splunk/src/main/java/com/splunk/modularinput/Event.java
similarity index 100%
rename from splunk/com/splunk/modularinput/Event.java
rename to splunk/src/main/java/com/splunk/modularinput/Event.java
diff --git a/splunk/com/splunk/modularinput/EventWriter.java b/splunk/src/main/java/com/splunk/modularinput/EventWriter.java
similarity index 96%
rename from splunk/com/splunk/modularinput/EventWriter.java
rename to splunk/src/main/java/com/splunk/modularinput/EventWriter.java
index 8bb6858c..c6ce3425 100755
--- a/splunk/com/splunk/modularinput/EventWriter.java
+++ b/splunk/src/main/java/com/splunk/modularinput/EventWriter.java
@@ -102,6 +102,7 @@ protected void setError() {
* {@code EventWriter} does not throw {@code IOException} errors, but does not ignore them entirely either. Instead it operates
* the same way as {@code PrintStream} in the standard library. You can always check if an {@code IOException} has been thrown
* by calling {@code checkError}.
+ * @return boolean value
*/
public boolean checkError() {
return hadIOException;
@@ -110,6 +111,8 @@ public boolean checkError() {
/**
* Thread safe version of {@code writeEvent}.
* @see #writeEvent
+ * @param event The Event instance
+ * @throws MalformedDataException The MalformedDataException instance
*/
public synchronized void synchronizedWriteEvent(Event event) throws MalformedDataException {
writeEvent(event);
@@ -123,7 +126,7 @@ public synchronized void synchronizedWriteEvent(Event event) throws MalformedDat
*
* @see #synchronizedWriteEvent
* @param event The {@code Event} object to write.
- * @throws MalformedDataException
+ * @throws MalformedDataException The MalformedDataException instance
*/
public void writeEvent(Event event) throws MalformedDataException {
try {
@@ -144,6 +147,8 @@ public void writeEvent(Event event) throws MalformedDataException {
/**
* Thread safe version of {@code log}.
* @see #log
+ * @param severity String value
+ * @param errorMessage String value
*/
public synchronized void synchronizedLog(String severity, String errorMessage) {
log(severity, errorMessage);
diff --git a/splunk/com/splunk/modularinput/InputDefinition.java b/splunk/src/main/java/com/splunk/modularinput/InputDefinition.java
similarity index 93%
rename from splunk/com/splunk/modularinput/InputDefinition.java
rename to splunk/src/main/java/com/splunk/modularinput/InputDefinition.java
index aee87fcb..f7431e78 100755
--- a/splunk/com/splunk/modularinput/InputDefinition.java
+++ b/splunk/src/main/java/com/splunk/modularinput/InputDefinition.java
@@ -16,7 +16,6 @@
package com.splunk.modularinput;
-import com.splunk.modularinput.Parameter;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
@@ -69,6 +68,7 @@ public String getField(String fieldName) {
/**
* Sets the name of the server on which this modular input is being run.
+ * @param serverHost String value
*/
public void setServerHost(String serverHost) {
this.metadata.put(serverHostField, serverHost);
@@ -175,16 +175,20 @@ public static InputDefinition parseDefinition(InputStream stream) throws ParserC
IOException, SAXException, MalformedDataException {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setIgnoringElementContentWhitespace(true);
+ documentBuilderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
+ documentBuilderFactory.setExpandEntityReferences(false);
+ documentBuilderFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
+ documentBuilderFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document doc = documentBuilder.parse(stream);
InputDefinition definition = new InputDefinition();
for (Node node = doc.getDocumentElement().getFirstChild(); node != null; node = node.getNextSibling()) {
- if (node.getNodeType() == node.TEXT_NODE) {
+ if (node.getNodeType() == Node.TEXT_NODE) {
continue;
} else if (node.getNodeName().equals("configuration")) {
for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
- if (child.getNodeType() == child.TEXT_NODE) {
+ if (child.getNodeType() == Node.TEXT_NODE) {
continue;
}
if (!child.getNodeName().equals("stanza")) {
diff --git a/splunk/com/splunk/modularinput/MalformedDataException.java b/splunk/src/main/java/com/splunk/modularinput/MalformedDataException.java
similarity index 100%
rename from splunk/com/splunk/modularinput/MalformedDataException.java
rename to splunk/src/main/java/com/splunk/modularinput/MalformedDataException.java
diff --git a/splunk/com/splunk/modularinput/MultiValueParameter.java b/splunk/src/main/java/com/splunk/modularinput/MultiValueParameter.java
similarity index 100%
rename from splunk/com/splunk/modularinput/MultiValueParameter.java
rename to splunk/src/main/java/com/splunk/modularinput/MultiValueParameter.java
diff --git a/splunk/com/splunk/modularinput/NonblockingInputStream.java b/splunk/src/main/java/com/splunk/modularinput/NonblockingInputStream.java
similarity index 100%
rename from splunk/com/splunk/modularinput/NonblockingInputStream.java
rename to splunk/src/main/java/com/splunk/modularinput/NonblockingInputStream.java
diff --git a/splunk/com/splunk/modularinput/Parameter.java b/splunk/src/main/java/com/splunk/modularinput/Parameter.java
similarity index 92%
rename from splunk/com/splunk/modularinput/Parameter.java
rename to splunk/src/main/java/com/splunk/modularinput/Parameter.java
index 05fc21dc..23cb8585 100755
--- a/splunk/com/splunk/modularinput/Parameter.java
+++ b/splunk/src/main/java/com/splunk/modularinput/Parameter.java
@@ -63,21 +63,21 @@ public static List nodeToParameterList(Node node) throws MalformedDat
List parameters = new ArrayList();
for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
- if (child.getNodeType() == child.TEXT_NODE) {
+ if (child.getNodeType() == Node.TEXT_NODE) {
continue;
}
- if (child.getNodeName() == "param") {
+ if ("param".equals(child.getNodeName())) {
// This is a single value parameter
String name = child.getAttributes().getNamedItem("name").getNodeValue();
String value = XmlUtil.textInNode(child, "Element param with name=\"" + name +
"\" did not contain text.");
parameters.add(new SingleValueParameter(name, value));
- } else if (child.getNodeName() == "param_list") {
+ } else if ("param_list".equals(child.getNodeName())) {
String name = child.getAttributes().getNamedItem("name").getNodeValue();
MultiValueParameter parameter = new MultiValueParameter(name);
for (Node valueNode = child.getFirstChild(); valueNode != null; valueNode = valueNode.getNextSibling()) {
- if (valueNode.getNodeType() == valueNode.TEXT_NODE) continue;
- if (valueNode.getNodeName() != "value") {
+ if (valueNode.getNodeType() == Node.TEXT_NODE) continue;
+ if (!"value".equals(valueNode.getNodeName())) {
throw new MalformedDataException("Expected a value element in parameter named " +
child.getNodeName() + "; found " + valueNode.getNodeName());
} else {
diff --git a/splunk/com/splunk/modularinput/Scheme.java b/splunk/src/main/java/com/splunk/modularinput/Scheme.java
similarity index 100%
rename from splunk/com/splunk/modularinput/Scheme.java
rename to splunk/src/main/java/com/splunk/modularinput/Scheme.java
diff --git a/splunk/com/splunk/modularinput/Script.java b/splunk/src/main/java/com/splunk/modularinput/Script.java
similarity index 95%
rename from splunk/com/splunk/modularinput/Script.java
rename to splunk/src/main/java/com/splunk/modularinput/Script.java
index 249b61ed..96447c73 100755
--- a/splunk/com/splunk/modularinput/Script.java
+++ b/splunk/src/main/java/com/splunk/modularinput/Script.java
@@ -149,6 +149,7 @@ protected String stackTraceToLogEntry(Exception e) {
* The default implementation always passes.
*
* @param definition The parameters for the proposed input passed by splunkd.
+ * @throws Exception The exception instance
*/
public void validateInput(ValidationDefinition definition) throws Exception {}
@@ -156,7 +157,11 @@ public void validateInput(ValidationDefinition definition) throws Exception {}
* Streams events into Splunk. It should do all of its output via
* {@code EventWriter} rather than assuming that there is a console attached.
*
+ * @param inputs InputDefinition instance
* @param ew An object with methods to write events and log messages to Splunk.
+ * @throws MalformedDataException The MalformedDataException instance
+ * @throws XMLStreamException The XMLStreamException instance
+ * @throws IOException The IOException instance
*/
public abstract void streamEvents(InputDefinition inputs, EventWriter ew)
throws MalformedDataException, XMLStreamException, IOException;
diff --git a/splunk/com/splunk/modularinput/SingleValueParameter.java b/splunk/src/main/java/com/splunk/modularinput/SingleValueParameter.java
similarity index 100%
rename from splunk/com/splunk/modularinput/SingleValueParameter.java
rename to splunk/src/main/java/com/splunk/modularinput/SingleValueParameter.java
diff --git a/splunk/com/splunk/modularinput/ValidationDefinition.java b/splunk/src/main/java/com/splunk/modularinput/ValidationDefinition.java
similarity index 94%
rename from splunk/com/splunk/modularinput/ValidationDefinition.java
rename to splunk/src/main/java/com/splunk/modularinput/ValidationDefinition.java
index eadb3e36..3ce60106 100755
--- a/splunk/com/splunk/modularinput/ValidationDefinition.java
+++ b/splunk/src/main/java/com/splunk/modularinput/ValidationDefinition.java
@@ -194,12 +194,16 @@ public static ValidationDefinition parseDefinition(InputStream stream) throws Pa
IOException, SAXException, MalformedDataException {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setIgnoringElementContentWhitespace(true);
+ documentBuilderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
+ documentBuilderFactory.setExpandEntityReferences(false);
+ documentBuilderFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
+ documentBuilderFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document doc = documentBuilder.parse(stream);
ValidationDefinition definition = new ValidationDefinition();
for (Node node = doc.getDocumentElement().getFirstChild(); node != null; node = node.getNextSibling()) {
- if (node.getNodeType() == node.TEXT_NODE || node.getNodeType() == node.COMMENT_NODE) {
+ if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.COMMENT_NODE) {
continue;
} else if (node.getNodeName().equals("item")) {
String name = node.getAttributes().getNamedItem("name").getNodeValue();
diff --git a/splunk/com/splunk/modularinput/XmlUtil.java b/splunk/src/main/java/com/splunk/modularinput/XmlUtil.java
similarity index 94%
rename from splunk/com/splunk/modularinput/XmlUtil.java
rename to splunk/src/main/java/com/splunk/modularinput/XmlUtil.java
index 349b25a0..3082aa47 100755
--- a/splunk/com/splunk/modularinput/XmlUtil.java
+++ b/splunk/src/main/java/com/splunk/modularinput/XmlUtil.java
@@ -35,10 +35,12 @@ class XmlUtil {
*/
static String textInNode(Node node, String errorMessage) throws MalformedDataException {
Node child = node.getFirstChild();
- if (child.getNodeType() != child.TEXT_NODE) {
+ if (null == child) {
+ return "";
+ } else if (child.getNodeType() != Node.TEXT_NODE) {
throw new MalformedDataException(errorMessage);
} else {
- return ((Text)child).getData();
+ return ((Text) child).getData();
}
}
diff --git a/tests/com/splunk/ApplicationTest.java b/splunk/src/test/java/com/splunk/ApplicationTest.java
similarity index 91%
rename from tests/com/splunk/ApplicationTest.java
rename to splunk/src/test/java/com/splunk/ApplicationTest.java
index cdd60211..df8afe2a 100644
--- a/tests/com/splunk/ApplicationTest.java
+++ b/splunk/src/test/java/com/splunk/ApplicationTest.java
@@ -16,10 +16,7 @@
package com.splunk;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.*;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -74,17 +71,9 @@ public boolean predicate() {
@Test
public void testForEmptySetup() {
- // Newly created applications have no setup.
- try {
- application.setup().getSetupXml();
- Assert.fail("Expected HTTP 500.");
- }
- catch (HttpException e) {
- Assert.assertEquals(500, e.getStatus());
- Assert.assertTrue(
- e.getMessage().contains("does not exits") || // 4.3.2
- e.getMessage().contains("does not exist")); // 5.0rc5
- }
+ final String setupXml = application.setup().getSetupXml();
+ // Newly created applications now has a setup stub.
+ Assert.assertTrue(setupXml.contains("stub"));
}
@Test
@@ -96,18 +85,18 @@ public void testForSetupPresent() throws Exception {
installApplicationFromTestData("has_setup_xml");
Assert.assertTrue(service.getApplications().containsKey("has_setup_xml"));
Application applicationWithSetupXml = service.getApplications().get("has_setup_xml");
-
+
ApplicationSetup applicationSetup = applicationWithSetupXml.setup();
Assert.assertEquals("has_setup_xml", applicationSetup.getName());
Assert.assertFalse(applicationSetup.getRefresh());
-
+
String setupXml = applicationSetup.getSetupXml();
Document parsedSetupXml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
new ByteArrayInputStream(setupXml.getBytes("UTF-8")));
parsedSetupXml.getDocumentElement().normalize();
-
+
Assert.assertEquals(parsedSetupXml.getDocumentElement().getNodeName(), "SetupInfo");
-
+
NodeList blocks = parsedSetupXml.getDocumentElement().getElementsByTagName("block");
Assert.assertEquals(1, blocks.getLength());
Node block = blocks.item(0);
diff --git a/tests/com/splunk/ArgsTest.java b/splunk/src/test/java/com/splunk/ArgsTest.java
similarity index 100%
rename from tests/com/splunk/ArgsTest.java
rename to splunk/src/test/java/com/splunk/ArgsTest.java
diff --git a/tests/com/splunk/AtomFeedTest.java b/splunk/src/test/java/com/splunk/AtomFeedTest.java
similarity index 96%
rename from tests/com/splunk/AtomFeedTest.java
rename to splunk/src/test/java/com/splunk/AtomFeedTest.java
index 2142d082..e534e21a 100644
--- a/tests/com/splunk/AtomFeedTest.java
+++ b/splunk/src/test/java/com/splunk/AtomFeedTest.java
@@ -38,7 +38,7 @@ public class AtomFeedTest {
private static Map expectedData = reader.fromJson(
SDKTestCase.streamToString(
SDKTestCase.openResource(
- "data/atom_test_data.json")),
+ "/data/atom_test_data.json")),
Map.class);
private Map expectedFeed;
@@ -48,7 +48,7 @@ public class AtomFeedTest {
public AtomFeedTest(String testName) {
this.testName = testName;
this.expectedFeed = (Map)expectedData.get(testName);
- this.xmlStream = SDKTestCase.openResource("data/atom/" + testName + ".xml");
+ this.xmlStream = SDKTestCase.openResource("/data/atom/" + testName + ".xml");
}
@Test
diff --git a/tests/com/splunk/ConfigurationTest.java b/splunk/src/test/java/com/splunk/ConfigurationTest.java
similarity index 100%
rename from tests/com/splunk/ConfigurationTest.java
rename to splunk/src/test/java/com/splunk/ConfigurationTest.java
diff --git a/tests/com/splunk/CookieTest.java b/splunk/src/test/java/com/splunk/CookieTest.java
similarity index 80%
rename from tests/com/splunk/CookieTest.java
rename to splunk/src/test/java/com/splunk/CookieTest.java
index 06b8e813..d11cda76 100644
--- a/tests/com/splunk/CookieTest.java
+++ b/splunk/src/test/java/com/splunk/CookieTest.java
@@ -16,13 +16,12 @@
package com.splunk;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Assume;
-import org.junit.Test;
+import java.net.HttpCookie;
import java.util.HashMap;
import java.util.Map;
+import org.junit.*;
+
public class CookieTest extends SDKTestCase {
@Before
@@ -123,6 +122,47 @@ public void testLoginWithMultipleCookies() {
s.getSettings().refresh();
}
+ @Test
+ public void testLoginWithOtherCookies() {
+ String otherCookies = "load=balancer;";
+ service.logout();
+ service.cookieStore.removeAll();
+ service.cookieStore.add(otherCookies);
+ service.login();
+ service.getApplications();
+ service.cookieStore.removeAll();
+ }
+
+ @Test
+ public void testUsingAuthTokenAndOtherCookie(){
+ String validToken = service.getToken();
+ Assert.assertTrue(validToken.startsWith("Splunk "));
+ String otherCookies = "load=balancer;";
+ Map args = new HashMap<>();
+ args.put("cookie", otherCookies);
+ args.put("host",service.getHost());
+ args.put("port", service.getPort());
+ Service s = new Service(args);
+ s.setToken(validToken);
+ s.getApplications();
+ Assert.assertEquals(otherCookies.trim(),s.cookieStore.getCookies().trim());
+ }
+
+ @Test
+ public void testLoginWithMultipleInvalidCookies() {
+ String validCookie = service.stringifyCookies();
+
+ Map args = getStandardArgs();
+
+ Service s = new Service(args);
+
+ s.addCookie("bad=cookie");
+ s.addCookie(validCookie);
+ s.addCookie("another_bad=cookie");
+
+ s.getSettings().refresh();
+ }
+
@Test
public void testLoginWithMultipleCookiesReversed() {
String validCookie = service.stringifyCookies();
diff --git a/tests/com/splunk/DataModelTest.java b/splunk/src/test/java/com/splunk/DataModelTest.java
similarity index 91%
rename from tests/com/splunk/DataModelTest.java
rename to splunk/src/test/java/com/splunk/DataModelTest.java
index ae2e5465..2a8585e8 100644
--- a/tests/com/splunk/DataModelTest.java
+++ b/splunk/src/test/java/com/splunk/DataModelTest.java
@@ -39,7 +39,7 @@ public void testDataModelCollectionCreateAndDelete() {
EntityCollection dataModels = service.getDataModels();
DataModelArgs args = new DataModelArgs();
- args.setRawJsonDescription(streamToString(openResource("data/datamodels/empty_data_model.json")));
+ args.setRawJsonDescription(streamToString(openResource("/data/datamodels/empty_data_model.json")));
int initialN = dataModels.size();
@@ -65,7 +65,7 @@ public void testDataModelWithZeroObjects() {
EntityCollection dataModels = service.getDataModels();
DataModelArgs args = new DataModelArgs();
- args.setRawJsonDescription(streamToString(openResource("data/datamodels/empty_data_model.json")));
+ args.setRawJsonDescription(streamToString(openResource("/data/datamodels/empty_data_model.json")));
DataModel model = dataModels.create(createTemporaryName(), args);
Assert.assertEquals(0, model.getObjects().size());
@@ -80,7 +80,7 @@ public void testDataModelWithOneObject() {
EntityCollection dataModels = service.getDataModels();
DataModelArgs args = new DataModelArgs();
- args.setRawJsonDescription(streamToString(openResource("data/datamodels/object_with_one_search.json")));
+ args.setRawJsonDescription(streamToString(openResource("/data/datamodels/object_with_one_search.json")));
DataModel model = dataModels.create(createTemporaryName(), args);
Assert.assertEquals(1, model.getObjects().size());
@@ -95,7 +95,7 @@ public void testDataModelWithTwoObjects() {
EntityCollection dataModels = service.getDataModels();
DataModelArgs args = new DataModelArgs();
- args.setRawJsonDescription(streamToString(openResource("data/datamodels/object_with_two_searches.json")));
+ args.setRawJsonDescription(streamToString(openResource("/data/datamodels/object_with_two_searches.json")));
DataModel model = dataModels.create(createTemporaryName(), args);
Assert.assertEquals(2, model.getObjects().size());
@@ -110,7 +110,7 @@ public void testGetAndContainsObjectWork() {
EntityCollection dataModels = service.getDataModels();
DataModelArgs args = new DataModelArgs();
- args.setRawJsonDescription(streamToString(openResource("data/datamodels/object_with_two_searches.json")));
+ args.setRawJsonDescription(streamToString(openResource("/data/datamodels/object_with_two_searches.json")));
DataModel model = dataModels.create(createTemporaryName(), args);
Assert.assertTrue(model.containsObject("search1"));
@@ -132,7 +132,7 @@ public void testDataModelWithUnicodeAttributes() {
String modelName = createTemporaryName();
DataModelArgs args = new DataModelArgs();
- args.setRawJsonDescription(streamToString(openResource("data/datamodels/model_with_unicode_headers.json")));
+ args.setRawJsonDescription(streamToString(openResource("/data/datamodels/model_with_unicode_headers.json")));
DataModel model = dataModels.create(modelName, args);
Assert.assertEquals(modelName, model.getName());
@@ -147,7 +147,7 @@ public void testDataModelWithEmptyAttributes() {
String modelName = createTemporaryName();
DataModelArgs args = new DataModelArgs();
- args.setRawJsonDescription(streamToString(openResource("data/datamodels/model_with_empty_headers.json")));
+ args.setRawJsonDescription(streamToString(openResource("/data/datamodels/model_with_empty_headers.json")));
DataModel model = dataModels.create(modelName, args);
Assert.assertEquals(modelName, model.getName());
@@ -170,33 +170,49 @@ public void testAccelerationSettings() {
EntityCollection dataModels = nonprivateService.getDataModels();
DataModelArgs args = new DataModelArgs();
- args.setRawJsonDescription(streamToString(openResource("data/datamodels/data_model_with_test_objects.json")));
+ args.setRawJsonDescription(streamToString(openResource("/data/datamodels/data_model_with_test_objects.json")));
DataModel model = dataModels.create(createTemporaryName(), args);
+ final String crontabA = "*/5 * * * *";
+ final String crontabB = "* * * * *";
+
model.setAcceleration(true);
model.setEarliestAcceleratedTime("-2mon");
- model.setAccelerationCronSchedule("5/* * * * *");
+ model.setAccelerationCronSchedule(crontabA);
model.update();
Assert.assertTrue(model.isAccelerated());
Assert.assertEquals("-2mon", model.getEarliestAcceleratedTime());
- Assert.assertEquals("5/* * * * *", model.getAccelerationCronSchedule());
+ Assert.assertEquals(crontabA, model.getAccelerationCronSchedule());
+ Assert.assertFalse(model.isManualRebuilds());
model.update(); // An empty update should also work
model.refresh();
Assert.assertTrue(model.isAccelerated());
Assert.assertEquals("-2mon", model.getEarliestAcceleratedTime());
- Assert.assertEquals("5/* * * * *", model.getAccelerationCronSchedule());
+ Assert.assertEquals(crontabA, model.getAccelerationCronSchedule());
+ Assert.assertFalse(model.isManualRebuilds());
model.setAcceleration(false);
model.setEarliestAcceleratedTime("-1mon");
- model.setAccelerationCronSchedule("* * * * *");
+ model.setAccelerationCronSchedule(crontabB);
+ model.update();
+
+ Assert.assertFalse(model.isAccelerated());
+ Assert.assertEquals("-1mon", model.getEarliestAcceleratedTime());
+ Assert.assertEquals(crontabB, model.getAccelerationCronSchedule());
+ Assert.assertFalse(model.isManualRebuilds());
+
+ model.setManualRebuilds(true);
+ // Acceleration must be set, or splunkd will crash
+ model.setAcceleration(false);
model.update();
Assert.assertFalse(model.isAccelerated());
Assert.assertEquals("-1mon", model.getEarliestAcceleratedTime());
- Assert.assertEquals("* * * * *", model.getAccelerationCronSchedule());
+ Assert.assertEquals(crontabB, model.getAccelerationCronSchedule());
+ Assert.assertTrue(model.isManualRebuilds());
}
@Test
@@ -204,7 +220,7 @@ public void testObjectMetadata() {
DataModelCollection models = service.getDataModels();
DataModelArgs args = new DataModelArgs();
- args.setRawJsonDescription(streamToString(openResource("data/datamodels/data_model_with_test_objects.json")));
+ args.setRawJsonDescription(streamToString(openResource("/data/datamodels/data_model_with_test_objects.json")));
DataModel model = models.create(createTemporaryName(), args);
DataModelObject object = model.getObject("event1");
@@ -220,7 +236,7 @@ public void testParentOnChild() {
DataModelCollection models = service.getDataModels();
DataModelArgs args = new DataModelArgs();
- args.setRawJsonDescription(streamToString(openResource("data/datamodels/data_model_with_test_objects.json")));
+ args.setRawJsonDescription(streamToString(openResource("/data/datamodels/data_model_with_test_objects.json")));
DataModel model = models.create(createTemporaryName(), args);
DataModelObject object = model.getObject("event1");
@@ -234,7 +250,7 @@ public void testLineage() {
DataModelCollection models = service.getDataModels();
DataModelArgs args = new DataModelArgs();
- args.setRawJsonDescription(streamToString(openResource("data/datamodels/inheritance_test_data.json")));
+ args.setRawJsonDescription(streamToString(openResource("/data/datamodels/inheritance_test_data.json")));
DataModel model = models.create(createTemporaryName(), args);
Collection children;
@@ -260,7 +276,7 @@ public void testObjectFields() {
DataModelCollection models = service.getDataModels();
DataModelArgs args = new DataModelArgs();
- args.setRawJsonDescription(streamToString(openResource("data/datamodels/inheritance_test_data.json")));
+ args.setRawJsonDescription(streamToString(openResource("/data/datamodels/inheritance_test_data.json")));
DataModel model = models.create(createTemporaryName(), args);
DataModelObject object = model.getObject("level_2");
@@ -297,7 +313,7 @@ public void testOutputObjectFields() {
DataModelCollection models = service.getDataModels();
DataModelArgs args = new DataModelArgs();
- args.setRawJsonDescription(streamToString(openResource("data/datamodels/data_model_for_pivot.json")));
+ args.setRawJsonDescription(streamToString(openResource("/data/datamodels/data_model_for_pivot.json")));
DataModel model = models.create(createTemporaryName(), args);
DataModelObject object = model.getObject("test_data");
@@ -314,7 +330,7 @@ public void testCreateLocalAccelerationJob() {
String dataModelName = createTemporaryName();
DataModelArgs args = new DataModelArgs();
- args.setRawJsonDescription(streamToString(openResource("data/datamodels/inheritance_test_data.json")));
+ args.setRawJsonDescription(streamToString(openResource("/data/datamodels/inheritance_test_data.json")));
DataModel model = models.create(dataModelName, args);
DataModelObject object = model.getObject("level_2");
@@ -345,7 +361,7 @@ public void testCreateLocalAccelerationJobWithEarliestTime() {
String dataModelName = createTemporaryName();
DataModelArgs args = new DataModelArgs();
- args.setRawJsonDescription(streamToString(openResource("data/datamodels/inheritance_test_data.json")));
+ args.setRawJsonDescription(streamToString(openResource("/data/datamodels/inheritance_test_data.json")));
DataModel model = models.create(dataModelName, args);
DataModelObject object = model.getObject("level_2");
@@ -376,7 +392,7 @@ public void testConstraints() {
EntityCollection dataModels = service.getDataModels();
DataModelArgs args = new DataModelArgs();
- args.setRawJsonDescription(streamToString(openResource("data/datamodels/data_model_with_test_objects.json")));
+ args.setRawJsonDescription(streamToString(openResource("/data/datamodels/data_model_with_test_objects.json")));
DataModel model = dataModels.create(createTemporaryName(), args);
DataModelObject object = model.getObject("event1");
@@ -398,7 +414,7 @@ public void testCalculations() {
EntityCollection dataModels = service.getDataModels();
DataModelArgs args = new DataModelArgs();
- args.setRawJsonDescription(streamToString(openResource("data/datamodels/data_model_with_test_objects.json")));
+ args.setRawJsonDescription(streamToString(openResource("/data/datamodels/data_model_with_test_objects.json")));
DataModel model = dataModels.create(createTemporaryName(), args);
DataModelObject object = model.getObject("event1");
@@ -494,7 +510,7 @@ public void testBaseSearchProperlyParsed() {
EntityCollection dataModels = service.getDataModels();
DataModelArgs args = new DataModelArgs();
- args.setRawJsonDescription(streamToString(openResource("data/datamodels/model_with_multiple_types.json")));
+ args.setRawJsonDescription(streamToString(openResource("/data/datamodels/model_with_multiple_types.json")));
DataModel model = dataModels.create(createTemporaryName(), args);
DataModelObject object = model.getObject("search1");
@@ -511,7 +527,7 @@ public void testBaseTransactionProperlyParsed() {
EntityCollection dataModels = service.getDataModels();
DataModelArgs args = new DataModelArgs();
- args.setRawJsonDescription(streamToString(openResource("data/datamodels/model_with_multiple_types.json")));
+ args.setRawJsonDescription(streamToString(openResource("/data/datamodels/model_with_multiple_types.json")));
DataModel model = dataModels.create(createTemporaryName(), args);
DataModelObject object = model.getObject("transaction1");
diff --git a/tests/com/splunk/DeploymentClientTest.java b/splunk/src/test/java/com/splunk/DeploymentClientTest.java
similarity index 100%
rename from tests/com/splunk/DeploymentClientTest.java
rename to splunk/src/test/java/com/splunk/DeploymentClientTest.java
diff --git a/tests/com/splunk/DeploymentServerClassTest.java b/splunk/src/test/java/com/splunk/DeploymentServerClassTest.java
similarity index 99%
rename from tests/com/splunk/DeploymentServerClassTest.java
rename to splunk/src/test/java/com/splunk/DeploymentServerClassTest.java
index 13c5532f..94dc00e8 100644
--- a/tests/com/splunk/DeploymentServerClassTest.java
+++ b/splunk/src/test/java/com/splunk/DeploymentServerClassTest.java
@@ -17,7 +17,6 @@
package com.splunk;
import org.junit.Assert;
-import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
diff --git a/tests/com/splunk/DeploymentServerTest.java b/splunk/src/test/java/com/splunk/DeploymentServerTest.java
similarity index 98%
rename from tests/com/splunk/DeploymentServerTest.java
rename to splunk/src/test/java/com/splunk/DeploymentServerTest.java
index 15c5f51b..ba75489f 100644
--- a/tests/com/splunk/DeploymentServerTest.java
+++ b/splunk/src/test/java/com/splunk/DeploymentServerTest.java
@@ -17,7 +17,6 @@
package com.splunk;
import org.junit.Assert;
-import org.junit.Assume;
import org.junit.Test;
public class DeploymentServerTest extends SDKTestCase {
diff --git a/tests/com/splunk/DeploymentTenantTest.java b/splunk/src/test/java/com/splunk/DeploymentTenantTest.java
similarity index 98%
rename from tests/com/splunk/DeploymentTenantTest.java
rename to splunk/src/test/java/com/splunk/DeploymentTenantTest.java
index 95129079..153b1064 100644
--- a/tests/com/splunk/DeploymentTenantTest.java
+++ b/splunk/src/test/java/com/splunk/DeploymentTenantTest.java
@@ -17,7 +17,6 @@
package com.splunk;
import org.junit.Assert;
-import org.junit.Assume;
import org.junit.Test;
public class DeploymentTenantTest extends SDKTestCase {
diff --git a/tests/com/splunk/DistributedConfTest.java b/splunk/src/test/java/com/splunk/DistributedConfTest.java
similarity index 100%
rename from tests/com/splunk/DistributedConfTest.java
rename to splunk/src/test/java/com/splunk/DistributedConfTest.java
diff --git a/tests/com/splunk/DistributedPeerTest.java b/splunk/src/test/java/com/splunk/DistributedPeerTest.java
similarity index 96%
rename from tests/com/splunk/DistributedPeerTest.java
rename to splunk/src/test/java/com/splunk/DistributedPeerTest.java
index 8bdb75dc..1b627f89 100644
--- a/tests/com/splunk/DistributedPeerTest.java
+++ b/splunk/src/test/java/com/splunk/DistributedPeerTest.java
@@ -16,11 +16,13 @@
package com.splunk;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.*;
+@Ignore
+/**
+ * To execute these test we need a separate splunk instance. Post splunk6.4, it is no longer allowed to connect to
+ * self as a peer because of name conflicts.
+ */
public class DistributedPeerTest extends SDKTestCase {
EntityCollection peers;
String temporaryUsername;
diff --git a/tests/com/splunk/EntityTest.java b/splunk/src/test/java/com/splunk/EntityTest.java
similarity index 100%
rename from tests/com/splunk/EntityTest.java
rename to splunk/src/test/java/com/splunk/EntityTest.java
diff --git a/tests/com/splunk/EventTypesTest.java b/splunk/src/test/java/com/splunk/EventTypesTest.java
similarity index 100%
rename from tests/com/splunk/EventTypesTest.java
rename to splunk/src/test/java/com/splunk/EventTypesTest.java
diff --git a/tests/com/splunk/ExportResultsReaderTest.java b/splunk/src/test/java/com/splunk/ExportResultsReaderTest.java
similarity index 93%
rename from tests/com/splunk/ExportResultsReaderTest.java
rename to splunk/src/test/java/com/splunk/ExportResultsReaderTest.java
index a6128b4d..0c460372 100644
--- a/tests/com/splunk/ExportResultsReaderTest.java
+++ b/splunk/src/test/java/com/splunk/ExportResultsReaderTest.java
@@ -40,7 +40,7 @@ public class ExportResultsReaderTest {
private static Map expectedData = reader.fromJson(
SDKTestCase.streamToString(
SDKTestCase.openResource(
- "data/export_test_data.json")),
+ "/data/export_test_data.json")),
Map.class
);
@@ -70,7 +70,7 @@ public void testExportWithoutPreview() throws IOException, XMLStreamException {
InputStream xmlStream = new ExportResultsStream(
SDKTestCase.openResource(
- "data/export/" + this.version + "/export_results.xml"));
+ "/data/export/" + this.version + "/export_results.xml"));
ResultsReaderXml resultsReader = new ResultsReaderXml(xmlStream);
ResultsReaderTestFromExpectedFile.verifyResultsReader(resultsReader, expectedEvents);
@@ -85,7 +85,7 @@ public void testExportWithPreview() throws IOException {
List