1 57 58 package org.apache.wsif.providers.soap.soaprmi; 59 60 import java.util.HashMap ; 61 import java.util.Iterator ; 62 import java.util.List ; 63 import java.util.Map ; 64 65 import javax.wsdl.Binding; 66 import javax.wsdl.BindingFault; 67 import javax.wsdl.BindingInput; 68 import javax.wsdl.BindingOperation; 69 import javax.wsdl.BindingOutput; 70 import javax.wsdl.Definition; 71 import javax.wsdl.Input; 72 import javax.wsdl.Operation; 73 import javax.wsdl.Output; 74 import javax.wsdl.Port; 75 import javax.wsdl.PortType; 76 import javax.wsdl.Service; 77 import javax.wsdl.extensions.soap.SOAPAddress; 78 import javax.wsdl.extensions.soap.SOAPBinding; 79 import javax.wsdl.extensions.soap.SOAPBody; 80 import javax.wsdl.extensions.soap.SOAPFault; 81 import javax.wsdl.extensions.soap.SOAPHeader; 82 import javax.wsdl.extensions.soap.SOAPOperation; 83 import org.apache.wsif.WSIFException; 84 import org.apache.wsif.WSIFMessage; 85 import org.apache.wsif.WSIFOperation; 86 import org.apache.wsif.base.WSIFDefaultPort; 87 import org.apache.wsif.logging.Trc; 88 import org.apache.wsif.providers.WSIFDynamicTypeMap; 89 90 95 public class WSIFPort_SoapRMI extends WSIFDefaultPort { 96 97 private static final long serialVersionUID = 1L; 98 99 protected Map operationInstances = new HashMap (); 100 101 protected Port port; 102 protected Definition definition; 103 protected String location; 104 105 111 public WSIFPort_SoapRMI( 112 Definition def, 113 Service service, 114 Port port, 115 WSIFDynamicTypeMap typeMap) 116 throws WSIFException { 117 setDefinition(def); 118 setPort(port); 119 120 SOAPAddress sa = 122 (SOAPAddress) getExtElem(port, 123 SOAPAddress.class, 124 port.getExtensibilityElements()); 125 if (sa != null) { 126 location = sa.getLocationURI(); 127 } 128 if (location == null) { 129 throw new WSIFException( 130 "soap:address with location URI is required for " + port); 131 } 132 133 String style = null; 135 Binding binding = port.getBinding(); 136 SOAPBinding soapBinding = 137 (SOAPBinding) getExtElem(binding, 138 SOAPBinding.class, 139 binding.getExtensibilityElements()); 140 if (soapBinding != null) { 141 style = soapBinding.getStyle(); 142 if (!"rpc".equals(style)) { 143 throw new WSIFException("unsupported style " + style + " for " + soapBinding); 144 } 145 String transport = soapBinding.getTransportURI(); 146 if (!"http://schemas.xmlsoap.org/soap/http".equals(transport)) { 147 throw new WSIFException( 148 "unsupported transport " + transport + " for " + soapBinding); 149 } 150 } 151 if (style == null) { 152 style = "document"; } 154 155 PortType portType = binding.getPortType(); 157 158 List operationList = portType.getOperations(); 159 160 for (Iterator i = operationList.iterator(); i.hasNext();) { 162 Operation op = (Operation) i.next(); 163 String name = op.getName(); 164 Input input = op.getInput(); 166 Output output = op.getOutput(); 167 if (input == null) { 168 throw new WSIFException("missing input message for operation " + name); 169 170 } 171 if (output == null) { 172 throw new WSIFException("missing output message for operation " + name); 173 } 174 175 WSIFOperation_SoapRMI opInst = new WSIFOperation_SoapRMI(this, op, typeMap); 176 177 BindingOperation bop = 178 binding.getBindingOperation(name, input.getName(), output.getName()); 179 180 if (bop == null) { 181 throw new WSIFException( 182 "mising required in WSDL 1.1 binding operation for " + name); 183 } 184 185 SOAPOperation soapOperation = 187 (SOAPOperation) getExtElem(bop, 188 SOAPOperation.class, 189 bop.getExtensibilityElements()); 190 if (soapOperation == null) { 191 throw new WSIFException( 192 "soapAction must be specified in " 193 + " required by WSDL 1.1 soap:operation binding for " 194 + bop); 195 } 196 String soapActionURI = soapOperation.getSoapActionURI(); 197 opInst.setSoapActionURI(soapActionURI); 198 199 if (Trc.ON) 200 Trc.event( 201 this, 202 "setting actionURI " 203 + soapActionURI 204 + " for op " 205 + opInst.getName()); 206 String opStyle = soapOperation.getStyle(); 207 if (opStyle != null && !"rpc".equals(opStyle)) { 208 throw new WSIFException( 209 "unsupported style " + style + " for operation " + name); 210 } else if (!"rpc".equals(style)) { 211 throw new WSIFException( 212 "default soap style must be rpc if operation " 213 + name 214 + " binding has not style attribute"); 215 } 216 217 BindingInput binpt = bop.getBindingInput(); 219 SOAPBody soapInputBody = 220 (SOAPBody) getExtElem(binpt, SOAPBody.class, binpt.getExtensibilityElements()); 221 if (soapInputBody != null) { 222 String namespaceURI = soapInputBody.getNamespaceURI(); 223 224 if (Trc.ON) 225 Trc.event( 226 this, 227 "setting namespace " 228 + namespaceURI 229 + " for op " 230 + opInst.getName()); 231 opInst.setInputNamespace(namespaceURI); 232 String use = soapInputBody.getUse(); 233 if (!"encoded".equals(use)) { 234 throw new WSIFException("unsupported use " + use + " in " + soapOperation); 235 } 236 List encodingStyles = soapInputBody.getEncodingStyles(); 237 if (encodingStyles != null) { 238 if (encodingStyles.size() == 0) { 239 } 240 opInst.setInputEncodingStyle((String ) encodingStyles.get(0)); 241 } 243 List parts = soapInputBody.getParts(); 244 if (parts != null) { 245 opInst.setPartNames(parts); 246 } 247 } 248 SOAPHeader soapHeader = 249 (SOAPHeader) getExtElem(binpt, 250 SOAPHeader.class, 251 binpt.getExtensibilityElements()); 252 if (soapHeader != null) { 253 throw new WSIFException("not supported input soap:header " + soapHeader); 254 } 255 256 BindingOutput boutpt = bop.getBindingOutput(); 258 SOAPBody soapOutputBody = 259 (SOAPBody) getExtElem(boutpt, 260 SOAPBody.class, 261 boutpt.getExtensibilityElements()); 262 if (soapOutputBody != null) { 263 String use = soapInputBody.getUse(); 266 if (!"encoded".equals(use)) { 267 throw new WSIFException("unsupported use " + use + " in " + soapOperation); 268 } 269 List parts = soapInputBody.getParts(); 272 if (parts != null && parts.size() > 0) { 273 opInst.setReturnName((String ) parts.get(0)); 274 } 275 } 276 soapHeader = 277 (SOAPHeader) getExtElem(boutpt, 278 SOAPHeader.class, 279 boutpt.getExtensibilityElements()); 280 if (soapHeader != null) { 281 throw new WSIFException("not supported output soap:header " + soapHeader); 282 } 283 284 for (Iterator bfaults = bop.getBindingFaults().values().iterator(); 285 bfaults.hasNext(); 286 ) { 287 BindingFault bfault = (BindingFault) bfaults.next(); 288 SOAPFault soapFault = 289 (SOAPFault) getExtElem(bfault, 290 SOAPFault.class, 291 bfault.getExtensibilityElements()); 292 } 298 299 setDynamicWSIFOperation( 301 op.getName(), 302 op.getInput().getName(), 303 op.getOutput().getName(), 304 opInst); 305 306 } } 308 309 public String getLocation() { 310 return location; 311 } 312 313 public void setLocation(String location) { 314 this.location = location; 315 } 316 317 public Definition getDefinition() { 319 return definition; 320 } 321 322 public void setDefinition(Definition value) { 323 definition = value; 324 } 325 326 public Port getPort() { 327 return port; 328 } 329 330 public void setPort(Port value) { 331 port = value; 332 } 333 334 public void setDynamicWSIFOperation( 336 String name, 337 String inputName, 338 String outputName, 339 WSIFOperation_SoapRMI value) { 340 operationInstances.put(getKey(name, inputName, outputName), value); 341 } 342 343 public WSIFOperation createOperation(String operationName) 344 throws WSIFException { 345 return createOperation(operationName, null, null); 346 } 347 348 public WSIFOperation createOperation( 349 String operationName, 350 String inputName, 351 String outputName) 352 throws WSIFException { 353 WSIFOperation_SoapRMI op = 354 getDynamicWSIFOperation(operationName, inputName, outputName); 355 if (op == null) { 356 throw new WSIFException( 357 "Could not create operation: " 358 + operationName 359 + ":" 360 + inputName 361 + ":" 362 + outputName); 363 } 364 return op.copy(); 365 } 366 367 public WSIFOperation_SoapRMI getDynamicWSIFOperation( 368 String name, 369 String inputName, 370 String outputName) 371 throws WSIFException { 372 WSIFOperation_SoapRMI tempOp = 373 (WSIFOperation_SoapRMI) operationInstances.get( 374 getKey(name, inputName, outputName)); 375 376 WSIFOperation_SoapRMI operation = null; 377 if (tempOp != null) { 378 operation = tempOp.copy(); 379 } 380 381 if (operation == null) { 382 BindingOperation bindingOperationModel = 383 port.getBinding().getBindingOperation(name, inputName, outputName); 384 385 if (bindingOperationModel != null) { 386 Iterator i = operationInstances.keySet().iterator(); 389 while (i.hasNext()) { 390 String key = (String ) i.next(); 391 if ((outputName != null && key.endsWith(outputName)) || outputName == null) { 392 String start = (inputName == null) ? name : name + ":" + inputName; 393 if (key.startsWith(start)) { 394 if (operation != null) { 395 operation = null; 397 break; 398 } 399 operation = (WSIFOperation_SoapRMI) operationInstances.get(key); 400 } 401 } 402 } 403 } 404 } 405 406 return operation; 407 } 408 } | Popular Tags |