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