You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2020/03/23 07:58:58 UTC

[dubbo] branch 2.7.6-release updated: Resolve the License issue (#5903)

This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch 2.7.6-release
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/2.7.6-release by this push:
     new af4cff2  Resolve the License issue (#5903)
af4cff2 is described below

commit af4cff2846bdfb9f105bf32b988616a4ed40a072
Author: Mercy Ma <me...@gmail.com>
AuthorDate: Mon Mar 23 15:58:16 2020 +0800

    Resolve the License issue (#5903)
---
 .../org/apache/dubbo/common/utils/HttpUtils.java   | 264 ---------------------
 .../org/apache/dubbo/common/utils/PathUtils.java   |  69 ++++++
 .../dubbo/metadata/rest/RequestMetadata.java       |   4 +-
 .../jaxrs/JAXRSServiceRestMetadataResolver.java    |   2 +-
 .../SpringMvcServiceRestMetadataResolver.java      |   2 +-
 .../jaxrs/JAXRSServiceRestMetadataResolver.java    |   2 +-
 .../SpringMvcServiceRestMetadataResolver.java      |   2 +-
 7 files changed, 75 insertions(+), 270 deletions(-)

diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/HttpUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/HttpUtils.java
deleted file mode 100644
index b944d5a..0000000
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/HttpUtils.java
+++ /dev/null
@@ -1,264 +0,0 @@
-/*
- * Copyright (C) 2018 the original author or authors.
- *
- * 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
- *
- *      https://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.dubbo.common.utils;
-
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import java.net.URLEncoder;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-import static java.util.Arrays.asList;
-import static java.util.Collections.unmodifiableSet;
-import static org.apache.dubbo.common.utils.StringUtils.AND;
-import static org.apache.dubbo.common.utils.StringUtils.EQUAL;
-import static org.apache.dubbo.common.utils.StringUtils.QUESTION_MASK;
-import static org.apache.dubbo.common.utils.StringUtils.SLASH;
-import static org.apache.dubbo.common.utils.StringUtils.isEmpty;
-import static org.apache.dubbo.common.utils.StringUtils.replace;
-
-/**
- * Http Utilities class
- *
- * @since 2.7.6
- */
-public abstract class HttpUtils {
-
-    private static final String UTF_8 = "UTF-8";
-
-    /**
-     * HTTP GET method.
-     */
-    public static final String GET = "GET";
-    /**
-     * HTTP POST method.
-     */
-    public static final String POST = "POST";
-    /**
-     * HTTP PUT method.
-     */
-    public static final String PUT = "PUT";
-    /**
-     * HTTP DELETE method.
-     */
-    public static final String DELETE = "DELETE";
-    /**
-     * HTTP HEAD method.
-     */
-    public static final String HEAD = "HEAD";
-    /**
-     * HTTP OPTIONS method.
-     */
-    public static final String OPTIONS = "OPTIONS";
-
-    /**
-     * The HTTP methods to support
-     */
-    public static final Set<String> HTTP_METHODS = unmodifiableSet(new LinkedHashSet<>(asList(
-            GET, POST, POST, PUT, DELETE, HEAD, OPTIONS
-    )));
-
-
-    public static String buildPath(String rootPath, String... subPaths) {
-
-        Set<String> paths = new LinkedHashSet<>();
-        paths.add(rootPath);
-        paths.addAll(asList(subPaths));
-
-        return normalizePath(paths.stream()
-                .filter(StringUtils::isNotEmpty)
-                .collect(Collectors.joining(SLASH)));
-    }
-
-    /**
-     * Normalize path:
-     * <ol>
-     * <li>To remove query string if presents</li>
-     * <li>To remove duplicated slash("/") if exists</li>
-     * </ol>
-     *
-     * @param path path to be normalized
-     * @return a normalized path if required
-     */
-    public static String normalizePath(String path) {
-        if (isEmpty(path)) {
-            return SLASH;
-        }
-        String normalizedPath = path;
-        int index = normalizedPath.indexOf(QUESTION_MASK);
-        if (index > -1) {
-            normalizedPath = normalizedPath.substring(0, index);
-        }
-        return replace(normalizedPath, "//", "/");
-    }
-
-//    /**
-//     * Get Parameters from the specified query string.
-//     * <p>
-//     *
-//     * @param queryString The query string
-//     * @return The query parameters
-//     */
-//    public static MultivaluedMap<String, String> getParameters(String queryString) {
-//        return getParameters(split(queryString, AND_CHAR));
-//    }
-
-//    /**
-//     * Get Parameters from the specified pairs of name-value.
-//     * <p>
-//     *
-//     * @param pairs The pairs of name-value
-//     * @return The query parameters
-//     */
-//    public static MultivaluedMap<String, String> getParameters(Iterable<String> pairs) {
-//        MultivaluedMap<String, String> parameters = new MultivaluedHashMap<>();
-//        if (pairs != null) {
-//            for (String pair : pairs) {
-//                String[] nameAndValue = split(pair, EQUAL_CHAR);
-//                String name = decode(nameAndValue[0]);
-//                String value = nameAndValue.length < 2 ? null : nameAndValue[1];
-//                value = decode(value);
-//                addParam(parameters, name, value);
-//            }
-//        }
-//        return parameters;
-//    }
-
-//    /**
-//     * Get Parameters from the specified pairs of name-value.
-//     * <p>
-//     *
-//     * @param pairs The pairs of name-value
-//     * @return The query parameters
-//     */
-//    public static MultivaluedMap<String, String> getParameters(String... pairs) {
-//        return getParameters(asList(pairs));
-//    }
-
-    // /**
-    // * Parse a read-only {@link MultivaluedMap} of {@link HttpCookie} from {@link
-    // HttpHeaders}
-    // *
-    // * @param httpHeaders {@link HttpHeaders}
-    // * @return non-null, the key is a cookie name , the value is {@link HttpCookie}
-    // */
-    // public static MultivaluedMap<String, HttpCookie> parseCookies(HttpHeaders
-    // httpHeaders) {
-    //
-    // String cookie = httpHeaders.getFirst(COOKIE);
-    //
-    // String[] cookieNameAndValues = StringUtils.delimitedListToStringArray(cookie,
-    // SEMICOLON);
-    //
-    // MultivaluedMap<String, HttpCookie> cookies = new
-    // LinkedMultiValueMap<>(cookieNameAndValues.length);
-    //
-    // for (String cookeNameAndValue : cookieNameAndValues) {
-    // String[] nameAndValue =
-    // delimitedListToStringArray(trimWhitespace(cookeNameAndValue), EQUAL);
-    // String name = nameAndValue[0];
-    // String value = nameAndValue.length < 2 ? null : nameAndValue[1];
-    // HttpCookie httpCookie = new HttpCookie(name, value);
-    // cookies.add(name, httpCookie);
-    // }
-    //
-    // return cookies;
-    // }
-
-    /**
-     * To the name and value line sets
-     *
-     * @param nameAndValuesMap the map of name and values
-     * @return non-null
-     */
-    public static Set<String> toNameAndValuesSet(
-            Map<String, List<String>> nameAndValuesMap) {
-        Set<String> nameAndValues = new LinkedHashSet<>();
-        for (Map.Entry<String, List<String>> entry : nameAndValuesMap.entrySet()) {
-            String name = entry.getKey();
-            List<String> values = entry.getValue();
-            for (String value : values) {
-                String nameAndValue = name + EQUAL + value;
-                nameAndValues.add(nameAndValue);
-            }
-        }
-        return nameAndValues;
-    }
-
-    public static String[] toNameAndValues(Map<String, List<String>> nameAndValuesMap) {
-        return toNameAndValuesSet(nameAndValuesMap).toArray(new String[0]);
-    }
-
-    /**
-     * Generate a string of query string from the specified request parameters {@link Map}
-     *
-     * @param params the specified request parameters {@link Map}
-     * @return non-null
-     */
-    public static String toQueryString(Map<String, List<String>> params) {
-        StringBuilder builder = new StringBuilder();
-        for (String line : toNameAndValuesSet(params)) {
-            builder.append(line).append(AND);
-        }
-        return builder.toString();
-    }
-
-    /**
-     * Decode value
-     *
-     * @param value the value requires to decode
-     * @return the decoded value
-     */
-    public static String decode(String value) {
-        if (value == null) {
-            return value;
-        }
-        String decodedValue = value;
-        try {
-            decodedValue = URLDecoder.decode(value, UTF_8);
-        } catch (UnsupportedEncodingException ex) {
-        }
-        return decodedValue;
-    }
-
-    /**
-     * encode value
-     *
-     * @param value the value requires to encode
-     * @return the encoded value
-     */
-    public static String encode(String value) {
-        String encodedValue = value;
-        try {
-            encodedValue = URLEncoder.encode(value, UTF_8);
-        } catch (UnsupportedEncodingException ex) {
-        }
-        return encodedValue;
-    }
-
-//    private static void addParam(MultivaluedMap<String, String> paramsMap, String name,
-//                                 String value) {
-//        String paramValue = trim(value);
-//        if (isEmpty(paramValue)) {
-//            paramValue = EMPTY_VALUE;
-//        }
-//        paramsMap.add(trim(name), paramValue);
-//    }
-}
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/PathUtils.java b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/PathUtils.java
new file mode 100644
index 0000000..3e38ce1
--- /dev/null
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/PathUtils.java
@@ -0,0 +1,69 @@
+/*
+ * 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.dubbo.common.utils;
+
+import java.util.LinkedHashSet;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static java.util.Arrays.asList;
+import static org.apache.dubbo.common.utils.StringUtils.QUESTION_MASK;
+import static org.apache.dubbo.common.utils.StringUtils.SLASH;
+import static org.apache.dubbo.common.utils.StringUtils.isEmpty;
+import static org.apache.dubbo.common.utils.StringUtils.replace;
+
+/**
+ * Path Utilities class
+ *
+ * @since 2.7.6
+ */
+public interface PathUtils {
+
+    static String buildPath(String rootPath, String... subPaths) {
+
+        Set<String> paths = new LinkedHashSet<>();
+        paths.add(rootPath);
+        paths.addAll(asList(subPaths));
+
+        return normalize(paths.stream()
+                .filter(StringUtils::isNotEmpty)
+                .collect(Collectors.joining(SLASH)));
+    }
+
+    /**
+     * Normalize path:
+     * <ol>
+     * <li>To remove query string if presents</li>
+     * <li>To remove duplicated slash("/") if exists</li>
+     * </ol>
+     *
+     * @param path path to be normalized
+     * @return a normalized path if required
+     */
+    static String normalize(String path) {
+        if (isEmpty(path)) {
+            return SLASH;
+        }
+        String normalizedPath = path;
+        int index = normalizedPath.indexOf(QUESTION_MASK);
+        if (index > -1) {
+            normalizedPath = normalizedPath.substring(0, index);
+        }
+        return replace(normalizedPath, "//", "/");
+    }
+
+}
diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/rest/RequestMetadata.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/rest/RequestMetadata.java
index 9381d20..dd797ca 100644
--- a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/rest/RequestMetadata.java
+++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/rest/RequestMetadata.java
@@ -30,7 +30,7 @@ import java.util.Objects;
 import java.util.Set;
 
 import static java.util.Collections.unmodifiableMap;
-import static org.apache.dubbo.common.utils.HttpUtils.normalizePath;
+import static org.apache.dubbo.common.utils.PathUtils.normalize;
 import static org.apache.dubbo.common.utils.StringUtils.isBlank;
 
 /**
@@ -73,7 +73,7 @@ public class RequestMetadata implements Serializable {
     }
 
     public void setPath(String path) {
-        this.path = normalizePath(path);
+        this.path = normalize(path);
     }
 
     public Map<String, List<String>> getParams() {
diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/JAXRSServiceRestMetadataResolver.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/JAXRSServiceRestMetadataResolver.java
index ca4a77f..78d174e 100644
--- a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/JAXRSServiceRestMetadataResolver.java
+++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/rest/jaxrs/JAXRSServiceRestMetadataResolver.java
@@ -28,7 +28,7 @@ import static org.apache.dubbo.common.utils.AnnotationUtils.findAnnotation;
 import static org.apache.dubbo.common.utils.AnnotationUtils.findMetaAnnotation;
 import static org.apache.dubbo.common.utils.AnnotationUtils.getValue;
 import static org.apache.dubbo.common.utils.AnnotationUtils.isAnnotationPresent;
-import static org.apache.dubbo.common.utils.HttpUtils.buildPath;
+import static org.apache.dubbo.common.utils.PathUtils.buildPath;
 import static org.apache.dubbo.metadata.rest.RestMetadataConstants.JAX_RS.CONSUMES_ANNOTATION_CLASS_NAME;
 import static org.apache.dubbo.metadata.rest.RestMetadataConstants.JAX_RS.HTTP_METHOD_ANNOTATION_CLASS_NAME;
 import static org.apache.dubbo.metadata.rest.RestMetadataConstants.JAX_RS.PATH_ANNOTATION_CLASS_NAME;
diff --git a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/rest/springmvc/SpringMvcServiceRestMetadataResolver.java b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/rest/springmvc/SpringMvcServiceRestMetadataResolver.java
index 2fde671..e24422a 100644
--- a/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/rest/springmvc/SpringMvcServiceRestMetadataResolver.java
+++ b/dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/rest/springmvc/SpringMvcServiceRestMetadataResolver.java
@@ -34,7 +34,7 @@ import static org.apache.dubbo.common.utils.AnnotationUtils.getAttribute;
 import static org.apache.dubbo.common.utils.AnnotationUtils.isAnnotationPresent;
 import static org.apache.dubbo.common.utils.ArrayUtils.isEmpty;
 import static org.apache.dubbo.common.utils.ArrayUtils.isNotEmpty;
-import static org.apache.dubbo.common.utils.HttpUtils.buildPath;
+import static org.apache.dubbo.common.utils.PathUtils.buildPath;
 import static org.apache.dubbo.metadata.rest.RestMetadataConstants.SPRING_MVC.CONTROLLER_ANNOTATION_CLASS_NAME;
 import static org.apache.dubbo.metadata.rest.RestMetadataConstants.SPRING_MVC.REQUEST_MAPPING_ANNOTATION_CLASS_NAME;
 
diff --git a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/JAXRSServiceRestMetadataResolver.java b/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/JAXRSServiceRestMetadataResolver.java
index dd30acc..02e52a2 100644
--- a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/JAXRSServiceRestMetadataResolver.java
+++ b/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/jaxrs/JAXRSServiceRestMetadataResolver.java
@@ -28,7 +28,7 @@ import javax.lang.model.element.TypeElement;
 import java.util.Set;
 import java.util.stream.Stream;
 
-import static org.apache.dubbo.common.utils.HttpUtils.buildPath;
+import static org.apache.dubbo.common.utils.PathUtils.buildPath;
 import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.findAnnotation;
 import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.findMetaAnnotation;
 import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.getAnnotation;
diff --git a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/springmvc/SpringMvcServiceRestMetadataResolver.java b/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/springmvc/SpringMvcServiceRestMetadataResolver.java
index 2a9eeb0..713bf74 100644
--- a/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/springmvc/SpringMvcServiceRestMetadataResolver.java
+++ b/dubbo-metadata/dubbo-metadata-processor/src/main/java/org/apache/dubbo/metadata/annotation/processing/rest/springmvc/SpringMvcServiceRestMetadataResolver.java
@@ -34,7 +34,7 @@ import static java.util.stream.Stream.of;
 import static org.apache.dubbo.common.function.Streams.filterFirst;
 import static org.apache.dubbo.common.utils.ArrayUtils.isEmpty;
 import static org.apache.dubbo.common.utils.ArrayUtils.isNotEmpty;
-import static org.apache.dubbo.common.utils.HttpUtils.buildPath;
+import static org.apache.dubbo.common.utils.PathUtils.buildPath;
 import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.findAnnotation;
 import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.findMetaAnnotation;
 import static org.apache.dubbo.metadata.annotation.processing.util.AnnotationUtils.getAllAnnotations;