src/share/jaxws_classes/com/sun/xml/internal/ws/addressing/WsaServerTube.java

Fri, 14 Feb 2014 11:13:45 +0100

author
mkos
date
Fri, 14 Feb 2014 11:13:45 +0100
changeset 515
6cd506508147
parent 368
0989ad8c0860
child 637
9c07ef4934dd
permissions
-rw-r--r--

8026188: Enhance envelope factory
Summary: Avoiding caching data initialized via TCCL in static context; fix also reviewed by Alexander Fomin
Reviewed-by: ahgross, mgrebac, skoivu

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.addressing;
ohair@286 27
ohair@286 28 import com.sun.istack.internal.NotNull;
ohair@286 29 import com.sun.istack.internal.Nullable;
ohair@286 30 import com.sun.xml.internal.ws.addressing.model.ActionNotSupportedException;
ohair@286 31 import com.sun.xml.internal.ws.addressing.model.InvalidAddressingHeaderException;
ohair@286 32 import com.sun.xml.internal.ws.api.EndpointAddress;
ohair@286 33 import com.sun.xml.internal.ws.api.SOAPVersion;
ohair@286 34 import com.sun.xml.internal.ws.api.WSBinding;
ohair@286 35 import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
ohair@286 36 import com.sun.xml.internal.ws.api.addressing.NonAnonymousResponseProcessor;
ohair@286 37 import com.sun.xml.internal.ws.api.addressing.WSEndpointReference;
alanb@368 38 import com.sun.xml.internal.ws.api.message.AddressingUtils;
ohair@286 39 import com.sun.xml.internal.ws.api.message.Message;
alanb@368 40 import com.sun.xml.internal.ws.api.message.MessageHeaders;
ohair@286 41 import com.sun.xml.internal.ws.api.message.Messages;
ohair@286 42 import com.sun.xml.internal.ws.api.message.Packet;
ohair@286 43 import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
ohair@286 44 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
ohair@286 45 import com.sun.xml.internal.ws.api.pipe.*;
ohair@286 46 import com.sun.xml.internal.ws.api.server.WSEndpoint;
ohair@286 47 import com.sun.xml.internal.ws.client.Stub;
ohair@286 48 import com.sun.xml.internal.ws.developer.JAXWSProperties;
ohair@286 49 import com.sun.xml.internal.ws.fault.SOAPFaultBuilder;
ohair@286 50 import com.sun.xml.internal.ws.message.FaultDetailHeader;
ohair@286 51 import com.sun.xml.internal.ws.resources.AddressingMessages;
ohair@286 52
ohair@286 53 import javax.xml.soap.SOAPFault;
ohair@286 54 import javax.xml.ws.WebServiceException;
ohair@286 55 import java.net.URI;
ohair@286 56 import java.util.logging.Level;
ohair@286 57 import java.util.logging.Logger;
ohair@286 58
ohair@286 59 /**
ohair@286 60 * Handles WS-Addressing for the server.
ohair@286 61 *
ohair@286 62 * @author Rama Pulavarthi
ohair@286 63 * @author Kohsuke Kawaguchi
ohair@286 64 * @author Arun Gupta
ohair@286 65 */
ohair@286 66 public class WsaServerTube extends WsaTube {
ohair@286 67 private WSEndpoint endpoint;
ohair@286 68 // store the replyTo/faultTo of the message currently being processed.
ohair@286 69 // both will be set to non-null in processRequest
ohair@286 70 private WSEndpointReference replyTo;
ohair@286 71 private WSEndpointReference faultTo;
ohair@286 72 private boolean isAnonymousRequired = false;
ohair@286 73 // Used by subclasses to avoid this class closing the transport back
ohair@286 74 // channel based on the ReplyTo/FaultTo addrs being non-anonymous. False
ohair@286 75 // can be useful in cases where special back-channel handling is required.
ohair@286 76 protected boolean isEarlyBackchannelCloseAllowed = true;
ohair@286 77
ohair@286 78 /**
ohair@286 79 * WSDLBoundOperation calculated on the Request payload.
ohair@286 80 * Used for determining ReplyTo or Fault Action for non-anonymous responses *
ohair@286 81 */
ohair@286 82 private WSDLBoundOperation wbo;
ohair@286 83 public WsaServerTube(WSEndpoint endpoint, @NotNull WSDLPort wsdlPort, WSBinding binding, Tube next) {
ohair@286 84 super(wsdlPort, binding, next);
ohair@286 85 this.endpoint = endpoint;
ohair@286 86 }
ohair@286 87
ohair@286 88 public WsaServerTube(WsaServerTube that, TubeCloner cloner) {
ohair@286 89 super(that, cloner);
ohair@286 90 endpoint = that.endpoint;
ohair@286 91 }
ohair@286 92
alanb@368 93 @Override
ohair@286 94 public WsaServerTube copy(TubeCloner cloner) {
ohair@286 95 return new WsaServerTube(this, cloner);
ohair@286 96 }
ohair@286 97
ohair@286 98 @Override
ohair@286 99 public @NotNull NextAction processRequest(Packet request) {
ohair@286 100 Message msg = request.getMessage();
alanb@368 101 if (msg == null) {
alanb@368 102 return doInvoke(next,request);
alanb@368 103 } // hmm?
ohair@286 104
ohair@286 105 // expose bunch of addressing related properties for advanced applications
ohair@286 106 request.addSatellite(new WsaPropertyBag(addressingVersion,soapVersion,request));
ohair@286 107
ohair@286 108 // Store request ReplyTo and FaultTo in requestPacket.invocationProperties
ohair@286 109 // so that they can be used after responsePacket is received.
ohair@286 110 // These properties are used if a fault is thrown from the subsequent Pipe/Tubes.
ohair@286 111
alanb@368 112 MessageHeaders hl = request.getMessage().getHeaders();
ohair@286 113 String msgId;
ohair@286 114 try {
alanb@368 115 replyTo = AddressingUtils.getReplyTo(hl, addressingVersion, soapVersion);
alanb@368 116 faultTo = AddressingUtils.getFaultTo(hl, addressingVersion, soapVersion);
alanb@368 117 msgId = AddressingUtils.getMessageID(hl, addressingVersion, soapVersion);
ohair@286 118 } catch (InvalidAddressingHeaderException e) {
ohair@286 119
ohair@286 120 LOGGER.log(Level.WARNING, addressingVersion.getInvalidMapText()+", Problem header:" + e.getProblemHeader()+ ", Reason: "+ e.getSubsubcode(),e);
ohair@286 121
ohair@286 122 // problematic header must be removed since it can fail during Fault message processing
ohair@286 123 hl.remove(e.getProblemHeader());
ohair@286 124
ohair@286 125 SOAPFault soapFault = helper.createInvalidAddressingHeaderFault(e, addressingVersion);
ohair@286 126 // WS-A fault processing for one-way methods
ohair@286 127 if ((wsdlPort!=null) && request.getMessage().isOneWay(wsdlPort)) {
ohair@286 128 Packet response = request.createServerResponse(null, wsdlPort, null, binding);
ohair@286 129 return doReturnWith(response);
ohair@286 130 }
ohair@286 131
ohair@286 132 Message m = Messages.create(soapFault);
ohair@286 133 if (soapVersion == SOAPVersion.SOAP_11) {
ohair@286 134 FaultDetailHeader s11FaultDetailHeader = new FaultDetailHeader(addressingVersion, addressingVersion.problemHeaderQNameTag.getLocalPart(), e.getProblemHeader());
ohair@286 135 m.getHeaders().add(s11FaultDetailHeader);
ohair@286 136 }
ohair@286 137
ohair@286 138 Packet response = request.createServerResponse(m, wsdlPort, null, binding);
ohair@286 139 return doReturnWith(response);
ohair@286 140 }
ohair@286 141
ohair@286 142 // defaulting
alanb@368 143 if (replyTo == null) {
alanb@368 144 replyTo = addressingVersion.anonymousEpr;
alanb@368 145 }
alanb@368 146 if (faultTo == null) {
alanb@368 147 faultTo = replyTo;
alanb@368 148 }
ohair@286 149
ohair@286 150 // Save a copy into the packet such that we can save it with that
ohair@286 151 // packet if we're going to deliver the response at a later time
ohair@286 152 // (async from the request).
ohair@286 153 request.put(WsaPropertyBag.WSA_REPLYTO_FROM_REQUEST, replyTo);
ohair@286 154 request.put(WsaPropertyBag.WSA_FAULTTO_FROM_REQUEST, faultTo);
ohair@286 155 request.put(WsaPropertyBag.WSA_MSGID_FROM_REQUEST, msgId);
ohair@286 156
ohair@286 157 wbo = getWSDLBoundOperation(request);
ohair@286 158 isAnonymousRequired = isAnonymousRequired(wbo);
ohair@286 159
ohair@286 160 Packet p = validateInboundHeaders(request);
ohair@286 161 // if one-way message and WS-A header processing fault has occurred,
ohair@286 162 // then do no further processing
alanb@368 163 if (p.getMessage() == null) {
ohair@286 164 return doReturnWith(p);
alanb@368 165 }
ohair@286 166
ohair@286 167 // if we find an error in addressing header, just turn around the direction here
ohair@286 168 if (p.getMessage().isFault()) {
ohair@286 169 // close the transportBackChannel if we know that
ohair@286 170 // we'll never use them
ohair@286 171 if (isEarlyBackchannelCloseAllowed &&
ohair@286 172 !(isAnonymousRequired) &&
ohair@286 173 !faultTo.isAnonymous() && request.transportBackChannel != null) {
ohair@286 174 request.transportBackChannel.close();
ohair@286 175 }
ohair@286 176 return processResponse(p);
ohair@286 177 }
ohair@286 178 // close the transportBackChannel if we know that
ohair@286 179 // we'll never use them
ohair@286 180 if (isEarlyBackchannelCloseAllowed &&
ohair@286 181 !(isAnonymousRequired) &&
ohair@286 182 !replyTo.isAnonymous() && !faultTo.isAnonymous() &&
ohair@286 183 request.transportBackChannel != null) {
ohair@286 184 request.transportBackChannel.close();
ohair@286 185 }
ohair@286 186 return doInvoke(next,p);
ohair@286 187 }
ohair@286 188
ohair@286 189 protected boolean isAnonymousRequired(@Nullable WSDLBoundOperation wbo) {
ohair@286 190 //this requirement can only be specified in W3C case, Override this in W3C case.
ohair@286 191 return false;
ohair@286 192 }
ohair@286 193
ohair@286 194 protected void checkAnonymousSemantics(WSDLBoundOperation wbo, WSEndpointReference replyTo, WSEndpointReference faultTo) {
ohair@286 195 //this requirement can only be specified in W3C case, Override this in W3C case.
ohair@286 196 }
ohair@286 197
ohair@286 198 @Override
ohair@286 199 public @NotNull NextAction processException(Throwable t) {
alanb@368 200 final Packet response = Fiber.current().getPacket();
alanb@368 201 ThrowableContainerPropertySet tc = response.getSatellite(ThrowableContainerPropertySet.class);
alanb@368 202 if (tc == null) {
alanb@368 203 tc = new ThrowableContainerPropertySet(t);
alanb@368 204 response.addSatellite(tc);
alanb@368 205 } else if (t != tc.getThrowable()) {
alanb@368 206 // This is a pathological case where an exception happens after a previous exception.
alanb@368 207 // Make sure you report the latest one.
alanb@368 208 tc.setThrowable(t);
alanb@368 209 }
alanb@368 210 return processResponse(response.endpoint.createServiceResponseForException(tc, response, soapVersion, wsdlPort,
alanb@368 211 response.endpoint.getSEIModel(),
alanb@368 212 binding));
ohair@286 213 }
ohair@286 214
ohair@286 215 @Override
ohair@286 216 public @NotNull NextAction processResponse(Packet response) {
ohair@286 217 Message msg = response.getMessage();
alanb@368 218 if (msg ==null) {
alanb@368 219 return doReturnWith(response);
alanb@368 220 } // one way message. Nothing to see here. Move on.
ohair@286 221
alanb@368 222 String to = AddressingUtils.getTo(msg.getHeaders(),
alanb@368 223 addressingVersion, soapVersion);
ohair@286 224 if (to != null) {
ohair@286 225 replyTo = faultTo = new WSEndpointReference(to, addressingVersion);
ohair@286 226 }
ohair@286 227
ohair@286 228 if (replyTo == null) {
ohair@286 229 // This is an async response or we're not processing the response in
ohair@286 230 // the same tube instance as we processed the request. Get the ReplyTo
ohair@286 231 // now, from the properties we stored into the request packet. We
ohair@286 232 // assume anyone that interrupted the request->response flow will have
ohair@286 233 // saved the ReplyTo and put it back into the packet for our use.
ohair@286 234 replyTo = (WSEndpointReference)response.
ohair@286 235 get(WsaPropertyBag.WSA_REPLYTO_FROM_REQUEST);
ohair@286 236 }
ohair@286 237
ohair@286 238 if (faultTo == null) {
ohair@286 239 // This is an async response or we're not processing the response in
ohair@286 240 // the same tube instance as we processed the request. Get the FaultTo
ohair@286 241 // now, from the properties we stored into the request packet. We
ohair@286 242 // assume anyone that interrupted the request->response flow will have
ohair@286 243 // saved the FaultTo and put it back into the packet for our use.
ohair@286 244 faultTo = (WSEndpointReference)response.
ohair@286 245 get(WsaPropertyBag.WSA_FAULTTO_FROM_REQUEST);
ohair@286 246 }
ohair@286 247
alanb@368 248 WSEndpointReference target = msg.isFault() ? faultTo : replyTo;
ohair@286 249 if (target == null && response.proxy instanceof Stub) {
ohair@286 250 target = ((Stub) response.proxy).getWSEndpointReference();
ohair@286 251 }
alanb@368 252 if (target == null || target.isAnonymous() || isAnonymousRequired) {
ohair@286 253 return doReturnWith(response);
alanb@368 254 }
alanb@368 255 if (target.isNone()) {
ohair@286 256 // the caller doesn't want to hear about it, so proceed like one-way
ohair@286 257 response.setMessage(null);
ohair@286 258 return doReturnWith(response);
ohair@286 259 }
ohair@286 260
ohair@286 261 if ((wsdlPort!=null) && response.getMessage().isOneWay(wsdlPort)) {
ohair@286 262 // one way message but with replyTo. I believe this is a hack for WS-TX - KK.
ohair@286 263 LOGGER.fine(AddressingMessages.NON_ANONYMOUS_RESPONSE_ONEWAY());
ohair@286 264 return doReturnWith(response);
ohair@286 265 }
ohair@286 266
ohair@286 267 // MTU: If we're not sending a response that corresponds to a WSDL op,
ohair@286 268 // then take whatever soapAction is set on the packet (as allowing
ohair@286 269 // helper.getOutputAction() will only result in a bogus 'unset'
ohair@286 270 // action value.
ohair@286 271 if (wbo != null || response.soapAction == null) {
ohair@286 272 String action = response.getMessage().isFault() ?
ohair@286 273 helper.getFaultAction(wbo, response) :
ohair@286 274 helper.getOutputAction(wbo);
ohair@286 275 //set the SOAPAction, as its got to be same as wsa:Action
ohair@286 276 if (response.soapAction == null ||
ohair@286 277 (action != null &&
ohair@286 278 !action.equals(AddressingVersion.UNSET_OUTPUT_ACTION))) {
ohair@286 279 response.soapAction = action;
ohair@286 280 }
ohair@286 281 }
ohair@286 282 response.expectReply = false;
ohair@286 283
ohair@286 284 EndpointAddress adrs;
ohair@286 285 try {
ohair@286 286 adrs = new EndpointAddress(URI.create(target.getAddress()));
ohair@286 287 } catch (NullPointerException e) {
ohair@286 288 throw new WebServiceException(e);
ohair@286 289 } catch (IllegalArgumentException e) {
ohair@286 290 throw new WebServiceException(e);
ohair@286 291 }
ohair@286 292
ohair@286 293 response.endpointAddress = adrs;
ohair@286 294
ohair@286 295 if (response.isAdapterDeliversNonAnonymousResponse) {
ohair@286 296 return doReturnWith(response);
ohair@286 297 }
ohair@286 298
ohair@286 299 return doReturnWith(NonAnonymousResponseProcessor.getDefault().process(response));
ohair@286 300 }
ohair@286 301
ohair@286 302 @Override
ohair@286 303 protected void validateAction(Packet packet) {
ohair@286 304 //There may not be a WSDL operation. There may not even be a WSDL.
ohair@286 305 //For instance this may be a RM CreateSequence message.
ohair@286 306 WSDLBoundOperation wsdlBoundOperation = getWSDLBoundOperation(packet);
ohair@286 307
alanb@368 308 if (wsdlBoundOperation == null) {
ohair@286 309 return;
alanb@368 310 }
ohair@286 311
alanb@368 312 String gotA = AddressingUtils.getAction(
alanb@368 313 packet.getMessage().getHeaders(),
alanb@368 314 addressingVersion, soapVersion);
ohair@286 315
alanb@368 316 if (gotA == null) {
ohair@286 317 throw new WebServiceException(AddressingMessages.VALIDATION_SERVER_NULL_ACTION());
alanb@368 318 }
ohair@286 319
ohair@286 320 String expected = helper.getInputAction(packet);
ohair@286 321 String soapAction = helper.getSOAPAction(packet);
alanb@368 322 if (helper.isInputActionDefault(packet) && (soapAction != null && !soapAction.equals(""))) {
ohair@286 323 expected = soapAction;
alanb@368 324 }
ohair@286 325
ohair@286 326 if (expected != null && !gotA.equals(expected)) {
ohair@286 327 throw new ActionNotSupportedException(gotA);
ohair@286 328 }
ohair@286 329 }
ohair@286 330
ohair@286 331 @Override
ohair@286 332 protected void checkMessageAddressingProperties(Packet packet) {
ohair@286 333 super.checkMessageAddressingProperties(packet);
ohair@286 334
ohair@286 335 // wsaw:Anonymous validation
ohair@286 336 WSDLBoundOperation wsdlBoundOperation = getWSDLBoundOperation(packet);
ohair@286 337 checkAnonymousSemantics(wsdlBoundOperation, replyTo, faultTo);
ohair@286 338 // check if addresses are valid
ohair@286 339 checkNonAnonymousAddresses(replyTo,faultTo);
ohair@286 340 }
ohair@286 341
alanb@368 342 @SuppressWarnings("ResultOfObjectAllocationIgnored")
ohair@286 343 private void checkNonAnonymousAddresses(WSEndpointReference replyTo, WSEndpointReference faultTo) {
ohair@286 344 if (!replyTo.isAnonymous()) {
ohair@286 345 try {
ohair@286 346 new EndpointAddress(URI.create(replyTo.getAddress()));
ohair@286 347 } catch (Exception e) {
ohair@286 348 throw new InvalidAddressingHeaderException(addressingVersion.replyToTag, addressingVersion.invalidAddressTag);
ohair@286 349 }
ohair@286 350 }
ohair@286 351 //for now only validate ReplyTo
ohair@286 352 /*
ohair@286 353 if (!faultTo.isAnonymous()) {
ohair@286 354 try {
ohair@286 355 new EndpointAddress(URI.create(faultTo.getAddress()));
ohair@286 356 } catch (IllegalArgumentException e) {
ohair@286 357 throw new InvalidAddressingHeaderException(addressingVersion.faultToTag, addressingVersion.invalidAddressTag);
ohair@286 358 }
ohair@286 359 }
ohair@286 360 */
ohair@286 361
ohair@286 362 }
ohair@286 363
ohair@286 364 /**
ohair@286 365 * @deprecated
ohair@286 366 * Use {@link JAXWSProperties#ADDRESSING_MESSAGEID}.
ohair@286 367 */
ohair@286 368 public static final String REQUEST_MESSAGE_ID = "com.sun.xml.internal.ws.addressing.request.messageID";
ohair@286 369
ohair@286 370 private static final Logger LOGGER = Logger.getLogger(WsaServerTube.class.getName());
ohair@286 371 }

mercurial