@CrossOriginResourceSharing
(
allowOrigins = {
},
allowCredentials =
true
,
maxAge =
1
,
allowHeaders = {
"X-custom-1"
,
"X-custom-2"
},
exposeHeaders = {
"X-custom-3"
,
"X-custom-4"
}
)
public
class
AnnotatedCorsServer {
@Context
private
HttpHeaders headers;
@GET
@Produces
(
"text/plain"
)
@Path
(
"/simpleGet/{echo}"
)
public
String simpleGet(
@PathParam
(
"echo"
) String echo) {
return
echo;
}
@POST
@Produces
(
"application/json"
)
@Consumes
(
"application/json"
)
@Path
(
"/unannotatedPost"
)
public
Response postSomething() {
return
Response.ok().build();
}
@DELETE
@Path
(
"/delete"
)
public
Response deleteSomething() {
return
Response.ok().build();
}
@OPTIONS
@Path
(
"/"
)
@LocalPreflight
public
Response options() {
String origin = headers.getRequestHeader(
"Origin"
).get(
0
);
return
Response.ok()
.header(CorsHeaderConstants.HEADER_AC_ALLOW_METHODS,
"DELETE PUT"
)
.header(CorsHeaderConstants.HEADER_AC_ALLOW_CREDENTIALS,
"false"
)
.build();
}
else
{
return
Response.ok().build();
}
}
@GET
@CrossOriginResourceSharing
(
allowCredentials =
true
,
exposeHeaders = {
"X-custom-3"
,
"X-custom-4"
}
)
@Produces
(
"text/plain"
)
@Path
(
"/annotatedGet/{echo}"
)
public
String annotatedGet(
@PathParam
(
"echo"
) String echo) {
return
echo;
}
/**
* A method annotated to test preflight.
*
* @param input
* @return
*/
@PUT
@Consumes
(
"text/plain"
)
@Produces
(
"text/plain"
)
@Path
(
"/annotatedPut"
)
public
String annotatedPut(String input) {
return
input;
}
}