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

Print this page


   1 /*
   2  * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.xml.internal.ws.addressing;
  27 
  28 import com.sun.xml.internal.ws.addressing.model.InvalidAddressingHeaderException;
  29 import com.sun.xml.internal.ws.addressing.model.MissingAddressingHeaderException;
  30 import com.sun.xml.internal.ws.api.SOAPVersion;
  31 import com.sun.xml.internal.ws.api.WSBinding;
  32 import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
  33 import com.sun.xml.internal.ws.api.message.Message;
  34 import com.sun.xml.internal.ws.api.message.Packet;
  35 import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
  36 import com.sun.xml.internal.ws.api.model.wsdl.WSDLFault;
  37 import com.sun.xml.internal.ws.api.model.wsdl.WSDLOperation;
  38 import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;
  39 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
  40 import com.sun.xml.internal.ws.api.model.SEIModel;
  41 import com.sun.xml.internal.ws.api.model.JavaMethod;

  42 import com.sun.xml.internal.ws.model.wsdl.WSDLOperationImpl;
  43 import com.sun.xml.internal.ws.model.JavaMethodImpl;
  44 import com.sun.xml.internal.ws.model.CheckedExceptionImpl;
  45 import com.sun.istack.internal.Nullable;
  46 import org.w3c.dom.Element;
  47 
  48 import javax.xml.namespace.QName;
  49 import javax.xml.soap.Detail;
  50 import javax.xml.soap.SOAPConstants;
  51 import javax.xml.soap.SOAPException;
  52 import javax.xml.soap.SOAPFactory;
  53 import javax.xml.soap.SOAPFault;
  54 import javax.xml.soap.SOAPMessage;
  55 import javax.xml.ws.WebServiceException;
  56 import java.util.Map;
  57 
  58 /**
  59  * @author Rama Pulavarthi
  60  * @author Arun Gupta
  61  */
  62 public abstract class WsaTubeHelper {
  63 
  64     public WsaTubeHelper(WSBinding binding, SEIModel seiModel, WSDLPort wsdlPort) {
  65         this.binding = binding;
  66         this.wsdlPort = wsdlPort;
  67         this.seiModel = seiModel;
  68         this.soapVer = binding.getSOAPVersion();
  69         this.addVer = binding.getAddressingVersion();
  70 
  71     }
  72 
  73     public String getFaultAction(Packet requestPacket, Packet responsePacket) {
  74         String action = null;
  75         if(seiModel != null) {
  76             action = getFaultActionFromSEIModel(requestPacket,responsePacket);
  77         }
  78         if(action != null)
  79             return action;
  80         else
  81             action = addVer.getDefaultFaultAction();

  82         if (wsdlPort != null) {
  83             QName wsdlOp = requestPacket.getWSDLOperation();
  84             if (wsdlOp != null) {
  85                 WSDLBoundOperation wbo = wsdlPort.getBinding().get(wsdlOp);
  86                 return getFaultAction(wbo, responsePacket);
  87             }
  88         }
  89         return action;
  90     }
  91 
  92     String getFaultActionFromSEIModel(Packet requestPacket, Packet responsePacket) {
  93         String action = null;
  94         if (seiModel == null || wsdlPort == null)
  95             return action;

  96 
  97         try {
  98             SOAPMessage sm = responsePacket.getMessage().copy().readAsSOAPMessage();
  99             if (sm == null)
 100                 return action;

 101 
 102             if (sm.getSOAPBody() == null)
 103                 return action;

 104 
 105             if (sm.getSOAPBody().getFault() == null)
 106                 return action;

 107 
 108             Detail detail = sm.getSOAPBody().getFault().getDetail();
 109             if (detail == null)
 110                 return action;

 111 
 112             String ns = detail.getFirstChild().getNamespaceURI();
 113             String name = detail.getFirstChild().getLocalName();
 114 
 115             QName wsdlOp = requestPacket.getWSDLOperation();
 116             JavaMethodImpl jm = (JavaMethodImpl) seiModel.getJavaMethodForWsdlOperation(wsdlOp);
 117             if (jm != null) {
 118               for (CheckedExceptionImpl ce : jm.getCheckedExceptions()) {
 119                   if (ce.getDetailType().tagName.getLocalPart().equals(name) &&
 120                           ce.getDetailType().tagName.getNamespaceURI().equals(ns)) {
 121                       return ce.getFaultAction();
 122                   }
 123               }
 124             }
 125             return action;
 126         } catch (SOAPException e) {
 127             throw new WebServiceException(e);
 128         }
 129     }
 130 
 131     String getFaultAction(@Nullable WSDLBoundOperation wbo, Packet responsePacket) {
 132         String action = responsePacket.getMessage().getHeaders().getAction(addVer, soapVer);
 133         if (action != null)
 134                 return action;

 135 
 136         action = addVer.getDefaultFaultAction();
 137         if (wbo == null)
 138             return action;

 139 
 140         try {
 141             SOAPMessage sm = responsePacket.getMessage().copy().readAsSOAPMessage();
 142             if (sm == null)
 143                 return action;

 144 
 145             if (sm.getSOAPBody() == null)
 146                 return action;

 147 
 148             if (sm.getSOAPBody().getFault() == null)
 149                 return action;

 150 
 151             Detail detail = sm.getSOAPBody().getFault().getDetail();
 152             if (detail == null)
 153                 return action;

 154 
 155             String ns = detail.getFirstChild().getNamespaceURI();
 156             String name = detail.getFirstChild().getLocalName();
 157 
 158             WSDLOperation o = wbo.getOperation();
 159 
 160             WSDLFault fault = o.getFault(new QName(ns, name));
 161             if (fault == null)
 162                 return action;

 163 
 164             WSDLOperationImpl impl = (WSDLOperationImpl)o;
 165             action = fault.getAction();
 166 
 167             return action;
 168         } catch (SOAPException e) {
 169             throw new WebServiceException(e);
 170         }
 171     }
 172 
 173     public String getInputAction(Packet packet) {
 174         String action = null;
 175 
 176         if (wsdlPort != null) {
 177             QName wsdlOp = packet.getWSDLOperation();
 178             if (wsdlOp != null) {
 179                 WSDLBoundOperation wbo = wsdlPort.getBinding().get(wsdlOp);
 180                 WSDLOperation op = wbo.getOperation();
 181                 action = op.getInput().getAction();
 182             }
 183         }
 184 
 185         return action;
 186     }
 187 
 188     /**
 189      * This method gives the Input addressing Action for a message.
 190      * It gives the Action set in the wsdl operation for the corresponding payload.
 191      * If it is not explicitly set, it gives the soapAction
 192      * @param packet
 193      * @return input Action
 194      */
 195     public String getEffectiveInputAction(Packet packet) {
 196         //non-default SOAPAction beomes wsa:action
 197         if(packet.soapAction != null && !packet.soapAction.equals(""))
 198                 return packet.soapAction;
 199         String action = null;

 200 
 201         if (wsdlPort != null) {
 202             QName wsdlOp = packet.getWSDLOperation();
 203             if (wsdlOp != null) {
 204                 WSDLBoundOperation wbo = wsdlPort.getBinding().get(wsdlOp);
 205                 WSDLOperation op = wbo.getOperation();
 206                 action = op.getInput().getAction();
 207             } else
 208                 action = packet.soapAction;

 209         } else {
 210             action = packet.soapAction;
 211         }
 212         return action;
 213     }
 214 
 215     public boolean isInputActionDefault(Packet packet) {
 216         if (wsdlPort == null)
 217             return false;
 218         QName wsdlOp = packet.getWSDLOperation();
 219         if(wsdlOp == null)

 220             return false;
 221         WSDLBoundOperation wbo = wsdlPort.getBinding().get(wsdlOp);

 222         WSDLOperation op = wbo.getOperation();
 223         return ((WSDLOperationImpl) op).getInput().isDefaultAction();
 224 
 225     }
 226 
 227     public String getSOAPAction(Packet packet) {
 228         String action = "";
 229 
 230         if (packet == null || packet.getMessage() == null)
 231             return action;

 232 
 233         if (wsdlPort == null)
 234             return action;

 235 
 236         QName opName = packet.getWSDLOperation();
 237         if(opName == null)
 238             return action;

 239 
 240         WSDLBoundOperation op = wsdlPort.getBinding().get(opName);
 241         action = op.getSOAPAction();
 242         return action;
 243     }
 244 
 245     public String getOutputAction(Packet packet) {
 246         //String action = AddressingVersion.UNSET_OUTPUT_ACTION;
 247         String action = null;
 248         QName wsdlOp = packet.getWSDLOperation();
 249         if (wsdlOp != null) {
 250             if (seiModel != null) {
 251                 JavaMethodImpl jm = (JavaMethodImpl) seiModel.getJavaMethodForWsdlOperation(wsdlOp);

 252                 if (jm != null && jm.getOutputAction() != null && !jm.getOutputAction().equals("")) {
 253                     return jm.getOutputAction();
 254                 }
 255             }
 256             if (wsdlPort != null) {
 257                 WSDLBoundOperation wbo = wsdlPort.getBinding().get(wsdlOp);
 258                 return getOutputAction(wbo);
 259             }
 260         }
 261         return action;
 262     }
 263 
 264     String getOutputAction(@Nullable WSDLBoundOperation wbo) {
 265         String action = AddressingVersion.UNSET_OUTPUT_ACTION;
 266         if (wbo != null) {
 267             WSDLOutput op = wbo.getOperation().getOutput();
 268             if (op != null)
 269                 action = op.getAction();

 270         }
 271         return action;
 272     }
 273 
 274     public SOAPFault createInvalidAddressingHeaderFault(InvalidAddressingHeaderException e, AddressingVersion av) {
 275         QName name = e.getProblemHeader();
 276         QName subsubcode = e.getSubsubcode();
 277         QName subcode = av.invalidMapTag;
 278         String faultstring = String.format(av.getInvalidMapText(), name, subsubcode);
 279 
 280         try {
 281             SOAPFactory factory;
 282             SOAPFault fault;
 283             if (soapVer == SOAPVersion.SOAP_12) {
 284                 factory = SOAPVersion.SOAP_12.getSOAPFactory();
 285                 fault = factory.createFault();
 286                 fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
 287                 fault.appendFaultSubcode(subcode);
 288                 fault.appendFaultSubcode(subsubcode);
 289                 getInvalidMapDetail(name, fault.addDetail());


   1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.xml.internal.ws.addressing;
  27 
  28 import com.sun.xml.internal.ws.addressing.model.InvalidAddressingHeaderException;
  29 import com.sun.xml.internal.ws.addressing.model.MissingAddressingHeaderException;
  30 import com.sun.xml.internal.ws.api.SOAPVersion;
  31 import com.sun.xml.internal.ws.api.WSBinding;
  32 import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
  33 import com.sun.xml.internal.ws.api.message.AddressingUtils;
  34 import com.sun.xml.internal.ws.api.message.Packet;
  35 import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
  36 import com.sun.xml.internal.ws.api.model.wsdl.WSDLFault;
  37 import com.sun.xml.internal.ws.api.model.wsdl.WSDLOperation;
  38 import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;
  39 import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
  40 import com.sun.xml.internal.ws.api.model.SEIModel;
  41 import com.sun.xml.internal.ws.api.model.JavaMethod;
  42 import com.sun.xml.internal.ws.api.model.WSDLOperationMapping;
  43 import com.sun.xml.internal.ws.model.wsdl.WSDLOperationImpl;
  44 import com.sun.xml.internal.ws.model.JavaMethodImpl;
  45 import com.sun.xml.internal.ws.model.CheckedExceptionImpl;
  46 import com.sun.istack.internal.Nullable;
  47 import org.w3c.dom.Element;
  48 
  49 import javax.xml.namespace.QName;
  50 import javax.xml.soap.Detail;
  51 import javax.xml.soap.SOAPConstants;
  52 import javax.xml.soap.SOAPException;
  53 import javax.xml.soap.SOAPFactory;
  54 import javax.xml.soap.SOAPFault;
  55 import javax.xml.soap.SOAPMessage;
  56 import javax.xml.ws.WebServiceException;

  57 
  58 /**
  59  * @author Rama Pulavarthi
  60  * @author Arun Gupta
  61  */
  62 public abstract class WsaTubeHelper {
  63 
  64     public WsaTubeHelper(WSBinding binding, SEIModel seiModel, WSDLPort wsdlPort) {
  65         this.binding = binding;
  66         this.wsdlPort = wsdlPort;
  67         this.seiModel = seiModel;
  68         this.soapVer = binding.getSOAPVersion();
  69         this.addVer = binding.getAddressingVersion();
  70 
  71     }
  72 
  73     public String getFaultAction(Packet requestPacket, Packet responsePacket) {
  74         String action = null;
  75         if(seiModel != null) {
  76             action = getFaultActionFromSEIModel(requestPacket,responsePacket);
  77         }
  78         if (action != null) {
  79             return action;
  80         } else {
  81             action = addVer.getDefaultFaultAction();
  82         }
  83         if (wsdlPort != null) {
  84             WSDLOperationMapping wsdlOp = requestPacket.getWSDLOperationMapping();
  85             if (wsdlOp != null) {
  86                 WSDLBoundOperation wbo = wsdlOp.getWSDLBoundOperation();
  87                 return getFaultAction(wbo, responsePacket);
  88             }
  89         }
  90         return action;
  91     }
  92 
  93     String getFaultActionFromSEIModel(Packet requestPacket, Packet responsePacket) {
  94         String action = null;
  95         if (seiModel == null || wsdlPort == null) {
  96             return action;
  97         }
  98 
  99         try {
 100             SOAPMessage sm = responsePacket.getMessage().copy().readAsSOAPMessage();
 101             if (sm == null) {
 102                 return action;
 103             }
 104 
 105             if (sm.getSOAPBody() == null) {
 106                 return action;
 107             }
 108 
 109             if (sm.getSOAPBody().getFault() == null) {
 110                 return action;
 111             }
 112 
 113             Detail detail = sm.getSOAPBody().getFault().getDetail();
 114             if (detail == null) {
 115                 return action;
 116             }
 117 
 118             String ns = detail.getFirstChild().getNamespaceURI();
 119             String name = detail.getFirstChild().getLocalName();
 120 
 121             WSDLOperationMapping wsdlOp = requestPacket.getWSDLOperationMapping();
 122             JavaMethodImpl jm = (wsdlOp != null) ? (JavaMethodImpl)wsdlOp.getJavaMethod() : null;
 123             if (jm != null) {
 124               for (CheckedExceptionImpl ce : jm.getCheckedExceptions()) {
 125                   if (ce.getDetailType().tagName.getLocalPart().equals(name) &&
 126                           ce.getDetailType().tagName.getNamespaceURI().equals(ns)) {
 127                       return ce.getFaultAction();
 128                   }
 129               }
 130             }
 131             return action;
 132         } catch (SOAPException e) {
 133             throw new WebServiceException(e);
 134         }
 135     }
 136 
 137     String getFaultAction(@Nullable WSDLBoundOperation wbo, Packet responsePacket) {
 138         String action = AddressingUtils.getAction(responsePacket.getMessage().getHeaders(), addVer, soapVer);
 139         if (action != null) {
 140             return action;
 141         }
 142 
 143         action = addVer.getDefaultFaultAction();
 144         if (wbo == null) {
 145             return action;
 146         }
 147 
 148         try {
 149             SOAPMessage sm = responsePacket.getMessage().copy().readAsSOAPMessage();
 150             if (sm == null) {
 151                 return action;
 152             }
 153 
 154             if (sm.getSOAPBody() == null) {
 155                 return action;
 156             }
 157 
 158             if (sm.getSOAPBody().getFault() == null) {
 159                 return action;
 160             }
 161 
 162             Detail detail = sm.getSOAPBody().getFault().getDetail();
 163             if (detail == null) {
 164                 return action;
 165             }
 166 
 167             String ns = detail.getFirstChild().getNamespaceURI();
 168             String name = detail.getFirstChild().getLocalName();
 169 
 170             WSDLOperation o = wbo.getOperation();
 171 
 172             WSDLFault fault = o.getFault(new QName(ns, name));
 173             if (fault == null) {
 174                 return action;
 175             }
 176 

 177             action = fault.getAction();
 178 
 179             return action;
 180         } catch (SOAPException e) {
 181             throw new WebServiceException(e);
 182         }
 183     }
 184 
 185     public String getInputAction(Packet packet) {
 186         String action = null;
 187 
 188         if (wsdlPort != null) {
 189             WSDLOperationMapping wsdlOp = packet.getWSDLOperationMapping();
 190             if (wsdlOp != null) {
 191                 WSDLBoundOperation wbo = wsdlOp.getWSDLBoundOperation();
 192                 WSDLOperation op = wbo.getOperation();
 193                 action = op.getInput().getAction();
 194             }
 195         }
 196 
 197         return action;
 198     }
 199 
 200     /**
 201      * This method gives the Input addressing Action for a message.
 202      * It gives the Action set in the wsdl operation for the corresponding payload.
 203      * If it is not explicitly set, it gives the soapAction
 204      * @param packet
 205      * @return input Action
 206      */
 207     public String getEffectiveInputAction(Packet packet) {
 208         //non-default SOAPAction beomes wsa:action
 209         if(packet.soapAction != null && !packet.soapAction.equals("")) {
 210             return packet.soapAction;
 211         }
 212         String action;
 213 
 214         if (wsdlPort != null) {
 215             WSDLOperationMapping wsdlOp = packet.getWSDLOperationMapping();
 216             if (wsdlOp != null) {
 217                 WSDLBoundOperation wbo = wsdlOp.getWSDLBoundOperation();
 218                 WSDLOperation op = wbo.getOperation();
 219                 action = op.getInput().getAction();
 220             } else {
 221                 action = packet.soapAction;
 222             }
 223         } else {
 224             action = packet.soapAction;
 225         }
 226         return action;
 227     }
 228 
 229     public boolean isInputActionDefault(Packet packet) {
 230         if (wsdlPort == null) {
 231             return false;
 232         }
 233         WSDLOperationMapping wsdlOp = packet.getWSDLOperationMapping();
 234         if(wsdlOp == null) {
 235             return false;
 236         }
 237         WSDLBoundOperation wbo = wsdlOp.getWSDLBoundOperation();
 238         WSDLOperation op = wbo.getOperation();
 239         return ((WSDLOperationImpl) op).getInput().isDefaultAction();
 240 
 241     }
 242 
 243     public String getSOAPAction(Packet packet) {
 244         String action = "";
 245 
 246         if (packet == null || packet.getMessage() == null) {
 247             return action;
 248         }
 249 
 250         if (wsdlPort == null) {
 251             return action;
 252         }
 253 
 254         WSDLOperationMapping wsdlOp = packet.getWSDLOperationMapping();
 255         if (wsdlOp == null) {
 256             return action;
 257         }
 258 
 259         WSDLBoundOperation op = wsdlOp.getWSDLBoundOperation();
 260         action = op.getSOAPAction();
 261         return action;
 262     }
 263 
 264     public String getOutputAction(Packet packet) {
 265         //String action = AddressingVersion.UNSET_OUTPUT_ACTION;
 266         String action = null;
 267         WSDLOperationMapping wsdlOp = packet.getWSDLOperationMapping();
 268         if (wsdlOp != null) {
 269             JavaMethod javaMethod = wsdlOp.getJavaMethod();
 270             if (javaMethod != null) {
 271                 JavaMethodImpl jm = (JavaMethodImpl) javaMethod;
 272                 if (jm != null && jm.getOutputAction() != null && !jm.getOutputAction().equals("")) {
 273                     return jm.getOutputAction();
 274                 }
 275             }
 276             WSDLBoundOperation wbo = wsdlOp.getWSDLBoundOperation();
 277             if (wbo != null) return getOutputAction(wbo);


 278         }
 279         return action;
 280     }
 281 
 282     String getOutputAction(@Nullable WSDLBoundOperation wbo) {
 283         String action = AddressingVersion.UNSET_OUTPUT_ACTION;
 284         if (wbo != null) {
 285             WSDLOutput op = wbo.getOperation().getOutput();
 286             if (op != null) {
 287                 action = op.getAction();
 288             }
 289         }
 290         return action;
 291     }
 292 
 293     public SOAPFault createInvalidAddressingHeaderFault(InvalidAddressingHeaderException e, AddressingVersion av) {
 294         QName name = e.getProblemHeader();
 295         QName subsubcode = e.getSubsubcode();
 296         QName subcode = av.invalidMapTag;
 297         String faultstring = String.format(av.getInvalidMapText(), name, subsubcode);
 298 
 299         try {
 300             SOAPFactory factory;
 301             SOAPFault fault;
 302             if (soapVer == SOAPVersion.SOAP_12) {
 303                 factory = SOAPVersion.SOAP_12.getSOAPFactory();
 304                 fault = factory.createFault();
 305                 fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
 306                 fault.appendFaultSubcode(subcode);
 307                 fault.appendFaultSubcode(subsubcode);
 308                 getInvalidMapDetail(name, fault.addDetail());