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

Fri, 04 Oct 2013 16:21:34 +0100

author
mkos
date
Fri, 04 Oct 2013 16:21:34 +0100
changeset 408
b0610cd08440
parent 368
0989ad8c0860
child 637
9c07ef4934dd
permissions
-rw-r--r--

8025054: Update JAX-WS RI integration to 2.2.9-b130926.1035
Reviewed-by: chegar

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.xml.internal.ws.addressing.model.InvalidAddressingHeaderException;
ohair@286 29 import com.sun.xml.internal.ws.addressing.model.MissingAddressingHeaderException;
ohair@286 30 import com.sun.xml.internal.ws.api.SOAPVersion;
ohair@286 31 import com.sun.xml.internal.ws.api.WSBinding;
ohair@286 32 import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
alanb@368 33 import com.sun.xml.internal.ws.api.message.AddressingUtils;
ohair@286 34 import com.sun.xml.internal.ws.api.message.Packet;
ohair@286 35 import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
ohair@286 36 import com.sun.xml.internal.ws.api.model.wsdl.WSDLFault;
ohair@286 37 import com.sun.xml.internal.ws.api.model.wsdl.WSDLOperation;
ohair@286 38 import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;
ohair@286 39 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
ohair@286 40 import com.sun.xml.internal.ws.api.model.SEIModel;
ohair@286 41 import com.sun.xml.internal.ws.api.model.JavaMethod;
alanb@368 42 import com.sun.xml.internal.ws.api.model.WSDLOperationMapping;
ohair@286 43 import com.sun.xml.internal.ws.model.JavaMethodImpl;
ohair@286 44 import com.sun.xml.internal.ws.model.CheckedExceptionImpl;
ohair@286 45 import com.sun.istack.internal.Nullable;
ohair@286 46 import org.w3c.dom.Element;
ohair@286 47
ohair@286 48 import javax.xml.namespace.QName;
ohair@286 49 import javax.xml.soap.Detail;
ohair@286 50 import javax.xml.soap.SOAPConstants;
ohair@286 51 import javax.xml.soap.SOAPException;
ohair@286 52 import javax.xml.soap.SOAPFactory;
ohair@286 53 import javax.xml.soap.SOAPFault;
ohair@286 54 import javax.xml.soap.SOAPMessage;
ohair@286 55 import javax.xml.ws.WebServiceException;
ohair@286 56
ohair@286 57 /**
ohair@286 58 * @author Rama Pulavarthi
ohair@286 59 * @author Arun Gupta
ohair@286 60 */
ohair@286 61 public abstract class WsaTubeHelper {
ohair@286 62
ohair@286 63 public WsaTubeHelper(WSBinding binding, SEIModel seiModel, WSDLPort wsdlPort) {
ohair@286 64 this.binding = binding;
ohair@286 65 this.wsdlPort = wsdlPort;
ohair@286 66 this.seiModel = seiModel;
ohair@286 67 this.soapVer = binding.getSOAPVersion();
ohair@286 68 this.addVer = binding.getAddressingVersion();
ohair@286 69
ohair@286 70 }
ohair@286 71
ohair@286 72 public String getFaultAction(Packet requestPacket, Packet responsePacket) {
ohair@286 73 String action = null;
ohair@286 74 if(seiModel != null) {
ohair@286 75 action = getFaultActionFromSEIModel(requestPacket,responsePacket);
ohair@286 76 }
alanb@368 77 if (action != null) {
ohair@286 78 return action;
alanb@368 79 } else {
ohair@286 80 action = addVer.getDefaultFaultAction();
alanb@368 81 }
ohair@286 82 if (wsdlPort != null) {
alanb@368 83 WSDLOperationMapping wsdlOp = requestPacket.getWSDLOperationMapping();
ohair@286 84 if (wsdlOp != null) {
alanb@368 85 WSDLBoundOperation wbo = wsdlOp.getWSDLBoundOperation();
ohair@286 86 return getFaultAction(wbo, responsePacket);
ohair@286 87 }
ohair@286 88 }
ohair@286 89 return action;
ohair@286 90 }
ohair@286 91
ohair@286 92 String getFaultActionFromSEIModel(Packet requestPacket, Packet responsePacket) {
ohair@286 93 String action = null;
alanb@368 94 if (seiModel == null || wsdlPort == null) {
ohair@286 95 return action;
alanb@368 96 }
ohair@286 97
ohair@286 98 try {
ohair@286 99 SOAPMessage sm = responsePacket.getMessage().copy().readAsSOAPMessage();
alanb@368 100 if (sm == null) {
ohair@286 101 return action;
alanb@368 102 }
ohair@286 103
alanb@368 104 if (sm.getSOAPBody() == null) {
ohair@286 105 return action;
alanb@368 106 }
ohair@286 107
alanb@368 108 if (sm.getSOAPBody().getFault() == null) {
ohair@286 109 return action;
alanb@368 110 }
ohair@286 111
ohair@286 112 Detail detail = sm.getSOAPBody().getFault().getDetail();
alanb@368 113 if (detail == null) {
ohair@286 114 return action;
alanb@368 115 }
ohair@286 116
ohair@286 117 String ns = detail.getFirstChild().getNamespaceURI();
ohair@286 118 String name = detail.getFirstChild().getLocalName();
ohair@286 119
alanb@368 120 WSDLOperationMapping wsdlOp = requestPacket.getWSDLOperationMapping();
alanb@368 121 JavaMethodImpl jm = (wsdlOp != null) ? (JavaMethodImpl)wsdlOp.getJavaMethod() : null;
ohair@286 122 if (jm != null) {
ohair@286 123 for (CheckedExceptionImpl ce : jm.getCheckedExceptions()) {
ohair@286 124 if (ce.getDetailType().tagName.getLocalPart().equals(name) &&
ohair@286 125 ce.getDetailType().tagName.getNamespaceURI().equals(ns)) {
ohair@286 126 return ce.getFaultAction();
ohair@286 127 }
ohair@286 128 }
ohair@286 129 }
ohair@286 130 return action;
ohair@286 131 } catch (SOAPException e) {
ohair@286 132 throw new WebServiceException(e);
ohair@286 133 }
ohair@286 134 }
ohair@286 135
ohair@286 136 String getFaultAction(@Nullable WSDLBoundOperation wbo, Packet responsePacket) {
alanb@368 137 String action = AddressingUtils.getAction(responsePacket.getMessage().getHeaders(), addVer, soapVer);
alanb@368 138 if (action != null) {
alanb@368 139 return action;
alanb@368 140 }
ohair@286 141
ohair@286 142 action = addVer.getDefaultFaultAction();
alanb@368 143 if (wbo == null) {
ohair@286 144 return action;
alanb@368 145 }
ohair@286 146
ohair@286 147 try {
ohair@286 148 SOAPMessage sm = responsePacket.getMessage().copy().readAsSOAPMessage();
alanb@368 149 if (sm == null) {
ohair@286 150 return action;
alanb@368 151 }
ohair@286 152
alanb@368 153 if (sm.getSOAPBody() == null) {
ohair@286 154 return action;
alanb@368 155 }
ohair@286 156
alanb@368 157 if (sm.getSOAPBody().getFault() == null) {
ohair@286 158 return action;
alanb@368 159 }
ohair@286 160
ohair@286 161 Detail detail = sm.getSOAPBody().getFault().getDetail();
alanb@368 162 if (detail == null) {
ohair@286 163 return action;
alanb@368 164 }
ohair@286 165
ohair@286 166 String ns = detail.getFirstChild().getNamespaceURI();
ohair@286 167 String name = detail.getFirstChild().getLocalName();
ohair@286 168
ohair@286 169 WSDLOperation o = wbo.getOperation();
ohair@286 170
ohair@286 171 WSDLFault fault = o.getFault(new QName(ns, name));
alanb@368 172 if (fault == null) {
ohair@286 173 return action;
alanb@368 174 }
ohair@286 175
ohair@286 176 action = fault.getAction();
ohair@286 177
ohair@286 178 return action;
ohair@286 179 } catch (SOAPException e) {
ohair@286 180 throw new WebServiceException(e);
ohair@286 181 }
ohair@286 182 }
ohair@286 183
ohair@286 184 public String getInputAction(Packet packet) {
ohair@286 185 String action = null;
ohair@286 186
ohair@286 187 if (wsdlPort != null) {
alanb@368 188 WSDLOperationMapping wsdlOp = packet.getWSDLOperationMapping();
ohair@286 189 if (wsdlOp != null) {
alanb@368 190 WSDLBoundOperation wbo = wsdlOp.getWSDLBoundOperation();
ohair@286 191 WSDLOperation op = wbo.getOperation();
ohair@286 192 action = op.getInput().getAction();
ohair@286 193 }
ohair@286 194 }
ohair@286 195
ohair@286 196 return action;
ohair@286 197 }
ohair@286 198
ohair@286 199 /**
ohair@286 200 * This method gives the Input addressing Action for a message.
ohair@286 201 * It gives the Action set in the wsdl operation for the corresponding payload.
ohair@286 202 * If it is not explicitly set, it gives the soapAction
ohair@286 203 * @param packet
ohair@286 204 * @return input Action
ohair@286 205 */
ohair@286 206 public String getEffectiveInputAction(Packet packet) {
ohair@286 207 //non-default SOAPAction beomes wsa:action
alanb@368 208 if(packet.soapAction != null && !packet.soapAction.equals("")) {
alanb@368 209 return packet.soapAction;
alanb@368 210 }
alanb@368 211 String action;
ohair@286 212
ohair@286 213 if (wsdlPort != null) {
alanb@368 214 WSDLOperationMapping wsdlOp = packet.getWSDLOperationMapping();
ohair@286 215 if (wsdlOp != null) {
alanb@368 216 WSDLBoundOperation wbo = wsdlOp.getWSDLBoundOperation();
ohair@286 217 WSDLOperation op = wbo.getOperation();
ohair@286 218 action = op.getInput().getAction();
alanb@368 219 } else {
ohair@286 220 action = packet.soapAction;
alanb@368 221 }
ohair@286 222 } else {
ohair@286 223 action = packet.soapAction;
ohair@286 224 }
ohair@286 225 return action;
ohair@286 226 }
ohair@286 227
ohair@286 228 public boolean isInputActionDefault(Packet packet) {
alanb@368 229 if (wsdlPort == null) {
ohair@286 230 return false;
alanb@368 231 }
alanb@368 232 WSDLOperationMapping wsdlOp = packet.getWSDLOperationMapping();
alanb@368 233 if(wsdlOp == null) {
ohair@286 234 return false;
alanb@368 235 }
alanb@368 236 WSDLBoundOperation wbo = wsdlOp.getWSDLBoundOperation();
ohair@286 237 WSDLOperation op = wbo.getOperation();
mkos@408 238 return op.getInput().isDefaultAction();
ohair@286 239
ohair@286 240 }
ohair@286 241
ohair@286 242 public String getSOAPAction(Packet packet) {
ohair@286 243 String action = "";
ohair@286 244
alanb@368 245 if (packet == null || packet.getMessage() == null) {
ohair@286 246 return action;
alanb@368 247 }
ohair@286 248
alanb@368 249 if (wsdlPort == null) {
ohair@286 250 return action;
alanb@368 251 }
ohair@286 252
alanb@368 253 WSDLOperationMapping wsdlOp = packet.getWSDLOperationMapping();
alanb@368 254 if (wsdlOp == null) {
ohair@286 255 return action;
alanb@368 256 }
ohair@286 257
alanb@368 258 WSDLBoundOperation op = wsdlOp.getWSDLBoundOperation();
ohair@286 259 action = op.getSOAPAction();
ohair@286 260 return action;
ohair@286 261 }
ohair@286 262
ohair@286 263 public String getOutputAction(Packet packet) {
ohair@286 264 //String action = AddressingVersion.UNSET_OUTPUT_ACTION;
ohair@286 265 String action = null;
alanb@368 266 WSDLOperationMapping wsdlOp = packet.getWSDLOperationMapping();
ohair@286 267 if (wsdlOp != null) {
alanb@368 268 JavaMethod javaMethod = wsdlOp.getJavaMethod();
alanb@368 269 if (javaMethod != null) {
alanb@368 270 JavaMethodImpl jm = (JavaMethodImpl) javaMethod;
ohair@286 271 if (jm != null && jm.getOutputAction() != null && !jm.getOutputAction().equals("")) {
ohair@286 272 return jm.getOutputAction();
ohair@286 273 }
ohair@286 274 }
alanb@368 275 WSDLBoundOperation wbo = wsdlOp.getWSDLBoundOperation();
alanb@368 276 if (wbo != null) return getOutputAction(wbo);
ohair@286 277 }
ohair@286 278 return action;
ohair@286 279 }
ohair@286 280
ohair@286 281 String getOutputAction(@Nullable WSDLBoundOperation wbo) {
ohair@286 282 String action = AddressingVersion.UNSET_OUTPUT_ACTION;
ohair@286 283 if (wbo != null) {
ohair@286 284 WSDLOutput op = wbo.getOperation().getOutput();
alanb@368 285 if (op != null) {
ohair@286 286 action = op.getAction();
alanb@368 287 }
ohair@286 288 }
ohair@286 289 return action;
ohair@286 290 }
ohair@286 291
ohair@286 292 public SOAPFault createInvalidAddressingHeaderFault(InvalidAddressingHeaderException e, AddressingVersion av) {
ohair@286 293 QName name = e.getProblemHeader();
ohair@286 294 QName subsubcode = e.getSubsubcode();
ohair@286 295 QName subcode = av.invalidMapTag;
ohair@286 296 String faultstring = String.format(av.getInvalidMapText(), name, subsubcode);
ohair@286 297
ohair@286 298 try {
ohair@286 299 SOAPFactory factory;
ohair@286 300 SOAPFault fault;
ohair@286 301 if (soapVer == SOAPVersion.SOAP_12) {
ohair@286 302 factory = SOAPVersion.SOAP_12.getSOAPFactory();
ohair@286 303 fault = factory.createFault();
ohair@286 304 fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
ohair@286 305 fault.appendFaultSubcode(subcode);
ohair@286 306 fault.appendFaultSubcode(subsubcode);
ohair@286 307 getInvalidMapDetail(name, fault.addDetail());
ohair@286 308 } else {
ohair@286 309 factory = SOAPVersion.SOAP_11.getSOAPFactory();
ohair@286 310 fault = factory.createFault();
ohair@286 311 fault.setFaultCode(subsubcode);
ohair@286 312 }
ohair@286 313
ohair@286 314 fault.setFaultString(faultstring);
ohair@286 315
ohair@286 316 return fault;
ohair@286 317 } catch (SOAPException se) {
ohair@286 318 throw new WebServiceException(se);
ohair@286 319 }
ohair@286 320 }
ohair@286 321
ohair@286 322 public SOAPFault newMapRequiredFault(MissingAddressingHeaderException e) {
ohair@286 323 QName subcode = addVer.mapRequiredTag;
ohair@286 324 QName subsubcode = addVer.mapRequiredTag;
ohair@286 325 String faultstring = addVer.getMapRequiredText();
ohair@286 326
ohair@286 327 try {
ohair@286 328 SOAPFactory factory;
ohair@286 329 SOAPFault fault;
ohair@286 330 if (soapVer == SOAPVersion.SOAP_12) {
ohair@286 331 factory = SOAPVersion.SOAP_12.getSOAPFactory();
ohair@286 332 fault = factory.createFault();
ohair@286 333 fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
ohair@286 334 fault.appendFaultSubcode(subcode);
ohair@286 335 fault.appendFaultSubcode(subsubcode);
ohair@286 336 getMapRequiredDetail(e.getMissingHeaderQName(), fault.addDetail());
ohair@286 337 } else {
ohair@286 338 factory = SOAPVersion.SOAP_11.getSOAPFactory();
ohair@286 339 fault = factory.createFault();
ohair@286 340 fault.setFaultCode(subsubcode);
ohair@286 341 }
ohair@286 342
ohair@286 343 fault.setFaultString(faultstring);
ohair@286 344
ohair@286 345 return fault;
ohair@286 346 } catch (SOAPException se) {
ohair@286 347 throw new WebServiceException(se);
ohair@286 348 }
ohair@286 349 }
ohair@286 350
ohair@286 351 public abstract void getProblemActionDetail(String action, Element element);
ohair@286 352 public abstract void getInvalidMapDetail(QName name, Element element);
ohair@286 353 public abstract void getMapRequiredDetail(QName name, Element element);
ohair@286 354
ohair@286 355 protected SEIModel seiModel;
ohair@286 356 protected WSDLPort wsdlPort;
ohair@286 357 protected WSBinding binding;
ohair@286 358 protected final SOAPVersion soapVer;
ohair@286 359 protected final AddressingVersion addVer;
ohair@286 360 }

mercurial