forked from javaee/jersey
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request javaee#60 from apemberton/master
Initial commit of 'Selectable' filtering implementation
- Loading branch information
Showing
16 changed files
with
1,172 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | ||
Copyright (c) 2013-2014 Oracle and/or its affiliates. All rights reserved. | ||
The contents of this file are subject to the terms of either the GNU | ||
General Public License Version 2 only ("GPL") or the Common Development | ||
and Distribution License("CDDL") (collectively, the "License"). You | ||
may not use this file except in compliance with the License. You can | ||
obtain a copy of the License at | ||
http://glassfish.java.net/public/CDDL+GPL_1_1.html | ||
or packager/legal/LICENSE.txt. See the License for the specific | ||
language governing permissions and limitations under the License. | ||
When distributing the software, include this License Header Notice in each | ||
file and include the License file at packager/legal/LICENSE.txt. | ||
GPL Classpath Exception: | ||
Oracle designates this particular file as subject to the "Classpath" | ||
exception as provided by Oracle in the GPL Version 2 section of the License | ||
file that accompanied this code. | ||
Modifications: | ||
If applicable, add the following below the License Header, with the fields | ||
enclosed by brackets [] replaced by your own identifying information: | ||
"Portions Copyright [year] [name of copyright owner]" | ||
Contributor(s): | ||
If you wish your version of this file to be governed by only the CDDL or | ||
only the GPL Version 2, indicate your decision by adding "[Contributor] | ||
elects to include this software in this distribution under the [CDDL or GPL | ||
Version 2] license." If you don't indicate a single choice of license, a | ||
recipient has the option to distribute your version of this file under | ||
either the CDDL, the GPL Version 2 or to extend the choice of license to | ||
its licensees as provided above. However, if you add GPL Version 2 code | ||
and therefore, elected the GPL Version 2 license, then the option applies | ||
only if the new code is made subject to such option by the copyright | ||
holder. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.glassfish.jersey.examples</groupId> | ||
<artifactId>project</artifactId> | ||
<version>2.6-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>entity-filtering-selectable</artifactId> | ||
<name>jersey-examples-entity-filtering-selectable</name> | ||
|
||
<description>Jersey Entity Data Filtering Selectable Example.</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.core</groupId> | ||
<artifactId>jersey-server</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.media</groupId> | ||
<artifactId>jersey-media-moxy</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.ext</groupId> | ||
<artifactId>jersey-entity-filtering</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.glassfish.jersey.containers</groupId> | ||
<artifactId>jersey-container-grizzly2-http</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.glassfish.jersey.test-framework.providers</groupId> | ||
<artifactId>jersey-test-framework-provider-bundle</artifactId> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<!-- Run the application using "mvn exec:java" --> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<configuration> | ||
<mainClass>org.glassfish.jersey.examples.entityfiltering.selectable.App</mainClass> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<profiles> | ||
<profile> | ||
<id>release</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
|
||
</project> |
82 changes: 82 additions & 0 deletions
82
...electable/src/main/java/org/glassfish/jersey/examples/entityfiltering/selectable/App.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | ||
* | ||
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* The contents of this file are subject to the terms of either the GNU | ||
* General Public License Version 2 only ("GPL") or the Common Development | ||
* and Distribution License("CDDL") (collectively, the "License"). You | ||
* may not use this file except in compliance with the License. You can | ||
* obtain a copy of the License at | ||
* http://glassfish.java.net/public/CDDL+GPL_1_1.html | ||
* or packager/legal/LICENSE.txt. See the License for the specific | ||
* language governing permissions and limitations under the License. | ||
* | ||
* When distributing the software, include this License Header Notice in each | ||
* file and include the License file at packager/legal/LICENSE.txt. | ||
* | ||
* GPL Classpath Exception: | ||
* Oracle designates this particular file as subject to the "Classpath" | ||
* exception as provided by Oracle in the GPL Version 2 section of the License | ||
* file that accompanied this code. | ||
* | ||
* Modifications: | ||
* If applicable, add the following below the License Header, with the fields | ||
* enclosed by brackets [] replaced by your own identifying information: | ||
* "Portions Copyright [year] [name of copyright owner]" | ||
* | ||
* Contributor(s): | ||
* If you wish your version of this file to be governed by only the CDDL or | ||
* only the GPL Version 2, indicate your decision by adding "[Contributor] | ||
* elects to include this software in this distribution under the [CDDL or GPL | ||
* Version 2] license." If you don't indicate a single choice of license, a | ||
* recipient has the option to distribute your version of this file under | ||
* either the CDDL, the GPL Version 2 or to extend the choice of license to | ||
* its licensees as provided above. However, if you add GPL Version 2 code | ||
* and therefore, elected the GPL Version 2 license, then the option applies | ||
* only if the new code is made subject to such option by the copyright | ||
* holder. | ||
*/ | ||
|
||
package org.glassfish.jersey.examples.entityfiltering.selectable; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
import org.glassfish.grizzly.http.server.HttpServer; | ||
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; | ||
|
||
/** | ||
* Java application class starting Grizzly2 server with Entity Data Filtering with query parameters. | ||
* | ||
* @author Andy Pemberton (pembertona at oracle.com) | ||
*/ | ||
public final class App { | ||
|
||
private static final URI BASE_URI = URI.create("http://localhost:8080/"); | ||
|
||
public static void main(String[] args) { | ||
try { | ||
System.out.println("Jersey Entity Data Filtering Example."); | ||
|
||
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(BASE_URI, new SelectableEntityFilteringApplication()); | ||
|
||
System.out.println("Application started.\nTry out one of these URIs:"); | ||
for (final String path : new String[]{"people/1234", "people/1234?select=familyName,givenName", | ||
"people/1234?select=region,addresses.region", | ||
"people/1234?select=familyName,givenName,addresses.phoneNumber.number"}) { | ||
System.out.println(BASE_URI + path); | ||
} | ||
System.out.println("Hit enter to stop it..."); | ||
|
||
System.in.read(); | ||
|
||
server.shutdownNow(); | ||
} catch (IOException ex) { | ||
Logger.getLogger(App.class.getName()) | ||
.log(Level.SEVERE, "I/O error occurred during reading from an system input stream.", ex); | ||
} | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...fish/jersey/examples/entityfiltering/selectable/SelectableEntityFilteringApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | ||
* | ||
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* The contents of this file are subject to the terms of either the GNU | ||
* General Public License Version 2 only ("GPL") or the Common Development | ||
* and Distribution License("CDDL") (collectively, the "License"). You | ||
* may not use this file except in compliance with the License. You can | ||
* obtain a copy of the License at | ||
* http://glassfish.java.net/public/CDDL+GPL_1_1.html | ||
* or packager/legal/LICENSE.txt. See the License for the specific | ||
* language governing permissions and limitations under the License. | ||
* | ||
* When distributing the software, include this License Header Notice in each | ||
* file and include the License file at packager/legal/LICENSE.txt. | ||
* | ||
* GPL Classpath Exception: | ||
* Oracle designates this particular file as subject to the "Classpath" | ||
* exception as provided by Oracle in the GPL Version 2 section of the License | ||
* file that accompanied this code. | ||
* | ||
* Modifications: | ||
* If applicable, add the following below the License Header, with the fields | ||
* enclosed by brackets [] replaced by your own identifying information: | ||
* "Portions Copyright [year] [name of copyright owner]" | ||
* | ||
* Contributor(s): | ||
* If you wish your version of this file to be governed by only the CDDL or | ||
* only the GPL Version 2, indicate your decision by adding "[Contributor] | ||
* elects to include this software in this distribution under the [CDDL or GPL | ||
* Version 2] license." If you don't indicate a single choice of license, a | ||
* recipient has the option to distribute your version of this file under | ||
* either the CDDL, the GPL Version 2 or to extend the choice of license to | ||
* its licensees as provided above. However, if you add GPL Version 2 code | ||
* and therefore, elected the GPL Version 2 license, then the option applies | ||
* only if the new code is made subject to such option by the copyright | ||
* holder. | ||
*/ | ||
package org.glassfish.jersey.examples.entityfiltering.selectable; | ||
|
||
import javax.ws.rs.ApplicationPath; | ||
|
||
import org.glassfish.jersey.message.filtering.SelectableEntityFilteringFeature; | ||
import org.glassfish.jersey.moxy.json.MoxyJsonConfig; | ||
import org.glassfish.jersey.server.ResourceConfig; | ||
|
||
/** | ||
* Entity Data Filtering application using request parameters. | ||
* | ||
* @author Andy Pemberton (pembertona at gmail.com) | ||
*/ | ||
@ApplicationPath("/") | ||
public class SelectableEntityFilteringApplication extends ResourceConfig { | ||
|
||
public SelectableEntityFilteringApplication() { | ||
// Register all resources present under the package. | ||
packages("org.glassfish.jersey.examples.entityfiltering.selectable"); | ||
|
||
// Register entity-filtering selectable feature. | ||
register(SelectableEntityFilteringFeature.class); | ||
|
||
// Configure MOXy Json provider. | ||
register(new MoxyJsonConfig().setFormattedOutput(true).resolver()); | ||
|
||
property(SelectableEntityFilteringFeature.QUERY_PARAM_NAME, "select"); | ||
|
||
} | ||
} |
Oops, something went wrong.