• <bdo id='cJB70'></bdo><ul id='cJB70'></ul>
    <tfoot id='cJB70'></tfoot>

    1. <i id='cJB70'><tr id='cJB70'><dt id='cJB70'><q id='cJB70'><span id='cJB70'><b id='cJB70'><form id='cJB70'><ins id='cJB70'></ins><ul id='cJB70'></ul><sub id='cJB70'></sub></form><legend id='cJB70'></legend><bdo id='cJB70'><pre id='cJB70'><center id='cJB70'></center></pre></bdo></b><th id='cJB70'></th></span></q></dt></tr></i><div id='cJB70'><tfoot id='cJB70'></tfoot><dl id='cJB70'><fieldset id='cJB70'></fieldset></dl></div>

      <small id='cJB70'></small><noframes id='cJB70'>

    2. <legend id='cJB70'><style id='cJB70'><dir id='cJB70'><q id='cJB70'></q></dir></style></legend>
      1. 问题 Resteasy 3.09 CorsFilter

        时间:2023-06-27
        <i id='ZeY5f'><tr id='ZeY5f'><dt id='ZeY5f'><q id='ZeY5f'><span id='ZeY5f'><b id='ZeY5f'><form id='ZeY5f'><ins id='ZeY5f'></ins><ul id='ZeY5f'></ul><sub id='ZeY5f'></sub></form><legend id='ZeY5f'></legend><bdo id='ZeY5f'><pre id='ZeY5f'><center id='ZeY5f'></center></pre></bdo></b><th id='ZeY5f'></th></span></q></dt></tr></i><div id='ZeY5f'><tfoot id='ZeY5f'></tfoot><dl id='ZeY5f'><fieldset id='ZeY5f'></fieldset></dl></div>

          <small id='ZeY5f'></small><noframes id='ZeY5f'>

          • <legend id='ZeY5f'><style id='ZeY5f'><dir id='ZeY5f'><q id='ZeY5f'></q></dir></style></legend>
                <tbody id='ZeY5f'></tbody>
              • <bdo id='ZeY5f'></bdo><ul id='ZeY5f'></ul>
                  <tfoot id='ZeY5f'></tfoot>
                  本文介绍了问题 Resteasy 3.09 CorsFilter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我尝试使用 Resteasy 3.0.9 中提供的新 CorsFilter.我在此页面底部找到了一个示例:使用 JAX-RS/RESTEasy 实现 CORS 的 Ajax 请求p>

                  如果我在 getSingletons() (Application 子类的)方法中定义此过滤器,那么我的资源将不再被扫描.这意味着将找不到任何资源并发生以下错误:

                  <块引用>

                  javax.ws.rs.NotFoundException:找不到完整路径的资源错误发生

                  在以下页面上,我找到了描述:javax.ws.rs.NotFoundException:找不到完整路径的资源错误发生

                  <块引用>

                  但基本上,此部署选项所做的是扫描应用程序的@Path、@Provider 等注释.原因是 JAX-RS 将首先分别在覆盖的 getClasses() 和 getSingletons() 中查找类和对象.如果然后返回空集,这会告诉 JAX-RS 进行扫描(根据规范).

                  所以如果我覆盖 getSingletons() 方法,JAX-RS 不会进行扫描?是否有另一种方法来配置此 CorsFilter 并启用资源扫描`?

                  解决方案

                  还有其他方法可以配置此 CorsFilter 并启用资源扫描吗?"

                  保持扫描的一种方法是实现 javax.ws.rs.core.Feature

                  import javax.ws.rs.core.Feature;导入 javax.ws.rs.core.FeatureContext;导入 javax.ws.rs.ext.Provider;导入 org.jboss.resteasy.plugins.interceptors.CorsFilter;@Provider公共类 CorsFeature 实现 Feature {@覆盖公共布尔配置(FeatureContext 上下文){CorsFilter corsFilter = new CorsFilter();corsFilter.getAllowedOrigins().add("*");context.register(corsFilter);返回真;}}

                  此功能将像所有其他 @Provider@Path 一样被扫描.

                  只用测试

                  @ApplicationPath("/api")公共类 RestApplication 扩展应用程序 {}

                  <块引用>

                  C:>curl -i http://localhost:8080/api/simple -H "Origin:stackoverflow.com"HTTP/1.1 200 正常日期:格林威治标准时间 2015 年 4 月 1 日星期三 12:07:22访问控制允许凭据:true访问控制允许来源:stackoverflow.com内容类型:应用程序/八位字节流内容长度:15服务器:码头(9.2.4.v20141103)

                  你好响应!

                  I tried to use the new CorsFilter which is available in Resteasy 3.0.9. I found an example at the bottom of this page: Ajax request with JAX-RS/RESTEasy implementing CORS

                  If I define this filter in the method getSingletons() (of the Application subclass) , then my Resources don't get scanned anymore. That means that no Resources will be found and the following error occurs:

                  javax.ws.rs.NotFoundException: Could not find resource for full path Error Occures

                  On the following page i found a description: javax.ws.rs.NotFoundException: Could not find resource for full path Error Occures

                  But basically, what this deployment option does is scan for annotations of @Path, @Provider, etc for the application. The reason is that JAX-RS will first look for classes and object in overridden getClasses() and getSingletons(), respectively. If then return empty sets, this tell JAX-RS to do scanning (per the spec).

                  So JAX-RS doesn't do a scanning if i overwrite the getSingletons() method? Is there another way to configure this CorsFilter and enable the resource scanning`?

                  解决方案

                  "Is there another way to configure this CorsFilter and enable the resource scanning?"

                  One way to keep the scanning is just to implement a javax.ws.rs.core.Feature

                  import javax.ws.rs.core.Feature;
                  import javax.ws.rs.core.FeatureContext;
                  import javax.ws.rs.ext.Provider;
                  import org.jboss.resteasy.plugins.interceptors.CorsFilter;
                  
                  @Provider
                  public class CorsFeature implements Feature {
                  
                      @Override
                      public boolean configure(FeatureContext context) {
                          CorsFilter corsFilter = new CorsFilter();
                          corsFilter.getAllowedOrigins().add("*");
                          context.register(corsFilter);
                          return true;
                      }  
                  }
                  

                  This feature will get scanned for just like all other @Providers and @Paths.

                  Test with only

                  @ApplicationPath("/api")
                  public class RestApplication extends Application {
                  }
                  

                  C:>curl -i http://localhost:8080/api/simple -H "Origin:stackoverflow.com" HTTP/1.1 200 OK Date: Wed, 01 Apr 2015 12:07:22 GMT Access-Control-Allow-Credentials: true Access-Control-Allow-Origin: stackoverflow.com Content-Type: application/octet-stream Content-Length: 15 Server: Jetty(9.2.4.v20141103)

                  Hello Response!

                  这篇关于问题 Resteasy 3.09 CorsFilter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:当我启动eclipse并运行android项目时,它每次都会打开一个新的模拟器, 下一篇:RESTful webservice:如何在 java 中设置标头以接受 Access-Control-Allow-Or

                  相关文章

                    <small id='2s4tn'></small><noframes id='2s4tn'>

                      <legend id='2s4tn'><style id='2s4tn'><dir id='2s4tn'><q id='2s4tn'></q></dir></style></legend>
                      <i id='2s4tn'><tr id='2s4tn'><dt id='2s4tn'><q id='2s4tn'><span id='2s4tn'><b id='2s4tn'><form id='2s4tn'><ins id='2s4tn'></ins><ul id='2s4tn'></ul><sub id='2s4tn'></sub></form><legend id='2s4tn'></legend><bdo id='2s4tn'><pre id='2s4tn'><center id='2s4tn'></center></pre></bdo></b><th id='2s4tn'></th></span></q></dt></tr></i><div id='2s4tn'><tfoot id='2s4tn'></tfoot><dl id='2s4tn'><fieldset id='2s4tn'></fieldset></dl></div>
                        <bdo id='2s4tn'></bdo><ul id='2s4tn'></ul>

                      <tfoot id='2s4tn'></tfoot>