• websocket cors and gradle


    gradle need to use bootRepackage which will package all the dependencies, not to use jar task which will only package your main class code

    websocket use two levels of cors.

    1. http level:  

    package org.sang;

    import java.io.IOException;

    import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import org.springframework.stereotype.Component;
    import org.springframework.web.bind.annotation.CrossOrigin;

    @CrossOrigin
    @Component
    public class SimpleCORSFilter implements Filter {

    @Override
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) res;
    System.out.println("hello");
    HttpServletRequest reqs = (HttpServletRequest)req;
    response.setHeader("Access-Control-Allow-Origin", reqs.getHeader("Origin"));

    System.out.println(reqs.getHeader("Origin"));
    response.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS, DELETE, PATCH");
    response.setHeader("Access-Control-Max-Age", "3600");
    response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    response.setHeader("Access-Control-Expose-Headers", "Location");
    response.setHeader("Access-Control-Allow-Credentials", "true");
    chain.doFilter(req, res);
    }

    @Override
    public void init(FilterConfig filterConfig) {}

    @Override
    public void destroy() {}

    }

    2 stomplevel:   

    public void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) {
    stompEndpointRegistry.addEndpoint("/endpointSang").setAllowedOrigins("*").withSockJS();
    }

  • 相关阅读:
    Appium元素定位方式
    Selenium和Appium的关系
    再生龙备份恢复
    删除CentOS更新后的旧内核
    文字识别网站https://ocr.space/
    kubeasz部署高可用kubernetes1.17.2 并实现traefik2.1.2部署 亲测可用
    docker之Dockerfile实践用dockerfile构建nginx环境
    WordPress如何设置先登录再进入主页
    docker 容器使用 systemctl 命令是报错
    bilibili
  • 原文地址:https://www.cnblogs.com/goldengallo/p/7767801.html
Copyright © 2020-2023  润新知