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

changeset 286
f50545b5e2f1
child 368
0989ad8c0860
     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	Tue Mar 06 16:09:35 2012 -0800
     1.3 @@ -0,0 +1,142 @@
     1.4 +/*
     1.5 + * Copyright (c) 2005, 2010, 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.Dispatch;
    1.34 +import javax.xml.ws.Endpoint;
    1.35 +import javax.xml.ws.Service;
    1.36 +
    1.37 +/**
    1.38 + * This feature represents the use of MTOM with a
    1.39 + * web service.
    1.40 + *
    1.41 + * This feature can be used during the creation of SEI proxy, and
    1.42 + * {@link Dispatch} instances on the client side and {@link Endpoint}
    1.43 + * instances on the server side. This feature cannot be used for {@link Service}
    1.44 + * instance creation on the client side.
    1.45 + *
    1.46 + * <p>
    1.47 + * The following describes the affects of this feature with respect
    1.48 + * to being enabled or disabled:
    1.49 + * <ul>
    1.50 + *  <li> ENABLED: In this Mode, MTOM will be enabled. A receiver MUST accept
    1.51 + * both a non-optimized and an optimized message, and a sender MAY send an
    1.52 + * optimized message, or a non-optimized message. The heuristics used by a
    1.53 + * sender to determine whether to use optimization or not are
    1.54 + * implementation-specific.
    1.55 + *  <li> DISABLED: In this Mode, MTOM will be disabled
    1.56 + * </ul>
    1.57 + * <p>
    1.58 + * The {@link #threshold} property can be used to set the threshold
    1.59 + * value used to determine when binary data should be XOP encoded.
    1.60 + *
    1.61 + * @since JAX-WS 2.1
    1.62 + */
    1.63 +public final class MTOMFeature extends WebServiceFeature {
    1.64 +    /**
    1.65 +     * Constant value identifying the MTOMFeature
    1.66 +     */
    1.67 +    public static final String ID = "http://www.w3.org/2004/08/soap/features/http-optimization";
    1.68 +
    1.69 +
    1.70 +    /**
    1.71 +     * Property for MTOM threshold value. This property serves as a hint when
    1.72 +     * MTOM is enabled, binary data above this size in bytes SHOULD be sent
    1.73 +     * as attachment.
    1.74 +     * The value of this property MUST always be >= 0. Default value is 0.
    1.75 +     */
    1.76 +    protected int threshold = 0;
    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 +    }
    1.86 +
    1.87 +    /**
    1.88 +     * Creates an <code>MTOMFeature</code>.
    1.89 +     *
    1.90 +     * @param enabled specifies if this feature should be enabled or not
    1.91 +     */
    1.92 +    public MTOMFeature(boolean enabled) {
    1.93 +        this.enabled = enabled;
    1.94 +    }
    1.95 +
    1.96 +
    1.97 +    /**
    1.98 +     * Creates an <code>MTOMFeature</code>.
    1.99 +     * The instance created will be enabled.
   1.100 +     *
   1.101 +     * @param threshold the size in bytes that binary data SHOULD be before
   1.102 +     * being sent as an attachment.
   1.103 +     *
   1.104 +     * @throws WebServiceException if threshold is < 0
   1.105 +     */
   1.106 +    public MTOMFeature(int threshold) {
   1.107 +        if (threshold < 0)
   1.108 +            throw new WebServiceException("MTOMFeature.threshold must be >= 0, actual value: "+threshold);
   1.109 +        this.enabled = true;
   1.110 +        this.threshold = threshold;
   1.111 +    }
   1.112 +
   1.113 +    /**
   1.114 +     * Creates an <code>MTOMFeature</code>.
   1.115 +     *
   1.116 +     * @param enabled specifies if this feature should be enabled or not
   1.117 +     * @param threshold the size in bytes that binary data SHOULD be before
   1.118 +     * being sent as an attachment.
   1.119 +     *
   1.120 +     * @throws WebServiceException if threshold is < 0
   1.121 +     */
   1.122 +    public MTOMFeature(boolean enabled, int threshold) {
   1.123 +        if (threshold < 0)
   1.124 +            throw new WebServiceException("MTOMFeature.threshold must be >= 0, actual value: "+threshold);
   1.125 +        this.enabled = enabled;
   1.126 +        this.threshold = threshold;
   1.127 +    }
   1.128 +
   1.129 +    /**
   1.130 +     * {@inheritDoc}
   1.131 +     */
   1.132 +    public String getID() {
   1.133 +        return ID;
   1.134 +    }
   1.135 +
   1.136 +    /**
   1.137 +     * Gets the threshold value used to determine when binary data
   1.138 +     * should be sent as an attachment.
   1.139 +     *
   1.140 +     * @return the current threshold size in bytes
   1.141 +     */
   1.142 +    public int getThreshold() {
   1.143 +        return threshold;
   1.144 +    }
   1.145 +}

mercurial