mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
以2.2.1.BUILD-SNAPSHOT 为基准,适配Greenwich版本的Spring Cloud
This commit is contained in:
@@ -345,4 +345,4 @@ HTTP 响应为:
|
||||
- [spring-cloud-dubbo-provider-web-sample](spring-cloud-dubbo-provider-web-sample):Dubbo Spring Cloud 服务提供方示例(Web 应用)
|
||||
- [spring-cloud-dubbo-provider-sample](spring-cloud-dubbo-provider-sample):Dubbo Spring Cloud 服务提供方示例(非 Web 应用)
|
||||
- [spring-cloud-dubbo-consumer-sample](spring-cloud-dubbo-consumer-sample):Dubbo Spring Cloud 服务消费方示例
|
||||
- [spring-cloud-dubbo-servlet-gateway](spring-cloud-dubbo-servlet-gateway)-sample:Dubbo Spring Cloud Servlet 网关简易实现示例
|
||||
- [spring-cloud-dubbo-servlet-gateway](spring-cloud-dubbo-servlet-gateway-sample):Dubbo Spring Cloud Servlet 网关简易实现示例
|
||||
|
@@ -3,8 +3,8 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>spring-cloud-alibaba-examples</artifactId>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-examples</artifactId>
|
||||
<version>2.1.1.RELEASE</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,10 +13,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.dubbo.bootstrap;
|
||||
|
||||
import com.alibaba.cloud.dubbo.service.EchoService;
|
||||
|
||||
import org.apache.dubbo.config.annotation.Reference;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@@ -26,7 +26,7 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* Dubbo Spring Cloud Client Bootstrap
|
||||
* Dubbo Spring Cloud Client Bootstrap.
|
||||
*/
|
||||
@EnableDiscoveryClient
|
||||
@EnableAutoConfiguration
|
||||
@@ -44,4 +44,5 @@ public class DubboSpringCloudClientBootstrap {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DubboSpringCloudClientBootstrap.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.dubbo.bootstrap;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -22,7 +23,6 @@ import com.alibaba.cloud.dubbo.annotation.DubboTransported;
|
||||
import com.alibaba.cloud.dubbo.service.RestService;
|
||||
import com.alibaba.cloud.dubbo.service.User;
|
||||
import com.alibaba.cloud.dubbo.service.UserService;
|
||||
|
||||
import org.apache.dubbo.config.annotation.Reference;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -48,9 +48,10 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE;
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
|
||||
|
||||
/**
|
||||
* Dubbo Spring Cloud Consumer Bootstrap
|
||||
* Dubbo Spring Cloud Consumer Bootstrap.
|
||||
*/
|
||||
@EnableDiscoveryClient
|
||||
@EnableAutoConfiguration
|
||||
@@ -80,51 +81,6 @@ public class DubboSpringCloudConsumerBootstrap {
|
||||
@LoadBalanced
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
@FeignClient("${provider.application.name}")
|
||||
public interface FeignRestService {
|
||||
|
||||
@GetMapping(value = "/param")
|
||||
String param(@RequestParam("param") String param);
|
||||
|
||||
@PostMapping("/params")
|
||||
public String params(@RequestParam("b") String b, @RequestParam("a") int a);
|
||||
|
||||
@PostMapping(value = "/request/body/map", produces = APPLICATION_JSON_UTF8_VALUE)
|
||||
User requestBody(@RequestParam("param") String param,
|
||||
@RequestBody Map<String, Object> data);
|
||||
|
||||
@GetMapping("/headers")
|
||||
public String headers(@RequestHeader("h2") String header2,
|
||||
@RequestHeader("h") String header, @RequestParam("v") Integer value);
|
||||
|
||||
@GetMapping("/path-variables/{p1}/{p2}")
|
||||
public String pathVariables(@PathVariable("p2") String path2,
|
||||
@PathVariable("p1") String path1, @RequestParam("v") String param);
|
||||
}
|
||||
|
||||
@FeignClient("${provider.application.name}")
|
||||
@DubboTransported(protocol = "dubbo")
|
||||
public interface DubboFeignRestService {
|
||||
|
||||
@GetMapping(value = "/param")
|
||||
String param(@RequestParam("param") String param);
|
||||
|
||||
@PostMapping("/params")
|
||||
String params(@RequestParam("b") String paramB, @RequestParam("a") int paramA);
|
||||
|
||||
@PostMapping(value = "/request/body/map", produces = APPLICATION_JSON_UTF8_VALUE)
|
||||
User requestBody(@RequestParam("param") String param,
|
||||
@RequestBody Map<String, Object> data);
|
||||
|
||||
@GetMapping("/headers")
|
||||
public String headers(@RequestHeader("h2") String header2,
|
||||
@RequestParam("v") Integer value, @RequestHeader("h") String header);
|
||||
|
||||
@GetMapping("/path-variables/{p1}/{p2}")
|
||||
public String pathVariables(@RequestParam("v") String param,
|
||||
@PathVariable("p2") String path2, @PathVariable("p1") String path1);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ApplicationRunner userServiceRunner() {
|
||||
return arguments -> {
|
||||
@@ -255,4 +211,52 @@ public class DubboSpringCloudConsumerBootstrap {
|
||||
new SpringApplicationBuilder(DubboSpringCloudConsumerBootstrap.class)
|
||||
.properties("spring.profiles.active=nacos").run(args);
|
||||
}
|
||||
|
||||
@FeignClient("${provider.application.name}")
|
||||
public interface FeignRestService {
|
||||
|
||||
@GetMapping("/param")
|
||||
String param(@RequestParam("param") String param);
|
||||
|
||||
@PostMapping("/params")
|
||||
String params(@RequestParam("b") String b, @RequestParam("a") int a);
|
||||
|
||||
@PostMapping(value = "/request/body/map", produces = APPLICATION_JSON_VALUE)
|
||||
User requestBody(@RequestParam("param") String param,
|
||||
@RequestBody Map<String, Object> data);
|
||||
|
||||
@GetMapping("/headers")
|
||||
String headers(@RequestHeader("h2") String header2,
|
||||
@RequestHeader("h") String header, @RequestParam("v") Integer value);
|
||||
|
||||
@GetMapping("/path-variables/{p1}/{p2}")
|
||||
String pathVariables(@PathVariable("p2") String path2,
|
||||
@PathVariable("p1") String path1, @RequestParam("v") String param);
|
||||
|
||||
}
|
||||
|
||||
@FeignClient("${provider.application.name}")
|
||||
@DubboTransported(protocol = "dubbo")
|
||||
public interface DubboFeignRestService {
|
||||
|
||||
@GetMapping("/param")
|
||||
String param(@RequestParam("param") String param);
|
||||
|
||||
@PostMapping("/params")
|
||||
String params(@RequestParam("b") String paramB, @RequestParam("a") int paramA);
|
||||
|
||||
@PostMapping(value = "/request/body/map", produces = APPLICATION_JSON_UTF8_VALUE)
|
||||
User requestBody(@RequestParam("param") String param,
|
||||
@RequestBody Map<String, Object> data);
|
||||
|
||||
@GetMapping("/headers")
|
||||
String headers(@RequestHeader("h2") String header2,
|
||||
@RequestParam("v") Integer value, @RequestHeader("h") String header);
|
||||
|
||||
@GetMapping("/path-variables/{p1}/{p2}")
|
||||
String pathVariables(@RequestParam("v") String param,
|
||||
@PathVariable("p2") String path2, @PathVariable("p1") String path1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -10,6 +10,9 @@ dubbo:
|
||||
# The subscribed services in consumer side
|
||||
subscribed-services: ${provider.application.name}
|
||||
|
||||
consumer:
|
||||
check: false
|
||||
|
||||
server:
|
||||
port: 0
|
||||
|
||||
|
@@ -136,18 +136,6 @@
|
||||
|
||||
</dependencies>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-bom</artifactId>
|
||||
<version>${dubbo.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.dubbo.bootstrap;
|
||||
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
@@ -21,7 +22,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
|
||||
/**
|
||||
* Dubbo Spring Cloud Provider Bootstrap
|
||||
* Dubbo Spring Cloud Provider Bootstrap.
|
||||
*/
|
||||
@EnableDiscoveryClient
|
||||
@EnableAutoConfiguration
|
||||
@@ -32,4 +33,5 @@ public class DubboSpringCloudProviderBootstrap {
|
||||
.properties("spring.profiles.active=nacos").web(WebApplicationType.NONE)
|
||||
.run(args);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.dubbo.service;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -22,7 +23,7 @@ import java.util.Map;
|
||||
import org.apache.dubbo.config.annotation.Service;
|
||||
|
||||
/**
|
||||
* In-Memory {@link UserService} implementation
|
||||
* In-Memory {@link UserService} implementation.
|
||||
*/
|
||||
@Service(protocol = "dubbo")
|
||||
public class InMemoryUserService implements UserService {
|
||||
@@ -43,4 +44,5 @@ public class InMemoryUserService implements UserService {
|
||||
public Collection<User> findAll() {
|
||||
return usersRepository.values();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.dubbo.service;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -37,7 +38,7 @@ import static com.alibaba.cloud.dubbo.util.LoggerUtils.log;
|
||||
import static org.springframework.util.MimeTypeUtils.APPLICATION_JSON_VALUE;
|
||||
|
||||
/**
|
||||
* Default {@link RestService}
|
||||
* Default {@link RestService}.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
@@ -118,4 +119,5 @@ public class StandardRestService implements RestService {
|
||||
map.put("age", user.getAge());
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.dubbo.bootstrap;
|
||||
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -20,7 +21,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
|
||||
/**
|
||||
* Dubbo Spring Cloud Provider Bootstrap
|
||||
* Dubbo Spring Cloud Provider Bootstrap.
|
||||
*/
|
||||
@EnableDiscoveryClient
|
||||
@EnableAutoConfiguration
|
||||
@@ -30,4 +31,5 @@ public class DubboSpringCloudWebProviderBootstrap {
|
||||
new SpringApplicationBuilder(DubboSpringCloudWebProviderBootstrap.class)
|
||||
.properties("spring.profiles.active=nacos").run(args);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.dubbo.service;
|
||||
|
||||
import java.util.Collection;
|
||||
@@ -22,7 +23,7 @@ import java.util.Map;
|
||||
import org.apache.dubbo.config.annotation.Service;
|
||||
|
||||
/**
|
||||
* In-Memory {@link UserService} implementation
|
||||
* In-Memory {@link UserService} implementation.
|
||||
*/
|
||||
@Service(protocol = "dubbo")
|
||||
public class InMemoryUserService implements UserService {
|
||||
@@ -43,4 +44,5 @@ public class InMemoryUserService implements UserService {
|
||||
public Collection<User> findAll() {
|
||||
return usersRepository.values();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.dubbo.service;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -34,7 +35,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import static com.alibaba.cloud.dubbo.util.LoggerUtils.log;
|
||||
|
||||
/**
|
||||
* Spring MVC {@link RestService}
|
||||
* Spring MVC {@link RestService}.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
@@ -45,7 +46,7 @@ public class SpringRestService implements RestService {
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@Override
|
||||
@GetMapping(value = "/param")
|
||||
@GetMapping("/param")
|
||||
public String param(@RequestParam String param) {
|
||||
log("/param", param);
|
||||
return param;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,12 +13,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.dubbo.service;
|
||||
|
||||
/**
|
||||
* Echo Service
|
||||
* Echo Service.
|
||||
*/
|
||||
public interface EchoService {
|
||||
|
||||
String echo(String message);
|
||||
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,12 +13,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.dubbo.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Rest Service
|
||||
* Rest Service.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
@@ -37,4 +38,5 @@ public interface RestService {
|
||||
User requestBodyMap(Map<String, Object> data, String param);
|
||||
|
||||
Map<String, Object> requestBodyUser(User user);
|
||||
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,12 +13,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.dubbo.service;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* User Entity
|
||||
* User Entity.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
@@ -58,4 +59,5 @@ public class User implements Serializable {
|
||||
public String toString() {
|
||||
return "User{" + "id=" + id + ", name='" + name + '\'' + ", age=" + age + '}';
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,12 +13,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.dubbo.service;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* {@link User} Service
|
||||
* {@link User} Service.
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
@@ -29,4 +30,5 @@ public interface UserService {
|
||||
boolean remove(Long userId);
|
||||
|
||||
Collection<User> findAll();
|
||||
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.dubbo.util;
|
||||
|
||||
import org.apache.dubbo.rpc.RpcContext;
|
||||
@@ -20,7 +21,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Logger Utilities
|
||||
* Logger Utilities.
|
||||
*/
|
||||
public abstract class LoggerUtils {
|
||||
|
||||
@@ -37,4 +38,5 @@ public abstract class LoggerUtils {
|
||||
logger.info(message);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018 the original author or authors.
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,10 +13,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.dubbo.bootstrap;
|
||||
|
||||
import com.alibaba.cloud.dubbo.service.EchoService;
|
||||
|
||||
import org.apache.dubbo.config.annotation.Service;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
@@ -24,7 +24,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
|
||||
/**
|
||||
* Dubbo Spring Cloud Server Bootstrap
|
||||
* Dubbo Spring Cloud Server Bootstrap.
|
||||
*/
|
||||
@EnableDiscoveryClient
|
||||
@EnableAutoConfiguration
|
||||
@@ -33,6 +33,7 @@ public class DubboSpringCloudServerBootstrap {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DubboSpringCloudServerBootstrap.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Service
|
||||
@@ -42,4 +43,5 @@ class EchoServiceImpl implements EchoService {
|
||||
public String echo(String message) {
|
||||
return "[echo] Hello, " + message;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.dubbo.bootstrap;
|
||||
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -7,7 +23,7 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
/**
|
||||
* Dubbo Spring Cloud Servlet Gateway Bootstrap
|
||||
* Dubbo Spring Cloud Servlet Gateway Bootstrap.
|
||||
*/
|
||||
@EnableDiscoveryClient
|
||||
@EnableAutoConfiguration
|
||||
@@ -19,4 +35,5 @@ public class DubboSpringCloudServletGatewayBootstrap {
|
||||
new SpringApplicationBuilder(DubboSpringCloudServletGatewayBootstrap.class)
|
||||
.properties("spring.profiles.active=nacos").run(args);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2013-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.cloud.dubbo.gateway;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -25,7 +41,6 @@ import com.alibaba.cloud.dubbo.metadata.repository.DubboServiceMetadataRepositor
|
||||
import com.alibaba.cloud.dubbo.service.DubboGenericServiceExecutionContext;
|
||||
import com.alibaba.cloud.dubbo.service.DubboGenericServiceExecutionContextFactory;
|
||||
import com.alibaba.cloud.dubbo.service.DubboGenericServiceFactory;
|
||||
|
||||
import org.apache.dubbo.rpc.service.GenericException;
|
||||
import org.apache.dubbo.rpc.service.GenericService;
|
||||
|
||||
@@ -132,37 +147,6 @@ public class DubboGatewayServlet extends HttpServletBean {
|
||||
return StreamUtils.copyToByteArray(inputStream);
|
||||
}
|
||||
|
||||
private static class HttpRequestAdapter implements HttpRequest {
|
||||
|
||||
private final HttpServletRequest request;
|
||||
|
||||
private HttpRequestAdapter(HttpServletRequest request) {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodValue() {
|
||||
return request.getMethod();
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getURI() {
|
||||
try {
|
||||
return new URI(request.getRequestURL().toString() + "?"
|
||||
+ request.getQueryString());
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpHeaders getHeaders() {
|
||||
return new HttpHeaders();
|
||||
}
|
||||
}
|
||||
|
||||
private RequestMetadata buildRequestMetadata(HttpServletRequest request,
|
||||
String restPath) {
|
||||
UriComponents uriComponents = fromUriString(request.getRequestURI()).build(true);
|
||||
@@ -192,4 +176,37 @@ public class DubboGatewayServlet extends HttpServletBean {
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private final static class HttpRequestAdapter implements HttpRequest {
|
||||
|
||||
private final HttpServletRequest request;
|
||||
|
||||
private HttpRequestAdapter(HttpServletRequest request) {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMethodValue() {
|
||||
return request.getMethod();
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getURI() {
|
||||
try {
|
||||
return new URI(request.getRequestURL().toString() + "?"
|
||||
+ request.getQueryString());
|
||||
}
|
||||
catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpHeaders getHeaders() {
|
||||
return new HttpHeaders();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user