| 1 |
/* |
| 2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
| 3 |
* |
| 4 |
* Copyright (c) 2010-2011 Oracle and/or its affiliates. All rights reserved. |
| 5 |
* |
| 6 |
* The contents of this file are subject to the terms of either the GNU |
| 7 |
* General Public License Version 2 only ("GPL") or the Common Development |
| 8 |
* and Distribution License("CDDL") (collectively, the "License"). You |
| 9 |
* may not use this file except in compliance with the License. You can |
| 10 |
* obtain a copy of the License at |
| 11 |
* http://glassfish.java.net/public/CDDL+GPL_1_1.html |
| 12 |
* or packager/legal/LICENSE.txt. See the License for the specific |
| 13 |
* language governing permissions and limitations under the License. |
| 14 |
* |
| 15 |
* When distributing the software, include this License Header Notice in each |
| 16 |
* file and include the License file at packager/legal/LICENSE.txt. |
| 17 |
* |
| 18 |
* GPL Classpath Exception: |
| 19 |
* Oracle designates this particular file as subject to the "Classpath" |
| 20 |
* exception as provided by Oracle in the GPL Version 2 section of the License |
| 21 |
* file that accompanied this code. |
| 22 |
* |
| 23 |
* Modifications: |
| 24 |
* If applicable, add the following below the License Header, with the fields |
| 25 |
* enclosed by brackets [] replaced by your own identifying information: |
| 26 |
* "Portions Copyright [year] [name of copyright owner]" |
| 27 |
* |
| 28 |
* Contributor(s): |
| 29 |
* If you wish your version of this file to be governed by only the CDDL or |
| 30 |
* only the GPL Version 2, indicate your decision by adding "[Contributor] |
| 31 |
* elects to include this software in this distribution under the [CDDL or GPL |
| 32 |
* Version 2] license." If you don't indicate a single choice of license, a |
| 33 |
* recipient has the option to distribute your version of this file under |
| 34 |
* either the CDDL, the GPL Version 2 or to extend the choice of license to |
| 35 |
* its licensees as provided above. However, if you add GPL Version 2 code |
| 36 |
* and therefore, elected the GPL Version 2 license, then the option applies |
| 37 |
* only if the new code is made subject to such option by the copyright |
| 38 |
* holder. |
| 39 |
*/ |
| 40 |
/** |
| 41 |
* Provides support for servlet-based and filter-based Web applications. |
| 42 |
* <p> |
| 43 |
* Web application support is enabled by referencing the servlet |
| 44 |
* {@link com.sun.jersey.spi.container.servlet.ServletContainer} in the |
| 45 |
* web.xml. |
| 46 |
* <p> |
| 47 |
* For example, the following will deploy Jersey and automatically |
| 48 |
* register any root resource or provider classes present in the directory |
| 49 |
* "/WEB-INF/classes" or jar files present in the directory "/WEB-INF/lib": |
| 50 |
* <blockquote><pre> |
| 51 |
* <web-app> |
| 52 |
* <servlet> |
| 53 |
* <servlet-name>Jersey Web Application</servlet-name> |
| 54 |
* <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> |
| 55 |
* </servlet> |
| 56 |
* <servlet-mapping> |
| 57 |
* <servlet-name>Jersey Web Application</servlet-name> |
| 58 |
* <url-pattern>/*</url-pattern> |
| 59 |
* </servlet-mapping> |
| 60 |
* </web-app> |
| 61 |
* </blockquote></pre> |
| 62 |
* <p> |
| 63 |
* A deployment approach, that is more portable with respect to maven and |
| 64 |
* application servers, is to declare the package names where root resource and provider |
| 65 |
* classes reside. For example, the following will deploy Jersey and |
| 66 |
* automatically register any root resource or provider classes present |
| 67 |
* in the package "managed", or any sub-packages. |
| 68 |
* <blockquote><pre> |
| 69 |
* <web-app> |
| 70 |
* <servlet> |
| 71 |
* <servlet-name>Jersey Web Application</servlet-name> |
| 72 |
* <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> |
| 73 |
* <init-param> |
| 74 |
* <param-name>com.sun.jersey.config.property.packages</param-name> |
| 75 |
* <param-value>managed</param-value> |
| 76 |
* </init-param> |
| 77 |
* </servlet> |
| 78 |
* <servlet-mapping> |
| 79 |
* <servlet-name>Jersey Web Application</servlet-name> |
| 80 |
* <url-pattern>/*</url-pattern> |
| 81 |
* </servlet-mapping> |
| 82 |
* </web-app> |
| 83 |
* </blockquote></pre> |
| 84 |
* The deployment approach that is portable accross JAX-RS implementations is to |
| 85 |
* register an implementation of {@link javax.ws.rs.core.Application}. For |
| 86 |
* example given an implementation as follows: |
| 87 |
* <blockquote><pre> |
| 88 |
* package com.foo; |
| 89 |
* |
| 90 |
* import ... |
| 91 |
* |
| 92 |
* public class MyApplicaton extends Application { |
| 93 |
* public Set<Class<?>> getClasses() { |
| 94 |
* Set<Class<?>> s = new HashSet<Class<?>>(); |
| 95 |
* s.add(HelloWorldResource.class); |
| 96 |
* return s; |
| 97 |
* } |
| 98 |
* } |
| 99 |
* </blockquote></pre> |
| 100 |
* then that implementation can be registered as follows: |
| 101 |
* <blockquote><pre> |
| 102 |
* <web-app> |
| 103 |
* <servlet> |
| 104 |
* <servlet-name>Jersey Web Application</servlet-name> |
| 105 |
* <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> |
| 106 |
* <init-param> |
| 107 |
* <param-name>javax.ws.rs.Application</param-name> |
| 108 |
* <param-value>com.foo.MyApplication</param-value> |
| 109 |
* </init-param> |
| 110 |
* </servlet> |
| 111 |
* <servlet-mapping> |
| 112 |
* <servlet-name>Jersey Web Application</servlet-name> |
| 113 |
* <url-pattern>/*</url-pattern> |
| 114 |
* </servlet-mapping> |
| 115 |
* </web-app> |
| 116 |
* </blockquote></pre> |
| 117 |
* It is possible to combine package-based registration and |
| 118 |
* {@link javax.ws.rs.core.Application} |
| 119 |
* registered by extending {@link com.sun.jersey.api.core.PackagesResourceConfig} |
| 120 |
* and registering the extended class, for example: |
| 121 |
* <blockquote><pre> |
| 122 |
* public class MyApplication extends PackagesResourceConfig { |
| 123 |
* public MyApplication() { |
| 124 |
* super("org.foo.rest;org.bar.rest"); |
| 125 |
* } |
| 126 |
* } |
| 127 |
* </blockquote></pre> |
| 128 |
* The above examples apply to Servlet-based configurations but they equally |
| 129 |
* applicable to Filter-based configurations. For example, the following |
| 130 |
* presents the same package-based configuration as above but utilizing a filter: |
| 131 |
* <blockquote><pre> |
| 132 |
* <web-app> |
| 133 |
* <filter> |
| 134 |
* <filter-name>Jersey Web Application</filter-name> |
| 135 |
* <filter-class>com.sun.jersey.spi.container.servlet.ServletContainer</filter-class> |
| 136 |
* <init-param> |
| 137 |
* <param-name>com.sun.jersey.config.property.packages</param-name> |
| 138 |
* <param-value>managed</param-value> |
| 139 |
* </init-param> |
| 140 |
* </filter> |
| 141 |
* <filter-mapping> |
| 142 |
* <filter-name>Jersey Web Application</filter-name> |
| 143 |
* <url-pattern>/*</url-pattern> |
| 144 |
* </filter-mapping> |
| 145 |
* </web-app> |
| 146 |
* </blockquote></pre> |
| 147 |
* |
| 148 |
*/ |
| 149 |
package com.sun.jersey.spi.container.servlet; |