From 0ffc0b56629e5778deeb32f4a458a363f8238243 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Wed, 21 Jun 2017 17:02:59 -0400 Subject: [PATCH] Fix most precommit Left so NOCOMMITs about things to think about. Original commit: elastic/x-pack-elasticsearch@446626d3a788974ae284058c51ee7cd5b74250a4 --- .../xpack/sql/jdbc/net/protocol/Message.java | 18 ------------------ .../sql/jdbc/net/protocol/ProtoUtils.java | 9 ++++----- .../xpack/sql/jdbc/net/client/HttpClient.java | 18 ------------------ sql-clients/test-utils/build.gradle | 6 ++++++ .../xpack/sql/test/server/ProtoHttpServer.java | 5 +++-- .../xpack/sql/test/server/RootHttpHandler.java | 12 +++++++----- 6 files changed, 20 insertions(+), 48 deletions(-) diff --git a/sql-clients/jdbc-proto/src/main/java/org/elasticsearch/xpack/sql/jdbc/net/protocol/Message.java b/sql-clients/jdbc-proto/src/main/java/org/elasticsearch/xpack/sql/jdbc/net/protocol/Message.java index 37a3b57a4e0..234b486c2e9 100644 --- a/sql-clients/jdbc-proto/src/main/java/org/elasticsearch/xpack/sql/jdbc/net/protocol/Message.java +++ b/sql-clients/jdbc-proto/src/main/java/org/elasticsearch/xpack/sql/jdbc/net/protocol/Message.java @@ -3,24 +3,6 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -/* -w * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch 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.elasticsearch.xpack.sql.jdbc.net.protocol; import java.io.DataOutput; diff --git a/sql-clients/jdbc-proto/src/main/java/org/elasticsearch/xpack/sql/jdbc/net/protocol/ProtoUtils.java b/sql-clients/jdbc-proto/src/main/java/org/elasticsearch/xpack/sql/jdbc/net/protocol/ProtoUtils.java index fc8b0e27924..2df2b4ccf21 100644 --- a/sql-clients/jdbc-proto/src/main/java/org/elasticsearch/xpack/sql/jdbc/net/protocol/ProtoUtils.java +++ b/sql-clients/jdbc-proto/src/main/java/org/elasticsearch/xpack/sql/jdbc/net/protocol/ProtoUtils.java @@ -5,15 +5,15 @@ */ package org.elasticsearch.xpack.sql.jdbc.net.protocol; +import org.elasticsearch.xpack.sql.jdbc.net.protocol.Proto.Action; +import org.elasticsearch.xpack.sql.jdbc.net.protocol.Proto.Status; + import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; import java.sql.JDBCType; import java.util.Locale; -import org.elasticsearch.xpack.sql.jdbc.net.protocol.Proto.Action; -import org.elasticsearch.xpack.sql.jdbc.net.protocol.Proto.Status; - import static java.lang.String.format; import static java.sql.Types.BIGINT; import static java.sql.Types.BINARY; @@ -32,7 +32,6 @@ import static java.sql.Types.TIMESTAMP_WITH_TIMEZONE; import static java.sql.Types.TINYINT; import static java.sql.Types.VARBINARY; import static java.sql.Types.VARCHAR; - import static org.elasticsearch.xpack.sql.jdbc.net.protocol.Proto.MAGIC_NUMBER; import static org.elasticsearch.xpack.sql.jdbc.net.protocol.Proto.VERSION; @@ -167,7 +166,7 @@ public abstract class ProtoUtils { result = in.readLong(); break; default: - throw new IOException(format("Don't know how to read type %d / %s", type, JDBCType.valueOf(type))); + throw new IOException("Don't know how to read type [" + type + " / " + JDBCType.valueOf(type) + "]"); } return (T) result; } diff --git a/sql-clients/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/net/client/HttpClient.java b/sql-clients/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/net/client/HttpClient.java index 30de1f3b4be..c775addf918 100644 --- a/sql-clients/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/net/client/HttpClient.java +++ b/sql-clients/jdbc/src/main/java/org/elasticsearch/xpack/sql/jdbc/net/client/HttpClient.java @@ -3,24 +3,6 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -/* -\ * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch 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.elasticsearch.xpack.sql.jdbc.net.client; import java.net.MalformedURLException; diff --git a/sql-clients/test-utils/build.gradle b/sql-clients/test-utils/build.gradle index fcca7ca4c88..1c2acee336f 100644 --- a/sql-clients/test-utils/build.gradle +++ b/sql-clients/test-utils/build.gradle @@ -10,3 +10,9 @@ dependencies { * hard to configure and (hopefully) much less important for tests than * production code. */ dependencyLicenses.enabled = false + +forbiddenApisMain { + //we are using jdk-internal instead of jdk-non-portable to allow for com.sun.net.httpserver.* usage + bundledSignatures -= 'jdk-non-portable' + bundledSignatures += 'jdk-internal' +} diff --git a/sql-clients/test-utils/src/main/java/org/elasticsearch/xpack/sql/test/server/ProtoHttpServer.java b/sql-clients/test-utils/src/main/java/org/elasticsearch/xpack/sql/test/server/ProtoHttpServer.java index 2a95e42dfd2..5a60a54549b 100644 --- a/sql-clients/test-utils/src/main/java/org/elasticsearch/xpack/sql/test/server/ProtoHttpServer.java +++ b/sql-clients/test-utils/src/main/java/org/elasticsearch/xpack/sql/test/server/ProtoHttpServer.java @@ -6,6 +6,7 @@ package org.elasticsearch.xpack.sql.test.server; import java.io.IOException; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.util.concurrent.Executors; @@ -30,7 +31,7 @@ public abstract class ProtoHttpServer { } public void start(int port) throws IOException { - server = HttpServer.create(new InetSocketAddress(port), 0); + server = HttpServer.create(new InetSocketAddress(InetAddress.getLoopbackAddress(), port), 0); server.createContext(defaultPrefix, new RootHttpHandler()); server.createContext(defaultPrefix + protoPrefix, handler); server.setExecutor(Executors.newCachedThreadPool()); @@ -47,7 +48,7 @@ public abstract class ProtoHttpServer { } public String url() { - return server != null ? format("localhost:%d%s%s", address().getPort(), defaultPrefix, protoPrefix): ""; + return server != null ? "localhost:" + address().getPort() + defaultPrefix + protoPrefix : ""; } public Client client() { diff --git a/sql-clients/test-utils/src/main/java/org/elasticsearch/xpack/sql/test/server/RootHttpHandler.java b/sql-clients/test-utils/src/main/java/org/elasticsearch/xpack/sql/test/server/RootHttpHandler.java index f7fac0e8c6c..9ef2e8db0ba 100644 --- a/sql-clients/test-utils/src/main/java/org/elasticsearch/xpack/sql/test/server/RootHttpHandler.java +++ b/sql-clients/test-utils/src/main/java/org/elasticsearch/xpack/sql/test/server/RootHttpHandler.java @@ -5,18 +5,20 @@ */ package org.elasticsearch.xpack.sql.test.server; -import java.io.IOException; - import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; +import org.apache.logging.log4j.Logger; +import org.elasticsearch.common.logging.ESLoggerFactory; + +import java.io.IOException; + class RootHttpHandler implements HttpHandler { + private static final Logger logger = ESLoggerFactory.getLogger(RootHttpHandler.class); @Override public void handle(HttpExchange t) throws IOException { - System.out.println("Received ping call..."); - //String m = "SQL Proto testing server"; - //byte[] bytes = StringUtils.toUTF(m); + logger.debug("Received ping call..."); t.sendResponseHeaders(200, -1); t.close(); }