Tue, 09 Apr 2013 14:51:13 +0100
8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com
ohair@286 | 1 | /* |
alanb@368 | 2 | * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
ohair@286 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ohair@286 | 4 | * |
ohair@286 | 5 | * This code is free software; you can redistribute it and/or modify it |
ohair@286 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@286 | 7 | * published by the Free Software Foundation. Oracle designates this |
ohair@286 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@286 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
ohair@286 | 10 | * |
ohair@286 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ohair@286 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ohair@286 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ohair@286 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
ohair@286 | 15 | * accompanied this code). |
ohair@286 | 16 | * |
ohair@286 | 17 | * You should have received a copy of the GNU General Public License version |
ohair@286 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
ohair@286 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ohair@286 | 20 | * |
ohair@286 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@286 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@286 | 23 | * questions. |
ohair@286 | 24 | */ |
ohair@286 | 25 | |
ohair@286 | 26 | package com.sun.xml.internal.ws.api.addressing; |
ohair@286 | 27 | |
ohair@286 | 28 | import java.net.URL; |
ohair@286 | 29 | |
ohair@286 | 30 | import com.sun.istack.internal.NotNull; |
ohair@286 | 31 | import com.sun.istack.internal.Nullable; |
ohair@286 | 32 | import com.sun.xml.internal.ws.api.FeatureConstructor; |
ohair@286 | 33 | |
ohair@286 | 34 | import javax.xml.ws.WebServiceFeature; |
ohair@286 | 35 | |
ohair@286 | 36 | import com.sun.org.glassfish.gmbal.ManagedAttribute; |
ohair@286 | 37 | import com.sun.org.glassfish.gmbal.ManagedData; |
ohair@286 | 38 | |
ohair@286 | 39 | /** |
ohair@286 | 40 | * Unsupported RI extension to work around an issue in WSIT. |
ohair@286 | 41 | * |
ohair@286 | 42 | * <p> |
ohair@286 | 43 | * <b>This feature is not meant to be used by a common Web service developer</b> as there |
ohair@286 | 44 | * is no need to send the above mentioned header for a one-way operation. But these |
ohair@286 | 45 | * properties may need to be sent in certain middleware Web services. |
ohair@286 | 46 | * |
ohair@286 | 47 | * <p> |
ohair@286 | 48 | * This feature allows ReplyTo, From and RelatesTo Message Addressing Properties |
ohair@286 | 49 | * to be added for all messages that are sent from the port configured with |
ohair@286 | 50 | * this annotation. All operations are assumed to be one-way, and |
ohair@286 | 51 | * this feature should be used for one-way |
ohair@286 | 52 | * operations only. |
ohair@286 | 53 | * |
ohair@286 | 54 | * If a non-null ReplyTo is specified, then MessageID property is also added. |
ohair@286 | 55 | * |
ohair@286 | 56 | * @author Arun Gupta |
ohair@286 | 57 | */ |
ohair@286 | 58 | @ManagedData |
ohair@286 | 59 | public class OneWayFeature extends WebServiceFeature { |
ohair@286 | 60 | /** |
ohair@286 | 61 | * Constant value identifying the {@link OneWayFeature} |
ohair@286 | 62 | */ |
ohair@286 | 63 | public static final String ID = "http://java.sun.com/xml/ns/jaxws/addressing/oneway"; |
ohair@286 | 64 | |
alanb@368 | 65 | private String messageId; |
ohair@286 | 66 | private WSEndpointReference replyTo; |
ohair@286 | 67 | private WSEndpointReference sslReplyTo; |
ohair@286 | 68 | private WSEndpointReference from; |
ohair@286 | 69 | private WSEndpointReference faultTo; |
ohair@286 | 70 | private WSEndpointReference sslFaultTo; |
ohair@286 | 71 | private String relatesToID; |
ohair@286 | 72 | private boolean useAsyncWithSyncInvoke = false; |
ohair@286 | 73 | |
ohair@286 | 74 | /** |
ohair@286 | 75 | * Create an {@link OneWayFeature}. The instance created will be enabled. |
ohair@286 | 76 | */ |
ohair@286 | 77 | public OneWayFeature() { |
ohair@286 | 78 | this.enabled = true; |
ohair@286 | 79 | } |
ohair@286 | 80 | |
ohair@286 | 81 | /** |
ohair@286 | 82 | * Create an {@link OneWayFeature} |
ohair@286 | 83 | * |
ohair@286 | 84 | * @param enabled specifies whether this feature should |
ohair@286 | 85 | * be enabled or not. |
ohair@286 | 86 | */ |
ohair@286 | 87 | public OneWayFeature(boolean enabled) { |
ohair@286 | 88 | this.enabled = enabled; |
ohair@286 | 89 | } |
ohair@286 | 90 | |
ohair@286 | 91 | /** |
ohair@286 | 92 | * Create an {@link OneWayFeature} |
ohair@286 | 93 | * |
ohair@286 | 94 | * @param enabled specifies whether this feature should be enabled or not. |
ohair@286 | 95 | * @param replyTo specifies the {@link WSEndpointReference} of wsa:ReplyTo header. |
ohair@286 | 96 | */ |
ohair@286 | 97 | public OneWayFeature(boolean enabled, WSEndpointReference replyTo) { |
ohair@286 | 98 | this.enabled = enabled; |
ohair@286 | 99 | this.replyTo = replyTo; |
ohair@286 | 100 | } |
ohair@286 | 101 | |
ohair@286 | 102 | /** |
ohair@286 | 103 | * Create an {@link OneWayFeature} |
ohair@286 | 104 | * |
ohair@286 | 105 | * @param enabled specifies whether this feature should be enabled or not. |
ohair@286 | 106 | * @param replyTo specifies the {@link WSEndpointReference} of wsa:ReplyTo header. |
ohair@286 | 107 | * @param from specifies the {@link WSEndpointReference} of wsa:From header. |
ohair@286 | 108 | * @param relatesTo specifies the MessageID to be used for wsa:RelatesTo header. |
ohair@286 | 109 | */ |
ohair@286 | 110 | @FeatureConstructor({"enabled","replyTo","from","relatesTo"}) |
ohair@286 | 111 | public OneWayFeature(boolean enabled, WSEndpointReference replyTo, WSEndpointReference from, String relatesTo) { |
ohair@286 | 112 | this.enabled = enabled; |
ohair@286 | 113 | this.replyTo = replyTo; |
ohair@286 | 114 | this.from = from; |
ohair@286 | 115 | this.relatesToID = relatesTo; |
ohair@286 | 116 | } |
ohair@286 | 117 | |
alanb@368 | 118 | public OneWayFeature(final AddressingPropertySet a, AddressingVersion v) { |
alanb@368 | 119 | this.enabled = true; |
alanb@368 | 120 | this.messageId = a.getMessageId(); |
alanb@368 | 121 | this.relatesToID = a.getRelatesTo(); |
alanb@368 | 122 | this.replyTo = makeEPR(a.getReplyTo(), v); |
alanb@368 | 123 | this.faultTo = makeEPR(a.getFaultTo(), v); |
alanb@368 | 124 | } |
alanb@368 | 125 | |
alanb@368 | 126 | private WSEndpointReference makeEPR(final String x, final AddressingVersion v) { |
alanb@368 | 127 | if (x == null) { return null; } |
alanb@368 | 128 | return new WSEndpointReference(x, v); |
alanb@368 | 129 | } |
alanb@368 | 130 | |
alanb@368 | 131 | public String getMessageId() { |
alanb@368 | 132 | return messageId; |
alanb@368 | 133 | } |
alanb@368 | 134 | |
ohair@286 | 135 | /** |
ohair@286 | 136 | * {@inheritDoc} |
ohair@286 | 137 | */ |
ohair@286 | 138 | @ManagedAttribute |
ohair@286 | 139 | public String getID() { |
ohair@286 | 140 | return ID; |
ohair@286 | 141 | } |
ohair@286 | 142 | |
ohair@286 | 143 | public boolean |
ohair@286 | 144 | hasSslEprs() { |
ohair@286 | 145 | return sslReplyTo != null || sslFaultTo != null; |
ohair@286 | 146 | } |
ohair@286 | 147 | |
ohair@286 | 148 | /** |
ohair@286 | 149 | * Getter for wsa:ReplyTo header {@link WSEndpointReference} . |
ohair@286 | 150 | * |
ohair@286 | 151 | * @return address of the wsa:ReplyTo header |
ohair@286 | 152 | */ |
ohair@286 | 153 | @ManagedAttribute |
ohair@286 | 154 | public WSEndpointReference getReplyTo() { |
ohair@286 | 155 | return replyTo; |
ohair@286 | 156 | } |
ohair@286 | 157 | |
ohair@286 | 158 | public WSEndpointReference getReplyTo(boolean ssl) { |
ohair@286 | 159 | return (ssl && sslReplyTo != null) ? sslReplyTo : replyTo; |
ohair@286 | 160 | } |
ohair@286 | 161 | |
ohair@286 | 162 | /** |
ohair@286 | 163 | * Setter for wsa:ReplyTo header {@link WSEndpointReference}. |
ohair@286 | 164 | * |
ohair@286 | 165 | * @param address |
ohair@286 | 166 | */ |
ohair@286 | 167 | public void setReplyTo(WSEndpointReference address) { |
ohair@286 | 168 | this.replyTo = address; |
ohair@286 | 169 | } |
ohair@286 | 170 | |
ohair@286 | 171 | public WSEndpointReference getSslReplyTo() { |
ohair@286 | 172 | return sslReplyTo; |
ohair@286 | 173 | } |
ohair@286 | 174 | |
ohair@286 | 175 | public void setSslReplyTo(WSEndpointReference sslReplyTo) { |
ohair@286 | 176 | this.sslReplyTo = sslReplyTo; |
ohair@286 | 177 | } |
ohair@286 | 178 | |
ohair@286 | 179 | /** |
ohair@286 | 180 | * Getter for wsa:From header {@link WSEndpointReference}. |
ohair@286 | 181 | * |
ohair@286 | 182 | * @return address of the wsa:From header |
ohair@286 | 183 | */ |
ohair@286 | 184 | @ManagedAttribute |
ohair@286 | 185 | public WSEndpointReference getFrom() { |
ohair@286 | 186 | return from; |
ohair@286 | 187 | } |
ohair@286 | 188 | |
ohair@286 | 189 | /** |
ohair@286 | 190 | * Setter for wsa:From header {@link WSEndpointReference}. |
ohair@286 | 191 | * |
ohair@286 | 192 | * @param address of the wsa:From header |
ohair@286 | 193 | */ |
ohair@286 | 194 | public void setFrom(WSEndpointReference address) { |
ohair@286 | 195 | this.from = address; |
ohair@286 | 196 | } |
ohair@286 | 197 | |
ohair@286 | 198 | /** |
ohair@286 | 199 | * Getter for MessageID for wsa:RelatesTo header. |
ohair@286 | 200 | * |
ohair@286 | 201 | * @return address of the wsa:FaultTo header |
ohair@286 | 202 | */ |
ohair@286 | 203 | @ManagedAttribute |
ohair@286 | 204 | public String getRelatesToID() { |
ohair@286 | 205 | return relatesToID; |
ohair@286 | 206 | } |
ohair@286 | 207 | |
ohair@286 | 208 | /** |
ohair@286 | 209 | * Setter for MessageID for wsa:RelatesTo header. |
ohair@286 | 210 | * |
ohair@286 | 211 | * @param id |
ohair@286 | 212 | */ |
ohair@286 | 213 | public void setRelatesToID(String id) { |
ohair@286 | 214 | this.relatesToID = id; |
ohair@286 | 215 | } |
ohair@286 | 216 | |
ohair@286 | 217 | /** |
ohair@286 | 218 | * Getter for wsa:FaultTo header {@link WSEndpointReference}. |
ohair@286 | 219 | * |
ohair@286 | 220 | * @return address of the wsa:FaultTo header |
ohair@286 | 221 | */ |
ohair@286 | 222 | public WSEndpointReference getFaultTo() { |
ohair@286 | 223 | return faultTo; |
ohair@286 | 224 | } |
ohair@286 | 225 | |
ohair@286 | 226 | public WSEndpointReference getFaultTo(boolean ssl) { |
ohair@286 | 227 | return (ssl && sslFaultTo != null) ? sslFaultTo : faultTo; |
ohair@286 | 228 | } |
ohair@286 | 229 | |
ohair@286 | 230 | /** |
ohair@286 | 231 | * Setter for wsa:FaultTo header {@link WSEndpointReference}. |
ohair@286 | 232 | * |
ohair@286 | 233 | * @param address of the wsa:FaultTo header |
ohair@286 | 234 | */ |
ohair@286 | 235 | public void setFaultTo(WSEndpointReference address) { |
ohair@286 | 236 | this.faultTo = address; |
ohair@286 | 237 | } |
ohair@286 | 238 | |
ohair@286 | 239 | public WSEndpointReference getSslFaultTo() { |
ohair@286 | 240 | return sslFaultTo; |
ohair@286 | 241 | } |
ohair@286 | 242 | |
ohair@286 | 243 | public void setSslFaultTo(WSEndpointReference sslFaultTo) { |
ohair@286 | 244 | this.sslFaultTo = sslFaultTo; |
ohair@286 | 245 | } |
ohair@286 | 246 | |
ohair@286 | 247 | /** |
ohair@286 | 248 | * Getter for whether async is to be used with sync invoke |
ohair@286 | 249 | * |
ohair@286 | 250 | * @return whether async is to be used with sync invoke |
ohair@286 | 251 | */ |
ohair@286 | 252 | public boolean isUseAsyncWithSyncInvoke() { |
ohair@286 | 253 | return useAsyncWithSyncInvoke; |
ohair@286 | 254 | } |
ohair@286 | 255 | |
ohair@286 | 256 | /** |
ohair@286 | 257 | * Setter for whether async is to be used with sync invoke |
ohair@286 | 258 | * |
ohair@286 | 259 | * @param useAsyncWithSyncInvoke whether async is to be used with sync invoke |
ohair@286 | 260 | */ |
ohair@286 | 261 | public void setUseAsyncWithSyncInvoke(boolean useAsyncWithSyncInvoke) { |
ohair@286 | 262 | this.useAsyncWithSyncInvoke = useAsyncWithSyncInvoke; |
ohair@286 | 263 | } |
ohair@286 | 264 | |
ohair@286 | 265 | /** |
ohair@286 | 266 | * Calculate a new EPR using an existing one and substituting SSL specific |
ohair@286 | 267 | * host and port values. |
ohair@286 | 268 | * @param epr Existing EPR that will be the starting point for the SSL |
ohair@286 | 269 | * version |
ohair@286 | 270 | * @param sslHost New SSL host or null if the existing host should be used |
ohair@286 | 271 | * @param sslPort New SSL port or -1 if the existing port should be used |
ohair@286 | 272 | * @return |
ohair@286 | 273 | */ |
ohair@286 | 274 | public static WSEndpointReference |
ohair@286 | 275 | enableSslForEpr(@NotNull WSEndpointReference epr, |
ohair@286 | 276 | @Nullable String sslHost, |
ohair@286 | 277 | int sslPort) { |
ohair@286 | 278 | if (!epr.isAnonymous()) { |
ohair@286 | 279 | String address = epr.getAddress(); |
ohair@286 | 280 | URL url; |
ohair@286 | 281 | try { |
ohair@286 | 282 | url = new URL(address); |
ohair@286 | 283 | } catch (Exception e) { |
ohair@286 | 284 | throw new RuntimeException(e); |
ohair@286 | 285 | } |
ohair@286 | 286 | String protocol = url.getProtocol(); |
ohair@286 | 287 | if (!protocol.equalsIgnoreCase("https")) { |
ohair@286 | 288 | protocol = "https"; |
ohair@286 | 289 | String host = url.getHost(); |
ohair@286 | 290 | if (sslHost != null) { |
ohair@286 | 291 | host = sslHost; |
ohair@286 | 292 | } |
ohair@286 | 293 | int port = url.getPort(); |
ohair@286 | 294 | if (sslPort > 0) { |
ohair@286 | 295 | port = sslPort; |
ohair@286 | 296 | } |
ohair@286 | 297 | try { |
ohair@286 | 298 | url = new URL(protocol, host, port, url.getFile()); |
ohair@286 | 299 | } catch (Exception e) { |
ohair@286 | 300 | throw new RuntimeException(e); |
ohair@286 | 301 | } |
ohair@286 | 302 | address = url.toExternalForm(); |
ohair@286 | 303 | return |
ohair@286 | 304 | new WSEndpointReference(address, epr.getVersion()); |
ohair@286 | 305 | } |
ohair@286 | 306 | } |
ohair@286 | 307 | |
ohair@286 | 308 | return epr; |
ohair@286 | 309 | } |
ohair@286 | 310 | |
ohair@286 | 311 | } |