package com.giraone.samples.pmspoc1.boundary.core;

import javax.ws.rs.OPTIONS;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;

/**
 * TODO: Only for non-production!
 */
public class BaseEndpoint
{
	protected final static String DEFAULT_PAGING_SIZE = "20";
	
	// Match root-resources
	@OPTIONS
	public Response options()
	{
	    return Response.status(Response.Status.NO_CONTENT)
	    	.header("Access-Control-Allow-Origin", "*") // "127.0.0.1" does not work
			.header("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT")
	    	.build();
	}
	
	// Match sub-resources
	@OPTIONS
	@Path("{path:.*}")
	public Response optionsAll(@PathParam("path") String path)
	{
	    return Response.status(Response.Status.NO_CONTENT)
	    	.header("Access-Control-Allow-Origin", "*") // "127.0.0.1" does not work
			.header("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT")
			.build();
	}
}
@@ -161,16 +161,66 @@
 esponse;
+%0Aimport javax.ws.rs.core.Response.ResponseBuilder;
 %0A%0A/**%0A *
@@ -353,16 +353,18 @@
 // Match
+es
  root-re
@@ -362,32 +362,70 @@
 s root-resources
+ also - handle CORS pre-flight request
 %0A%09@OPTIONS%0A%09publ
@@ -577,34 +577,39 @@
  does not work%0A%09
-%09%09
+    %09//
 .header(%22Access-
@@ -651,24 +651,81 @@
  DELETE, PUT
+, OPTIONS%22)%0A%09%09%09.header(%22Access-Control-Allow-Methods%22, %22*
 %22)%0A%09    %09.bu
@@ -759,16 +759,49 @@
 esources
+ - handle CORS pre-flight request
 %0A%09@OPTIO
@@ -1069,36 +1069,226 @@
 %22, %22
-GET, POST, DELETE, PUT%22)%0A%09%09%09
+*%22)%0A%09%09%09.build();%0A%09%7D%0A%09%0A%09// No more used - see CorsFeature class%0A%09public Response buildWithCorsHeader(ResponseBuilder builder)%0A%09%7B%09        %0A%09%09builder.header(%22Access-Control-Allow-Origin%22, %22*%22);     %0A        return builder
 .bui

Support for CORS pre-flight requests added