Jetty - Access-Control-Allow-Origin

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Jetty - Access-Control-Allow-Origin

AlanS
Hello.

 I create a context for a certain war file in Java code and would like to make sure the HTTP Response Header has "Access-Control-Allow-Origin:  *". I can do this in the doGet code section of course with a:

 public void handle(..., HttpServletResponse httpResponse, ...){

     httpResponse.setHeader("Access-Control-Allow-Origin", "*");

 ---

 but my question is how do I do it for the home page of a war file that is added to the server like:

 Server server = new Server(80);
 List<Handler> listHandler = new ArrayList<Handler>();
 WebAppContext webAppContext = new WebAppContext("../webapps/ePAD.war","/epad");
 listHanlder.add(webAppContext);

 Thanks for any responses.

Alan
 
Reply | Threaded
Open this post in threaded view
|

Re: Jetty - Access-Control-Allow-Origin

AlanS

I think that means to be able to do this in the code above:

<web-app>
 <filter>
   <filter-name>cross-origin</filter-name>
   <filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
   <init-param>
       <param-name>allowedOrigins</param-name>
       <param-value>*</param-value>
   </init-param>
   <init-param>
       <param-name>allowedMethods</param-name>
       <param-value>*</param-value>
   </init-param>
   <init-param>
       <param-name>allowedHeaders</param-name>
       <param-value>*</param-value>
   </init-param>
 </filter>
 <filter-mapping>
     <filter-name>cross-origin</filter-name>
     <url-pattern>/*</url-pattern>
 </filter-mapping>
</web-app>

what is the equivalent of this in code that starts this automatically?