Mar*_*Dez 3 cxf jax-rs cross-domain apache-camel cxfrs
我希望能够在我的localhost Camel实例上执行HTTP请求(仅用于开发目的,我知道这是不好的做法).现在,我坚持:
Origin http://localhost:8000 is not allowed by Access-Control-Allow-Origin.
Run Code Online (Sandbox Code Playgroud)
我搜索了如何告诉Camel允许这样的请求,但没有找到答案.我正在使用camel-cxf和rsServer来创建我的端点.
我有一个端点看起来像这样:
public class LoginEndpoint {
@GET
@Path(LOGIN)
@Produces(MediaType.APPLICATION_JSON)
public Customer login(@QueryParam("email") String email, @QueryParam("password") String password) {
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
比标准路线正在做这项工作.
我如何告诉Camel(或JAX-RS或CXFRS组件,我不知道......)允许跨域请求?
您需要在端点上添加注释
@CrossOriginResourceSharing(allowAllOrigins = true, allowAnyHeaders = true)
public class LoginEndpoint {
@GET
@Path(LOGIN)
@Produces(MediaType.APPLICATION_JSON)
public Customer login(@QueryParam("email") String email, @QueryParam("password") String password) {
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
我不认为你需要一个新的依赖,因为注释是在camel-cxf中.但是你需要告诉Camel使用providers标签查找这个注释.
<cxf:rsServer id="login" address="your adress"
serviceClass="LoginEndpoint">
<cxf:providers>
<bean class="org.apache.cxf.jaxrs.cors.CrossOriginResourceSharingFilter" />
</cxf:providers>
</cxf:rsServer>
Run Code Online (Sandbox Code Playgroud)
那么你应该没问题(但请记住,这仅适用于本地测试).
| 归档时间: |
|
| 查看次数: |
3687 次 |
| 最近记录: |