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

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 408
b0610cd08440
parent 0
373ffda63c9a
permissions
-rw-r--r--

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

mercurial