1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

How to enable cors on jboss eap 7.3?

Discussão em 'StackOverflow' iniciado por Stack, Maio 28, 2021.

  1. Stack

    Stack Membro Participativo

    I know, this question has been asked a lot,

    I have a simple war file of spring boot rest project.

    using global cors I am successfully able to resolve cors on tomcat, but same code and config fails on jbos.

    @Bean
    public WebMvcConfigurer corsConfigurer() {
    return new WebMvcConfigurer() {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
    registry.addMapping("/**").allowedMethods("*")
    .allowedOrigins("http://localhost:9000").allowCredentials(true);
    }
    };
    }


    But even with this config jboss gives cors error.

    So do we need to additionally update jboss configuration to enable cors ?

    [​IMG]

    [​IMG]

    Adding xml config from here.

    http://www.mastertheboss.com/jboss-web/jbosswebserver/how-to-configure-cors-on-wildfly

    So after I added filter mentioned in above link, now my request are giving 404 error.

    My updated standalone.xml file updated code snippet

    <subsystem xmlns="urn:jboss:domain:undertow:10.0" default-server="default-server" default-virtual-host="default-host" default-servlet-container="default" default-security-domain="other" statistics-enabled="${wildfly.undertow.statistics-enabled:${wildfly.statistics-enabled:false}}">
    <buffer-cache name="default"/>
    <server name="default-server">
    <http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true"/>
    <https-listener name="https" socket-binding="https" security-realm="ApplicationRealm" enable-http2="true"/>
    <host name="default-host" alias="localhost">
    <location name="/" handler="welcome-content"/>
    <http-invoker security-realm="ApplicationRealm"/>
    <filter-ref name="server-header"/>
    <filter-ref name="x-powered-by-header"/>
    <filter-ref name="Access-Control-Allow-Origin"/>
    <filter-ref name="Access-Control-Allow-Methods"/>
    <filter-ref name="Access-Control-Allow-Headers"/>
    <filter-ref name="Access-Control-Allow-Credentials"/>
    <filter-ref name="Access-Control-Max-Age"/>
    </host>
    </server>
    <servlet-container name="default">
    <jsp-config/>
    <websockets/>
    </servlet-container>
    <handlers>
    <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
    </handlers>
    <filters>
    <response-header name="server-header" header-name="Server" header-value="WildFly/10"/>
    <response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/>
    <response-header name="Access-Control-Allow-Origin" header-name="Access-Control-Allow-Origin" header-value="http://localhost:9000"/>
    <response-header name="Access-Control-Allow-Methods" header-name="Access-Control-Allow-Methods" header-value="GET, POST, OPTIONS, PUT"/>
    <response-header name="Access-Control-Allow-Headers" header-name="Access-Control-Allow-Headers" header-value="*"/>
    <response-header name="Access-Control-Allow-Credentials" header-name="Access-Control-Allow-Credentials" header-value="true"/>
    <response-header name="Access-Control-Max-Age" header-name="Access-Control-Max-Age" header-value="1"/>
    </filters>
    </subsystem>

    Continue reading...

Compartilhe esta Página