src/share/jaxws_classes/javax/xml/ws/soap/MTOMFeature.java

changeset 0
373ffda63c9a
child 637
9c07ef4934dd
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/javax/xml/ws/soap/MTOMFeature.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,144 @@
     1.4 +/*
     1.5 + * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package javax.xml.ws.soap;
    1.30 +
    1.31 +import javax.xml.ws.WebServiceFeature;
    1.32 +import javax.xml.ws.WebServiceException;
    1.33 +import javax.xml.ws.Endpoint;
    1.34 +import javax.xml.ws.Service;
    1.35 +
    1.36 +/**
    1.37 + * This feature represents the use of MTOM with a
    1.38 + * web service.
    1.39 + *
    1.40 + * This feature can be used during the creation of SEI proxy, and
    1.41 + * {@link javax.xml.ws.Dispatch} instances on the client side and {@link Endpoint}
    1.42 + * instances on the server side. This feature cannot be used for {@link Service}
    1.43 + * instance creation on the client side.
    1.44 + *
    1.45 + * <p>
    1.46 + * The following describes the affects of this feature with respect
    1.47 + * to being enabled or disabled:
    1.48 + * <ul>
    1.49 + *  <li> ENABLED: In this Mode, MTOM will be enabled. A receiver MUST accept
    1.50 + * both a non-optimized and an optimized message, and a sender MAY send an
    1.51 + * optimized message, or a non-optimized message. The heuristics used by a
    1.52 + * sender to determine whether to use optimization or not are
    1.53 + * implementation-specific.
    1.54 + *  <li> DISABLED: In this Mode, MTOM will be disabled
    1.55 + * </ul>
    1.56 + * <p>
    1.57 + * The {@link #threshold} property can be used to set the threshold
    1.58 + * value used to determine when binary data should be XOP encoded.
    1.59 + *
    1.60 + * @since JAX-WS 2.1
    1.61 + */
    1.62 +public final class MTOMFeature extends WebServiceFeature {
    1.63 +    /**
    1.64 +     * Constant value identifying the MTOMFeature
    1.65 +     */
    1.66 +    public static final String ID = "http://www.w3.org/2004/08/soap/features/http-optimization";
    1.67 +
    1.68 +
    1.69 +    /**
    1.70 +     * Property for MTOM threshold value. This property serves as a hint when
    1.71 +     * MTOM is enabled, binary data above this size in bytes SHOULD be sent
    1.72 +     * as attachment.
    1.73 +     * The value of this property MUST always be >= 0. Default value is 0.
    1.74 +     */
    1.75 +    // should be changed to private final, keeping original modifier to keep backwards compatibility
    1.76 +    protected int threshold;
    1.77 +
    1.78 +
    1.79 +    /**
    1.80 +     * Create an <code>MTOMFeature</code>.
    1.81 +     * The instance created will be enabled.
    1.82 +     */
    1.83 +    public MTOMFeature() {
    1.84 +        this.enabled = true;
    1.85 +        this.threshold = 0;
    1.86 +    }
    1.87 +
    1.88 +    /**
    1.89 +     * Creates an <code>MTOMFeature</code>.
    1.90 +     *
    1.91 +     * @param enabled specifies if this feature should be enabled or not
    1.92 +     */
    1.93 +    public MTOMFeature(boolean enabled) {
    1.94 +        this.enabled = enabled;
    1.95 +        this.threshold = 0;
    1.96 +    }
    1.97 +
    1.98 +
    1.99 +    /**
   1.100 +     * Creates an <code>MTOMFeature</code>.
   1.101 +     * The instance created will be enabled.
   1.102 +     *
   1.103 +     * @param threshold the size in bytes that binary data SHOULD be before
   1.104 +     * being sent as an attachment.
   1.105 +     *
   1.106 +     * @throws WebServiceException if threshold is < 0
   1.107 +     */
   1.108 +    public MTOMFeature(int threshold) {
   1.109 +        if (threshold < 0)
   1.110 +            throw new WebServiceException("MTOMFeature.threshold must be >= 0, actual value: "+threshold);
   1.111 +        this.enabled = true;
   1.112 +        this.threshold = threshold;
   1.113 +    }
   1.114 +
   1.115 +    /**
   1.116 +     * Creates an <code>MTOMFeature</code>.
   1.117 +     *
   1.118 +     * @param enabled specifies if this feature should be enabled or not
   1.119 +     * @param threshold the size in bytes that binary data SHOULD be before
   1.120 +     * being sent as an attachment.
   1.121 +     *
   1.122 +     * @throws WebServiceException if threshold is < 0
   1.123 +     */
   1.124 +    public MTOMFeature(boolean enabled, int threshold) {
   1.125 +        if (threshold < 0)
   1.126 +            throw new WebServiceException("MTOMFeature.threshold must be >= 0, actual value: "+threshold);
   1.127 +        this.enabled = enabled;
   1.128 +        this.threshold = threshold;
   1.129 +    }
   1.130 +
   1.131 +    /**
   1.132 +     * {@inheritDoc}
   1.133 +     */
   1.134 +    public String getID() {
   1.135 +        return ID;
   1.136 +    }
   1.137 +
   1.138 +    /**
   1.139 +     * Gets the threshold value used to determine when binary data
   1.140 +     * should be sent as an attachment.
   1.141 +     *
   1.142 +     * @return the current threshold size in bytes
   1.143 +     */
   1.144 +    public int getThreshold() {
   1.145 +        return threshold;
   1.146 +    }
   1.147 +}

mercurial