当前位置: 首页 > news >正文

卡片式设计的网站全网网络营销推广

卡片式设计的网站,全网网络营销推广,google网站质量,河南建设集团网站学习链接 springboot如何将http转https SpringBoot配置HTTPS及开发调试 Tomcat8.5配置https和SpringBoot配置https 可借鉴的参考: springboot如何配置ssl支持httpsSpringBoot配置HTTPS及开发调试的操作方法springboot实现的https单向认证和双向认证(java生成证…

学习链接

springboot如何将http转https

SpringBoot配置HTTPS及开发调试

Tomcat8.5配置https和SpringBoot配置https

可借鉴的参考:

  • springboot如何配置ssl支持https
  • SpringBoot配置HTTPS及开发调试的操作方法
  • springboot实现的https单向认证和双向认证(java生成证书)
  • SpringBoot配置Https访问的详细步骤
  • SpringBoot配置Https入门实践
  • springboot项目开启https协议的项目实现
  • SpringBoot的HTTPS配置实现
  • springboot配置http跳转https的过程
  • springboot支持https请求的实现
  • SpringBoot中支持Https协议的实现
  • SpringBoot整合HTTPS的项目实践

文章目录

  • 学习链接
  • 步骤
    • 搭建springboot基础项目
      • pom.xml
      • TomcatHttpsConfig
      • WebSocketConfig
      • WsHandler
      • WsHandshakeInterceptor
      • TestApplication
      • index.html
    • 生成安全证书
    • 将证书放到项目目录下
    • 访问

步骤

搭建springboot基础项目

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.2.6.RELEASE</version><relativePath/></parent><groupId>org.example</groupId><artifactId>demo-springboot-https</artifactId><version>1.0-SNAPSHOT</version><properties><maven.compiler.source>8</maven.compiler.source><maven.compiler.target>8</maven.compiler.target></properties><dependencies><!-- web --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-websocket</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></dependency></dependencies><build><finalName>demo-springboot-https</finalName><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin><!-- maven 打包时跳过测试 --><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><configuration><skip>true</skip></configuration></plugin></plugins></build></project>

TomcatHttpsConfig

@Configuration
public class TomcatHttpsConfig {@Beanpublic ServletWebServerFactory servletContainer() {TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {@Overrideprotected void postProcessContext(Context context) {SecurityConstraint securityConstraint = new SecurityConstraint();securityConstraint.setUserConstraint("CONFIDENTIAL");SecurityCollection collection = new SecurityCollection();collection.addPattern("/*");securityConstraint.addCollection(collection);context.addConstraint(securityConstraint);}};tomcat.addAdditionalTomcatConnectors(redirectConnector8080());return tomcat;}private Connector redirectConnector8080() {Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");connector.setScheme("http");connector.setPort(8080);connector.setSecure(false);connector.setRedirectPort(8081);return connector;}}

WebSocketConfig

@Slf4j
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {@Autowiredprivate WsHandler wsHandler;@Autowiredprivate WsHandshakeInterceptor wsHandshakeInterceptor;@Overridepublic void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {registry// 设置处理器处理/custom/**.addHandler(wsHandler, "/wsTest/websocket")// 允许跨越.setAllowedOrigins("*")// 设置监听器.addInterceptors(wsHandshakeInterceptor);}@Beanpublic ServerEndpointExporter serverEndpointExporter() {return new ServerEndpointExporter();}@Beanpublic ServletServerContainerFactoryBean serverContainer() {ServletServerContainerFactoryBean containerFactoryBean = new ServletServerContainerFactoryBean();containerFactoryBean.setMaxTextMessageBufferSize(2 * 1024 * 1024);return containerFactoryBean;}
}

WsHandler

@Slf4j
@Component
public class WsHandler extends TextWebSocketHandler {@Overrideprotected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {log.info("收到客户端数据: {}", message.getPayload());session.sendMessage(new TextMessage("收到了您的消息"));}
}

WsHandshakeInterceptor

@Slf4j
@Component
public class WsHandshakeInterceptor implements HandshakeInterceptor {@Overridepublic boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception {log.info("beforeHandsShake...握手前");return true;}@Overridepublic void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Exception exception) {log.info("beforeHandsShake...握手后");}}

application.yml

server:port: 8081ssl:key-store: tomcat.keystorekey-alias: tomcatenabled: truekey-store-type: JKSkey-store-password: 123456

TestApplication

@SpringBootApplication
public class TestApplication {public static void main(String[] args) {SpringApplication.run(TestApplication.class, args);}}

index.html

<html>
<head><meta charset="utf8"/>
</head><body><h1>hello word!!!</h1><p>this is a html page</p><input type="text" id="ipt" value="wss://192.168.134.5:8081/wsTest/websocket" style="width: 1200px"><br/><button type="button" id="btn">连接ws</button></body><script>var ws = nullconst btn = document.querySelector('#btn')btn.onclick = function(){console.log('halo')const ipt = document.querySelector('#ipt')console.log(ipt.value)ws = new WebSocket(ipt.value)ws.onopen = () => {console.log('连接成功')}ws.onmessage = (msg) => {console.log('收到消息: ' + msg)}ws.onerror = (err) => {console.log('连接失败: ' + err)}}</script>
</html>

生成安全证书

keytool -genkey -alias tomcat -keypass 123456 -keyalg RSA -keysize 1024 -validity 365 -keystore D:/tmp/tomcat.keystore -storepass 123456

在这里插入图片描述

将证书放到项目目录下

在这里插入图片描述

访问

访问http://192.168.134.5:8080时,会自动跳转到https://192.168.134.5:8081,由于是自签名证书,所以会有安全警告,点击继续
在这里插入图片描述
看到下方页面
在这里插入图片描述
点击上面的连接ws,可以看到连接成功了
在这里插入图片描述

http://www.tj-hxxt.cn/news/35921.html

相关文章:

  • 创意平面设计公司公司排名沧州seo公司
  • 制作网站复杂吗长沙企业网站建设报价
  • 有没有专做食品批发的网站杭州seo公司
  • 广州一起做网店网站东莞营销网站建设优化
  • wordpress邮件样式美化厦门seo哪家强
  • 淘宝网站开发费用站长统计app软件下载2021
  • 网站建设 关于我们网站联盟广告
  • 平面艺术设计网站怎么优化排名靠前
  • 太原做app网站建设日本今日新闻头条
  • 网站建设宗旨怎么写重庆seo招聘
  • 一站式做网站哪家好谷歌浏览器下载手机版安卓
  • 企业宣传网站怎么做广告外链购买交易平台
  • 做网站销售大概多少钱网络营销的发展概述
  • 如何提网站建设需求全国培训机构排名前十
  • 乔托运智能建站友情链接的作用
  • 阜新网站建设全球十大网站排名
  • sublime做网站常州seo外包公司
  • 做校服的网站淘宝店铺怎么运营
  • 大型电商网站开发成本关键词数据分析工具有哪些
  • 做网站导航栏目怎么做解封后中国死了多少人
  • 如何评判一个网站建设的怎么样宁波网站关键词优化排名
  • 网站建设要点沈阳关键词优化价格
  • 网站推广教学今日头条关键词工具
  • 潮州有没有做网站的人账号权重查询入口站长工具
  • 专做电子产品评测的网站木卢seo教程
  • 游戏网站制作郑州seo关键词排名优化
  • 宁波网站建设哪家公司好苏州seo关键词排名
  • 推荐一本学做网站的书seo工具优化软件
  • 汽配做的最好的网站网络推广公司可不可靠
  • 网站建设书2024年度关键词