Skip to content

Commit

Permalink
ok
Browse files Browse the repository at this point in the history
  • Loading branch information
upliveapp committed Apr 10, 2019
1 parent dd539cd commit dc7989e
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 5 deletions.
6 changes: 6 additions & 0 deletions jswitcher-sample/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@
<version>2.1.3.RELEASE</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.3.RELEASE</version>
<scope>provided</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
Expand Down
4 changes: 4 additions & 0 deletions jswitcher-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2019 [email protected].
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.xincao9.jswitcher.sample.controller;

import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* 输出随机字符串
*
* @author [email protected]
*/
@RestController
public class RootController {

@GetMapping("/")
public ResponseEntity<String> root () {
return ResponseEntity.ok(RandomStringUtils.randomAscii(128));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;

/**
* Uri拦截器
Expand Down Expand Up @@ -60,13 +61,17 @@ public void init(FilterConfig filterConfig) throws ServletException {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest hsr = (HttpServletRequest) request;
String path = hsr.getPathInfo();
String path = hsr.getRequestURI();
String method = hsr.getMethod();
if (StringUtils.isBlank(path)) {
path = "/";
}
String key = String.format("%s:%s", method, path);
switcherService.register(key, Boolean.TRUE, key, QoS.API);
if (switcherService.isOpen(key)) {
chain.doFilter(request, response);
} else {
request.getRequestDispatcher("/404").forward(request, response);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.github.xincao9.jswitcher.api.service.SwitcherService;
import com.github.xincao9.jswitcher.api.vo.Switcher;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -303,6 +304,7 @@ private ResponseEntity cmd(String cmd, String host, Integer port, String key, Bo
if (StringUtils.isBlank(host) || port == null || port <= 0 || port > 65535 || StringUtils.isBlank(key)) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();
}
key = new String(Base64.getDecoder().decode(key));
StringBuilder method = new StringBuilder();
method.append(SwitcherService.class.getTypeName())
.append('.')
Expand Down
2 changes: 1 addition & 1 deletion jswitcher-ui/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ spring:
restart:
enabled: true
server:
port: 8080
port: 8181
4 changes: 2 additions & 2 deletions jswitcher-ui/src/main/resources/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
},
methods: {
change: function (key) {
var url = '/switcher/key/' + (key.open ? 'off' : 'on') + '/' + key.host + '/' + key.port + '/' + key.key;
var url = '/switcher/key/' + (key.open ? 'off' : 'on') + '/' + key.host + '/' + key.port + '/' + window.btoa(key.key);
axios.get(url).then(
(response) => {
if (response.status !== 200) {
Expand All @@ -131,7 +131,7 @@
});
},
persistence: function (key) {
var url = '/switcher/key/set/' + key.host + '/' + key.port + '/' + key.key + '/' + key.open;
var url = '/switcher/key/set/' + key.host + '/' + key.port + '/' + window.btoa(key.key) + '/' + key.open;
axios.get(url).then(
(response) => {
if (response.status !== 200) {
Expand Down

0 comments on commit dc7989e

Please sign in to comment.