Repository: cxf Updated Branches: refs/heads/master f6b091154 -> 1b3f01b4f
CXF-5923: Create sample to demonstrate usage of search extension with Lucene and Tika. Added CORS provider. Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/1b3f01b4 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/1b3f01b4 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/1b3f01b4 Branch: refs/heads/master Commit: 1b3f01b4f640beea1f1247416ad9891e615f816c Parents: f6b0911 Author: reta <drr...@gmail.com> Authored: Mon Sep 8 22:05:04 2014 -0400 Committer: reta <drr...@gmail.com> Committed: Mon Sep 8 22:05:04 2014 -0400 ---------------------------------------------------------------------- .../main/release/samples/jax_rs/search/pom.xml | 7 ++++++- .../java/demo/jaxrs/search/server/Catalog.java | 18 ++++++++---------- .../java/demo/jaxrs/search/server/Server.java | 2 ++ 3 files changed, 16 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/1b3f01b4/distribution/src/main/release/samples/jax_rs/search/pom.xml ---------------------------------------------------------------------- diff --git a/distribution/src/main/release/samples/jax_rs/search/pom.xml b/distribution/src/main/release/samples/jax_rs/search/pom.xml index 9a9a1fa..05c1ef1 100644 --- a/distribution/src/main/release/samples/jax_rs/search/pom.xml +++ b/distribution/src/main/release/samples/jax_rs/search/pom.xml @@ -107,7 +107,12 @@ <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-rs-extension-providers</artifactId> <version>${cxf.version}</version> - </dependency> + </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-rs-security-cors</artifactId> + <version>${cxf.version}</version> + </dependency> <dependency> <groupId>org.apache.lucene</groupId> <artifactId>lucene-core</artifactId> http://git-wip-us.apache.org/repos/asf/cxf/blob/1b3f01b4/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Catalog.java ---------------------------------------------------------------------- diff --git a/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Catalog.java b/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Catalog.java index ead0cd0..d9cf249 100644 --- a/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Catalog.java +++ b/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Catalog.java @@ -62,6 +62,7 @@ import org.apache.cxf.jaxrs.ext.search.SearchContext; import org.apache.cxf.jaxrs.ext.search.lucene.LuceneQueryVisitor; import org.apache.cxf.jaxrs.ext.search.tika.LuceneDocumentMetadata; import org.apache.cxf.jaxrs.ext.search.tika.TikaLuceneContentExtractor; +import org.apache.cxf.rs.security.cors.CrossOriginResourceSharing; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.Document; @@ -84,8 +85,6 @@ import org.apache.tika.parser.pdf.PDFParser; @Path("/catalog") public class Catalog { - private static final String ACCESS_CONTROL_ALLOW_ORIGIN_HEADER = "Access-Control-Allow-Origin"; - private final TikaLuceneContentExtractor extractor = new TikaLuceneContentExtractor(new PDFParser()); private final Directory directory = new RAMDirectory(); private final Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_4_9); @@ -101,6 +100,7 @@ public class Catalog { } @POST + @CrossOriginResourceSharing(allowAllOrigins = true) @Consumes("multipart/form-data") public void addBook(@Suspended final AsyncResponse response, @Context final UriInfo uri, final MultipartBody body) { @@ -119,29 +119,26 @@ public class Catalog { try { if (exists(source)) { - response.resume(Response.status(Status.CONFLICT) - .header(ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, "*").build()); + response.resume(Response.status(Status.CONFLICT).build()); return; } final byte[] content = IOUtils.readBytesFromStream(handler.getInputStream()); storeAndIndex(metadata, content); } catch (final Exception ex) { - response.resume(Response.serverError() - .header(ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, "*").build()); + response.resume(Response.serverError().build()); } if (response.isSuspended()) { response.resume(Response .created(uri.getRequestUriBuilder().path(source).build()) - .header(ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, "*").build()); + .build()); } } } if (response.isSuspended()) { - response.resume(Response.status(Status.BAD_REQUEST) - .header(ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, "*").build()); + response.resume(Response.status(Status.BAD_REQUEST).build()); } } }); @@ -176,6 +173,7 @@ public class Catalog { @GET @Produces(MediaType.APPLICATION_JSON) + @CrossOriginResourceSharing(allowAllOrigins = true) @Path("/search") public Response findBook(@Context SearchContext searchContext, @Context final UriInfo uri) throws IOException { @@ -209,7 +207,7 @@ public class Catalog { } } - return Response.ok(builder.build()).header(ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, "*").build(); + return Response.ok(builder.build()).build(); } finally { reader.close(); } http://git-wip-us.apache.org/repos/asf/cxf/blob/1b3f01b4/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Server.java ---------------------------------------------------------------------- diff --git a/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Server.java b/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Server.java index 9b885c2..14bb74d 100644 --- a/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Server.java +++ b/distribution/src/main/release/samples/jax_rs/search/src/main/java/demo/jaxrs/search/server/Server.java @@ -30,6 +30,7 @@ import org.apache.cxf.jaxrs.ext.search.fiql.FiqlParser; import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider; import org.apache.cxf.jaxrs.provider.MultipartProvider; import org.apache.cxf.jaxrs.provider.jsrjsonp.JsrJsonpProvider; +import org.apache.cxf.rs.security.cors.CrossOriginResourceSharingFilter; public class Server { @@ -48,6 +49,7 @@ public class Server { sf.setProvider(new MultipartProvider()); sf.setProvider(new SearchContextProvider()); sf.setProvider(new JsrJsonpProvider()); + sf.setProvider(new CrossOriginResourceSharingFilter()); sf.create(); }