Skip to content

Commit

Permalink
[ISSUE alibaba#5756] Fix PathVariable is not supported by DistroFilter.
Browse files Browse the repository at this point in the history
  • Loading branch information
pixystone committed May 17, 2021
1 parent 9a738e8 commit 8111549
Showing 1 changed file with 29 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
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.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down Expand Up @@ -227,9 +226,9 @@ private ObjectNode getMetrics() throws NacosException {
* @return 'ok' if success
* @throws Exception exception
*/
@PostMapping("/{ver:v2}/service")
@PostMapping("/service")
@Secured(parser = NamingResourceParser.class, action = ActionTypes.WRITE)
public String createService(@PathVariable String ver,
public String createService(@RequestParam(defaultValue = "v2", required = false) String ver,
HttpServletRequest request,
@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId,
@RequestParam String serviceName,
Expand All @@ -255,9 +254,9 @@ public String createService(@PathVariable String ver,
* @return 'ok' if success
* @throws Exception exception
*/
@DeleteMapping("/{ver:v2}/service")
@DeleteMapping("/service")
@Secured(parser = NamingResourceParser.class, action = ActionTypes.WRITE)
public String removeService(@PathVariable String ver,
public String removeService(@RequestParam(defaultValue = "v2", required = false) String ver,
@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId,
@RequestParam String serviceName) throws Exception {
getServiceOperator(ver).delete(namespaceId, serviceName);
Expand All @@ -276,9 +275,9 @@ private ServiceOperator getServiceOperator(String ver) {
* @return detail information of service
* @throws NacosException nacos exception
*/
@GetMapping("/{ver:v2}/service")
@GetMapping("/service")
@Secured(parser = NamingResourceParser.class, action = ActionTypes.READ)
public ObjectNode detailService(@PathVariable String ver,
public ObjectNode detailService(@RequestParam(defaultValue = "v2", required = false) String ver,
@RequestParam(defaultValue = Constants.DEFAULT_NAMESPACE_ID) String namespaceId,
@RequestParam String serviceName) throws NacosException {
return getServiceOperator(ver).queryService(namespaceId, serviceName);
Expand All @@ -291,9 +290,10 @@ public ObjectNode detailService(@PathVariable String ver,
* @return all service names
* @throws Exception exception
*/
@GetMapping("/{ver:v2}/service/list")
@GetMapping("/service/list")
@Secured(parser = NamingResourceParser.class, action = ActionTypes.READ)
public ObjectNode listService(@PathVariable String ver, HttpServletRequest request) throws Exception {
public ObjectNode listService(@RequestParam(defaultValue = "v2", required = false) String ver,
HttpServletRequest request) throws Exception {
final int pageNo = NumberUtils.toInt(WebUtils.required(request, "pageNo"));
final int pageSize = NumberUtils.toInt(WebUtils.required(request, "pageSize"));
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID);
Expand All @@ -314,9 +314,10 @@ public ObjectNode listService(@PathVariable String ver, HttpServletRequest reque
* @return 'ok' if success
* @throws Exception exception
*/
@PutMapping("/{ver:v2}/service")
@PutMapping("/service")
@Secured(parser = NamingResourceParser.class, action = ActionTypes.WRITE)
public String updateService(@PathVariable String ver, HttpServletRequest request) throws Exception {
public String updateService(@RequestParam(defaultValue = "v2", required = false) String ver,
HttpServletRequest request) throws Exception {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID);
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
ServiceMetadata serviceMetadata = new ServiceMetadata();
Expand All @@ -339,9 +340,9 @@ public String updateService(@PathVariable String ver, HttpServletRequest request
* @param responsibleOnly whether only search responsible service
* @return search result
*/
@RequestMapping("/{ver:v2}/service/names")
@RequestMapping("/service/names")
@Secured(parser = NamingResourceParser.class, action = ActionTypes.READ)
public ObjectNode searchService(@PathVariable String ver,
public ObjectNode searchService(@RequestParam(defaultValue = "v2", required = false) String ver,
@RequestParam(defaultValue = StringUtils.EMPTY) String namespaceId,
@RequestParam(defaultValue = StringUtils.EMPTY) String expr,
@RequestParam(required = false) boolean responsibleOnly) throws NacosException {
Expand Down Expand Up @@ -396,9 +397,10 @@ private Selector parseSelector(String selectorJsonString) throws Exception {
* @throws Exception any error during register
*/
@CanDistro
@PostMapping("/{ver:v2}/instance")
@PostMapping("/instance")
@Secured(parser = NamingResourceParser.class, action = ActionTypes.WRITE)
public String registerInstance(@PathVariable String ver, HttpServletRequest request) throws Exception {
public String registerInstance(@RequestParam(defaultValue = "v2", required = false) String ver,
HttpServletRequest request) throws Exception {

final String namespaceId = WebUtils
.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID);
Expand All @@ -419,9 +421,10 @@ public String registerInstance(@PathVariable String ver, HttpServletRequest requ
* @throws Exception any error during deregister
*/
@CanDistro
@DeleteMapping("/{ver:v2}/instance")
@DeleteMapping("/instance")
@Secured(parser = NamingResourceParser.class, action = ActionTypes.WRITE)
public String deregisterInstance(@PathVariable String ver, HttpServletRequest request) throws Exception {
public String deregisterInstance(@RequestParam(defaultValue = "v2", required = false) String ver,
HttpServletRequest request) throws Exception {
Instance instance = getIpAddress(request);
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID);
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
Expand All @@ -439,9 +442,10 @@ public String deregisterInstance(@PathVariable String ver, HttpServletRequest re
* @throws Exception any error during update
*/
@CanDistro
@PutMapping("/{ver:v2}/instance")
@PutMapping("/instance")
@Secured(parser = NamingResourceParser.class, action = ActionTypes.WRITE)
public String updateInstance(@PathVariable String ver, HttpServletRequest request) throws Exception {
public String updateInstance(@RequestParam(defaultValue = "v2", required = false) String ver,
HttpServletRequest request) throws Exception {
String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID);
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
NamingUtils.checkServiceNameFormat(serviceName);
Expand All @@ -457,9 +461,10 @@ public String updateInstance(@PathVariable String ver, HttpServletRequest reques
* @return list of instance
* @throws Exception any error during list
*/
@GetMapping("/{ver:v2}/instance/list")
@GetMapping("/instance/list")
@Secured(parser = NamingResourceParser.class, action = ActionTypes.READ)
public Object listInstance(@PathVariable String ver, HttpServletRequest request) throws Exception {
public Object listInstance(@RequestParam(defaultValue = "v2", required = false) String ver,
HttpServletRequest request) throws Exception {

String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID);
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
Expand Down Expand Up @@ -489,9 +494,10 @@ public Object listInstance(@PathVariable String ver, HttpServletRequest request)
* @return detail information of instance
* @throws Exception any error during get
*/
@GetMapping("/{ver:v2}/instance")
@GetMapping("/instance")
@Secured(parser = NamingResourceParser.class, action = ActionTypes.READ)
public ObjectNode detailInstance(@PathVariable String ver, HttpServletRequest request) throws Exception {
public ObjectNode detailInstance(@RequestParam(defaultValue = "v2", required = false) String ver,
HttpServletRequest request) throws Exception {

String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID);
String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
Expand Down

0 comments on commit 8111549

Please sign in to comment.