src/share/jaxws_classes/com/sun/xml/internal/ws/developer/HttpConfigFeature.java

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 368
0989ad8c0860
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

     1 /*
     2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.xml.internal.ws.developer;
    28 import javax.xml.ws.WebServiceException;
    29 import javax.xml.ws.WebServiceFeature;
    30 import java.lang.reflect.Constructor;
    31 import java.net.CookieHandler;
    33 /**
    34  * A proxy's HTTP configuration (e.g cookie handling) can be configured using
    35  * this feature. While creating the proxy, this can be passed just like other
    36  * features.
    37  *
    38  * <p>
    39  * <b>THIS feature IS EXPERIMENTAL AND IS SUBJECT TO CHANGE WITHOUT NOTICE IN FUTURE.</b>
    40  *
    41  * @author Jitendra Kotamraju
    42  */
    43 public final class HttpConfigFeature extends WebServiceFeature {
    44     /**
    45      * Constant value identifying the {@link HttpConfigFeature} feature.
    46      */
    47     public static final String ID = "http://jax-ws.java.net/features/http-config";
    49     private static final Constructor cookieManagerConstructor;
    50     private static final Object cookiePolicy;
    51     static {
    52         Constructor tempConstructor;
    53         Object tempPolicy;
    54         try {
    55             /*
    56              * Using reflection to create CookieManger so that RI would continue to
    57              * work with JDK 5.
    58              */
    59             Class policyClass = Class.forName("java.net.CookiePolicy");
    60             Class storeClass = Class.forName("java.net.CookieStore");
    61             tempConstructor = Class.forName("java.net.CookieManager").getConstructor(storeClass, policyClass);
    62             // JDK's default policy is ACCEPT_ORIGINAL_SERVER, but ACCEPT_ALL
    63             // is used for backward compatibility
    64             tempPolicy = policyClass.getField("ACCEPT_ALL").get(null);
    65         } catch(Exception e) {
    66             try {
    67                 /*
    68                  * Using reflection so that these classes won't have to be
    69                  * integrated in JDK 6.
    70                  */
    71                 Class policyClass = Class.forName("com.sun.xml.internal.ws.transport.http.client.CookiePolicy");
    72                 Class storeClass = Class.forName("com.sun.xml.internal.ws.transport.http.client.CookieStore");
    73                 tempConstructor = Class.forName("com.sun.xml.internal.ws.transport.http.client.CookieManager").getConstructor(storeClass, policyClass);
    74                 // JDK's default policy is ACCEPT_ORIGINAL_SERVER, but ACCEPT_ALL
    75                 // is used for backward compatibility
    76                 tempPolicy = policyClass.getField("ACCEPT_ALL").get(null);
    77             } catch(Exception ce) {
    78                 throw new WebServiceException(ce);
    79             }
    80         }
    81         cookieManagerConstructor = tempConstructor;
    82         cookiePolicy = tempPolicy;
    83     }
    85     private final CookieHandler cookieJar;      // shared object among the tubes
    87     public HttpConfigFeature() {
    88         this(getInternalCookieHandler());
    89     }
    91     public HttpConfigFeature(CookieHandler cookieJar) {
    92         this.enabled = true;
    93         this.cookieJar = cookieJar;
    94     }
    96     private static CookieHandler getInternalCookieHandler() {
    97         try {
    98             return (CookieHandler)cookieManagerConstructor.newInstance(null, cookiePolicy);
    99         } catch(Exception e) {
   100             throw new WebServiceException(e);
   101         }
   102     }
   104     public String getID() {
   105         return ID;
   106     }
   108     public CookieHandler getCookieHandler() {
   109         return cookieJar;
   110     }
   112 }

mercurial