Added new example

This commit is contained in:
Jens Kristian Villadsen 2016-11-09 11:37:00 +01:00
parent 0aaadc5228
commit 0a93db572e
2 changed files with 0 additions and 57 deletions

View File

@ -1,24 +0,0 @@
package filters;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import com.sun.jersey.spi.container.ContainerRequest;
import com.sun.jersey.spi.container.ContainerResponse;
import com.sun.jersey.spi.container.ContainerResponseFilter;
public class CharsetResponseFilter implements ContainerResponseFilter {
@Override
public ContainerResponse filter(final ContainerRequest request,
final ContainerResponse response) {
final MediaType contentType = response.getMediaType();
if (contentType != null) {
response.getHttpHeaders().putSingle(HttpHeaders.CONTENT_TYPE,
contentType.toString() + ";charset=UTF-8");
}
return response;
}
}

View File

@ -1,33 +0,0 @@
package filters;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import com.sun.jersey.spi.container.ContainerRequest;
import com.sun.jersey.spi.container.ContainerResponse;
import com.sun.jersey.spi.container.ContainerResponseFilter;
public class CorsResponseFilter implements ContainerResponseFilter {
@Override
public ContainerResponse filter(final ContainerRequest req,
final ContainerResponse contResp) {
final ResponseBuilder resp = Response.fromResponse(contResp
.getResponse());
resp.header("Access-Control-Allow-Origin", "*").header(
"Access-Control-Allow-Methods", "GET, POST, OPTIONS");
final String reqHead = req
.getHeaderValue("Access-Control-Request-Headers");
if (null != reqHead && !reqHead.equals("")) {
resp.header("Access-Control-Allow-Headers", reqHead);
}
contResp.setResponse(resp.build());
return contResp;
}
}