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