You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2016/04/22 10:07:33 UTC
[04/13] calcite git commit: Move HTTP utilities from splunk adapter
to core
Move HTTP utilities from splunk adapter to core
Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/f97cdfbe
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/f97cdfbe
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/f97cdfbe
Branch: refs/heads/master
Commit: f97cdfbee4f7ccaeaa91328005bf3e3a52e6666a
Parents: b666f72
Author: Julian Hyde <jh...@apache.org>
Authored: Mon Apr 18 22:31:12 2016 -0700
Committer: Julian Hyde <jh...@apache.org>
Committed: Tue Apr 19 11:11:37 2016 -0700
----------------------------------------------------------------------
.../org/apache/calcite/runtime/HttpUtils.java | 169 +++++++++++++++++++
.../calcite/runtime/SocketFactoryImpl.java | 165 ++++++++++++++++++
.../runtime/TrustAllSslSocketFactory.java | 129 ++++++++++++++
.../splunk/search/SplunkConnectionImpl.java | 6 +-
.../calcite/adapter/splunk/util/HttpUtils.java | 167 ------------------
.../adapter/splunk/util/SocketFactoryImpl.java | 165 ------------------
.../splunk/util/TrustAllSslSocketFactory.java | 129 --------------
7 files changed, 466 insertions(+), 464 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite/blob/f97cdfbe/core/src/main/java/org/apache/calcite/runtime/HttpUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/runtime/HttpUtils.java b/core/src/main/java/org/apache/calcite/runtime/HttpUtils.java
new file mode 100644
index 0000000..011092c
--- /dev/null
+++ b/core/src/main/java/org/apache/calcite/runtime/HttpUtils.java
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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 org.apache.calcite.runtime;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStreamWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLEncoder;
+import java.util.Map;
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLSession;
+
+/**
+ * Utilities for connecting to REST services such as Splunk via HTTP.
+ */
+public class HttpUtils {
+ private HttpUtils() {}
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(HttpUtils.class);
+
+ public static HttpURLConnection getURLConnection(String url)
+ throws IOException {
+ URLConnection conn = new URL(url).openConnection();
+ final HttpURLConnection httpConn = (HttpURLConnection) conn;
+
+ // take care of https stuff - most of the time it's only needed to
+ // secure client/server comm
+ // not to establish the identity of the server
+ if (httpConn instanceof HttpsURLConnection) {
+ HttpsURLConnection httpsConn = (HttpsURLConnection) httpConn;
+ httpsConn.setSSLSocketFactory(
+ TrustAllSslSocketFactory.createSSLSocketFactory());
+ httpsConn.setHostnameVerifier(
+ new HostnameVerifier() {
+ public boolean verify(String arg0, SSLSession arg1) {
+ return true;
+ }
+ });
+ }
+
+ return httpConn;
+ }
+
+ public static void appendURLEncodedArgs(
+ StringBuilder out, Map<String, String> args) {
+ int i = 0;
+ try {
+ for (Map.Entry<String, String> me : args.entrySet()) {
+ if (i++ != 0) {
+ out.append("&");
+ }
+ out.append(URLEncoder.encode(me.getKey(), "UTF-8"));
+ out.append("=")
+ .append(URLEncoder.encode(me.getValue(), "UTF-8"));
+ }
+ } catch (UnsupportedEncodingException ignore) {
+ // ignore
+ }
+ }
+
+ public static void appendURLEncodedArgs(
+ StringBuilder out, CharSequence ... args) {
+ if (args.length % 2 != 0) {
+ throw new IllegalArgumentException(
+ "args should contain an even number of items");
+ }
+ try {
+ int appended = 0;
+ for (int i = 0; i < args.length; i += 2) {
+ if (args[i + 1] == null) {
+ continue;
+ }
+ if (appended++ > 0) {
+ out.append("&");
+ }
+ out.append(URLEncoder.encode(args[i].toString(), "UTF-8"))
+ .append("=")
+ .append(URLEncoder.encode(args[i + 1].toString(), "UTF-8"));
+ }
+ } catch (UnsupportedEncodingException ignore) {
+ // ignore
+ }
+ }
+
+ public static void close(Closeable c) {
+ try {
+ c.close();
+ } catch (Exception ignore) {
+ // ignore
+ }
+ }
+
+ public static InputStream post(
+ String url,
+ CharSequence data,
+ Map<String, String> headers) throws IOException {
+ return post(url, data, headers, 10000, 60000);
+ }
+
+ public static InputStream post(
+ String url,
+ CharSequence data,
+ Map<String, String> headers,
+ int cTimeout,
+ int rTimeout) throws IOException {
+ return executeMethod("POST", url, data, headers, cTimeout, rTimeout);
+ }
+
+ public static InputStream executeMethod(
+ String method, String url,
+ CharSequence data, Map<String, String> headers,
+ int ctimeout, int rtimeout) throws IOException {
+ HttpURLConnection conn;
+ OutputStreamWriter wr = null;
+
+ try {
+ conn = getURLConnection(url);
+ conn.setRequestMethod(method);
+ conn.setReadTimeout(rtimeout);
+ conn.setConnectTimeout(ctimeout);
+
+ if (headers != null) {
+ for (Map.Entry<String, String> me : headers.entrySet()) {
+ conn.setRequestProperty(me.getKey(), me.getValue());
+ }
+ }
+ if (data != null) {
+ conn.setDoOutput(true);
+ wr = new OutputStreamWriter(conn.getOutputStream());
+ wr.write(data.toString());
+ wr.flush(); // Get the response
+ }
+ InputStream in = conn.getInputStream();
+ if (wr != null) {
+ wr.close();
+ }
+
+ LOGGER.debug("url: {}, data: {}", url, String.valueOf(data));
+ return in;
+ } finally {
+ close(wr);
+ }
+ }
+}
+
+// End HttpUtils.java
http://git-wip-us.apache.org/repos/asf/calcite/blob/f97cdfbe/core/src/main/java/org/apache/calcite/runtime/SocketFactoryImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/runtime/SocketFactoryImpl.java b/core/src/main/java/org/apache/calcite/runtime/SocketFactoryImpl.java
new file mode 100644
index 0000000..16413c7
--- /dev/null
+++ b/core/src/main/java/org/apache/calcite/runtime/SocketFactoryImpl.java
@@ -0,0 +1,165 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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 org.apache.calcite.runtime;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.SocketException;
+import javax.net.SocketFactory;
+
+/**
+ * Extends the SocketFactory object with the main functionality being that the
+ * created sockets inherit a set of options whose values are set in the
+ * SocketFactoryImpl.
+ *
+ * <pre>
+ * 1. SO_KEEPALIVE - is keepalive enabled?
+ * 2. OOBINLINE - is out of band in-line enabled?
+ * 3. SO_REUSEADDR - should the address be reused?
+ * 4. TCP_NODELAY - should data buffering for tcp be used?
+ * 5. SO_RCVBUF - size of receive buffer
+ * 6. SO_SNDBUF - size of send buffer
+ * 7. SO_TIMEOUT - read timeout (millisecs)
+ * 8. SO_CONNECT_TIMEOUT - connect timeout (millisecs)
+ * 9. SO_LINGER - is lingering enabled?
+ * 10. LINGER - amount of time to linger (seconds)
+ *
+ *
+ * </pre>
+ */
+public class SocketFactoryImpl extends SocketFactory {
+ /**
+ * should keep alives be sent
+ */
+ public static final boolean SO_KEEPALIVE = false;
+
+ /**
+ * is out of band in-line enabled
+ */
+ public static final boolean OOBINLINE = false;
+
+ /**
+ * should the address be reused
+ */
+ public static final boolean SO_REUSEADDR = false;
+
+ /**
+ * do not buffer send(s) iff true
+ */
+ public static final boolean TCP_NODELAY = true;
+
+ /**
+ * size of receiving buffer
+ */
+ public static final int SO_RCVBUF = 8192;
+
+ /**
+ * size of sending buffer iff needed
+ */
+ public static final int SO_SNDBUF = 1024;
+
+ /**
+ * read timeout in milliseconds
+ */
+ public static final int SO_TIMEOUT = 12000;
+
+ /**
+ * connect timeout in milliseconds
+ */
+ public static final int SO_CONNECT_TIMEOUT = 5000;
+
+ /**
+ * enabling lingering with 0-timeout will cause the socket to be
+ * closed forcefully upon execution of close()
+ */
+ public static final boolean SO_LINGER = true;
+
+ /**
+ * amount of time to linger
+ */
+ public static final int LINGER = 0;
+
+ @Override public Socket createSocket() throws IOException {
+ Socket s = new Socket();
+ return applySettings(s);
+ }
+
+ /**
+ * Applies the current settings to the given socket.
+ *
+ * @param s Socket to apply the settings to
+ * @return Socket the input socket
+ */
+ protected Socket applySettings(Socket s) {
+ try {
+ s.setKeepAlive(SO_KEEPALIVE);
+ s.setOOBInline(OOBINLINE);
+ s.setReuseAddress(SO_REUSEADDR);
+ s.setTcpNoDelay(TCP_NODELAY);
+ s.setOOBInline(OOBINLINE);
+
+ s.setReceiveBufferSize(SO_RCVBUF);
+ s.setSendBufferSize(SO_SNDBUF);
+ s.setSoTimeout(SO_TIMEOUT);
+ s.setSoLinger(SO_LINGER, LINGER);
+ } catch (SocketException e) {
+ throw new RuntimeException(e);
+ }
+ return s;
+ }
+
+ @Override public Socket createSocket(String host, int port)
+ throws IOException {
+ Socket s = createSocket();
+ s.connect(new InetSocketAddress(host, port), SO_CONNECT_TIMEOUT);
+ return s;
+ }
+
+ @Override public Socket createSocket(InetAddress host, int port)
+ throws IOException {
+ Socket s = createSocket();
+ s.connect(new InetSocketAddress(host, port), SO_CONNECT_TIMEOUT);
+ return s;
+ }
+
+ @Override public Socket createSocket(String host, int port, InetAddress local,
+ int localPort) throws IOException {
+ Socket s = createSocket();
+ s.bind(new InetSocketAddress(local, localPort));
+ s.connect(new InetSocketAddress(host, port), SO_CONNECT_TIMEOUT);
+ return s;
+ }
+
+ @Override public Socket createSocket(InetAddress host, int port,
+ InetAddress local, int localPort) throws IOException {
+ Socket s = createSocket();
+ s.bind(new InetSocketAddress(local, localPort));
+ s.connect(new InetSocketAddress(host, port), SO_CONNECT_TIMEOUT);
+ return s;
+ }
+
+ /**
+ * @see javax.net.SocketFactory#getDefault()
+ */
+ public static SocketFactory getDefault() {
+ return new SocketFactoryImpl();
+ }
+}
+
+// End SocketFactoryImpl.java
http://git-wip-us.apache.org/repos/asf/calcite/blob/f97cdfbe/core/src/main/java/org/apache/calcite/runtime/TrustAllSslSocketFactory.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/runtime/TrustAllSslSocketFactory.java b/core/src/main/java/org/apache/calcite/runtime/TrustAllSslSocketFactory.java
new file mode 100644
index 0000000..b7ff117
--- /dev/null
+++ b/core/src/main/java/org/apache/calcite/runtime/TrustAllSslSocketFactory.java
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you 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 org.apache.calcite.runtime;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.Socket;
+import java.security.SecureRandom;
+import java.security.cert.X509Certificate;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
+
+/**
+ * Socket factory that trusts all SSL connections.
+ */
+public class TrustAllSslSocketFactory extends SocketFactoryImpl {
+ private static final TrustAllSslSocketFactory DEFAULT =
+ new TrustAllSslSocketFactory();
+
+ private final SSLSocketFactory sslSocketFactory;
+
+ protected TrustAllSslSocketFactory() {
+ TrustManager[] trustAllCerts = {new DummyTrustManager()};
+ SSLSocketFactory factory = null;
+ try {
+ SSLContext sc = SSLContext.getInstance("SSL");
+ sc.init(null, trustAllCerts, new SecureRandom());
+ factory = sc.getSocketFactory();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ this.sslSocketFactory = factory;
+ }
+
+ @Override public Socket createSocket() throws IOException {
+ return applySettings(sslSocketFactory.createSocket());
+ }
+
+ @Override public Socket createSocket(InetAddress host, int port)
+ throws IOException {
+ return applySettings(sslSocketFactory.createSocket(host, port));
+ }
+
+ @Override public Socket createSocket(InetAddress address, int port,
+ InetAddress localAddress, int localPort) throws IOException {
+ return applySettings(
+ sslSocketFactory.createSocket(
+ address, port, localAddress, localPort));
+ }
+
+ @Override public Socket createSocket(String host, int port)
+ throws IOException {
+ return applySettings(sslSocketFactory.createSocket(host, port));
+ }
+
+ @Override public Socket createSocket(String host, int port,
+ InetAddress localHost, int localPort) throws IOException {
+ return applySettings(
+ sslSocketFactory.createSocket(host, port, localHost, localPort));
+ }
+
+ /**
+ * @see javax.net.SocketFactory#getDefault()
+ */
+ public static TrustAllSslSocketFactory getDefault() {
+ return DEFAULT;
+ }
+
+ public static SSLSocketFactory getDefaultSSLSocketFactory() {
+ return DEFAULT.sslSocketFactory;
+ }
+
+ /**
+ * Creates an "accept-all" SSLSocketFactory - ssl sockets will accept ANY
+ * certificate sent to them - thus effectively just securing the
+ * communications. This could be set in a HttpsURLConnection using
+ * HttpsURLConnection.setSSLSocketFactory(.....)
+ *
+ * @return SSLSocketFactory
+ */
+ public static SSLSocketFactory createSSLSocketFactory() {
+ SSLSocketFactory sslsocketfactory = null;
+ TrustManager[] trustAllCerts = {new DummyTrustManager()};
+ try {
+ SSLContext sc = SSLContext.getInstance("SSL");
+ sc.init(null, trustAllCerts, new java.security.SecureRandom());
+ sslsocketfactory = sc.getSocketFactory();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return sslsocketfactory;
+ }
+
+ /** Implementation of {@link X509TrustManager} that trusts all
+ * certificates. */
+ private static class DummyTrustManager implements X509TrustManager {
+ public X509Certificate[] getAcceptedIssuers() {
+ return null;
+ }
+
+ public void checkClientTrusted(
+ X509Certificate[] certs,
+ String authType) {
+ }
+
+ public void checkServerTrusted(
+ X509Certificate[] certs,
+ String authType) {
+ }
+ }
+}
+
+// End TrustAllSslSocketFactory.java
http://git-wip-us.apache.org/repos/asf/calcite/blob/f97cdfbe/splunk/src/main/java/org/apache/calcite/adapter/splunk/search/SplunkConnectionImpl.java
----------------------------------------------------------------------
diff --git a/splunk/src/main/java/org/apache/calcite/adapter/splunk/search/SplunkConnectionImpl.java b/splunk/src/main/java/org/apache/calcite/adapter/splunk/search/SplunkConnectionImpl.java
index 8a41556..b6297fa 100644
--- a/splunk/src/main/java/org/apache/calcite/adapter/splunk/search/SplunkConnectionImpl.java
+++ b/splunk/src/main/java/org/apache/calcite/adapter/splunk/search/SplunkConnectionImpl.java
@@ -16,10 +16,10 @@
*/
package org.apache.calcite.adapter.splunk.search;
-import org.apache.calcite.adapter.splunk.util.HttpUtils;
import org.apache.calcite.adapter.splunk.util.StringUtils;
import org.apache.calcite.linq4j.Enumerator;
import org.apache.calcite.linq4j.Linq4j;
+import org.apache.calcite.runtime.HttpUtils;
import au.com.bytecode.opencsv.CSVReader;
@@ -43,8 +43,8 @@ import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import static org.apache.calcite.adapter.splunk.util.HttpUtils.appendURLEncodedArgs;
-import static org.apache.calcite.adapter.splunk.util.HttpUtils.post;
+import static org.apache.calcite.runtime.HttpUtils.appendURLEncodedArgs;
+import static org.apache.calcite.runtime.HttpUtils.post;
/**
* Implementation of {@link SplunkConnection} based on Splunk's REST API.
http://git-wip-us.apache.org/repos/asf/calcite/blob/f97cdfbe/splunk/src/main/java/org/apache/calcite/adapter/splunk/util/HttpUtils.java
----------------------------------------------------------------------
diff --git a/splunk/src/main/java/org/apache/calcite/adapter/splunk/util/HttpUtils.java b/splunk/src/main/java/org/apache/calcite/adapter/splunk/util/HttpUtils.java
deleted file mode 100644
index e259397..0000000
--- a/splunk/src/main/java/org/apache/calcite/adapter/splunk/util/HttpUtils.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you 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 org.apache.calcite.adapter.splunk.util;
-
-import org.slf4j.Logger;
-
-import java.io.Closeable;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStreamWriter;
-import java.io.UnsupportedEncodingException;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.net.URLConnection;
-import java.net.URLEncoder;
-import java.util.Map;
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLSession;
-
-/**
- * Utilities for connecting to Splunk via HTTP.
- */
-public class HttpUtils {
- private HttpUtils() {}
-
- private static final Logger LOGGER =
- StringUtils.getClassTracer(HttpUtils.class);
-
- public static HttpURLConnection getURLConnection(String url)
- throws IOException {
- URLConnection conn = new URL(url).openConnection();
- final HttpURLConnection httpConn = (HttpURLConnection) conn;
-
- // take care of https stuff - most of the time it's only needed to
- // secure client/server comm
- // not to establish the identity of the server
- if (httpConn instanceof HttpsURLConnection) {
- HttpsURLConnection httpsConn = (HttpsURLConnection) httpConn;
- httpsConn.setSSLSocketFactory(
- TrustAllSslSocketFactory.createSSLSocketFactory());
- httpsConn.setHostnameVerifier(
- new HostnameVerifier() {
- public boolean verify(String arg0, SSLSession arg1) {
- return true;
- }
- });
- }
-
- return httpConn;
- }
-
- public static void appendURLEncodedArgs(
- StringBuilder out, Map<String, String> args) {
- int i = 0;
- try {
- for (Map.Entry<String, String> me : args.entrySet()) {
- if (i++ != 0) {
- out.append("&");
- }
- out.append(URLEncoder.encode(me.getKey(), "UTF-8"));
- out.append("=")
- .append(URLEncoder.encode(me.getValue(), "UTF-8"));
- }
- } catch (UnsupportedEncodingException ignore) {
- // ignore
- }
- }
-
- public static void appendURLEncodedArgs(
- StringBuilder out, CharSequence ... args) {
- if (args.length % 2 != 0) {
- throw new IllegalArgumentException(
- "args should contain an even number of items");
- }
- try {
- int appended = 0;
- for (int i = 0; i < args.length; i += 2) {
- if (args[i + 1] == null) {
- continue;
- }
- if (appended++ > 0) {
- out.append("&");
- }
- out.append(URLEncoder.encode(args[i].toString(), "UTF-8"))
- .append("=")
- .append(URLEncoder.encode(args[i + 1].toString(), "UTF-8"));
- }
- } catch (UnsupportedEncodingException ignore) {
- // ignore
- }
- }
-
- public static void close(Closeable c) {
- try {
- c.close();
- } catch (Exception ignore) {
- // ignore
- }
- }
-
- public static InputStream post(
- String url,
- CharSequence data,
- Map<String, String> headers) throws IOException {
- return post(url, data, headers, 10000, 60000);
- }
-
- public static InputStream post(
- String url,
- CharSequence data,
- Map<String, String> headers,
- int cTimeout,
- int rTimeout) throws IOException {
- return executeMethod("POST", url, data, headers, cTimeout, rTimeout);
- }
-
- public static InputStream executeMethod(
- String method, String url,
- CharSequence data, Map<String, String> headers,
- int ctimeout, int rtimeout) throws IOException {
- HttpURLConnection conn;
- OutputStreamWriter wr = null;
-
- try {
- conn = getURLConnection(url);
- conn.setRequestMethod(method);
- conn.setReadTimeout(rtimeout);
- conn.setConnectTimeout(ctimeout);
-
- if (headers != null) {
- for (Map.Entry<String, String> me : headers.entrySet()) {
- conn.setRequestProperty(me.getKey(), me.getValue());
- }
- }
- if (data != null) {
- conn.setDoOutput(true);
- wr = new OutputStreamWriter(conn.getOutputStream());
- wr.write(data.toString());
- wr.flush(); // Get the response
- }
- InputStream in = conn.getInputStream();
- wr.close();
-
- LOGGER.debug("url: {}, data: {}", url, String.valueOf(data));
- return in;
- } finally {
- close(wr);
- }
- }
-}
-
-// End HttpUtils.java
http://git-wip-us.apache.org/repos/asf/calcite/blob/f97cdfbe/splunk/src/main/java/org/apache/calcite/adapter/splunk/util/SocketFactoryImpl.java
----------------------------------------------------------------------
diff --git a/splunk/src/main/java/org/apache/calcite/adapter/splunk/util/SocketFactoryImpl.java b/splunk/src/main/java/org/apache/calcite/adapter/splunk/util/SocketFactoryImpl.java
deleted file mode 100644
index cd2e0c8..0000000
--- a/splunk/src/main/java/org/apache/calcite/adapter/splunk/util/SocketFactoryImpl.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you 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 org.apache.calcite.adapter.splunk.util;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-import java.net.SocketException;
-import javax.net.SocketFactory;
-
-/**
- * Extends the SocketFactory object with the main functionality being that the
- * created sockets inherit a set of options whose values are set in the
- * SocketFactoryImpl.
- *
- * <pre>
- * 1. SO_KEEPALIVE - is keepalive enabled?
- * 2. OOBINLINE - is out of band in-line enabled?
- * 3. SO_REUSEADDR - should the address be reused?
- * 4. TCP_NODELAY - should data buffering for tcp be used?
- * 5. SO_RCVBUF - size of receive buffer
- * 6. SO_SNDBUF - size of send buffer
- * 7. SO_TIMEOUT - read timeout (millisecs)
- * 8. SO_CONNECT_TIMEOUT - connect timeout (millisecs)
- * 9. SO_LINGER - is lingering enabled?
- * 10. LINGER - amount of time to linger (seconds)
- *
- *
- * </pre>
- */
-public class SocketFactoryImpl extends SocketFactory {
- /**
- * should keep alives be sent
- */
- public static final boolean SO_KEEPALIVE = false;
-
- /**
- * is out of band in-line enabled
- */
- public static final boolean OOBINLINE = false;
-
- /**
- * should the address be reused
- */
- public static final boolean SO_REUSEADDR = false;
-
- /**
- * do not buffer send(s) iff true
- */
- public static final boolean TCP_NODELAY = true;
-
- /**
- * size of receiving buffer
- */
- public static final int SO_RCVBUF = 8192;
-
- /**
- * size of sending buffer iff needed
- */
- public static final int SO_SNDBUF = 1024;
-
- /**
- * read timeout in milliseconds
- */
- public static final int SO_TIMEOUT = 12000;
-
- /**
- * connect timeout in milliseconds
- */
- public static final int SO_CONNECT_TIMEOUT = 5000;
-
- /**
- * enabling lingering with 0-timeout will cause the socket to be
- * closed forcefully upon execution of close()
- */
- public static final boolean SO_LINGER = true;
-
- /**
- * amount of time to linger
- */
- public static final int LINGER = 0;
-
- @Override public Socket createSocket() throws IOException {
- Socket s = new Socket();
- return applySettings(s);
- }
-
- /**
- * Applies the current settings to the given socket.
- *
- * @param s Socket to apply the settings to
- * @return Socket the input socket
- */
- protected Socket applySettings(Socket s) {
- try {
- s.setKeepAlive(SO_KEEPALIVE);
- s.setOOBInline(OOBINLINE);
- s.setReuseAddress(SO_REUSEADDR);
- s.setTcpNoDelay(TCP_NODELAY);
- s.setOOBInline(OOBINLINE);
-
- s.setReceiveBufferSize(SO_RCVBUF);
- s.setSendBufferSize(SO_SNDBUF);
- s.setSoTimeout(SO_TIMEOUT);
- s.setSoLinger(SO_LINGER, LINGER);
- } catch (SocketException e) {
- throw new RuntimeException(e);
- }
- return s;
- }
-
- @Override public Socket createSocket(String host, int port)
- throws IOException {
- Socket s = createSocket();
- s.connect(new InetSocketAddress(host, port), SO_CONNECT_TIMEOUT);
- return s;
- }
-
- @Override public Socket createSocket(InetAddress host, int port)
- throws IOException {
- Socket s = createSocket();
- s.connect(new InetSocketAddress(host, port), SO_CONNECT_TIMEOUT);
- return s;
- }
-
- @Override public Socket createSocket(String host, int port, InetAddress local,
- int localPort) throws IOException {
- Socket s = createSocket();
- s.bind(new InetSocketAddress(local, localPort));
- s.connect(new InetSocketAddress(host, port), SO_CONNECT_TIMEOUT);
- return s;
- }
-
- @Override public Socket createSocket(InetAddress host, int port,
- InetAddress local, int localPort) throws IOException {
- Socket s = createSocket();
- s.bind(new InetSocketAddress(local, localPort));
- s.connect(new InetSocketAddress(host, port), SO_CONNECT_TIMEOUT);
- return s;
- }
-
- /**
- * @see javax.net.SocketFactory#getDefault()
- */
- public static SocketFactory getDefault() {
- return new SocketFactoryImpl();
- }
-}
-
-// End SocketFactoryImpl.java
http://git-wip-us.apache.org/repos/asf/calcite/blob/f97cdfbe/splunk/src/main/java/org/apache/calcite/adapter/splunk/util/TrustAllSslSocketFactory.java
----------------------------------------------------------------------
diff --git a/splunk/src/main/java/org/apache/calcite/adapter/splunk/util/TrustAllSslSocketFactory.java b/splunk/src/main/java/org/apache/calcite/adapter/splunk/util/TrustAllSslSocketFactory.java
deleted file mode 100644
index 24a6591..0000000
--- a/splunk/src/main/java/org/apache/calcite/adapter/splunk/util/TrustAllSslSocketFactory.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to you 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 org.apache.calcite.adapter.splunk.util;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.Socket;
-import java.security.SecureRandom;
-import java.security.cert.X509Certificate;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSocketFactory;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.X509TrustManager;
-
-/**
- * Socket factory that trusts all SSL connections.
- */
-public class TrustAllSslSocketFactory extends SocketFactoryImpl {
- private static final TrustAllSslSocketFactory DEFAULT =
- new TrustAllSslSocketFactory();
-
- private final SSLSocketFactory sslSocketFactory;
-
- protected TrustAllSslSocketFactory() {
- TrustManager[] trustAllCerts = {new DummyTrustManager()};
- SSLSocketFactory factory = null;
- try {
- SSLContext sc = SSLContext.getInstance("SSL");
- sc.init(null, trustAllCerts, new SecureRandom());
- factory = sc.getSocketFactory();
- } catch (Exception e) {
- e.printStackTrace();
- }
- this.sslSocketFactory = factory;
- }
-
- @Override public Socket createSocket() throws IOException {
- return applySettings(sslSocketFactory.createSocket());
- }
-
- @Override public Socket createSocket(InetAddress host, int port)
- throws IOException {
- return applySettings(sslSocketFactory.createSocket(host, port));
- }
-
- @Override public Socket createSocket(InetAddress address, int port,
- InetAddress localAddress, int localPort) throws IOException {
- return applySettings(
- sslSocketFactory.createSocket(
- address, port, localAddress, localPort));
- }
-
- @Override public Socket createSocket(String host, int port)
- throws IOException {
- return applySettings(sslSocketFactory.createSocket(host, port));
- }
-
- @Override public Socket createSocket(String host, int port,
- InetAddress localHost, int localPort) throws IOException {
- return applySettings(
- sslSocketFactory.createSocket(host, port, localHost, localPort));
- }
-
- /**
- * @see javax.net.SocketFactory#getDefault()
- */
- public static TrustAllSslSocketFactory getDefault() {
- return DEFAULT;
- }
-
- public static SSLSocketFactory getDefaultSSLSocketFactory() {
- return DEFAULT.sslSocketFactory;
- }
-
- /**
- * Creates an "accept-all" SSLSocketFactory - ssl sockets will accept ANY
- * certificate sent to them - thus effectively just securing the
- * communications. This could be set in a HttpsURLConnection using
- * HttpsURLConnection.setSSLSocketFactory(.....)
- *
- * @return SSLSocketFactory
- */
- public static SSLSocketFactory createSSLSocketFactory() {
- SSLSocketFactory sslsocketfactory = null;
- TrustManager[] trustAllCerts = {new DummyTrustManager()};
- try {
- SSLContext sc = SSLContext.getInstance("SSL");
- sc.init(null, trustAllCerts, new java.security.SecureRandom());
- sslsocketfactory = sc.getSocketFactory();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return sslsocketfactory;
- }
-
- /** Implementation of {@link X509TrustManager} that trusts all
- * certificates. */
- private static class DummyTrustManager implements X509TrustManager {
- public X509Certificate[] getAcceptedIssuers() {
- return null;
- }
-
- public void checkClientTrusted(
- X509Certificate[] certs,
- String authType) {
- }
-
- public void checkServerTrusted(
- X509Certificate[] certs,
- String authType) {
- }
- }
-}
-
-// End TrustAllSslSocketFactory.java