You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aurora.apache.org by zm...@apache.org on 2016/09/06 22:25:34 UTC
aurora git commit: Remove HttpServletRequestParams.
Repository: aurora
Updated Branches:
refs/heads/master 0c90c862a -> 19866b516
Remove HttpServletRequestParams.
`HttpServletRequestParams` is dead code can be removed safely.
Reviewed at https://reviews.apache.org/r/51667/
Project: http://git-wip-us.apache.org/repos/asf/aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/aurora/commit/19866b51
Tree: http://git-wip-us.apache.org/repos/asf/aurora/tree/19866b51
Diff: http://git-wip-us.apache.org/repos/asf/aurora/diff/19866b51
Branch: refs/heads/master
Commit: 19866b516b580bbec24f09f05d648b7311e7ef8f
Parents: 0c90c86
Author: Zameer Manji <zm...@apache.org>
Authored: Tue Sep 6 15:25:20 2016 -0700
Committer: Zameer Manji <zm...@apache.org>
Committed: Tue Sep 6 15:25:20 2016 -0700
----------------------------------------------------------------------
.../http/handlers/HttpServletRequestParams.java | 89 --------------------
.../handlers/HttpServletRequestParamsTest.java | 81 ------------------
2 files changed, 170 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/aurora/blob/19866b51/commons/src/main/java/org/apache/aurora/common/net/http/handlers/HttpServletRequestParams.java
----------------------------------------------------------------------
diff --git a/commons/src/main/java/org/apache/aurora/common/net/http/handlers/HttpServletRequestParams.java b/commons/src/main/java/org/apache/aurora/common/net/http/handlers/HttpServletRequestParams.java
deleted file mode 100644
index e906f94..0000000
--- a/commons/src/main/java/org/apache/aurora/common/net/http/handlers/HttpServletRequestParams.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/**
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.aurora.common.net.http.handlers;
-
-import javax.annotation.Nullable;
-import javax.servlet.http.HttpServletRequest;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Simple utility for parsing HttpServletRequest parameters by type.
- */
-public class HttpServletRequestParams {
- private static final Logger LOG = LoggerFactory.getLogger(HttpServletRequestParams.class);
-
- /**
- * Parses an int param from an HttpServletRequest, returns a default value
- * if the parameter is not set or is not a valid int.
- */
- public static int getInt(HttpServletRequest request, String param, int defaultValue) {
- final String value = request.getParameter(param);
- int result = defaultValue;
- if (value != null) {
- try {
- result = Integer.parseInt(value);
- } catch (NumberFormatException e) {
- LOG.warn("Invalid int for " + param + ": " + value);
- }
- }
- return result;
- }
-
- /**
- * Parses a long param from an HttpServletRequest, returns a defualt value
- * if the parameter is not set or is not a valid long.
- */
- public static long getLong(HttpServletRequest request, String param, long defaultValue) {
- final String value = request.getParameter(param);
- long result = defaultValue;
- if (value != null) {
- try {
- result = Long.parseLong(value);
- } catch (NumberFormatException e) {
- LOG.warn("Invalid long for " + param + ": " + value);
- }
- }
- return result;
- }
-
- /**
- * Parses a bool param from an HttpServletRequest, returns a default value
- * if the parameter is not set. Note that any value that is set will be
- * considered a legal bool by Boolean.valueOf, defualting to false if not
- * understood.
- */
- public static boolean getBool(HttpServletRequest request, String param, boolean defaultValue) {
- if (request.getParameter(param) != null) {
- return Boolean.valueOf(request.getParameter(param));
- } else {
- return defaultValue;
- }
- }
-
- /**
- * Returns a string param from an HttpServletRequest if set, returns a defualt value
- * if the parameter is not set.
- */
- @Nullable
- public static String getString(HttpServletRequest request, String param,
- @Nullable String defaultValue) {
- if (request.getParameter(param) != null) {
- return request.getParameter(param);
- } else {
- return defaultValue;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/aurora/blob/19866b51/commons/src/test/java/org/apache/aurora/common/net/http/handlers/HttpServletRequestParamsTest.java
----------------------------------------------------------------------
diff --git a/commons/src/test/java/org/apache/aurora/common/net/http/handlers/HttpServletRequestParamsTest.java b/commons/src/test/java/org/apache/aurora/common/net/http/handlers/HttpServletRequestParamsTest.java
deleted file mode 100644
index f1479bf..0000000
--- a/commons/src/test/java/org/apache/aurora/common/net/http/handlers/HttpServletRequestParamsTest.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/**
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.aurora.common.net.http.handlers;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.aurora.common.testing.easymock.EasyMockTest;
-import org.easymock.EasyMock;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.easymock.EasyMock.expect;
-import static org.junit.Assert.assertEquals;
-
-public class HttpServletRequestParamsTest extends EasyMockTest {
- private static final String INT_PARAM = "int_param";
- private static final String LONG_PARAM = "long_param";
- private static final String STRING_PARAM = "string_param";
- private static final String UNSET_PARAM = "unset_param";
- private static final String BOOL_PARAM = "bool_param";
-
- private HttpServletRequest request;
-
- @Before
- public void setUp() throws Exception {
- request = createMock(HttpServletRequest.class);
- expect(request.getParameter(INT_PARAM)).andReturn("123").anyTimes();
- expect(request.getParameter(LONG_PARAM)).andReturn("260833376896966656").anyTimes();
- expect(request.getParameter(STRING_PARAM)).andReturn("asdf").anyTimes();
- expect(request.getParameter(UNSET_PARAM)).andReturn(null).anyTimes();
- expect(request.getParameter(BOOL_PARAM)).andReturn("TRUE").anyTimes();
- }
-
- @Test
- public void testGetIntParam() {
- EasyMock.replay(request);
- assertEquals(123, HttpServletRequestParams.getInt(request, INT_PARAM, 456));
- assertEquals(456, HttpServletRequestParams.getInt(request, STRING_PARAM, 456));
- assertEquals(456, HttpServletRequestParams.getInt(request, UNSET_PARAM, 456));
- assertEquals(456, HttpServletRequestParams.getInt(request, LONG_PARAM, 456));
- }
-
- @Test
- public void testGetLongParam() {
- EasyMock.replay(request);
- assertEquals(123, HttpServletRequestParams.getLong(request, INT_PARAM, 456));
- assertEquals(260833376896966656L, HttpServletRequestParams.getLong(request, LONG_PARAM, 456));
- assertEquals(123456789012345678L,
- HttpServletRequestParams.getLong(request, STRING_PARAM, 123456789012345678L));
- assertEquals(456, HttpServletRequestParams.getLong(request, UNSET_PARAM, 456));
- }
-
- @Test
- public void testGetStringParam() {
- EasyMock.replay(request);
- assertEquals("123", HttpServletRequestParams.getString(request, INT_PARAM, "default"));
- assertEquals("260833376896966656",
- HttpServletRequestParams.getString(request, LONG_PARAM, "default"));
- assertEquals("asdf", HttpServletRequestParams.getString(request, STRING_PARAM, "default"));
- assertEquals("default", HttpServletRequestParams.getString(request, UNSET_PARAM, "default"));
- }
-
- @Test
- public void testGetBoolParam() {
- EasyMock.replay(request);
- assertEquals(false, HttpServletRequestParams.getBool(request, INT_PARAM, true));
- assertEquals(false, HttpServletRequestParams.getBool(request, LONG_PARAM, false));
- assertEquals(true, HttpServletRequestParams.getBool(request, BOOL_PARAM, false));
- }
-}