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

Tue, 06 Mar 2012 16:09:35 -0800

author
ohair
date
Tue, 06 Mar 2012 16:09:35 -0800
changeset 286
f50545b5e2f1
child 368
0989ad8c0860
permissions
-rw-r--r--

7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom

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

mercurial