在耳包装中启用CORS

时间:2014-03-06 21:42:31

标签: maven ejb cors resteasy ear

考虑一个包含无状态ejb类的ejb模块(hello-ejb),如下所示。

@Stateless
@Path("/v1")
public class HelloREST{

    @GET
    @Path("/hello")
    @Produces({MediaType.APPLICATION_JSON})
    public String sayHello(){
        return "Hello REST";
    }
}

我的JaxRest Activator类如下:

@ApplicationPath("/")
public class JaxRsActivator extends Application {

    private Set<Object> sigletons = new HashSet<Object>();

    private Set<Class<?>> classes = new HashSet<Class<?>>();

    public JaxRsActivator() {
        classes.add(HelloREST.class);
    }

    public Set<Object> getSigletons() {
        return sigletons;
    }

    public Set<Class<?>> getClasses() {
        return classes;
    }
}

现在,我在ejb pom.xml中添加了cors-filter的maven依赖项,如下所示:

<dependency>
    <groupId>com.thetransactioncompany</groupId>
    <artifactId>cors-filter</artifactId>
    <version>1.9.2</version>
</dependency>

war模块中cors-filter的web.xml详细信息如下:

      <filter>
        <!-- The CORS filter with parameters -->
        <filter-name>CORS</filter-name>
        <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>

        <!-- Note: All parameters are options, if omitted the CORS 
             Filter will fall back to the respective default values.
          -->
        <init-param>
            <param-name>cors.allowGenericHttpRequests</param-name>
            <param-value>true</param-value>
        </init-param>

        <init-param>
            <param-name>cors.allowOrigin</param-name>
            <param-value>*</param-value>
        </init-param>

        <init-param>
            <param-name>cors.supportedMethods</param-name>
            <param-value>GET, HEAD, POST, OPTIONS</param-value>
        </init-param>

        <init-param>
            <param-name>cors.supportedHeaders</param-name>
            <param-value>Origin, Content-Type</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <!-- CORS Filter mapping -->
        <filter-name>CORS</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

ejb模块和war模块打包成耳朵并成功部署在jboss服务器中。但是,过滤器无法正常工作。任何人都可以更好地启用角色。

0 个答案:

没有答案