コード例 #1
0
ファイル: WSIBPValidator.java プロジェクト: Jutten/cxf
  private boolean checkR2717AndR2726(final BindingOperation bop) {
    if (null == bop) {
      return true;
    }
    SoapBody inSoapBody = SOAPBindingUtil.getBindingInputSOAPBody(bop);
    SoapBody outSoapBody = SOAPBindingUtil.getBindingOutputSOAPBody(bop);
    if (inSoapBody != null && StringUtils.isEmpty(inSoapBody.getNamespaceURI())
        || outSoapBody != null && StringUtils.isEmpty(outSoapBody.getNamespaceURI())) {
      addErrorMessage(
          getErrorPrefix("WSI-BP-1.0 R2717")
              + "soapBody in the input/output of the binding operation '"
              + bop.getName()
              + "' MUST have namespace attribute");
      return false;
    }

    SoapHeader inSoapHeader = SOAPBindingUtil.getBindingInputSOAPHeader(bop);
    SoapHeader outSoapHeader = SOAPBindingUtil.getBindingOutputSOAPHeader(bop);
    if (inSoapHeader != null && !StringUtils.isEmpty(inSoapHeader.getNamespaceURI())
        || outSoapHeader != null && !StringUtils.isEmpty(outSoapHeader.getNamespaceURI())) {
      addErrorMessage(
          getErrorPrefix("WSI-BP-1.0 R2726")
              + "Operation '"
              + bop.getName()
              + "' soapHeader MUST NOT have namespace attribute");
      return false;
    }

    List<SoapFault> soapFaults = SOAPBindingUtil.getBindingOperationSoapFaults(bop);
    for (SoapFault fault : soapFaults) {
      if (!StringUtils.isEmpty(fault.getNamespaceURI())) {
        addErrorMessage(
            getErrorPrefix("WSI-BP-1.0 R2726")
                + "Operation '"
                + bop.getName()
                + "' soapFault MUST NOT have namespace attribute");
        return false;
      }
    }
    return true;
  }
コード例 #2
0
  private void createSoapBinding(final SoapBindingInfo bi) throws WSDLException {
    boolean isSoap12 = bi.getSoapVersion() instanceof Soap12;
    Bus bs = getBus();
    WSDLManager m = bs.getExtension(WSDLManager.class);
    ExtensionRegistry extensionRegistry = m.getExtensionRegistry();

    SoapBinding soapBinding = SOAPBindingUtil.createSoapBinding(extensionRegistry, isSoap12);
    soapBinding.setStyle(bi.getStyle());
    soapBinding.setTransportURI(bi.getTransportURI());
    bi.addExtensor(soapBinding);

    for (BindingOperationInfo b : bi.getOperations()) {
      for (BindingFaultInfo faultInfo : b.getFaults()) {
        SoapFault soapFault = SOAPBindingUtil.createSoapFault(extensionRegistry, isSoap12);
        soapFault.setUse("literal");
        soapFault.setName(faultInfo.getFaultInfo().getFaultName().getLocalPart());
        faultInfo.addExtensor(soapFault);
      }
      SoapOperationInfo soi = b.getExtensor(SoapOperationInfo.class);

      SoapOperation soapOperation =
          SOAPBindingUtil.createSoapOperation(extensionRegistry, isSoap12);
      soapOperation.setSoapActionURI(soi.getAction());
      soapOperation.setStyle(soi.getStyle());
      boolean isRpc = "rpc".equals(soapOperation.getStyle());

      b.addExtensor(soapOperation);

      if (b.getInput() != null) {
        List<String> bodyParts = null;
        List<SoapHeaderInfo> headerInfos = b.getInput().getExtensors(SoapHeaderInfo.class);
        if (headerInfos != null && headerInfos.size() > 0) {
          bodyParts = new ArrayList<String>();
          for (MessagePartInfo part : b.getInput().getMessageParts()) {
            bodyParts.add(part.getName().getLocalPart());
          }

          for (SoapHeaderInfo headerInfo : headerInfos) {
            SoapHeader soapHeader =
                SOAPBindingUtil.createSoapHeader(extensionRegistry, BindingInput.class, isSoap12);
            soapHeader.setMessage(b.getInput().getMessageInfo().getName());
            soapHeader.setPart(headerInfo.getPart().getName().getLocalPart());
            soapHeader.setUse("literal");
            bodyParts.remove(headerInfo.getPart().getName().getLocalPart());
            headerInfo.getPart().setProperty(HEADER, true);
            b.getInput().addExtensor(soapHeader);
          }
        }
        SoapBody body =
            SOAPBindingUtil.createSoapBody(extensionRegistry, BindingInput.class, isSoap12);
        body.setUse("literal");
        if (isRpc) {
          body.setNamespaceURI(b.getName().getNamespaceURI());
        }

        if (bodyParts != null) {
          body.setParts(bodyParts);
        }

        b.getInput().addExtensor(body);
      }

      if (b.getOutput() != null) {
        List<String> bodyParts = null;
        List<SoapHeaderInfo> headerInfos = b.getOutput().getExtensors(SoapHeaderInfo.class);
        if (headerInfos != null && headerInfos.size() > 0) {
          bodyParts = new ArrayList<String>();
          for (MessagePartInfo part : b.getOutput().getMessageParts()) {
            bodyParts.add(part.getName().getLocalPart());
          }
          for (SoapHeaderInfo headerInfo : headerInfos) {
            SoapHeader soapHeader =
                SOAPBindingUtil.createSoapHeader(extensionRegistry, BindingOutput.class, isSoap12);
            soapHeader.setMessage(b.getOutput().getMessageInfo().getName());
            soapHeader.setPart(headerInfo.getPart().getName().getLocalPart());
            soapHeader.setUse("literal");
            bodyParts.remove(headerInfo.getPart().getName().getLocalPart());
            b.getOutput().addExtensor(soapHeader);
          }
        }
        SoapBody body =
            SOAPBindingUtil.createSoapBody(extensionRegistry, BindingOutput.class, isSoap12);
        body.setUse("literal");
        if (isRpc) {
          body.setNamespaceURI(b.getName().getNamespaceURI());
        }

        if (bodyParts != null) {
          body.setParts(bodyParts);
        }

        b.getOutput().addExtensor(body);
      }
    }
  }