I want to create a REST-API with Jax-Rs with enabled enabled. So how did I do it and found it:
The solution is a response filter, which adds some header information in every response, so that the user's browser can know that the cross domain There is permission to enter.
Because I have tried any request (received, post and option) when ResponseFilter is not executed, I googled again and found it:
@Leflo gave a good answer, which seems to be the logic (to remove annotation @ premaching) did so, but still my filter is not applied, when I request an HTTP-HTT.
This is my code:
import javax.ws.rs.container .ContainerRequestContext; Import javax.ws.rs.container.ContainerResponseContext; Import javax.ws.rs.container.ContainerResponseFilter; Import javax.ws.rs.ext.Provider; Import java.io.IOException; @Provider Public Sector RESTServiceResponseFilter Applies Container Response Filters {@Override Public Zero Filter (ContainerQuest Content Containing Container Reference Contains, Container Response Contact ParContainerResponseContext) IOException throws {parContainerResponseContext.getHeaders (). Add ("access-control-permission-origin", "*"); ParContainerResponseContext.getHeaders (). Add ("access-control-permission-credentials", "true"); ParContainerResponseContext.getHeaders (). Add ("access-control-permission-methods", "GET, POST, DELETE, PUT"); ParContainerResponseContext.getHeaders (). Add ("access-control-permission-header", "content-type"); }}
I kept on googling and found out that I forgot to add the web.xml filter so I also did the following:
& lt ; Servlet & gt; & Lt; Display-name & gt; Webinterface.api & lt; / Display-name & gt; & Lt; Servlet-name & gt; JX-RS Rest Servlet & lt; / Servlet-name & gt; & Lt; Servlet category & gt; Com.sun.jersey.spi.container.servlet.ServletContainer & lt; / Servlet category & gt; & Lt; Init-param & gt; & Lt; Ultimate Name & gt; Com.sun.jersey.config.property.packages & lt; / Lastname & gt; & Lt; Ultimate Price & gt; De.tsystems.lbus.apprestserver & lt; / Super-valued & gt; & Lt; / Init-param & gt; & Lt; Init-param & gt; & Lt; Ultimate Name & gt; Com.sun.jersey.spi.container.ContainerResponseFilters & lt; / Lastname & gt; & Lt; Ultimate Price & gt; De.apprestserver.filter.RESTServiceResponseFilter & lt; / Super-valued & gt; & Lt; / Init-param & gt; & Lt; Load-On-Startup & gt; 1 & lt; / Load-on-startup & gt; & Lt; / Servlet & gt; & Lt; Servlet-mapping & gt; & Lt; Servlet-name & gt; JX-RS Rest Servlet & lt; / Servlet-name & gt; & Lt; URL pattern & gt; / TNR / * & lt; / URL pattern & gt; & Lt; / Servlet-mapping & gt;
I do not have any other ideas anymore and you want to ask, if you have a solution for me maybe thanks in advance!
You are using jersey 1 ( com.sun.
in your web.xml). The implementation of the filter you are using (or show) jersey 2. There is a subtle difference, but this is a big difference. The latter will not work with Jersey 1.
And the fact is that even compiled (if this is the case) means that you have to get rid of some dependency. You have a class JX-RS2 class (interface). Dependence of any JX-RS / Jersey 2, you may get rid of them They do not play well (maybe not the cause of the issue, but to release any confusion they get rid of)
- jersey1 ==
com.sun.jersey
- jersey2 ==
org.glassfish.jersey
(to get rid of) - JX-RS2 API ==
javax.ws
View
No comments:
Post a Comment