From 04e82e959cbd87eac927eb5910b95145ff01fb76 Mon Sep 17 00:00:00 2001 From: enoch Date: Mon, 25 Sep 2023 09:49:23 +0800 Subject: [PATCH] fix: HttpURLConnectionPlugin moved to package com.megaease.easeagent.plugin.httpurlconnection; --- .../plugin/api/config/ConfigConst.java | 1 + plugins/httpclient/pom.xml | 5 -- plugins/httpurlconnection/pom.xml | 50 +++++++++++++++++++ .../httpurlconnection/ForwardedPlugin.java | 33 ++++++++++++ .../HttpURLConnectionPlugin.java | 33 ++++++++++++ ...ttpURLConnectionGetResponseCodeAdvice.java | 2 +- ...LConnectionGetResponseCodeInterceptor.java | 8 +-- ...nectionGetResponseCodeInterceptorTest.java | 17 ++++++- .../interceptor/TestConst.java | 23 +++++++++ .../src/test/resources/mock_agent.properties | 19 +++++++ plugins/pom.xml | 1 + 11 files changed, 180 insertions(+), 12 deletions(-) create mode 100644 plugins/httpurlconnection/pom.xml create mode 100644 plugins/httpurlconnection/src/main/java/com/megaease/easeagent/plugin/httpurlconnection/ForwardedPlugin.java create mode 100644 plugins/httpurlconnection/src/main/java/com/megaease/easeagent/plugin/httpurlconnection/HttpURLConnectionPlugin.java rename plugins/{httpclient/src/main/java/com/megaease/easeagent/plugin/httpclient => httpurlconnection/src/main/java/com/megaease/easeagent/plugin/httpurlconnection}/advice/HttpURLConnectionGetResponseCodeAdvice.java (95%) rename plugins/{httpclient/src/main/java/com/megaease/easeagent/plugin/httpclient => httpurlconnection/src/main/java/com/megaease/easeagent/plugin/httpurlconnection}/interceptor/HttpURLConnectionGetResponseCodeInterceptor.java (93%) rename plugins/{httpclient/src/test/java/com/megaease/easeagent/plugin/httpclient => httpurlconnection/src/test/java/com/megaease/easeagent/plugin/httpurlconnection}/interceptor/HttpURLConnectionGetResponseCodeInterceptorTest.java (88%) create mode 100644 plugins/httpurlconnection/src/test/java/com/megaease/easeagent/plugin/httpurlconnection/interceptor/TestConst.java create mode 100644 plugins/httpurlconnection/src/test/resources/mock_agent.properties diff --git a/plugin-api/src/main/java/com/megaease/easeagent/plugin/api/config/ConfigConst.java b/plugin-api/src/main/java/com/megaease/easeagent/plugin/api/config/ConfigConst.java index 7addef69c..b741cd73e 100644 --- a/plugin-api/src/main/java/com/megaease/easeagent/plugin/api/config/ConfigConst.java +++ b/plugin-api/src/main/java/com/megaease/easeagent/plugin/api/config/ConfigConst.java @@ -159,6 +159,7 @@ interface Namespace { String WEB_CLIENT = "webclient"; String FEIGN_CLIENT = "feignClient"; String REST_TEMPLATE = "resTemplate"; + String HTTPURLCONNECTION = "httpURLConnection"; String FORWARDED = "forwarded"; } diff --git a/plugins/httpclient/pom.xml b/plugins/httpclient/pom.xml index 65de7b9f0..9d8332e2c 100644 --- a/plugins/httpclient/pom.xml +++ b/plugins/httpclient/pom.xml @@ -35,11 +35,6 @@ plugin-api provided - - com.google.guava - guava - provided - org.apache.httpcomponents httpclient diff --git a/plugins/httpurlconnection/pom.xml b/plugins/httpurlconnection/pom.xml new file mode 100644 index 000000000..0a85893e5 --- /dev/null +++ b/plugins/httpurlconnection/pom.xml @@ -0,0 +1,50 @@ + + + + + + plugins + com.megaease.easeagent + 2.2.7 + + 4.0.0 + + httpurlconnection + + + + + com.megaease.easeagent + plugin-api + provided + + + com.google.guava + guava + provided + + + com.megaease.easeagent + plugin-api-mock + ${project.version} + test + + + diff --git a/plugins/httpurlconnection/src/main/java/com/megaease/easeagent/plugin/httpurlconnection/ForwardedPlugin.java b/plugins/httpurlconnection/src/main/java/com/megaease/easeagent/plugin/httpurlconnection/ForwardedPlugin.java new file mode 100644 index 000000000..6bcf4cf20 --- /dev/null +++ b/plugins/httpurlconnection/src/main/java/com/megaease/easeagent/plugin/httpurlconnection/ForwardedPlugin.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023, MegaEase + * All rights reserved. + * + * 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 com.megaease.easeagent.plugin.httpurlconnection; + +import com.megaease.easeagent.plugin.AgentPlugin; +import com.megaease.easeagent.plugin.api.config.ConfigConst; + +public class ForwardedPlugin implements AgentPlugin { + @Override + public String getNamespace() { + return ConfigConst.Namespace.FORWARDED; + } + + @Override + public String getDomain() { + return ConfigConst.INTEGRABILITY; + } +} diff --git a/plugins/httpurlconnection/src/main/java/com/megaease/easeagent/plugin/httpurlconnection/HttpURLConnectionPlugin.java b/plugins/httpurlconnection/src/main/java/com/megaease/easeagent/plugin/httpurlconnection/HttpURLConnectionPlugin.java new file mode 100644 index 000000000..efcc97dd2 --- /dev/null +++ b/plugins/httpurlconnection/src/main/java/com/megaease/easeagent/plugin/httpurlconnection/HttpURLConnectionPlugin.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023, MegaEase + * All rights reserved. + * + * 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 com.megaease.easeagent.plugin.httpurlconnection; + +import com.megaease.easeagent.plugin.AgentPlugin; +import com.megaease.easeagent.plugin.api.config.ConfigConst; + +public class HttpURLConnectionPlugin implements AgentPlugin { + @Override + public String getNamespace() { + return ConfigConst.Namespace.HTTPURLCONNECTION; + } + + @Override + public String getDomain() { + return ConfigConst.OBSERVABILITY; + } +} diff --git a/plugins/httpclient/src/main/java/com/megaease/easeagent/plugin/httpclient/advice/HttpURLConnectionGetResponseCodeAdvice.java b/plugins/httpurlconnection/src/main/java/com/megaease/easeagent/plugin/httpurlconnection/advice/HttpURLConnectionGetResponseCodeAdvice.java similarity index 95% rename from plugins/httpclient/src/main/java/com/megaease/easeagent/plugin/httpclient/advice/HttpURLConnectionGetResponseCodeAdvice.java rename to plugins/httpurlconnection/src/main/java/com/megaease/easeagent/plugin/httpurlconnection/advice/HttpURLConnectionGetResponseCodeAdvice.java index a4a180b02..1a1156117 100644 --- a/plugins/httpclient/src/main/java/com/megaease/easeagent/plugin/httpclient/advice/HttpURLConnectionGetResponseCodeAdvice.java +++ b/plugins/httpurlconnection/src/main/java/com/megaease/easeagent/plugin/httpurlconnection/advice/HttpURLConnectionGetResponseCodeAdvice.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package com.megaease.easeagent.plugin.httpclient.advice; +package com.megaease.easeagent.plugin.httpurlconnection.advice; import com.megaease.easeagent.plugin.Points; import com.megaease.easeagent.plugin.matcher.ClassMatcher; diff --git a/plugins/httpclient/src/main/java/com/megaease/easeagent/plugin/httpclient/interceptor/HttpURLConnectionGetResponseCodeInterceptor.java b/plugins/httpurlconnection/src/main/java/com/megaease/easeagent/plugin/httpurlconnection/interceptor/HttpURLConnectionGetResponseCodeInterceptor.java similarity index 93% rename from plugins/httpclient/src/main/java/com/megaease/easeagent/plugin/httpclient/interceptor/HttpURLConnectionGetResponseCodeInterceptor.java rename to plugins/httpurlconnection/src/main/java/com/megaease/easeagent/plugin/httpurlconnection/interceptor/HttpURLConnectionGetResponseCodeInterceptor.java index 68d7c7fdf..a4f99d0a0 100644 --- a/plugins/httpclient/src/main/java/com/megaease/easeagent/plugin/httpclient/interceptor/HttpURLConnectionGetResponseCodeInterceptor.java +++ b/plugins/httpurlconnection/src/main/java/com/megaease/easeagent/plugin/httpurlconnection/interceptor/HttpURLConnectionGetResponseCodeInterceptor.java @@ -15,15 +15,15 @@ * limitations under the License. */ -package com.megaease.easeagent.plugin.httpclient.interceptor; +package com.megaease.easeagent.plugin.httpurlconnection.interceptor; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; import com.megaease.easeagent.plugin.annotation.AdviceTo; import com.megaease.easeagent.plugin.api.Context; import com.megaease.easeagent.plugin.api.trace.Span; -import com.megaease.easeagent.plugin.httpclient.HttpClientPlugin; -import com.megaease.easeagent.plugin.httpclient.advice.HttpURLConnectionGetResponseCodeAdvice; +import com.megaease.easeagent.plugin.httpurlconnection.HttpURLConnectionPlugin; +import com.megaease.easeagent.plugin.httpurlconnection.advice.HttpURLConnectionGetResponseCodeAdvice; import com.megaease.easeagent.plugin.interceptor.MethodInfo; import com.megaease.easeagent.plugin.tools.trace.BaseHttpClientTracingInterceptor; import com.megaease.easeagent.plugin.tools.trace.HttpRequest; @@ -35,7 +35,7 @@ import java.util.Map; -@AdviceTo(value = HttpURLConnectionGetResponseCodeAdvice.class, qualifier = "default", plugin = HttpClientPlugin.class) +@AdviceTo(value = HttpURLConnectionGetResponseCodeAdvice.class, qualifier = "default", plugin = HttpURLConnectionPlugin.class) public class HttpURLConnectionGetResponseCodeInterceptor extends BaseHttpClientTracingInterceptor { @Override public Object getProgressKey() { diff --git a/plugins/httpclient/src/test/java/com/megaease/easeagent/plugin/httpclient/interceptor/HttpURLConnectionGetResponseCodeInterceptorTest.java b/plugins/httpurlconnection/src/test/java/com/megaease/easeagent/plugin/httpurlconnection/interceptor/HttpURLConnectionGetResponseCodeInterceptorTest.java similarity index 88% rename from plugins/httpclient/src/test/java/com/megaease/easeagent/plugin/httpclient/interceptor/HttpURLConnectionGetResponseCodeInterceptorTest.java rename to plugins/httpurlconnection/src/test/java/com/megaease/easeagent/plugin/httpurlconnection/interceptor/HttpURLConnectionGetResponseCodeInterceptorTest.java index 6cafe0148..84119d2f3 100644 --- a/plugins/httpclient/src/test/java/com/megaease/easeagent/plugin/httpclient/interceptor/HttpURLConnectionGetResponseCodeInterceptorTest.java +++ b/plugins/httpurlconnection/src/test/java/com/megaease/easeagent/plugin/httpurlconnection/interceptor/HttpURLConnectionGetResponseCodeInterceptorTest.java @@ -1,8 +1,21 @@ /* - * Copyright (c) 2023, Inspireso and/or its affiliates. All rights reserved. + * Copyright (c) 2023, MegaEase + * All rights reserved. + * + * 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 com.megaease.easeagent.plugin.httpclient.interceptor; +package com.megaease.easeagent.plugin.httpurlconnection.interceptor; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; diff --git a/plugins/httpurlconnection/src/test/java/com/megaease/easeagent/plugin/httpurlconnection/interceptor/TestConst.java b/plugins/httpurlconnection/src/test/java/com/megaease/easeagent/plugin/httpurlconnection/interceptor/TestConst.java new file mode 100644 index 000000000..89c4fee04 --- /dev/null +++ b/plugins/httpurlconnection/src/test/java/com/megaease/easeagent/plugin/httpurlconnection/interceptor/TestConst.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2021, MegaEase + * All rights reserved. + * + * 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 com.megaease.easeagent.plugin.httpurlconnection.interceptor; + +public class TestConst { + public static final String RESPONSE_TAG_NAME = "X-EG-Test"; + public static final String RESPONSE_TAG_VALUE = "X-EG-Test-Value"; +} diff --git a/plugins/httpurlconnection/src/test/resources/mock_agent.properties b/plugins/httpurlconnection/src/test/resources/mock_agent.properties new file mode 100644 index 000000000..8fb0c2983 --- /dev/null +++ b/plugins/httpurlconnection/src/test/resources/mock_agent.properties @@ -0,0 +1,19 @@ +# +# Copyright (c) 2023, MegaEase +# All rights reserved. +# +# 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. +# + +easeagent.progress.forwarded.headers=X-Forwarded-For +observability.tracings.tag.response.headers.eg.0=X-EG-Test diff --git a/plugins/pom.xml b/plugins/pom.xml index d81a14cca..85caab04b 100644 --- a/plugins/pom.xml +++ b/plugins/pom.xml @@ -52,6 +52,7 @@ dubbo motan sofarpc + httpurlconnection