Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 4137E200C6E for ; Mon, 8 May 2017 17:32:51 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 3FB0F160BCD; Mon, 8 May 2017 15:32:51 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 166C4160BA5 for ; Mon, 8 May 2017 17:32:48 +0200 (CEST) Received: (qmail 17518 invoked by uid 500); 8 May 2017 15:32:48 -0000 Mailing-List: contact commits-help@juneau.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@juneau.incubator.apache.org Delivered-To: mailing list commits@juneau.incubator.apache.org Received: (qmail 17508 invoked by uid 99); 8 May 2017 15:32:48 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 May 2017 15:32:48 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id C22CF18140E for ; Mon, 8 May 2017 15:32:47 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -3.022 X-Spam-Level: X-Spam-Status: No, score=-3.022 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LINEPADDING=1.2, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id tEfsaMe7Mc-s for ; Mon, 8 May 2017 15:32:35 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 2FAAE5FDEE for ; Mon, 8 May 2017 15:32:33 +0000 (UTC) Received: (qmail 16997 invoked by uid 99); 8 May 2017 15:32:31 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 May 2017 15:32:31 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 6B975E93E1; Mon, 8 May 2017 15:32:31 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jamesbognar@apache.org To: commits@juneau.incubator.apache.org Date: Mon, 08 May 2017 15:32:39 -0000 Message-Id: <383655e9f70a44ae9bf09eeedfd06de1@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [09/51] [partial] incubator-juneau-website git commit: Support for passing in more class types to REST methods. archived-at: Mon, 08 May 2017 15:32:51 -0000 http://git-wip-us.apache.org/repos/asf/incubator-juneau-website/blob/f1f17bc3/content/site/apidocs/src-html/org/apache/juneau/rest/RequestHeaders.html ---------------------------------------------------------------------- diff --git a/content/site/apidocs/src-html/org/apache/juneau/rest/RequestHeaders.html b/content/site/apidocs/src-html/org/apache/juneau/rest/RequestHeaders.html new file mode 100644 index 0000000..4e18519 --- /dev/null +++ b/content/site/apidocs/src-html/org/apache/juneau/rest/RequestHeaders.html @@ -0,0 +1,747 @@ + + + +Source code + + + +
+
001// ***************************************************************************************************************************
+002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
+003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
+004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
+005// * with the License.  You may obtain a copy of the License at                                                              *
+006// *                                                                                                                         *
+007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
+008// *                                                                                                                         *
+009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
+010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
+011// * specific language governing permissions and limitations under the License.                                              *
+012// ***************************************************************************************************************************
+013package org.apache.juneau.rest;
+014
+015import java.lang.reflect.*;
+016import java.util.*;
+017
+018import org.apache.juneau.*;
+019import org.apache.juneau.http.*;
+020import org.apache.juneau.http.Date;
+021import org.apache.juneau.internal.*;
+022import org.apache.juneau.parser.*;
+023import org.apache.juneau.urlencoding.*;
+024
+025/**
+026 * Represents the headers in an HTTP request.
+027 * <p>
+028 * Entries are stored in a case-insensitive map.
+029 */
+030public class RequestHeaders extends TreeMap<String,String[]> {
+031   private static final long serialVersionUID = 1L;
+032
+033   private UrlEncodingParser parser;
+034   private BeanSession beanSession;
+035   private RequestQuery queryParams;
+036
+037   RequestHeaders() {
+038      super(String.CASE_INSENSITIVE_ORDER);
+039   }
+040
+041   RequestHeaders setParser(UrlEncodingParser parser) {
+042      this.parser = parser;
+043      return this;
+044   }
+045
+046   RequestHeaders setBeanSession(BeanSession beanSession) {
+047      this.beanSession = beanSession;
+048      return this;
+049   }
+050
+051   RequestHeaders setQueryParams(RequestQuery queryParams) {
+052      this.queryParams = queryParams;
+053      return this;
+054   }
+055
+056   /**
+057    * Adds default entries to these headers.
+058    * <p>
+059    * This includes the default headers defined on the servlet and method levels.
+060    *
+061    * @param defaultEntries The default entries.  Can be <jk>null</jk>.
+062    * @return This object (for method chaining).
+063    */
+064   public RequestHeaders addDefault(Map<String,String> defaultEntries) {
+065      if (defaultEntries != null) {
+066         for (Map.Entry<String,String> e : defaultEntries.entrySet()) {
+067            String key = e.getKey(), value = e.getValue();
+068            String[] v = get(key);
+069            if (v == null)
+070               put(key, new String[]{value});
+071         }
+072      }
+073      return this;
+074   }
+075
+076   /**
+077    * Adds a set of header values to this object.
+078    *
+079    * @param name The header name.
+080    * @param values The header values.
+081    * @return This object (for method chaining).
+082    */
+083   public RequestHeaders put(String name, Enumeration<String> values) {
+084      // Optimized for enumerations of one entry, the most-common case.
+085      if (values.hasMoreElements()) {
+086         String v = values.nextElement();
+087         if (! v.isEmpty()) {
+088            String[] s = new String[]{v};
+089            while (values.hasMoreElements())
+090               s = ArrayUtils.append(s, values.nextElement());
+091            put(name, s);
+092         }
+093      }
+094      return this;
+095   }
+096
+097   /**
+098    * Returns the specified header value, or <jk>null</jk> if the header doesn't exist.
+099    * <p>
+100    * If {@code allowHeaderParams} init parameter is <jk>true</jk>, then first looks for {@code &HeaderName=x} in the URL query string.
+101    * <p>
+102    * @param name The header name.
+103    * @return The header value, or <jk>null</jk> if it doesn't exist.
+104    */
+105   public String getFirst(String name) {
+106      return getFirst(name, null);
+107   }
+108
+109   /**
+110    * Returns the specified header value, or a default value if the header doesn't exist.
+111    * <p>
+112    * If {@code allowHeaderParams} init parameter is <jk>true</jk>, then first looks for {@code &HeaderName=x} in the URL query string.
+113    *
+114    * @param name The HTTP header name.
+115    * @param def The default value to return if the header value isn't found.
+116    * @return The header value, or the default value if the header isn't present.
+117    */
+118   public String getFirst(String name, String def) {
+119      String[] v = null;
+120      if (queryParams != null)
+121         v = queryParams.get(name);
+122      if (v == null || v.length == 0)
+123         v = get(name);
+124      if (v == null || v.length == 0)
+125         return def;
+126      return v[0];
+127   }
+128
+129   /**
+130    * Sets a request header value.
+131    *
+132    * @param name The header name.
+133    * @param value The header value.
+134    */
+135   public void put(String name, Object value) {
+136      super.put(name, new String[]{StringUtils.toString(value)});
+137   }
+138
+139   /**
+140    * Returns the specified header value converted to a POJO.
+141    * <p>
+142    * The type can be any POJO type convertable from a <code>String</code>
+143    * (See <a class="doclink" href="package-summary.html#PojosConvertableFromString">POJOs Convertable From Strings</a>).
+144    * <p>
+145    * <h5 class='section'>Examples:</h5>
+146    * <p class='bcode'>
+147    *    <jc>// Parse into an integer.</jc>
+148    *    <jk>int</jk> myheader = req.getHeader(<js>"My-Header"</js>, <jk>int</jk>.<jk>class</jk>);
+149    *
+150    *    <jc>// Parse a UUID.</jc>
+151    *    UUID myheader = req.getHeader(<js>"My-Header"</js>, UUID.<jk>class</jk>);
+152    * </p>
+153    *
+154    * @param name The HTTP header name.
+155    * @param type The class type to convert the header value to.
+156    * @param <T> The class type to convert the header value to.
+157    * @return The parameter value converted to the specified class type.
+158    */
+159   public <T> T get(String name, Class<T> type) {
+160      String h = getFirst(name);
+161      return beanSession.convertToType(h, type);
+162   }
+163
+164   /**
+165    * Same as {@link #get(String, Class)} but returns a default value if not found.
+166    *
+167    * @param name The HTTP header name.
+168    * @param def The default value if the header was not specified or is <jk>null</jk>.
+169    * @param type The class type to convert the header value to.
+170    * @param <T> The class type to convert the header value to.
+171    * @return The parameter value converted to the specified class type.
+172    */
+173   public <T> T get(String name, T def, Class<T> type) {
+174      String h = getFirst(name);
+175      if (h == null)
+176         return def;
+177      return beanSession.convertToType(h, type);
+178   }
+179
+180   /**
+181    * Returns the specified header value converted to a POJO.
+182    * <p>
+183    * The type can be any POJO type convertable from a <code>String</code>
+184    * (See <a class="doclink" href="package-summary.html#PojosConvertableFromString">POJOs Convertable From Strings</a>).
+185    * <p>
+186    * <h5 class='section'>Examples:</h5>
+187    * <p class='bcode'>
+188    *    <jc>// Parse into a linked-list of strings.</jc>
+189    *    List&lt;String&gt; myheader = req.getHeader(<js>"My-Header"</js>, LinkedList.<jk>class</jk>, String.<jk>class</jk>);
+190    * </p>
+191    *
+192    * @param name The HTTP header name.
+193    * @param type The type of object to create.
+194    *    <br>Can be any of the following: {@link ClassMeta}, {@link Class}, {@link ParameterizedType}, {@link GenericArrayType}
+195    * @param args The type arguments of the class if it's a collection or map.
+196    *    <br>Can be any of the following: {@link ClassMeta}, {@link Class}, {@link ParameterizedType}, {@link GenericArrayType}
+197    *    <br>Ignored if the main type is not a map or collection.
+198    * @param <T> The class type to convert the header value to.
+199    * @return The parameter value converted to the specified class type.
+200    * @throws ParseException If the header could not be converted to the specified type.
+201    */
+202   public <T> T get(String name, Type type, Type...args) throws ParseException {
+203      String h = getFirst(name);
+204      return parser.parsePart(h, type, args);
+205   }
+206
+207   /**
+208    * Returns the <code>Accept</code> header on the request.
+209    * <p>
+210    * Content-Types that are acceptable for the response.
+211    *
+212    * <h6 class='figure'>Example:</h6>
+213    * <p class='bcode'>
+214    *    Accept: text/plain
+215    * </p>
+216    *
+217    * @return The parsed <code>Accept</code> header on the request, or <jk>null</jk> if not found.
+218    *
+219    */
+220   public Accept getAccept() {
+221      return Accept.forString(getFirst("Accept"));
+222   }
+223
+224   /**
+225    * Returns the <code>Accept-Charset</code> header on the request.
+226    * <p>
+227    * Character sets that are acceptable.
+228    *
+229    * <h6 class='figure'>Example:</h6>
+230    * <p class='bcode'>
+231    *    Accept-Charset: utf-8
+232    * </p>
+233    *
+234    * @return The parsed <code>Accept-Charset</code> header on the request, or <jk>null</jk> if not found.
+235    */
+236   public AcceptCharset getAcceptCharset() {
+237      return AcceptCharset.forString(getFirst("Accept-Charset"));
+238   }
+239
+240   /**
+241    * Returns the <code>Accept-Encoding</code> header on the request.
+242    * <p>
+243    * List of acceptable encodings.
+244    *
+245    * <h6 class='figure'>Example:</h6>
+246    * <p class='bcode'>
+247    *    Accept-Encoding: gzip, deflate
+248    * </p>
+249    *
+250    * @return The parsed <code>Accept-Encoding</code> header on the request, or <jk>null</jk> if not found.
+251    */
+252   public AcceptEncoding getAcceptEncoding() {
+253      return AcceptEncoding.forString(getFirst("Accept-Encoding"));
+254   }
+255
+256   /**
+257    * Returns the <code>Accept-Language</code> header on the request.
+258    * <p>
+259    * List of acceptable human languages for response.
+260    *
+261    * <h6 class='figure'>Example:</h6>
+262    * <p class='bcode'>
+263    *    Accept-Language: en-US
+264    * </p>
+265    *
+266    * @return The parsed <code>Accept-Language</code> header on the request, or <jk>null</jk> if not found.
+267    */
+268   public AcceptLanguage getAcceptLanguage() {
+269      return AcceptLanguage.forString(getFirst("Accept-Language"));
+270   }
+271
+272   /**
+273    * Returns the <code>Authorization</code> header on the request.
+274    * <p>
+275    * Authentication credentials for HTTP authentication.
+276    *
+277    * <h6 class='figure'>Example:</h6>
+278    * <p class='bcode'>
+279    *    Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
+280    * </p>
+281    *
+282    * @return The parsed <code>Authorization</code> header on the request, or <jk>null</jk> if not found.
+283    */
+284   public Authorization getAuthorization() {
+285      return Authorization.forString(getFirst("Authorization"));
+286   }
+287
+288   /**
+289    * Returns the <code>Cache-Control</code> header on the request.
+290    * <p>
+291    * Used to specify directives that must be obeyed by all caching mechanisms along the request-response chain.
+292    *
+293    * <h6 class='figure'>Example:</h6>
+294    * <p class='bcode'>
+295    *    Cache-Control: no-cache
+296    * </p>
+297    *
+298    * @return The parsed <code>Cache-Control</code> header on the request, or <jk>null</jk> if not found.
+299    */
+300   public CacheControl getCacheControl() {
+301      return CacheControl.forString(getFirst("Cache-Control"));
+302   }
+303
+304   /**
+305    * Returns the <code>Connection</code> header on the request.
+306    * <p>
+307    * Control options for the current connection and list of hop-by-hop request fields.
+308    *
+309    * <h6 class='figure'>Example:</h6>
+310    * <p class='bcode'>
+311    *    Connection: keep-alive
+312    *    Connection: Upgrade
+313    * </p>
+314    *
+315    * @return The parsed <code></code> header on the request, or <jk>null</jk> if not found.
+316    */
+317   public Connection getConnection() {
+318      return Connection.forString(getFirst("Connection"));
+319   }
+320
+321   /**
+322    * Returns the <code>Content-Length</code> header on the request.
+323    * <p>
+324    * The length of the request body in octets (8-bit bytes).
+325    *
+326    * <h6 class='figure'>Example:</h6>
+327    * <p class='bcode'>
+328    *    Content-Length: 348
+329    * </p>
+330    *
+331    * @return The parsed <code>Content-Length</code> header on the request, or <jk>null</jk> if not found.
+332    */
+333   public ContentLength getContentLength() {
+334      return ContentLength.forString(getFirst("Content-Length"));
+335   }
+336
+337   /**
+338    * Returns the <code>Content-Type</code> header on the request.
+339    * <p>
+340    * The MIME type of the body of the request (used with POST and PUT requests).
+341    *
+342    * <h6 class='figure'>Example:</h6>
+343    * <p class='bcode'>
+344    *    Content-Type: application/x-www-form-urlencoded
+345    * </p>
+346    *
+347    * @return The parsed <code>Content-Type</code> header on the request, or <jk>null</jk> if not found.
+348    */
+349   public ContentType getContentType() {
+350      return ContentType.forString(getFirst("Content-Type"));
+351   }
+352
+353   /**
+354    * Returns the <code>Date</code> header on the request.
+355    * <p>
+356    * The date and time that the message was originated (in "HTTP-date" format as defined by RFC 7231 Date/Time Formats).
+357    *
+358    * <h6 class='figure'>Example:</h6>
+359    * <p class='bcode'>
+360    *    Date: Tue, 15 Nov 1994 08:12:31 GMT
+361    * </p>
+362    *
+363    * @return The parsed <code>Date</code> header on the request, or <jk>null</jk> if not found.
+364    */
+365   public Date getDate() {
+366      return Date.forString(getFirst("Date"));
+367   }
+368
+369   /**
+370    * Returns the <code>Expect</code> header on the request.
+371    * <p>
+372    * Indicates that particular server behaviors are required by the client.
+373    *
+374    * <h6 class='figure'>Example:</h6>
+375    * <p class='bcode'>
+376    *    Expect: 100-continue
+377    * </p>
+378    *
+379    * @return The parsed <code>Expect</code> header on the request, or <jk>null</jk> if not found.
+380    */
+381   public Expect getExpect() {
+382      return Expect.forString(getFirst("Expect"));
+383   }
+384
+385   /**
+386    * Returns the <code>From</code> header on the request.
+387    * <p>
+388    * The email address of the user making the request.
+389    *
+390    * <h6 class='figure'>Example:</h6>
+391    * <p class='bcode'>
+392    *    From: user@example.com
+393    * </p>
+394    *
+395    * @return The parsed <code>From</code> header on the request, or <jk>null</jk> if not found.
+396    */
+397   public From getFrom() {
+398      return From.forString(getFirst("From"));
+399   }
+400
+401   /**
+402    * Returns the <code>Host</code> header on the request.
+403    * <p>
+404    * The domain name of the server (for virtual hosting), and the TCP port number on which the server is listening.
+405    * The port number may be omitted if the port is the standard port for the service requested.
+406    *
+407    * <h6 class='figure'>Example:</h6>
+408    * <p class='bcode'>
+409    *    Host: en.wikipedia.org:8080
+410    *    Host: en.wikipedia.org
+411    * </p>
+412    *
+413    * @return The parsed <code>Host</code> header on the request, or <jk>null</jk> if not found.
+414    */
+415   public Host getHost() {
+416      return Host.forString(getFirst("Host"));
+417   }
+418
+419   /**
+420    * Returns the <code>If-Match</code> header on the request.
+421    * <p>
+422    * Only perform the action if the client supplied entity matches the same entity on the server.
+423    * This is mainly for methods like PUT to only update a resource if it has not been modified since the user last updated it.
+424    *
+425    * <h6 class='figure'>Example:</h6>
+426    * <p class='bcode'>
+427    *    If-Match: "737060cd8c284d8af7ad3082f209582d"
+428    * </p>
+429    *
+430    * @return The parsed <code>If-Match</code> header on the request, or <jk>null</jk> if not found.
+431    */
+432   public IfMatch getIfMatch() {
+433      return IfMatch.forString(getFirst("If-Match"));
+434   }
+435
+436   /**
+437    * Returns the <code>If-Modified-Since</code> header on the request.
+438    * <p>
+439    * Allows a 304 Not Modified to be returned if content is unchanged.
+440    *
+441    * <h6 class='figure'>Example:</h6>
+442    * <p class='bcode'>
+443    *    If-Modified-Since: Sat, 29 Oct 1994 19:43:31 GMT
+444    * </p>
+445    *
+446    * @return The parsed <code>If-Modified-Since</code> header on the request, or <jk>null</jk> if not found.
+447    */
+448   public IfModifiedSince getIfModifiedSince() {
+449      return IfModifiedSince.forString(getFirst("If-Modified-Since"));
+450   }
+451
+452   /**
+453    * Returns the <code>If-None-Match</code> header on the request.
+454    * <p>
+455    * Allows a 304 Not Modified to be returned if content is unchanged, see HTTP ETag.
+456    *
+457    * <h6 class='figure'>Example:</h6>
+458    * <p class='bcode'>
+459    *    If-None-Match: "737060cd8c284d8af7ad3082f209582d"
+460    * </p>
+461    *
+462    * @return The parsed <code>If-None-Match</code> header on the request, or <jk>null</jk> if not found.
+463    */
+464   public IfNoneMatch getIfNoneMatch() {
+465      return IfNoneMatch.forString(getFirst("If-None-Match"));
+466   }
+467
+468   /**
+469    * Returns the <code>If-Range</code> header on the request.
+470    * <p>
+471    * If the entity is unchanged, send me the part(s) that I am missing; otherwise, send me the entire new entity.
+472    *
+473    * <h6 class='figure'>Example:</h6>
+474    * <p class='bcode'>
+475    *    If-Range: "737060cd8c284d8af7ad3082f209582d"
+476    * </p>
+477    *
+478    * @return The parsed <code>If-Range</code> header on the request, or <jk>null</jk> if not found.
+479    */
+480   public IfRange getIfRange() {
+481      return IfRange.forString(getFirst("If-Range"));
+482   }
+483
+484   /**
+485    * Returns the <code>If-Unmodified-Since</code> header on the request.
+486    * <p>
+487    * Only send the response if the entity has not been modified since a specific time.
+488    *
+489    * <h6 class='figure'>Example:</h6>
+490    * <p class='bcode'>
+491    *    If-Unmodified-Since: Sat, 29 Oct 1994 19:43:31 GMT
+492    * </p>
+493    *
+494    * @return The parsed <code>If-Unmodified-Since</code> header on the request, or <jk>null</jk> if not found.
+495    */
+496   public IfUnmodifiedSince getIfUnmodifiedSince() {
+497      return IfUnmodifiedSince.forString(getFirst("If-Unmodified-Since"));
+498   }
+499
+500   /**
+501    * Returns the <code>Max-Forwards</code> header on the request.
+502    * <p>
+503    * Limit the number of times the message can be forwarded through proxies or gateways.
+504    *
+505    * <h6 class='figure'>Example:</h6>
+506    * <p class='bcode'>
+507    *    Max-Forwards: 10
+508    * </p>
+509    *
+510    * @return The parsed <code>Max-Forwards</code> header on the request, or <jk>null</jk> if not found.
+511    */
+512   public MaxForwards getMaxForwards() {
+513      return MaxForwards.forString(getFirst("Max-Forwards"));
+514   }
+515
+516   /**
+517    * Returns the <code>Pragma</code> header on the request.
+518    * <p>
+519    * Implementation-specific fields that may have various effects anywhere along the request-response chain.
+520    *
+521    * <h6 class='figure'>Example:</h6>
+522    * <p class='bcode'>
+523    *    Pragma: no-cache
+524    * </p>
+525    *
+526    * @return The parsed <code>Pragma</code> header on the request, or <jk>null</jk> if not found.
+527    */
+528   public Pragma getPragma() {
+529      return Pragma.forString(getFirst("Pragma"));
+530   }
+531
+532   /**
+533    * Returns the <code>Proxy-Authorization</code> header on the request.
+534    * <p>
+535    * Authorization credentials for connecting to a proxy.
+536    *
+537    * <h6 class='figure'>Example:</h6>
+538    * <p class='bcode'>
+539    *    Proxy-Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
+540    * </p>
+541    *
+542    * @return The parsed <code>Proxy-Authorization</code> header on the request, or <jk>null</jk> if not found.
+543    */
+544   public ProxyAuthorization getProxyAuthorization() {
+545      return ProxyAuthorization.forString(getFirst("Proxy-Authorization"));
+546   }
+547
+548   /**
+549    * Returns the <code>Range</code> header on the request.
+550    * <p>
+551    * Request only part of an entity. Bytes are numbered from 0.
+552    *
+553    * <h6 class='figure'>Example:</h6>
+554    * <p class='bcode'>
+555    *    Range: bytes=500-999
+556    * </p>
+557    *
+558    * @return The parsed <code>Range</code> header on the request, or <jk>null</jk> if not found.
+559    */
+560   public Range getRange() {
+561      return Range.forString(getFirst("Range"));
+562   }
+563
+564   /**
+565    * Returns the <code>Referer</code> header on the request.
+566    * <p>
+567    * This is the address of the previous web page from which a link to the currently requested page was followed.
+568    *
+569    * <h6 class='figure'>Example:</h6>
+570    * <p class='bcode'>
+571    *    Referer: http://en.wikipedia.org/wiki/Main_Page
+572    * </p>
+573    *
+574    * @return The parsed <code>Referer</code> header on the request, or <jk>null</jk> if not found.
+575    */
+576   public Referer getReferer() {
+577      return Referer.forString(getFirst("Referer"));
+578   }
+579
+580   /**
+581    * Returns the <code>TE</code> header on the request.
+582    * <p>
+583    * The transfer encodings the user agent is willing to accept: the same values as for the response header field
+584    * Transfer-Encoding can be used, plus the "trailers" value (related to the "chunked" transfer method) to notify the
+585    * server it expects to receive additional fields in the trailer after the last, zero-sized, chunk.
+586    *
+587    * <h6 class='figure'>Example:</h6>
+588    * <p class='bcode'>
+589    *    TE: trailers, deflate
+590    * </p>
+591    *
+592    * @return The parsed <code>TE</code> header on the request, or <jk>null</jk> if not found.
+593    */
+594   public TE getTE() {
+595      return TE.forString(getFirst("TE"));
+596   }
+597
+598   /**
+599    * Returns the <code>Time-Zone</code> header value on the request if there is one.
+600    * <p>
+601    * Example: <js>"GMT"</js>.
+602    *
+603    * @return The <code>Time-Zone</code> header value on the request, or <jk>null</jk> if not present.
+604    */
+605   public TimeZone getTimeZone() {
+606      String tz = getFirst("Time-Zone");
+607      if (tz != null)
+608         return TimeZone.getTimeZone(tz);
+609      return null;
+610   }
+611
+612   /**
+613    * Returns the <code>User-Agent</code> header on the request.
+614    * <p>
+615    * The user agent string of the user agent.
+616    *
+617    * <h6 class='figure'>Example:</h6>
+618    * <p class='bcode'>
+619    *    User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20100101 Firefox/21.0
+620    * </p>
+621    *
+622    * @return The parsed <code>User-Agent</code> header on the request, or <jk>null</jk> if not found.
+623    */
+624   public UserAgent getUserAgent() {
+625      return UserAgent.forString(getFirst("User-Agent"));
+626   }
+627
+628   /**
+629    * Returns the <code>Upgrade</code> header on the request.
+630    * <p>
+631    * Ask the server to upgrade to another protocol.
+632    *
+633    * <h6 class='figure'>Example:</h6>
+634    * <p class='bcode'>
+635    *    Upgrade: HTTP/2.0, HTTPS/1.3, IRC/6.9, RTA/x11, websocket
+636    * </p>
+637    *
+638    * @return The parsed <code>Upgrade</code> header on the request, or <jk>null</jk> if not found.
+639    */
+640   public Upgrade getUpgrade() {
+641      return Upgrade.forString(getFirst("Upgrade"));
+642   }
+643
+644   /**
+645    * Returns the <code>Via</code> header on the request.
+646    * <p>
+647    * Informs the server of proxies through which the request was sent.
+648    *
+649    * <h6 class='figure'>Example:</h6>
+650    * <p class='bcode'>
+651    *    Via: 1.0 fred, 1.1 example.com (Apache/1.1)
+652    * </p>
+653    *
+654    * @return The parsed <code>Via</code> header on the request, or <jk>null</jk> if not found.
+655    */
+656   public Via getVia() {
+657      return Via.forString(getFirst("Via"));
+658   }
+659
+660   /**
+661    * Returns the <code>Warning</code> header on the request.
+662    * <p>
+663    * A general warning about possible problems with the entity body.
+664    *
+665    * <h6 class='figure'>Example:</h6>
+666    * <p class='bcode'>
+667    *    Warning: 199 Miscellaneous warning
+668    * </p>
+669    *
+670    * @return The parsed <code>Warning</code> header on the request, or <jk>null</jk> if not found.
+671    */
+672   public Warning getWarning() {
+673      return Warning.forString(getFirst("Warning"));
+674   }
+675}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + http://git-wip-us.apache.org/repos/asf/incubator-juneau-website/blob/f1f17bc3/content/site/apidocs/src-html/org/apache/juneau/rest/RequestPathParams.html ---------------------------------------------------------------------- diff --git a/content/site/apidocs/src-html/org/apache/juneau/rest/RequestPathParams.html b/content/site/apidocs/src-html/org/apache/juneau/rest/RequestPathParams.html new file mode 100644 index 0000000..66dd1b8 --- /dev/null +++ b/content/site/apidocs/src-html/org/apache/juneau/rest/RequestPathParams.html @@ -0,0 +1,209 @@ + + + +Source code + + + +
+
001// ***************************************************************************************************************************
+002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
+003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
+004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
+005// * with the License.  You may obtain a copy of the License at                                                              *
+006// *                                                                                                                         *
+007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
+008// *                                                                                                                         *
+009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
+010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
+011// * specific language governing permissions and limitations under the License.                                              *
+012// ***************************************************************************************************************************
+013package org.apache.juneau.rest;
+014
+015import java.lang.reflect.*;
+016import java.util.*;
+017
+018import org.apache.juneau.*;
+019import org.apache.juneau.parser.*;
+020import org.apache.juneau.urlencoding.*;
+021
+022/**
+023 * Represents the path parameters on an HTTP request.
+024 */
+025@SuppressWarnings("unchecked")
+026public class RequestPathParams extends TreeMap<String,String> {
+027   private static final long serialVersionUID = 1L;
+028
+029   private UrlEncodingParser parser;
+030   private BeanSession beanSession;
+031
+032   RequestPathParams() {
+033      super(String.CASE_INSENSITIVE_ORDER);
+034   }
+035
+036   RequestPathParams setParser(UrlEncodingParser parser) {
+037      this.parser = parser;
+038      return this;
+039   }
+040
+041   RequestPathParams setBeanSession(BeanSession beanSession) {
+042      this.beanSession = beanSession;
+043      return this;
+044   }
+045
+046   /**
+047    * Sets a request query parameter value.
+048    *
+049    * @param name The parameter name.
+050    * @param value The parameter value.
+051    */
+052   public void put(String name, Object value) {
+053      put(name, value);
+054   }
+055
+056   /**
+057    * Returns the specified path parameter converted to a POJO.
+058    * <p>
+059    * The type can be any POJO type convertable from a <code>String</code> (See <a class="doclink" 
+060    * href="package-summary.html#PojosConvertableFromString">POJOs Convertable From Strings</a>).
+061    * <p>
+062    * <h5 class='section'>Examples:</h5>
+063    * <p class='bcode'>
+064    *    <jc>// Parse into an integer.</jc>
+065    *    <jk>int</jk> myparam = req.getPathParameter(<js>"myparam"</js>, <jk>int</jk>.<jk>class</jk>);
+066    *
+067    *    <jc>// Parse into an int array.</jc>
+068    *    <jk>int</jk>[] myparam = req.getPathParameter(<js>"myparam"</js>, <jk>int</jk>[].<jk>class</jk>);
+069
+070    *    <jc>// Parse into a bean.</jc>
+071    *    MyBean myparam = req.getPathParameter(<js>"myparam"</js>, MyBean.<jk>class</jk>);
+072    *
+073    *    <jc>// Parse into a linked-list of objects.</jc>
+074    *    List myparam = req.getPathParameter(<js>"myparam"</js>, LinkedList.<jk>class</jk>);
+075    *
+076    *    <jc>// Parse into a map of object keys/values.</jc>
+077    *    Map myparam = req.getPathParameter(<js>"myparam"</js>, TreeMap.<jk>class</jk>);
+078    * </p>
+079    *
+080    * @param name The attribute name.
+081    * @param type The class type to convert the attribute value to.
+082    * @param <T> The class type to convert the attribute value to.
+083    * @return The attribute value converted to the specified class type.
+084    * @throws ParseException
+085    */
+086   public <T> T get(String name, Class<T> type) throws ParseException {
+087      return parse(name, beanSession.getClassMeta(type));
+088   }
+089
+090   /**
+091    * Returns the specified path parameter converted to a POJO.
+092    * <p>
+093    * The type can be any POJO type convertable from a <code>String</code> (See <a class="doclink" href="package-summary.html#PojosConvertableFromString">POJOs Convertable From Strings</a>).
+094    * <p>
+095    * Use this method if you want to parse into a parameterized <code>Map</code>/<code>Collection</code> object.
+096    * <p>
+097    * <h5 class='section'>Examples:</h5>
+098    * <p class='bcode'>
+099    *    <jc>// Parse into a linked-list of strings.</jc>
+100    *    List&lt;String&gt; myparam = req.getPathParameter(<js>"myparam"</js>, LinkedList.<jk>class</jk>, String.<jk>class</jk>);
+101    *
+102    *    <jc>// Parse into a linked-list of linked-lists of strings.</jc>
+103    *    List&lt;List&lt;String&gt;&gt; myparam = req.getPathParameter(<js>"myparam"</js>, LinkedList.<jk>class</jk>, LinkedList.<jk>class</jk>, String.<jk>class</jk>);
+104    *
+105    *    <jc>// Parse into a map of string keys/values.</jc>
+106    *    Map&lt;String,String&gt; myparam = req.getPathParameter(<js>"myparam"</js>, TreeMap.<jk>class</jk>, String.<jk>class</jk>, String.<jk>class</jk>);
+107    *
+108    *    <jc>// Parse into a map containing string keys and values of lists containing beans.</jc>
+109    *    Map&lt;String,List&lt;MyBean&gt;&gt; myparam = req.getPathParameter(<js>"myparam"</js>, TreeMap.<jk>class</jk>, String.<jk>class</jk>, List.<jk>class</jk>, MyBean.<jk>class</jk>);
+110    * </p>
+111    *
+112    * @param name The attribute name.
+113    * @param type The type of object to create.
+114    *    <br>Can be any of the following: {@link ClassMeta}, {@link Class}, {@link ParameterizedType}, {@link GenericArrayType}
+115    * @param args The type arguments of the class if it's a collection or map.
+116    *    <br>Can be any of the following: {@link ClassMeta}, {@link Class}, {@link ParameterizedType}, {@link GenericArrayType}
+117    *    <br>Ignored if the main type is not a map or collection.
+118    * @param <T> The class type to convert the attribute value to.
+119    * @return The attribute value converted to the specified class type.
+120    * @throws ParseException
+121    */
+122   public <T> T get(String name, Type type, Type...args) throws ParseException {
+123      return (T)parse(name, beanSession.getClassMeta(type, args));
+124   }
+125
+126   /* Workhorse method */
+127   <T> T parse(String name, ClassMeta<T> cm) throws ParseException {
+128      Object attr = get(name);
+129      T t = null;
+130      if (attr != null)
+131         t = parser.parsePart(attr.toString(), cm);
+132      if (t == null && cm.isPrimitive())
+133         return cm.getPrimitiveDefault();
+134      return t;
+135   }
+136
+137}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +