From ffdb94854fe3843745e722d17c587850a8a54858 Mon Sep 17 00:00:00 2001 From: heliang666s <147408835+heliang666s@users.noreply.github.com> Date: Wed, 4 Dec 2024 09:39:46 +0800 Subject: [PATCH 1/4] remove mesh-router samples to spi-samples (#1196) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * remove mesh-router samples to spi-samples * fix ci * fix ci --------- Co-authored-by: 何亮 --- .../case-configuration.yml | 68 -------- .../case-versions.conf | 25 --- .../dubbo-samples-meshrule-router/pom.xml | 150 ------------------ .../samples/governance/BasicConsumer.java | 37 ----- .../samples/governance/BasicProvider.java | 36 ----- .../samples/governance/BasicProvider2.java | 36 ----- .../dubbo/samples/governance/RuleUtil.java | 82 ---------- .../samples/governance/api/DemoService.java | 26 --- .../governance/impl/DemoServiceImpl.java | 30 ---- .../governance/impl/DemoServiceImpl2.java | 30 ---- .../resources/dubbo-routers-mesh-rule.yml | 51 ------ .../src/main/resources/log4j2.xml | 29 ---- .../resources/spring/dubbo-demo-consumer.xml | 36 ----- .../resources/spring/dubbo-demo-provider.xml | 43 ----- .../resources/spring/dubbo-demo-provider2.xml | 42 ----- .../samples/governance/DemoServiceIT.java | 52 ------ 4-governance/pom.xml | 1 - 17 files changed, 774 deletions(-) delete mode 100644 4-governance/dubbo-samples-meshrule-router/case-configuration.yml delete mode 100644 4-governance/dubbo-samples-meshrule-router/case-versions.conf delete mode 100644 4-governance/dubbo-samples-meshrule-router/pom.xml delete mode 100644 4-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/BasicConsumer.java delete mode 100644 4-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/BasicProvider.java delete mode 100644 4-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/BasicProvider2.java delete mode 100644 4-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/RuleUtil.java delete mode 100644 4-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/api/DemoService.java delete mode 100644 4-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl.java delete mode 100644 4-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl2.java delete mode 100644 4-governance/dubbo-samples-meshrule-router/src/main/resources/dubbo-routers-mesh-rule.yml delete mode 100644 4-governance/dubbo-samples-meshrule-router/src/main/resources/log4j2.xml delete mode 100644 4-governance/dubbo-samples-meshrule-router/src/main/resources/spring/dubbo-demo-consumer.xml delete mode 100644 4-governance/dubbo-samples-meshrule-router/src/main/resources/spring/dubbo-demo-provider.xml delete mode 100644 4-governance/dubbo-samples-meshrule-router/src/main/resources/spring/dubbo-demo-provider2.xml delete mode 100644 4-governance/dubbo-samples-meshrule-router/src/test/java/org/apache/dubbo/samples/governance/DemoServiceIT.java diff --git a/4-governance/dubbo-samples-meshrule-router/case-configuration.yml b/4-governance/dubbo-samples-meshrule-router/case-configuration.yml deleted file mode 100644 index 1f6c337569..0000000000 --- a/4-governance/dubbo-samples-meshrule-router/case-configuration.yml +++ /dev/null @@ -1,68 +0,0 @@ -# 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. - -services: - zookeeper: - image: zookeeper:latest - - dubbo-samples-mesh-router-1: - type: app - basedir: . - mainClass: org.apache.dubbo.samples.governance.BasicProvider - systemProps: - - zookeeper.address=zookeeper - - zookeeper.port=2181 - - dubbo.port=20880 - waitPortsBeforeRun: - - zookeeper:2181 - checkPorts: - - 20880 - checkLog: "dubbo service started" - depends_on: - - zookeeper - - dubbo-samples-mesh-router-2: - type: app - basedir: . - mainClass: org.apache.dubbo.samples.governance.BasicProvider2 - systemProps: - - zookeeper.address=zookeeper - - zookeeper.port=2181 - - dubbo.port=20881 - waitPortsBeforeRun: - - zookeeper:2181 - checkPorts: - - 20881 - checkLog: "dubbo service started" - depends_on: - - zookeeper - - dubbo-samples-mesh-router-test: - type: test - basedir: . - tests: - - "**/*IT.class" - systemProps: - - zookeeper.address=zookeeper - - zookeeper.port=2181 - waitPortsBeforeRun: - - zookeeper:2181 - - dubbo-samples-mesh-router-1:20880 - - dubbo-samples-mesh-router-2:20881 - depends_on: - - zookeeper - - dubbo-samples-mesh-router-1 - - dubbo-samples-mesh-router-2 diff --git a/4-governance/dubbo-samples-meshrule-router/case-versions.conf b/4-governance/dubbo-samples-meshrule-router/case-versions.conf deleted file mode 100644 index b03fb1ae45..0000000000 --- a/4-governance/dubbo-samples-meshrule-router/case-versions.conf +++ /dev/null @@ -1,25 +0,0 @@ -# -# -# 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. -# - - -# Supported component versions of the test case - -# Spring app -dubbo.version=3.* -spring.version=4.*, 5.* -java.version= [>= 8] diff --git a/4-governance/dubbo-samples-meshrule-router/pom.xml b/4-governance/dubbo-samples-meshrule-router/pom.xml deleted file mode 100644 index 8219cdee1c..0000000000 --- a/4-governance/dubbo-samples-meshrule-router/pom.xml +++ /dev/null @@ -1,150 +0,0 @@ - - - - - org.apache.dubbo - 1.0-SNAPSHOT - - 4.0.0 - - dubbo-samples-meshrule-router - Dubbo Samples Mesh Rule Router - Dubbo Samples Mesh Rule Router - - - 1.8 - 1.8 - UTF-8 - - 3.3.1 - 4.3.30.RELEASE - 2.20.0 - 4.13.1 - - 3.7.0 - - - - - - org.springframework - spring-framework-bom - ${spring.version} - pom - import - - - - org.apache.dubbo - dubbo-bom - ${dubbo.version} - pom - import - - - - junit - junit - ${junit.version} - - - - - - - org.apache.dubbo - dubbo - - - - org.apache.dubbo - dubbo-zookeeper-curator5-spring-boot-starter - - - - org.springframework - spring-context-support - ${spring.version} - - - - org.apache.logging.log4j - log4j-slf4j-impl - ${log4j2.version} - - - - junit - junit - test - - - - org.springframework - spring-test - test - - - - - - - javax.annotation - - [1.11,) - - - - javax.annotation - javax.annotation-api - 1.3.2 - - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - - - - - - apache.snapshots.https - Apache Development Snapshot Repository - https://repository.apache.org/content/repositories/snapshots - default - - false - - - true - daily - - - - diff --git a/4-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/BasicConsumer.java b/4-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/BasicConsumer.java deleted file mode 100644 index f36c2d1a30..0000000000 --- a/4-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/BasicConsumer.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * - * 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.samples.governance; - -import org.apache.dubbo.samples.governance.api.DemoService; - -import org.springframework.context.support.ClassPathXmlApplicationContext; - -public class BasicConsumer { - - public static void main(String[] args) { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-demo-consumer.xml"); - context.start(); - DemoService demoService = context.getBean("demoService", DemoService.class); - for (int index = 0; index < 100; index++) { - String result = demoService.sayHello("java"); - System.out.println(result); - } - } -} diff --git a/4-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/BasicProvider.java b/4-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/BasicProvider.java deleted file mode 100644 index 033bf625a4..0000000000 --- a/4-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/BasicProvider.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * - * 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.samples.governance; - -import org.springframework.context.support.ClassPathXmlApplicationContext; - -import java.util.concurrent.CountDownLatch; - -public class BasicProvider { - - public static void main(String[] args) throws Exception { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-demo-provider.xml"); - context.start(); - - System.out.println("dubbo service started"); - new CountDownLatch(1).await(); - } - -} diff --git a/4-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/BasicProvider2.java b/4-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/BasicProvider2.java deleted file mode 100644 index c6d5898045..0000000000 --- a/4-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/BasicProvider2.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * - * 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.samples.governance; - -import org.springframework.context.support.ClassPathXmlApplicationContext; - -import java.util.concurrent.CountDownLatch; - -public class BasicProvider2 { - - public static void main(String[] args) throws Exception { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-demo-provider2.xml"); - context.start(); - - System.out.println("dubbo service started"); - new CountDownLatch(1).await(); - } - -} diff --git a/4-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/RuleUtil.java b/4-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/RuleUtil.java deleted file mode 100644 index f30abe87ea..0000000000 --- a/4-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/RuleUtil.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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.samples.governance; - -import org.apache.dubbo.common.utils.StringUtils; - -import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.framework.CuratorFrameworkFactory; -import org.apache.curator.retry.ExponentialBackoffRetry; - -import java.io.IOException; -import java.io.InputStream; - -public class RuleUtil { - private static String zookeeperHost = System.getProperty("zookeeper.address", "127.0.0.1"); - private static CuratorFramework client; - - public static void main(String[] args) throws Exception { - initClient(); - generateRule(); - System.in.read(); - deleteRule(); - } - - public static void initClient() { - client = CuratorFrameworkFactory.newClient(zookeeperHost + ":2181", 60 * 1000, 60 * 1000, - new ExponentialBackoffRetry(1000, 3)); - client.start(); - } - - public static void generateRule() { - try (InputStream yamlStream = RuleUtil.class.getResourceAsStream("/dubbo-routers-mesh-rule.yml")) { - String path = "/dubbo/config/dubbo/governance-mesh-rule-router-provider.MESHAPPRULE"; - if (client.checkExists().forPath(path) == null) { - client.create().creatingParentsIfNeeded().forPath(path); - } - setData(path, streamToString(yamlStream)); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public static void deleteRule() throws Exception { - String path = "/dubbo/config/dubbo/governance-mesh-rule-router-provider.MESHAPPRULE"; - if (client.checkExists().forPath(path) == null) { - client.create().creatingParentsIfNeeded().forPath(path); - } - setData(path, ""); - } - - private static String streamToString(InputStream stream) throws IOException { - byte[] bytes = new byte[stream.available()]; - stream.read(bytes); - return new String(bytes); - } - - private static void setData(String path, String data) throws Exception { - client.setData().forPath(path, data.getBytes()); - } - - private static String pathToKey(String path) { - if (StringUtils.isEmpty(path)) { - return path; - } - return path.replace("/dubbo/config/", "").replaceAll("/", "."); - } - -} diff --git a/4-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/api/DemoService.java b/4-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/api/DemoService.java deleted file mode 100644 index bde5f6eb6a..0000000000 --- a/4-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/api/DemoService.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * - * 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.samples.governance.api; - -public interface DemoService { - - String sayHello(String name); - -} diff --git a/4-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl.java b/4-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl.java deleted file mode 100644 index 8825f2a764..0000000000 --- a/4-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * - * 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.samples.governance.impl; - -import org.apache.dubbo.samples.governance.api.DemoService; - -public class DemoServiceImpl implements DemoService { - - @Override - public String sayHello(String name) { - return "Hello," + name + " I'm Other Unit"; - } -} diff --git a/4-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl2.java b/4-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl2.java deleted file mode 100644 index e415108ba1..0000000000 --- a/4-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl2.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * - * 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.samples.governance.impl; - -import org.apache.dubbo.samples.governance.api.DemoService; - -public class DemoServiceImpl2 implements DemoService { - - @Override - public String sayHello(String name) { - return "Hello," + name + " I'm Center"; - } -} diff --git a/4-governance/dubbo-samples-meshrule-router/src/main/resources/dubbo-routers-mesh-rule.yml b/4-governance/dubbo-samples-meshrule-router/src/main/resources/dubbo-routers-mesh-rule.yml deleted file mode 100644 index 84eee652ca..0000000000 --- a/4-governance/dubbo-samples-meshrule-router/src/main/resources/dubbo-routers-mesh-rule.yml +++ /dev/null @@ -1,51 +0,0 @@ -# -# -# 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. -# -# - - -apiVersion: service.dubbo.apache.org/v1alpha1 -kind: VirtualService -metadata: {name: demo-route} -spec: - dubbo: - - routedetail: - - match: - - sourceLabels: {trafficLabel: xxx} - name: other-condition - route: - - destination: {host: demo, subset: other} - - name: center-match - route: - - destination: {host: demo, subset: center} - services: - - {regex: org.apache.dubbo.samples.governance.api.DemoService.*} - hosts: [demo] - ---- - -apiVersion: service.dubbo.apache.org/v1alpha1 -kind: DestinationRule -metadata: { name: demo-route } -spec: - host: demo - subsets: - - name: all - - labels: { ut: CENTER } - name: center - - labels: { ut: other } - name: other \ No newline at end of file diff --git a/4-governance/dubbo-samples-meshrule-router/src/main/resources/log4j2.xml b/4-governance/dubbo-samples-meshrule-router/src/main/resources/log4j2.xml deleted file mode 100644 index 69e1321d22..0000000000 --- a/4-governance/dubbo-samples-meshrule-router/src/main/resources/log4j2.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - diff --git a/4-governance/dubbo-samples-meshrule-router/src/main/resources/spring/dubbo-demo-consumer.xml b/4-governance/dubbo-samples-meshrule-router/src/main/resources/spring/dubbo-demo-consumer.xml deleted file mode 100644 index 20c9ac5c05..0000000000 --- a/4-governance/dubbo-samples-meshrule-router/src/main/resources/spring/dubbo-demo-consumer.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/4-governance/dubbo-samples-meshrule-router/src/main/resources/spring/dubbo-demo-provider.xml b/4-governance/dubbo-samples-meshrule-router/src/main/resources/spring/dubbo-demo-provider.xml deleted file mode 100644 index d4ece1d7b4..0000000000 --- a/4-governance/dubbo-samples-meshrule-router/src/main/resources/spring/dubbo-demo-provider.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/4-governance/dubbo-samples-meshrule-router/src/main/resources/spring/dubbo-demo-provider2.xml b/4-governance/dubbo-samples-meshrule-router/src/main/resources/spring/dubbo-demo-provider2.xml deleted file mode 100644 index e72aa5815c..0000000000 --- a/4-governance/dubbo-samples-meshrule-router/src/main/resources/spring/dubbo-demo-provider2.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/4-governance/dubbo-samples-meshrule-router/src/test/java/org/apache/dubbo/samples/governance/DemoServiceIT.java b/4-governance/dubbo-samples-meshrule-router/src/test/java/org/apache/dubbo/samples/governance/DemoServiceIT.java deleted file mode 100644 index 4a522d280d..0000000000 --- a/4-governance/dubbo-samples-meshrule-router/src/test/java/org/apache/dubbo/samples/governance/DemoServiceIT.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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.samples.governance; - -import org.apache.dubbo.samples.governance.api.DemoService; - -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = {"classpath:/spring/dubbo-demo-consumer.xml"}) -public class DemoServiceIT { - @Autowired - @Qualifier("demoService") - private DemoService demoService; - - @BeforeClass - public static void setUp() throws Exception { - RuleUtil.initClient(); - RuleUtil.generateRule(); - Thread.sleep(1000); - } - - @Test - public void testDemoService() throws Exception { - for (int i = 0; i < 100; i++) { - Assert.assertEquals("Hello,java I'm Center", demoService.sayHello("java")); - } - } - -} diff --git a/4-governance/pom.xml b/4-governance/pom.xml index 2868d99569..a151666a72 100644 --- a/4-governance/pom.xml +++ b/4-governance/pom.xml @@ -30,7 +30,6 @@ dubbo-samples-applevel-override dubbo-samples-configconditionrouter dubbo-samples-conditionrouterv31 - dubbo-samples-meshrule-router dubbo-samples-metrics-prometheus dubbo-samples-metrics-spring-boot dubbo-samples-sentinel From f9a3d5f4c10172512732e22a2cd973e3813ad76d Mon Sep 17 00:00:00 2001 From: ZeruiYang Date: Fri, 6 Dec 2024 11:43:35 +0800 Subject: [PATCH 2/4] Add RESTful Dubbo Integration with Spring Security and OAuth2 Sample (#1193) * feat: add authorization server * feat: create a resource server * feat: create case-configuration.yml * feat: create case-versions.conf * feat: add RestExtension spi * fix: use restExtension to intercept request(unfinished) * fix: use restExtension to intercept request * feat: update case-configuration.yml * fix: use restExtension to intercept request * fix: change the name of the test file * fix: change the systemProps in the case-configuration.yml * fix: change the systemProps in the case-configuration.yml * feat: add test cases * fix: update config in AuthorizationSeverConfig.java --------- Co-authored-by: Sean Yang --- .../case-configuration.yml | 51 ++++++++ .../case-versions.conf | 25 ++++ .../pom.xml | 61 +++++++++ .../pom.xml | 98 +++++++++++++++ .../rest/demo/AuthorizationApplication.java | 30 +++++ .../demo/config/AuthorizationSeverConfig.java | 73 +++++++++++ .../src/main/resources/application.yml | 27 ++++ .../java/OAuth2AuthorizationServerTest.java | 75 +++++++++++ .../spring-security-resource-server/pom.xml | 106 ++++++++++++++++ .../dubbo/rest/demo/ResourceApplication.java | 32 +++++ .../dubbo/rest/demo/filter/OAuthFilter.java | 95 ++++++++++++++ .../dubbo/rest/demo/service/HelloService.java | 29 +++++ .../demo/service/impl/HelloServiceImpl.java | 30 +++++ ...rpc.protocol.tri.rest.filter.RestExtension | 1 + .../src/main/resources/application.yml | 31 +++++ .../src/test/java/ResourceServerIT.java | 116 ++++++++++++++++++ 2-advanced/dubbo-samples-triple-rest/pom.xml | 1 + 17 files changed, 881 insertions(+) create mode 100644 2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/case-configuration.yml create mode 100644 2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/case-versions.conf create mode 100644 2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/pom.xml create mode 100644 2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-authorization-server/pom.xml create mode 100644 2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-authorization-server/src/main/java/org/apache/dubbo/rest/demo/AuthorizationApplication.java create mode 100644 2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-authorization-server/src/main/java/org/apache/dubbo/rest/demo/config/AuthorizationSeverConfig.java create mode 100644 2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-authorization-server/src/main/resources/application.yml create mode 100644 2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-authorization-server/src/test/java/OAuth2AuthorizationServerTest.java create mode 100644 2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/pom.xml create mode 100644 2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/src/main/java/org/apache/dubbo/rest/demo/ResourceApplication.java create mode 100644 2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/src/main/java/org/apache/dubbo/rest/demo/filter/OAuthFilter.java create mode 100644 2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/src/main/java/org/apache/dubbo/rest/demo/service/HelloService.java create mode 100644 2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/src/main/java/org/apache/dubbo/rest/demo/service/impl/HelloServiceImpl.java create mode 100644 2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.protocol.tri.rest.filter.RestExtension create mode 100644 2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/src/main/resources/application.yml create mode 100644 2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/src/test/java/ResourceServerIT.java diff --git a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/case-configuration.yml b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/case-configuration.yml new file mode 100644 index 0000000000..a6ffa9f6a8 --- /dev/null +++ b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/case-configuration.yml @@ -0,0 +1,51 @@ +# 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. + +services: + authorization: + type: app + basedir: spring-security-authorization-server + mainClass: org.apache.dubbo.rest.demo.AuthorizationApplication + systemProps: + - authorization.address=authorization + checkPorts: + - 9000 + checkLog: "authorization service started" + + resource: + type: app + basedir: spring-security-resource-server + mainClass: org.apache.dubbo.rest.demo.ResourceApplication + systemProps: + - authorization.address=authorization + checkPorts: + - 50051 + checkLog: "resource service started" + + test: + type: test + basedir: spring-security-resource-server + tests: + - "**/*IT.class" + systemProps: + - authorization.address=authorization + - resource.address=resource + waitPortsBeforeRun: + - authorization:9000 + - resource:50051 + depends_on: + - authorization + - resource diff --git a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/case-versions.conf b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/case-versions.conf new file mode 100644 index 0000000000..82aeb45603 --- /dev/null +++ b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/case-versions.conf @@ -0,0 +1,25 @@ +# +# +# 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. +# + + +# Supported component versions of the test case + +# Spring app +dubbo.version=3.3.* +spring.version=6.* +java.version= [>= 17] diff --git a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/pom.xml b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/pom.xml new file mode 100644 index 0000000000..f4d69047fe --- /dev/null +++ b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/pom.xml @@ -0,0 +1,61 @@ + + + + 4.0.0 + + org.apache.dubbo + dubbo-samples-triple-rest + 1.0.0-SNAPSHOT + + pom + + spring-security-resource-server + spring-security-authorization-server + + + + + + org.springframework.security + spring-security-core + 6.2.2 + + + org.springframework.security + spring-security-oauth2-authorization-server + 1.2.3 + + + org.springframework.security + spring-security-oauth2-resource-server + 6.2.2 + + + org.springframework.security + spring-security-oauth2-jose + 6.2.2 + + + + + org.apache.dubbo.rest.demo + dubbo-samples-triple-rest-spring-security + + diff --git a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-authorization-server/pom.xml b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-authorization-server/pom.xml new file mode 100644 index 0000000000..3bfd26479b --- /dev/null +++ b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-authorization-server/pom.xml @@ -0,0 +1,98 @@ + + + + 4.0.0 + + + org.apache.dubbo.rest.demo + dubbo-samples-triple-rest-spring-security + 1.0.0-SNAPSHOT + + + org.apache.dubbo.rest.demo + spring-security-authorization-server + 1.0-SNAPSHOT + + + 17 + + + + + + + org.springframework.boot + spring-boot-starter-web + + + + + org.springframework.boot + spring-boot-starter-security + + + + + org.springframework.security + spring-security-oauth2-authorization-server + + + + + org.springframework.security + spring-security-oauth2-jose + + + nimbus-jose-jwt + com.nimbusds + + + + + + + org.springframework.boot + spring-boot-starter-logging + + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.springframework.security + spring-security-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-authorization-server/src/main/java/org/apache/dubbo/rest/demo/AuthorizationApplication.java b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-authorization-server/src/main/java/org/apache/dubbo/rest/demo/AuthorizationApplication.java new file mode 100644 index 0000000000..0d8278670b --- /dev/null +++ b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-authorization-server/src/main/java/org/apache/dubbo/rest/demo/AuthorizationApplication.java @@ -0,0 +1,30 @@ +/* + * 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.rest.demo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class AuthorizationApplication { + public static void main(String[] args) { + SpringApplication.run(AuthorizationApplication.class, args); + System.out.println("authorization service started"); + } +} + diff --git a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-authorization-server/src/main/java/org/apache/dubbo/rest/demo/config/AuthorizationSeverConfig.java b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-authorization-server/src/main/java/org/apache/dubbo/rest/demo/config/AuthorizationSeverConfig.java new file mode 100644 index 0000000000..393e0a9032 --- /dev/null +++ b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-authorization-server/src/main/java/org/apache/dubbo/rest/demo/config/AuthorizationSeverConfig.java @@ -0,0 +1,73 @@ +/* + * 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.rest.demo.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.oauth2.core.AuthorizationGrantType; +import org.springframework.security.oauth2.server.authorization.client.InMemoryRegisteredClientRepository; +import org.springframework.security.oauth2.server.authorization.client.RegisteredClient; +import org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepository; +import org.springframework.security.oauth2.server.authorization.config.annotation.web.configuration.OAuth2AuthorizationServerConfiguration; +import org.springframework.security.oauth2.server.authorization.settings.AuthorizationServerSettings; +import org.springframework.security.web.SecurityFilterChain; + +import java.util.UUID; + +@Configuration +@EnableWebSecurity +public class AuthorizationSeverConfig { + + private static final String HOST = System.getProperty("authorization.address", "localhost"); + + String issuer = "http://" + HOST + ":9000"; + + @Bean + public SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception { + OAuth2AuthorizationServerConfiguration.applyDefaultSecurity(http); + + return http.build(); + } + + @Bean + public RegisteredClientRepository registeredClientRepository() { + RegisteredClient registeredClient = RegisteredClient.withId(UUID.randomUUID().toString()) + .clientId("49fd8518-12eb-422b-9264-2bae0ab89f66") //configure the client id + .clientSecret("{noop}H3DTtm2fR3GRAdr4ls1mcg") // configure the client secret + .authorizationGrantType(AuthorizationGrantType.AUTHORIZATION_CODE) + .authorizationGrantType(AuthorizationGrantType.CLIENT_CREDENTIALS) + .authorizationGrantType(AuthorizationGrantType.REFRESH_TOKEN) + .redirectUri("http://localhost:9000/oauth2/token") // configure the redirect uri + .scope("openid") + .scope("read") + .scope("write") + .build(); + + return new InMemoryRegisteredClientRepository(registeredClient); + } + + @Bean + public AuthorizationServerSettings authorizationServerSettings() { + return AuthorizationServerSettings.builder() + .issuer(issuer) // set the address of the authorization server + .build(); + } + +} diff --git a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-authorization-server/src/main/resources/application.yml b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-authorization-server/src/main/resources/application.yml new file mode 100644 index 0000000000..a4c8163a8f --- /dev/null +++ b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-authorization-server/src/main/resources/application.yml @@ -0,0 +1,27 @@ +# 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. + +server: + port: 9000 + +spring: + application: + name: authorization-server # Application name for Spring Boot + +logging: + level: + org.springframework.security: DEBUG + org.springframework.boot.autoconfigure.security: DEBUG diff --git a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-authorization-server/src/test/java/OAuth2AuthorizationServerTest.java b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-authorization-server/src/test/java/OAuth2AuthorizationServerTest.java new file mode 100644 index 0000000000..5cf0335088 --- /dev/null +++ b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-authorization-server/src/test/java/OAuth2AuthorizationServerTest.java @@ -0,0 +1,75 @@ +/* + * 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. + */ + +import org.apache.dubbo.rest.demo.AuthorizationApplication; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.server.LocalServerPort; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; + +import org.springframework.web.client.RestClient; +import org.springframework.web.client.RestClientResponseException; + +import java.util.Base64; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; + +@SpringBootTest(classes = AuthorizationApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class OAuth2AuthorizationServerTest { + + @LocalServerPort + private int port; + + private final String clientId = "49fd8518-12eb-422b-9264-2bae0ab89f66"; + private final String clientSecret = "H3DTtm2fR3GRAdr4ls1mcg"; + + @Test + public void testClientCredentialsGrantFlow() { + assertNotEquals(0, port, "Port should not be 0"); + // build Basic Auth header + String credentials = clientId + ":" + clientSecret; + String encodedCredentials = Base64.getEncoder().encodeToString(credentials.getBytes()); + System.out.println("Encoded Credentials: " + encodedCredentials); + + // build RestClient request + RestClient restClient = RestClient.builder().build(); + String url = "http://localhost:" + port + "/oauth2/token"; + + try { + // make a post request + String response = restClient.post() + .uri(url) + .header(HttpHeaders.AUTHORIZATION, "Basic " + encodedCredentials) + .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE) + .body("grant_type=client_credentials&scope=read") + .retrieve() + .body(String.class); + + System.out.println("Access Token Response: " + response); + + } catch (RestClientResponseException e) { + // use getStatusCode().value() to get status code + assertEquals(HttpStatus.UNAUTHORIZED.value(), e.getStatusCode() + .value(), "The request failed and was not authorized"); + System.err.println("Error Response: " + e.getResponseBodyAsString()); + } + } +} diff --git a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/pom.xml b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/pom.xml new file mode 100644 index 0000000000..83f268c38e --- /dev/null +++ b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/pom.xml @@ -0,0 +1,106 @@ + + + + 4.0.0 + + + org.apache.dubbo.rest.demo + dubbo-samples-triple-rest-spring-security + 1.0.0-SNAPSHOT + + + spring-security-resource-server + + + 17 + 3.2.3 + 3.3.1 + + + + + + org.apache.dubbo + dubbo-spring-boot-starter + ${dubbo.version} + + + + + org.springframework.boot + spring-boot-starter-web + ${spring.boot.version} + + + + + org.springframework.boot + spring-boot-starter-logging + ${spring.boot.version} + + + + + + + + + + + + org.springframework.boot + spring-boot-starter-oauth2-resource-server + ${spring.boot.version} + + + + + org.springframework.security + spring-security-oauth2-jose + 6.2.2 + + + + + + + + + + + + + org.springframework.boot + spring-boot-starter-test + ${spring.boot.version} + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring.boot.version} + + + + diff --git a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/src/main/java/org/apache/dubbo/rest/demo/ResourceApplication.java b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/src/main/java/org/apache/dubbo/rest/demo/ResourceApplication.java new file mode 100644 index 0000000000..305b2fde3c --- /dev/null +++ b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/src/main/java/org/apache/dubbo/rest/demo/ResourceApplication.java @@ -0,0 +1,32 @@ +/* + * 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.rest.demo; + +import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +@EnableDubbo +public class ResourceApplication { + public static void main(String[] args) { + SpringApplication.run(ResourceApplication.class, args); + System.out.println("resource service started"); + } +} diff --git a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/src/main/java/org/apache/dubbo/rest/demo/filter/OAuthFilter.java b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/src/main/java/org/apache/dubbo/rest/demo/filter/OAuthFilter.java new file mode 100644 index 0000000000..f14ea351c8 --- /dev/null +++ b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/src/main/java/org/apache/dubbo/rest/demo/filter/OAuthFilter.java @@ -0,0 +1,95 @@ +/* + * 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.rest.demo.filter; + +import jakarta.servlet.Filter; + +import jakarta.servlet.FilterChain; +import jakarta.servlet.FilterConfig; +import jakarta.servlet.ServletRequest; +import jakarta.servlet.ServletResponse; + +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +import org.apache.dubbo.common.extension.Activate; +import org.apache.dubbo.rpc.protocol.tri.rest.filter.RestExtension; + +import org.springframework.security.oauth2.jwt.Jwt; +import org.springframework.security.oauth2.jwt.JwtDecoder; +import org.springframework.security.oauth2.jwt.NimbusJwtDecoder; +import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationConverter; +import org.springframework.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter; + +import java.io.IOException; + +@Activate +public class OAuthFilter implements Filter, RestExtension { + + private static final String HOST = System.getProperty("authorization.address", "localhost"); + + String issuer = "http://" + HOST + ":9000"; + + private JwtDecoder jwtDecoder; + private JwtAuthenticationConverter jwtAuthenticationConverter; + + @Override + public void init(FilterConfig filterConfig) { + // Initialize the JwtDecoder and obtain the public key from the configured authorization server URL for decoding the JWT + jwtDecoder = NimbusJwtDecoder.withIssuerLocation(issuer).build(); + // Initialize JwtAuthenticationConverter to convert JWT + jwtAuthenticationConverter = new JwtAuthenticationConverter(); + JwtGrantedAuthoritiesConverter authoritiesConverter = new JwtGrantedAuthoritiesConverter(); + jwtAuthenticationConverter.setJwtGrantedAuthoritiesConverter(authoritiesConverter); + } + + @Override + public String[] getPatterns() { + return new String[] {"/**"}; // Intercept all requests + } + + @Override + public void doFilter( + ServletRequest servletRequest, + ServletResponse servletResponse, + FilterChain filterChain) throws IOException { + HttpServletRequest request = (HttpServletRequest) servletRequest; + HttpServletResponse response = (HttpServletResponse) servletResponse; + String authorization = request.getHeader("Authorization"); + if (authorization != null && authorization.startsWith("Bearer ")) { + String jwtToken = authorization.substring("Bearer ".length()); + // Decode the JWT token + try { + Jwt jwt = jwtDecoder.decode(jwtToken); + jwtAuthenticationConverter.convert(jwt); + filterChain.doFilter(request, response); + } catch (Exception e) { + response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Invalid JWT token"); + } + + } else { + response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Missing JWT token"); + } + + } + + @Override + public int getPriority() { + return -200; + } +} diff --git a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/src/main/java/org/apache/dubbo/rest/demo/service/HelloService.java b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/src/main/java/org/apache/dubbo/rest/demo/service/HelloService.java new file mode 100644 index 0000000000..a2230a1f79 --- /dev/null +++ b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/src/main/java/org/apache/dubbo/rest/demo/service/HelloService.java @@ -0,0 +1,29 @@ +/* + * 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.rest.demo.service; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; + +@RequestMapping("/hello") +public interface HelloService { + + @GetMapping("/sayHello/{name}") + String sayHello(@PathVariable String name); +} diff --git a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/src/main/java/org/apache/dubbo/rest/demo/service/impl/HelloServiceImpl.java b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/src/main/java/org/apache/dubbo/rest/demo/service/impl/HelloServiceImpl.java new file mode 100644 index 0000000000..49e1c14741 --- /dev/null +++ b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/src/main/java/org/apache/dubbo/rest/demo/service/impl/HelloServiceImpl.java @@ -0,0 +1,30 @@ +/* + * 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.rest.demo.service.impl; + +import org.apache.dubbo.config.annotation.DubboService; +import org.apache.dubbo.rest.demo.service.HelloService; + +@DubboService +public class HelloServiceImpl implements HelloService { + + @Override + public String sayHello(String name) { + return "Hello, " + name; + } +} diff --git a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.protocol.tri.rest.filter.RestExtension b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.protocol.tri.rest.filter.RestExtension new file mode 100644 index 0000000000..69e53cb32f --- /dev/null +++ b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/src/main/resources/META-INF/dubbo/org.apache.dubbo.rpc.protocol.tri.rest.filter.RestExtension @@ -0,0 +1 @@ +OAuthFilter=org.apache.dubbo.rest.demo.filter.OAuthFilter diff --git a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/src/main/resources/application.yml b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/src/main/resources/application.yml new file mode 100644 index 0000000000..88148fd184 --- /dev/null +++ b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/src/main/resources/application.yml @@ -0,0 +1,31 @@ +# 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. +server: + port: 9001 + +spring: + application: + name: resource-server # Application name for Spring Boot + +dubbo: + application: + name: ${spring.application.name} + qos-enable: false + protocol: + name: tri # Use the Triple protocol + port: 50051 # Service port (adjust as needed) + triple: + verbose: true # Enable verbose mode diff --git a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/src/test/java/ResourceServerIT.java b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/src/test/java/ResourceServerIT.java new file mode 100644 index 0000000000..aabfdeda4c --- /dev/null +++ b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-spring-security/spring-security-resource-server/src/test/java/ResourceServerIT.java @@ -0,0 +1,116 @@ +/* + * 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. + */ + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; + +import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.runner.RunWith; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.client.RestClient; +import org.springframework.web.client.RestClientResponseException; + +import java.util.Base64; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@EnableDubbo +@RunWith(SpringRunner.class) +public class ResourceServerIT { + + // @LocalServerPort + // private int port; + +// @DubboReference(url = "tri://localhost:50051") +// private HelloService helloService; + + private final String clientId = "49fd8518-12eb-422b-9264-2bae0ab89f66"; + private final String clientSecret = "H3DTtm2fR3GRAdr4ls1mcg"; + + private static final String OAUTH2HOST = System.getProperty("authorization.address", "localhost"); + private static final String HOST = System.getProperty("resource.address", "localhost"); + + @Test + public void testGetUserEndpoint() { + String credentials = clientId + ":" + clientSecret; + String encodedCredentials = Base64.getEncoder().encodeToString(credentials.getBytes()); + + // build RestClient request + RestClient restClient = RestClient.builder().build(); + String url = "http://"+ OAUTH2HOST + ":9000/oauth2/token"; + + try { + // make a post request + String response = restClient.post() + .uri(url) + .header(HttpHeaders.AUTHORIZATION, "Basic " + encodedCredentials) + .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE) + .body("grant_type=client_credentials&scope=read") + .retrieve() + .body(String.class); + + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode jsonNode = objectMapper.readTree(response); + String accessToken = jsonNode.get("access_token").asText(); + + // Use the access token to authenticate the request to the /user endpoint + assert accessToken != null; + String userUrl = "http://" + HOST + ":50051/hello/sayHello/World"; + try { + String userResponse = restClient.get() + .uri(userUrl) + .header(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken) + .retrieve() + .body(String.class); + + assertEquals("\"Hello, World\"", userResponse, "error"); + } catch (RestClientResponseException e) { + System.err.println("Error Response: " + e.getResponseBodyAsString()); + Assertions.fail("Request failed with response: " + e.getResponseBodyAsString()); + } + + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } + + @Test + public void testGetUserEndpointWithInvalidToken() { + String invalidAccessToken = "invalid_token"; + RestClient restClient = RestClient.builder().build(); + String userUrl = "http://" + HOST + ":50051/hello/sayHello/World"; + + try { + restClient.get() + .uri(userUrl) + .header(HttpHeaders.AUTHORIZATION, "Bearer " + invalidAccessToken) + .retrieve() + .body(String.class); + + Assertions.fail("Request should have failed with an invalid token"); + } catch (RestClientResponseException e) { + System.err.println("Error Response: " + e.getResponseBodyAsString()); + assertEquals(401, e.getStatusCode().value(), "Expected 401 Unauthorized status"); + } + } +} diff --git a/2-advanced/dubbo-samples-triple-rest/pom.xml b/2-advanced/dubbo-samples-triple-rest/pom.xml index 4826d54178..d0910334d8 100644 --- a/2-advanced/dubbo-samples-triple-rest/pom.xml +++ b/2-advanced/dubbo-samples-triple-rest/pom.xml @@ -46,6 +46,7 @@ dubbo-samples-triple-rest-basic dubbo-samples-triple-rest-jaxrs dubbo-samples-triple-rest-springmvc + dubbo-samples-triple-rest-spring-security From 10033bf4c06d69bf3673253c2544ceb3369d4376 Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Fri, 6 Dec 2024 17:51:37 +0800 Subject: [PATCH 3/4] Fix jacoco merger --- .../org/apache/dubbo/test/JacocoReport.java | 83 +++++++------------ 1 file changed, 31 insertions(+), 52 deletions(-) diff --git a/test/dubbo-test-jacoco-merger/src/main/java/org/apache/dubbo/test/JacocoReport.java b/test/dubbo-test-jacoco-merger/src/main/java/org/apache/dubbo/test/JacocoReport.java index 4915326fd7..d6ac4e2973 100644 --- a/test/dubbo-test-jacoco-merger/src/main/java/org/apache/dubbo/test/JacocoReport.java +++ b/test/dubbo-test-jacoco-merger/src/main/java/org/apache/dubbo/test/JacocoReport.java @@ -16,12 +16,13 @@ */ package org.apache.dubbo.test; -import org.jacoco.cli.internal.Main; - import java.io.File; +import java.io.PrintWriter; +import java.lang.reflect.Constructor; import java.util.LinkedList; import java.util.List; -import java.util.stream.Stream; + +import org.jacoco.cli.internal.Main; public class JacocoReport { public static void main(String[] args) throws Exception { @@ -32,42 +33,43 @@ public static void main(String[] args) throws Exception { String dubboRepo = args[1]; List execFiles = loadExecFiles(new File(basePath + File.separator + "target")); - List classFiles = loadClassFiles(new File(dubboRepo)); - List sourceFiles = loadSourceFiles(new File(dubboRepo)); + List moduelFiles = loadModuleFiles(new File(dubboRepo)); if (execFiles.isEmpty()) { System.out.println(basePath + File.separator + "target" + File.separator + "jacoco*.exec" + " does not exist"); return; } + for (File classFile : moduelFiles) { + System.out.println("Generating report for " + classFile.getAbsolutePath()); - String[] execs = execFiles.stream() - .map(File::getAbsolutePath) - .toArray(String[]::new); - String[] classes = classFiles.stream() - .map(File::getAbsolutePath) - .flatMap(s -> Stream.of("--classfiles", s)) - .toArray(String[]::new); - String[] sources = sourceFiles.stream() - .map(File::getAbsolutePath) - .flatMap(s -> Stream.of("--sourcefiles", s)) - .toArray(String[]::new); + String[] execs = execFiles.stream() + .map(File::getAbsolutePath) + .toArray(String[]::new); + String[] classes = new String[]{"--classfiles", classFile.getAbsolutePath() + File.separator + "target" + File.separator + "classes" + File.separator + "org" + File.separator + "apache" + File.separator + "dubbo"}; + String[] sources = new String[]{"--sourcefiles", classFile.getAbsolutePath() + File.separator + "src" + File.separator + "main" + File.separator + "java"}; - String[] reportArgs = new String[execs.length + classes.length + sources.length + 5]; - reportArgs[0] = "report"; - System.arraycopy(execs, 0, reportArgs, 1, execs.length); - System.arraycopy(classes, 0, reportArgs, execs.length + 1, classes.length); - System.arraycopy(sources, 0, reportArgs, execs.length + classes.length + 1, sources.length); - reportArgs[execs.length + classes.length + sources.length + 1] = "--xml"; - reportArgs[execs.length + classes.length + sources.length + 2] = basePath + File.separator + "target" + File.separator + "report.xml"; - reportArgs[execs.length + classes.length + sources.length + 3] = "--html"; - reportArgs[execs.length + classes.length + sources.length + 4] = basePath + File.separator + "target" + File.separator + "site"; + String[] reportArgs = new String[execs.length + classes.length + sources.length + 5]; + reportArgs[0] = "report"; + System.arraycopy(execs, 0, reportArgs, 1, execs.length); + System.arraycopy(classes, 0, reportArgs, execs.length + 1, classes.length); + System.arraycopy(sources, 0, reportArgs, execs.length + classes.length + 1, sources.length); + reportArgs[execs.length + classes.length + sources.length + 1] = "--xml"; + reportArgs[execs.length + classes.length + sources.length + 2] = basePath + File.separator + "target" + File.separator + "report.xml"; + reportArgs[execs.length + classes.length + sources.length + 3] = "--html"; + reportArgs[execs.length + classes.length + sources.length + 4] = basePath + File.separator + "target" + File.separator + "site"; - Main.main(reportArgs); + PrintWriter out = new PrintWriter(System.out, true); + PrintWriter err = new PrintWriter(System.err, true); + Constructor
declaredConstructor = Main.class.getDeclaredConstructor(String[].class); + declaredConstructor.setAccessible(true); + int returncode = (declaredConstructor.newInstance((Object) reportArgs)).execute(out, err); + System.out.println("Generating report for " + classFile.getAbsolutePath() + " finished with return code " + returncode); + } } - private static List loadClassFiles(File baseFile) { + private static List loadModuleFiles(File baseFile) { List result = new LinkedList<>(); if (baseFile.isDirectory()) { if (baseFile.getAbsolutePath().contains("dubbo-demo")) { @@ -77,20 +79,19 @@ private static List loadClassFiles(File baseFile) { return result; } if (new File(baseFile.getAbsolutePath() + File.separator + "target" + File.separator + "classes" + File.separator + "org" + File.separator + "apache" + File.separator + "dubbo").exists()) { - result.add(new File(baseFile.getAbsolutePath() + File.separator + "target" + File.separator + "classes" + File.separator + "org" + File.separator + "apache" + File.separator + "dubbo")); + result.add(new File(baseFile.getAbsolutePath())); return result; } File[] files = baseFile.listFiles(); if (files != null) { for (File file : files) { - result.addAll(loadClassFiles(file)); + result.addAll(loadModuleFiles(file)); } } } return result; } - private static List loadExecFiles(File baseFile) { List result = new LinkedList<>(); if (baseFile.isDirectory()) { @@ -105,26 +106,4 @@ private static List loadExecFiles(File baseFile) { } return result; } - private static List loadSourceFiles(File baseFile) { - List result = new LinkedList<>(); - if (baseFile.isDirectory()) { - if (baseFile.getAbsolutePath().contains("dubbo-demo")) { - return result; - } - if (baseFile.getAbsolutePath().contains("dubbo-native")) { - return result; - } - if (new File(baseFile.getAbsolutePath() + File.separator + "src" + File.separator + "main" + File.separator + "java").exists()) { - result.add(new File(baseFile.getAbsolutePath() + File.separator + "src" + File.separator + "main" + File.separator + "java")); - return result; - } - File[] files = baseFile.listFiles(); - if (files != null) { - for (File file : files) { - result.addAll(loadSourceFiles(file)); - } - } - } - return result; - } } From 609d867de3d86c461936b21e1a0a412a9c7ef1df Mon Sep 17 00:00:00 2001 From: Albumen Kevin Date: Fri, 6 Dec 2024 20:40:35 +0800 Subject: [PATCH 4/4] Fix jacoco merger --- .../src/main/java/org/apache/dubbo/test/JacocoReport.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/dubbo-test-jacoco-merger/src/main/java/org/apache/dubbo/test/JacocoReport.java b/test/dubbo-test-jacoco-merger/src/main/java/org/apache/dubbo/test/JacocoReport.java index d6ac4e2973..b2c54930d9 100644 --- a/test/dubbo-test-jacoco-merger/src/main/java/org/apache/dubbo/test/JacocoReport.java +++ b/test/dubbo-test-jacoco-merger/src/main/java/org/apache/dubbo/test/JacocoReport.java @@ -55,9 +55,9 @@ public static void main(String[] args) throws Exception { System.arraycopy(classes, 0, reportArgs, execs.length + 1, classes.length); System.arraycopy(sources, 0, reportArgs, execs.length + classes.length + 1, sources.length); reportArgs[execs.length + classes.length + sources.length + 1] = "--xml"; - reportArgs[execs.length + classes.length + sources.length + 2] = basePath + File.separator + "target" + File.separator + "report.xml"; + reportArgs[execs.length + classes.length + sources.length + 2] = classFile.getAbsolutePath() + File.separator + "target" + File.separator + "report.xml"; reportArgs[execs.length + classes.length + sources.length + 3] = "--html"; - reportArgs[execs.length + classes.length + sources.length + 4] = basePath + File.separator + "target" + File.separator + "site"; + reportArgs[execs.length + classes.length + sources.length + 4] = classFile.getAbsolutePath() + File.separator + "target" + File.separator + "site"; PrintWriter out = new PrintWriter(System.out, true); PrintWriter err = new PrintWriter(System.err, true);