diff --git a/spring-cloud-alibaba-coverage/pom.xml b/spring-cloud-alibaba-coverage/pom.xml index 6a0b650b6a..8279e00417 100644 --- a/spring-cloud-alibaba-coverage/pom.xml +++ b/spring-cloud-alibaba-coverage/pom.xml @@ -70,6 +70,12 @@ ${revision} + + com.alibaba.cloud + spring-cloud-starter-alibaba-rpc + ${revision} + + diff --git a/spring-cloud-alibaba-dependencies/pom.xml b/spring-cloud-alibaba-dependencies/pom.xml index 432cb95a98..780e36597a 100644 --- a/spring-cloud-alibaba-dependencies/pom.xml +++ b/spring-cloud-alibaba-dependencies/pom.xml @@ -29,11 +29,16 @@ 4.23.0 1.11.4 + + 3.3.0-beta.4 + 3.2.1 3.2.0 3.0.1 1.2.7 + + @@ -186,6 +191,12 @@ schedulerx2-worker ${schedulerx.worker.version} + + + org.apache.dubbo + dubbo-remoting-netty4 + ${dubbo.version} + @@ -265,7 +276,19 @@ spring-cloud-starter-alibaba-schedulerx ${revision} - + + com.alibaba.cloud + spring-cloud-starter-alibaba-rpc + ${revision} + + + + + org.springframework.ai + spring-ai-test + ${spring.ai.version} + test + diff --git a/spring-cloud-alibaba-starters/pom.xml b/spring-cloud-alibaba-starters/pom.xml index 3414d035e2..cc7edeb22d 100644 --- a/spring-cloud-alibaba-starters/pom.xml +++ b/spring-cloud-alibaba-starters/pom.xml @@ -13,7 +13,7 @@ pom Spring Cloud Alibaba Starters Spring Cloud Alibaba Starters - + spring-alibaba-nacos-config @@ -29,6 +29,7 @@ spring-cloud-alibaba-sentinel-gateway spring-cloud-alibaba-commons spring-cloud-starter-alibaba-schedulerx + spring-cloud-starter-alibaba-rpc @@ -55,4 +56,4 @@ - \ No newline at end of file + diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/pom.xml b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/pom.xml new file mode 100644 index 0000000000..1b3c26123a --- /dev/null +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/pom.xml @@ -0,0 +1,52 @@ + + 4.0.0 + + com.alibaba.cloud + spring-cloud-alibaba-starters + ${revision} + ../pom.xml + + + spring-cloud-starter-alibaba-rpc + Spring Cloud Starter Alibaba Rpc + + + + org.springframework.boot + spring-boot-starter + true + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + org.springframework.boot + spring-boot-starter-actuator + + + org.apache.dubbo + dubbo-remoting-netty4 + + + + org.springframework.boot + spring-boot-starter-test + + + + org.springframework.boot + spring-boot-starter-web + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + org.springframework.cloud + spring-cloud-starter-loadbalancer + + + diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/RpcConfiguration.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/RpcConfiguration.java new file mode 100644 index 0000000000..bf4926ad93 --- /dev/null +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/RpcConfiguration.java @@ -0,0 +1,50 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.cloud.rpc; + +import com.alibaba.cloud.rpc.utils.UrlResolver; + +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; + + +/** + * @author :Lictory + * @date : 2024/09/27 + */ + +@AutoConfiguration +@ConditionalOnProperty(prefix = RpcProperties.PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true) +@EnableConfigurationProperties(RpcProperties.class) +public class RpcConfiguration { + @Bean + @ConditionalOnMissingBean + public RpcProperties rpcProperties() { + return new RpcProperties(); + } + + + @Bean + @ConditionalOnMissingBean + public UrlResolver initUrlResolver() { + return new UrlResolver(); + } + +} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/RpcProperties.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/RpcProperties.java new file mode 100644 index 0000000000..9d16dcfc03 --- /dev/null +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/RpcProperties.java @@ -0,0 +1,61 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.cloud.rpc; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * @author :Lictory + * @date : 2024/09/27 + */ +@ConfigurationProperties("spring.cloud.rpc.netty") +public class RpcProperties { + + /** + * config prefix. + */ + public static final String PREFIX = "spring.cloud.rpc"; + + /** + * prefix of netty port. + */ + public static final String NETTY_PORT_PREFIX = "spring.cloud.rpc.netty.port"; + + /** + * prefix of netty host. + */ + public static final String HOST_PREFIX = "spring.cloud.rpc.netty.host"; + + private Integer port; + private String host; + + public Integer getPort() { + return port; + } + + public String getHost() { + return host; + } + + public void setPort(Integer port) { + this.port = port; + } + + public void setHost(String host) { + this.host = host; + } +} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/client/FeignRpcClient.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/client/FeignRpcClient.java new file mode 100644 index 0000000000..50f7c3d148 --- /dev/null +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/client/FeignRpcClient.java @@ -0,0 +1,86 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.cloud.rpc.client; + +import java.util.Collection; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; + +import com.alibaba.cloud.rpc.metadata.HttpMetadata; +import com.alibaba.cloud.rpc.metadata.HttpRpcResponse; +import com.alibaba.cloud.rpc.utils.UrlResolver; +import feign.Client; +import feign.Request; +import feign.Response; +import org.apache.dubbo.remoting.RemotingException; +import org.apache.dubbo.remoting.exchange.ExchangeClient; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.client.loadbalancer.LoadBalancerClient; +import org.springframework.stereotype.Component; + +/** + * @author :Lictory + * @date : 2024/08/12 + */ + +@Component +public class FeignRpcClient implements Client { + @Autowired + private LoadBalancerClient loadBalancerClient; + private ExchangeClient client; + + @Autowired + private UrlResolver urlResolver; + + @Override + public Response execute(Request request, Request.Options options) { + String url = urlResolver.resolveOriginalUrl(loadBalancerClient, request.url()); + this.client = urlResolver.getClient(url); + HttpMetadata httpMetadata = initHttpMetadata( + urlResolver.getPathFromUrl(request.url()), + request.httpMethod().name(), + request.headers(), + request.body() + ); + HttpRpcResponse httpRpcResponse = null; + try { + CompletableFuture future = client.request(httpMetadata); + httpRpcResponse = (HttpRpcResponse) future.get(); + } + catch (RemotingException | InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + return Response.builder() + .status(httpRpcResponse.getStatusCode()) + .reason(httpRpcResponse.getReasonPhrase()) + .headers(httpRpcResponse.getHeaders()) + .body(httpRpcResponse.getBody()) + .request(request) + .build(); + } + + private HttpMetadata initHttpMetadata(String url, String method, Map> headers, byte[] body) { + HttpMetadata httpMetadata = new HttpMetadata(); + httpMetadata.setBody(body); + httpMetadata.setUrl(url); + httpMetadata.setHeaders(headers); + httpMetadata.setMethod(method); + return httpMetadata; + } +} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/config/RpcFeignConfiguration.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/config/RpcFeignConfiguration.java new file mode 100644 index 0000000000..51716b8bd6 --- /dev/null +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/config/RpcFeignConfiguration.java @@ -0,0 +1,38 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.cloud.rpc.config; + +import com.alibaba.cloud.rpc.RpcProperties; +import com.alibaba.cloud.rpc.client.FeignRpcClient; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @author :Lictory + * @date : 2024/08/11 + */ + +@Configuration(proxyBeanMethods = false) +@ConditionalOnProperty(prefix = RpcProperties.PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true) +public class RpcFeignConfiguration { + @Bean + public feign.Client feignClient() { + return new FeignRpcClient(); + } +} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/config/RpcRegistryConfiguration.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/config/RpcRegistryConfiguration.java new file mode 100644 index 0000000000..f616fbe440 --- /dev/null +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/config/RpcRegistryConfiguration.java @@ -0,0 +1,61 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.cloud.rpc.config; + + +import java.util.HashMap; +import java.util.Map; + +import com.alibaba.cloud.nacos.registry.NacosRegistration; +import com.alibaba.cloud.rpc.RpcProperties; +import com.alibaba.cloud.rpc.server.RpcNettyServerListener; +import jakarta.annotation.PostConstruct; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + + +/** + * @author :Lictory + * @date : 2024/08/12 + */ + +@Configuration(proxyBeanMethods = false) +@ConditionalOnProperty(prefix = RpcProperties.PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true) +public class RpcRegistryConfiguration { + + @Autowired + private NacosRegistration nacosRegistration; + @Autowired + private RpcProperties rpcProperties; + + @PostConstruct + public void init() { + Map metadata = new HashMap<>(); + metadata.put(RpcProperties.NETTY_PORT_PREFIX, String.valueOf(rpcProperties.getPort())); + nacosRegistration.getMetadata().putAll(metadata); + } + + @Bean + @ConditionalOnMissingBean + public RpcNettyServerListener initRpcNettyServerListener() { + return new RpcNettyServerListener(); + } +} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/metadata/HttpMetadata.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/metadata/HttpMetadata.java new file mode 100644 index 0000000000..024f7d688b --- /dev/null +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/metadata/HttpMetadata.java @@ -0,0 +1,68 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.cloud.rpc.metadata; + +import java.io.Serializable; +import java.util.Collection; +import java.util.Map; + +/** + * @author :Lictory + * @date : 2024/08/16 + */ +public class HttpMetadata implements Serializable { + + private String url; + + private String method; + + private byte[] body; + + private Map> headers; + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getMethod() { + return method; + } + + public void setMethod(String method) { + this.method = method; + } + + public byte[] getBody() { + return body; + } + + public void setBody(byte[] body) { + this.body = body; + } + + public Map> getHeaders() { + return headers; + } + + public void setHeaders(Map> headers) { + this.headers = headers; + } +} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/metadata/HttpRpcResponse.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/metadata/HttpRpcResponse.java new file mode 100644 index 0000000000..c2d2dcdb32 --- /dev/null +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/metadata/HttpRpcResponse.java @@ -0,0 +1,75 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.cloud.rpc.metadata; + +import java.io.Serializable; +import java.util.Collection; +import java.util.Map; + +/** + * @author :Lictory + * @date : 2024/08/16 + */ +public class HttpRpcResponse implements Serializable { + private int statusCode; + private String reasonPhrase; + private Map> headers; + private byte[] body; + + public HttpRpcResponse(int statusCode, String reasonPhrase, Map> headers, byte[] body) { + this.statusCode = statusCode; + this.reasonPhrase = reasonPhrase; + this.headers = headers; + this.body = body; + } + + public HttpRpcResponse() { + } + + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + + public String getReasonPhrase() { + return reasonPhrase; + } + + public void setReasonPhrase(String reasonPhrase) { + this.reasonPhrase = reasonPhrase; + } + + public Map> getHeaders() { + return headers; + } + + public void setHeaders(Map> headers) { + this.headers = headers; + } + + public byte[] getBody() { + return body; + } + + public void setBody(byte[] body) { + this.body = body; + } +} + diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/server/RpcDispatcherServlet.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/server/RpcDispatcherServlet.java new file mode 100644 index 0000000000..3f3ea5d7ca --- /dev/null +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/server/RpcDispatcherServlet.java @@ -0,0 +1,34 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.cloud.rpc.server; + + +import org.springframework.context.ApplicationContext; +import org.springframework.web.servlet.DispatcherServlet; + +/** + * @author :Lictory + * @date : 2024/08/31 + */ + +public class RpcDispatcherServlet extends DispatcherServlet { + public RpcDispatcherServlet(ApplicationContext applicationContext) { + super(); + // initial mapping + onRefresh(applicationContext); + } +} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/server/RpcNettyServerListener.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/server/RpcNettyServerListener.java new file mode 100644 index 0000000000..d203b5744d --- /dev/null +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/server/RpcNettyServerListener.java @@ -0,0 +1,113 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.cloud.rpc.server; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.CompletableFuture; + +import com.alibaba.cloud.rpc.RpcProperties; +import com.alibaba.cloud.rpc.metadata.HttpMetadata; +import com.alibaba.cloud.rpc.metadata.HttpRpcResponse; +import com.alibaba.cloud.rpc.utils.MockHttpServletRequestConverter; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServletResponse; +import org.apache.dubbo.common.URL; +import org.apache.dubbo.remoting.RemotingException; +import org.apache.dubbo.remoting.exchange.ExchangeChannel; +import org.apache.dubbo.remoting.exchange.ExchangeServer; +import org.apache.dubbo.remoting.exchange.Exchangers; +import org.apache.dubbo.remoting.exchange.support.ExchangeHandlerAdapter; +import org.apache.dubbo.rpc.model.FrameworkModel; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.event.ApplicationReadyEvent; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationListener; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; + +/** + * @author :Lictory + * @date : 2024/08/18 + */ + +public class RpcNettyServerListener implements ApplicationListener { + private ExchangeServer server; + + @Autowired + private RpcProperties rpcProperties; + + private RpcDispatcherServlet dispatcherServlet; + + @Autowired + private ApplicationContext applicationContext; + + @Override + public void onApplicationEvent(ApplicationReadyEvent event) { + initLocalServer(rpcProperties.getHost(), rpcProperties.getPort()); + this.dispatcherServlet = new RpcDispatcherServlet(applicationContext); + } + + private void initLocalServer(String host, int port) { + URL url = URL.valueOf("exchange://" + host + ":" + port); + try { + this.server = Exchangers.bind(url, new ExchangeHandlerAdapter(FrameworkModel.defaultModel()) { + @Override + public CompletableFuture reply(ExchangeChannel channel, Object msg) { + HttpMetadata httpMetadata = (HttpMetadata) msg; + String url = httpMetadata.getUrl(); + System.out.println(url); + MockHttpServletRequest request = MockHttpServletRequestConverter.getMockHttpServletRequest(httpMetadata, url); + MockHttpServletResponse response = new MockHttpServletResponse(); + try { + dispatcherServlet.service(request, response); + } + catch (ServletException | IOException e) { + throw new RuntimeException(e); + } + HttpRpcResponse httpRpcResponse = new HttpRpcResponse(); + httpRpcResponse.setStatusCode(response.getStatus()); + httpRpcResponse.setBody(response.getContentAsByteArray()); + httpRpcResponse.setReasonPhrase(response.getErrorMessage()); + httpRpcResponse.setHeaders(convertHeaders(response)); + return CompletableFuture.completedFuture(httpRpcResponse); + } + } + ); + } + catch (RemotingException e) { + throw new RuntimeException(e); + } + } + + public Map> convertHeaders(HttpServletResponse httpServletResponse) { + Map> feignHeaders = new HashMap<>(); + // get all headers + for (String headerName : httpServletResponse.getHeaderNames()) { + Collection headerValues = httpServletResponse.getHeaders(headerName); + feignHeaders.put(headerName, new ArrayList<>(headerValues)); + } + return feignHeaders; + } +} + + + diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/utils/MockHttpServletRequestConverter.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/utils/MockHttpServletRequestConverter.java new file mode 100644 index 0000000000..1c5b5f82ae --- /dev/null +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/utils/MockHttpServletRequestConverter.java @@ -0,0 +1,60 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.cloud.rpc.utils; + +import java.util.Collection; +import java.util.Map; + +import com.alibaba.cloud.rpc.metadata.HttpMetadata; + +import org.springframework.mock.web.MockHttpServletRequest; + + +/** + * @author :Lictory + * @date : 2024/08/23 + */ +public final class MockHttpServletRequestConverter { + private MockHttpServletRequestConverter() { + + } + + public static MockHttpServletRequest getMockHttpServletRequest(HttpMetadata httpMetadata, String url) { + // create MockHttpServletRequest instance + MockHttpServletRequest mockRequest = new MockHttpServletRequest(); + + // set HTTP method + mockRequest.setMethod(httpMetadata.getMethod()); + + // set URL + mockRequest.setRequestURI(url); + + // set request headers + Map> headers = httpMetadata.getHeaders(); + for (Map.Entry> entry : headers.entrySet()) { + String headerName = entry.getKey(); + for (String headerValue : entry.getValue()) { + mockRequest.addHeader(headerName, headerValue); + } + } + // set request body(if exist) + if (httpMetadata.getBody() != null) { + mockRequest.setContent(httpMetadata.getBody()); + } + return mockRequest; + } +} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/utils/UrlResolver.java b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/utils/UrlResolver.java new file mode 100644 index 0000000000..2679a49a90 --- /dev/null +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/java/com/alibaba/cloud/rpc/utils/UrlResolver.java @@ -0,0 +1,100 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.cloud.rpc.utils; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.concurrent.ConcurrentHashMap; + +import com.alibaba.cloud.rpc.RpcProperties; +import org.apache.dubbo.remoting.Channel; +import org.apache.dubbo.remoting.RemotingException; +import org.apache.dubbo.remoting.exchange.ExchangeClient; +import org.apache.dubbo.remoting.exchange.Exchangers; +import org.apache.dubbo.remoting.exchange.support.ExchangeHandlerDispatcher; + +import org.springframework.cloud.client.ServiceInstance; +import org.springframework.cloud.client.loadbalancer.LoadBalancerClient; + +/** + * @author :Lictory + * @date : 2024/08/13 + */ + +public class UrlResolver { + + private static final ConcurrentHashMap clientMap = new ConcurrentHashMap<>(); + + public String resolveOriginalUrl(LoadBalancerClient loadBalancerClient, String url) { + URL result = null; + try { + result = new URL(url); + } + catch (MalformedURLException e) { + throw new RuntimeException(e); + } + String serviceId = result.getHost(); + ServiceInstance choose = loadBalancerClient.choose(serviceId); + int nettyPort = Integer.parseInt(choose.getMetadata().get(RpcProperties.NETTY_PORT_PREFIX)); + return "exchange://" + choose.getHost() + ":" + nettyPort; + } + + private void initLocalClient(String url) { + + org.apache.dubbo.common.URL targetUrl = org.apache.dubbo.common.URL.valueOf(url); + try { + clientMap.put(url, Exchangers.connect(targetUrl, new ExchangeHandlerDispatcher() { + @Override + public void received(Channel channel, Object message) { + super.received(channel, message); + } + } + )); + } + catch (RemotingException e) { + throw new RuntimeException(e); + } + } + + public String getPathFromUrl(String urlString) { + try { + URL url = new URL(urlString); + StringBuilder path = new StringBuilder(); + path.append(url.getPath()); + if (url.getQuery() != null) { + path.append("?").append(url.getQuery()); + } + if (url.getRef() != null) { + path.append("#").append(url.getRef()); + } + return path.toString(); + } + catch (MalformedURLException e) { + throw new IllegalArgumentException("Invalid URL: " + urlString, e); + } + } + + public ExchangeClient getClient(String url) { + if (url == null || url.length() == 0) { + return null; + } + if (!clientMap.containsKey(url)) { + initLocalClient(url); + } + return clientMap.get(url); + } +} diff --git a/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 0000000000..77bdbb3e14 --- /dev/null +++ b/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-rpc/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1,3 @@ +com.alibaba.cloud.rpc.RpcConfiguration +com.alibaba.cloud.rpc.config.RpcFeignConfiguration +com.alibaba.cloud.rpc.config.RpcRegistryConfiguration diff --git a/spring-cloud-alibaba-tests/pom.xml b/spring-cloud-alibaba-tests/pom.xml index cb11432df8..2c2de31388 100644 --- a/spring-cloud-alibaba-tests/pom.xml +++ b/spring-cloud-alibaba-tests/pom.xml @@ -18,6 +18,7 @@ sentinel-tests + rpc-tests @@ -54,4 +55,4 @@ - \ No newline at end of file + diff --git a/spring-cloud-alibaba-tests/rpc-tests/pom.xml b/spring-cloud-alibaba-tests/rpc-tests/pom.xml new file mode 100644 index 0000000000..153f44d927 --- /dev/null +++ b/spring-cloud-alibaba-tests/rpc-tests/pom.xml @@ -0,0 +1,19 @@ + + + 4.0.0 + + com.alibaba.cloud + spring-cloud-alibaba-tests + ${revision} + + rpc-tests + pom + RPC Tests + + spring-cloud-alibaba-rpc-consumer + spring-cloud-alibaba-rpc-provider + spring-cloud-alibaba-rpc-api + + diff --git a/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-api/pom.xml b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-api/pom.xml new file mode 100644 index 0000000000..50dd0a91e7 --- /dev/null +++ b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-api/pom.xml @@ -0,0 +1,19 @@ + + + 4.0.0 + + com.alibaba.cloud + rpc-tests + ${revision} + + + spring-cloud-alibaba-rpc-api + + + org.springframework.cloud + spring-cloud-openfeign-core + + + diff --git a/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-api/src/main/java/com/alibaba/api/ProviderService.java b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-api/src/main/java/com/alibaba/api/ProviderService.java new file mode 100644 index 0000000000..4dc5e897c2 --- /dev/null +++ b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-api/src/main/java/com/alibaba/api/ProviderService.java @@ -0,0 +1,44 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.api; + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; + +/** + * @author :Lictory + */ +@FeignClient("provider") +public interface ProviderService { + /** + * string test. + * + * @return string + */ + @GetMapping("/api/get") + String hi(); + + /** + * post test. + * + * @param userId id + */ + @PostMapping("/api/post/{userId}") + void post(@PathVariable("userId") Integer userId); +} diff --git a/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-consumer/pom.xml b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-consumer/pom.xml new file mode 100644 index 0000000000..35bc36ae0f --- /dev/null +++ b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-consumer/pom.xml @@ -0,0 +1,26 @@ + + + 4.0.0 + + com.alibaba.cloud + rpc-tests + ${revision} + + + spring-cloud-alibaba-rpc-consumer + + + com.alibaba.cloud + spring-cloud-starter-alibaba-rpc + ${revision} + + + com.alibaba.cloud + spring-cloud-alibaba-rpc-api + ${revision} + + + + diff --git a/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-consumer/src/main/java/com/alibaba/dubbo/consumer/ConsumerApplication.java b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-consumer/src/main/java/com/alibaba/dubbo/consumer/ConsumerApplication.java new file mode 100644 index 0000000000..78e3ab3e4d --- /dev/null +++ b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-consumer/src/main/java/com/alibaba/dubbo/consumer/ConsumerApplication.java @@ -0,0 +1,38 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.dubbo.consumer; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.context.annotation.ComponentScan; + +/** + * @author :Lictory + * @date : 2024/08/01 + */ + +@SpringBootApplication +@EnableFeignClients +@EnableDiscoveryClient +@ComponentScan(basePackages = {"com.alibaba.api"}) +public class ConsumerApplication { + public static void main(String[] args) { + SpringApplication.run(ConsumerApplication.class, args); + } +} diff --git a/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-consumer/src/main/java/com/alibaba/dubbo/consumer/service/TestService.java b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-consumer/src/main/java/com/alibaba/dubbo/consumer/service/TestService.java new file mode 100644 index 0000000000..f9dbe14f92 --- /dev/null +++ b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-consumer/src/main/java/com/alibaba/dubbo/consumer/service/TestService.java @@ -0,0 +1,48 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.dubbo.consumer.service; + + +import com.alibaba.api.ProviderService; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author :Lictory + * @date : 2024/08/01 + */ +@RestController +public class TestService { + @Autowired + private ProviderService providerService; + + @GetMapping("/test/get") + public String testGet() { + return providerService.hi(); + } + + @PostMapping("/test/post/{userId}") + public void testPost(@PathVariable("userId") Integer userId) { + providerService.post(userId); + } +} + + diff --git a/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-consumer/src/main/resources/application.yml b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-consumer/src/main/resources/application.yml new file mode 100644 index 0000000000..0c5d78dc0a --- /dev/null +++ b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-consumer/src/main/resources/application.yml @@ -0,0 +1,22 @@ +spring: + main: + allow-bean-definition-overriding: true + application: + name: consumer + cloud: + nacos: + discovery: + server-addr: 10.21.32.154:8848 + rpc: + enabled: true + netty: + host: 127.0.0.1 + port: 20880 + +server: + port: 8081 +management: + endpoints: + web: + exposure: + include: "*" diff --git a/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-consumer/src/main/resources/dubbo.properties b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-consumer/src/main/resources/dubbo.properties new file mode 100644 index 0000000000..4f760cc70a --- /dev/null +++ b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-consumer/src/main/resources/dubbo.properties @@ -0,0 +1,2 @@ +dubbo.application.check-serializable=false +dubbo.application.serialize-check-status=DISABLE diff --git a/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-consumer/src/main/resources/security/serialize.allowlist b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-consumer/src/main/resources/security/serialize.allowlist new file mode 100644 index 0000000000..5421d68abe --- /dev/null +++ b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-consumer/src/main/resources/security/serialize.allowlist @@ -0,0 +1,22 @@ +# +# +# 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. +# +# + +org.apache.dubbo.common.serialize.hessian2 +com.alibaba.cloud.rpc.metadata.HttpMetadata +com.alibaba.cloud.rpc.metadata.HttpRpcResponse diff --git a/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-provider/pom.xml b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-provider/pom.xml new file mode 100644 index 0000000000..a6e0a20dc2 --- /dev/null +++ b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-provider/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + + com.alibaba.cloud + rpc-tests + ${revision} + + + spring-cloud-alibaba-rpc-provider + + + com.alibaba.cloud + spring-cloud-starter-alibaba-rpc + ${revision} + + + com.alibaba.cloud + spring-cloud-alibaba-rpc-api + ${revision} + + + diff --git a/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-provider/src/main/java/com/alibaba/dubbo/provider/ProviderApplication.java b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-provider/src/main/java/com/alibaba/dubbo/provider/ProviderApplication.java new file mode 100644 index 0000000000..0ef1160eda --- /dev/null +++ b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-provider/src/main/java/com/alibaba/dubbo/provider/ProviderApplication.java @@ -0,0 +1,34 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.dubbo.provider; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.openfeign.EnableFeignClients; + +/** + * @author :Lictory + * @date : 2024/08/01 + */ + +@SpringBootApplication +@EnableFeignClients +public class ProviderApplication { + public static void main(String[] args) { + SpringApplication.run(ProviderApplication.class, args); + } +} diff --git a/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-provider/src/main/java/com/alibaba/dubbo/provider/controller/TestController.java b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-provider/src/main/java/com/alibaba/dubbo/provider/controller/TestController.java new file mode 100644 index 0000000000..85f6ab8873 --- /dev/null +++ b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-provider/src/main/java/com/alibaba/dubbo/provider/controller/TestController.java @@ -0,0 +1,50 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.dubbo.provider.controller; + +import com.alibaba.api.ProviderService; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + + +/** + * @author :Lictory + * @date : 2024/08/09 + */ + +@RestController +@RequestMapping("/api") +public class TestController { + + @Autowired + private ProviderService providerService; + + @GetMapping("/get") + public String getTest() { + return providerService.hi(); + } + + @PostMapping("/post/{userId}") + public void postTest(@PathVariable("userId") Integer userId) { + providerService.post(userId); + } +} diff --git a/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-provider/src/main/java/com/alibaba/dubbo/provider/service/impl/ProviderServiceImpl.java b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-provider/src/main/java/com/alibaba/dubbo/provider/service/impl/ProviderServiceImpl.java new file mode 100644 index 0000000000..b44a60d667 --- /dev/null +++ b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-provider/src/main/java/com/alibaba/dubbo/provider/service/impl/ProviderServiceImpl.java @@ -0,0 +1,40 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.alibaba.dubbo.provider.service.impl; + + +import com.alibaba.api.ProviderService; + +import org.springframework.stereotype.Service; + +/** + * @author :Lictory + * @date : 2024/08/01 + */ +@Service +public class ProviderServiceImpl implements ProviderService { + @Override + public String hi() { + return "Hi Spring Cloud Alibaba 测试成功"; + } + + @Override + public void post(Integer userId) { + System.out.println("sca post Test 测试" + userId); + } + +} diff --git a/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-provider/src/main/resources/application.yml b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-provider/src/main/resources/application.yml new file mode 100644 index 0000000000..195382710b --- /dev/null +++ b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-provider/src/main/resources/application.yml @@ -0,0 +1,21 @@ +spring: + main: + allow-bean-definition-overriding: true + application: + name: provider + cloud: + nacos: + discovery: + server-addr: 10.21.32.154:8848 + rpc: + enabled: true + netty: + host: 127.0.0.1 + port: 20881 +management: + endpoints: + web: + exposure: + include: "*" +server: + port: 8080 diff --git a/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-provider/src/main/resources/dubbo.properties b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-provider/src/main/resources/dubbo.properties new file mode 100644 index 0000000000..4f760cc70a --- /dev/null +++ b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-provider/src/main/resources/dubbo.properties @@ -0,0 +1,2 @@ +dubbo.application.check-serializable=false +dubbo.application.serialize-check-status=DISABLE diff --git a/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-provider/src/main/resources/security/serialize.allowlist b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-provider/src/main/resources/security/serialize.allowlist new file mode 100644 index 0000000000..5421d68abe --- /dev/null +++ b/spring-cloud-alibaba-tests/rpc-tests/spring-cloud-alibaba-rpc-provider/src/main/resources/security/serialize.allowlist @@ -0,0 +1,22 @@ +# +# +# 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. +# +# + +org.apache.dubbo.common.serialize.hessian2 +com.alibaba.cloud.rpc.metadata.HttpMetadata +com.alibaba.cloud.rpc.metadata.HttpRpcResponse