You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by wu...@apache.org on 2018/06/05 07:29:44 UTC
[incubator-servicecomb-java-chassis] 02/06: [SCB-616] define new
AccessLogPatternParser
This is an automated email from the ASF dual-hosted git repository.
wujimin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git
commit 789593956bb9a396d838b63fa948894417adcc56
Author: yaohaishi <ya...@huawei.com>
AuthorDate: Sun May 27 01:31:50 2018 +0800
[SCB-616] define new AccessLogPatternParser
---
.../vertx/accesslog/parser/AccessLogItemMeta.java | 57 ++++++++++++++++
.../accesslog/parser/AccessLogPatternParser.java | 33 +++++++++
.../parser/VertxRestAccessLogItemCreator.java | 45 ++++++++++++
.../impl/VertxRestAccessLogPatternParser.java | 79 ++++++++++++++++++++++
.../impl/VertxRestAccessLogPatternParserTest.java | 21 ++++++
5 files changed, 235 insertions(+)
diff --git a/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/accesslog/parser/AccessLogItemMeta.java b/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/accesslog/parser/AccessLogItemMeta.java
new file mode 100644
index 0000000..131743e
--- /dev/null
+++ b/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/accesslog/parser/AccessLogItemMeta.java
@@ -0,0 +1,57 @@
+/*
+ * 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.servicecomb.transport.rest.vertx.accesslog.parser;
+
+import org.apache.servicecomb.transport.rest.vertx.accesslog.element.AccessLogItem;
+
+/**
+ * The meta data of {@linkplain AccessLogItem}.
+ */
+public class AccessLogItemMeta {
+ private String prefix;
+
+ private String suffix;
+
+ /**
+ * Used for sorting {@linkplain AccessLogItemMeta}. Default value is 0.
+ * Smaller one has higher priority.
+ */
+ private int order;
+
+ public AccessLogItemMeta(String prefix, String suffix, int order) {
+ this.prefix = prefix;
+ this.suffix = suffix;
+ this.order = order;
+ }
+
+ public AccessLogItemMeta(String prefix, String suffix) {
+ this(prefix, suffix, 0);
+ }
+
+ public String getPrefix() {
+ return prefix;
+ }
+
+ public String getSuffix() {
+ return suffix;
+ }
+
+ public int getOrder() {
+ return order;
+ }
+}
diff --git a/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/accesslog/parser/AccessLogPatternParser.java b/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/accesslog/parser/AccessLogPatternParser.java
new file mode 100644
index 0000000..bc38768
--- /dev/null
+++ b/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/accesslog/parser/AccessLogPatternParser.java
@@ -0,0 +1,33 @@
+/*
+ * 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.servicecomb.transport.rest.vertx.accesslog.parser;
+
+import java.util.List;
+
+import org.apache.servicecomb.transport.rest.vertx.accesslog.element.AccessLogItem;
+
+/**
+ * This parser will parse the rawPattern of access log and generate a list of {@link AccessLogItem},
+ * which will be used in {@link org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogGenerator} to generate
+ * access log content.
+ * @param <T> the type of {@linkplain org.apache.servicecomb.transport.rest.vertx.accesslog.AccessLogParam#contextData
+ * AccessLogParam.contextData}, which usually depends on the transport way.
+ */
+public interface AccessLogPatternParser<T> {
+ List<AccessLogItem<T>> parsePattern(String rawPattern);
+}
diff --git a/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/accesslog/parser/VertxRestAccessLogItemCreator.java b/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/accesslog/parser/VertxRestAccessLogItemCreator.java
new file mode 100644
index 0000000..f1917eb
--- /dev/null
+++ b/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/accesslog/parser/VertxRestAccessLogItemCreator.java
@@ -0,0 +1,45 @@
+/*
+ * 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.servicecomb.transport.rest.vertx.accesslog.parser;
+
+import java.util.List;
+
+import org.apache.servicecomb.transport.rest.vertx.accesslog.element.AccessLogItem;
+
+import io.vertx.ext.web.RoutingContext;
+
+/**
+ * The {@linkplain VertxRestAccessLogItemCreator}s are able to instantiate a group of {@linkplain AccessLogItem}.
+ */
+public interface VertxRestAccessLogItemCreator {
+ /**
+ * @return A list of {@linkplain AccessLogItemMeta} to show that what kinds of {@linkplain AccessLogItem}
+ * this creator is able to instantiate.
+ */
+ List<AccessLogItemMeta> getAccessLogItemMeta();
+
+ /**
+ * Create an instance of {@linkplain AccessLogItem} which is specified by {@linkplain AccessLogItemMeta} and config.
+ * @param accessLogItemMeta determine which kind of {@linkplain AccessLogItem} is created.
+ * @param config
+ * e.g. For {@linkplain org.apache.servicecomb.transport.rest.vertx.accesslog.element.impl.CookieItem CookieItem},
+ * the pattern may be "%{varName}C", and it's config is "varName". Some {@linkplain AccessLogItem} with no configurable
+ * pattern (like "%m") will receive {@code null} as config.
+ */
+ AccessLogItem<RoutingContext> createItem(AccessLogItemMeta accessLogItemMeta, String config);
+}
diff --git a/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/accesslog/parser/impl/VertxRestAccessLogPatternParser.java b/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/accesslog/parser/impl/VertxRestAccessLogPatternParser.java
new file mode 100644
index 0000000..666d9a9
--- /dev/null
+++ b/transports/transport-rest/transport-rest-vertx/src/main/java/org/apache/servicecomb/transport/rest/vertx/accesslog/parser/impl/VertxRestAccessLogPatternParser.java
@@ -0,0 +1,79 @@
+/*
+ * 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.servicecomb.transport.rest.vertx.accesslog.parser.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.servicecomb.transport.rest.vertx.accesslog.element.AccessLogItem;
+import org.apache.servicecomb.transport.rest.vertx.accesslog.parser.AccessLogItemMeta;
+import org.apache.servicecomb.transport.rest.vertx.accesslog.parser.AccessLogPatternParser;
+import org.apache.servicecomb.transport.rest.vertx.accesslog.parser.VertxRestAccessLogItemCreator;
+
+import io.vertx.ext.web.RoutingContext;
+
+/**
+ * The parser is used for rest-over-vertx transport.
+ */
+public class VertxRestAccessLogPatternParser implements AccessLogPatternParser<RoutingContext> {
+ private List<VertxRestAccessLogItemCreator> creators = new ArrayList<>();
+
+ /**
+ * All of the {@linkplain AccessLogItemMeta} will be wrapped into {@linkplain AccessLogItemMetaWrapper}.
+ */
+ private List<AccessLogItemMetaWrapper> accessLogItemMetaWrappers = new ArrayList<>();
+
+ public VertxRestAccessLogPatternParser() {
+ for (VertxRestAccessLogItemCreator creator : creators) {
+ for (AccessLogItemMeta accessLogItemMeta : creator.getAccessLogItemMeta()) {
+ accessLogItemMetaWrappers.add(new AccessLogItemMetaWrapper(accessLogItemMeta, creator));
+ }
+ }
+ }
+
+ /**
+ * @param rawPattern The access log pattern string specified by users.
+ * @return A list of {@linkplain AccessLogItem} which actually generate the content of access log.
+ */
+ @Override
+ public List<AccessLogItem<RoutingContext>> parsePattern(String rawPattern) {
+ List<AccessLogItem<RoutingContext>> itemList = new ArrayList<>();
+ // the algorithm is unimplemented.
+ return itemList;
+ }
+
+ public static class AccessLogItemMetaWrapper {
+ private AccessLogItemMeta accessLogItemMeta;
+
+ private VertxRestAccessLogItemCreator vertxRestAccessLogItemCreator;
+
+ public AccessLogItemMetaWrapper(AccessLogItemMeta accessLogItemMeta,
+ VertxRestAccessLogItemCreator vertxRestAccessLogItemCreator) {
+ this.accessLogItemMeta = accessLogItemMeta;
+ this.vertxRestAccessLogItemCreator = vertxRestAccessLogItemCreator;
+ }
+
+ public AccessLogItemMeta getAccessLogItemMeta() {
+ return accessLogItemMeta;
+ }
+
+ public VertxRestAccessLogItemCreator getVertxRestAccessLogItemCreator() {
+ return vertxRestAccessLogItemCreator;
+ }
+ }
+}
diff --git a/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/accesslog/parser/impl/VertxRestAccessLogPatternParserTest.java b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/accesslog/parser/impl/VertxRestAccessLogPatternParserTest.java
new file mode 100644
index 0000000..c27503e
--- /dev/null
+++ b/transports/transport-rest/transport-rest-vertx/src/test/java/org/apache/servicecomb/transport/rest/vertx/accesslog/parser/impl/VertxRestAccessLogPatternParserTest.java
@@ -0,0 +1,21 @@
+/*
+ * 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.servicecomb.transport.rest.vertx.accesslog.parser.impl;
+
+public class VertxRestAccessLogPatternParserTest {
+}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
wujimin@apache.org.