コード例 #1
0
  public Binding createBinding(BindingInfo binding) {
    // TODO what about the mix style/use?

    // The default style should be doc-lit wrapped.
    String parameterStyle = SoapBindingConstants.PARAMETER_STYLE_WRAPPED;
    String bindingStyle = SoapBindingConstants.BINDING_STYLE_DOC;

    boolean hasWrapped = false;

    org.apache.cxf.binding.soap.SoapBinding sb = null;
    SoapVersion version = null;
    if (binding instanceof SoapBindingInfo) {
      SoapBindingInfo sbi = (SoapBindingInfo) binding;
      version = sbi.getSoapVersion();
      sb = new org.apache.cxf.binding.soap.SoapBinding(binding, version);
      // Service wide style
      if (!StringUtils.isEmpty(sbi.getStyle())) {
        bindingStyle = sbi.getStyle();
      }

      boolean hasRPC = false;
      boolean hasDoc = false;

      // Operation wide style, what to do with the mixed style/use?
      for (BindingOperationInfo boi : sbi.getOperations()) {
        String st = sbi.getStyle(boi.getOperationInfo());
        if (st != null) {
          bindingStyle = st;
          if (SoapBindingConstants.BINDING_STYLE_RPC.equalsIgnoreCase(st)) {
            hasRPC = true;
          } else {
            hasDoc = true;
          }
        }
        if (boi.getUnwrappedOperation() == null) {
          parameterStyle = SoapBindingConstants.PARAMETER_STYLE_BARE;
        } else {
          hasWrapped = true;
        }
      }

      if (Boolean.TRUE.equals(binding.getService().getProperty("soap.force.doclit.bare"))) {
        hasDoc = true;
        hasRPC = false;
        parameterStyle = SoapBindingConstants.PARAMETER_STYLE_BARE;
        bindingStyle = SoapBindingConstants.BINDING_STYLE_DOC;
      }
      if (hasRPC && hasDoc) {
        throw new RuntimeException(
            "WSI-BP prohibits RPC and Document style " + "operations in same service.");
      }

      // jms
      if (sbi.getTransportURI().equals(SoapJMSConstants.SOAP_JMS_SPECIFICIATION_TRANSPORTID)) {
        sb.getInInterceptors().add(new SoapJMSInInterceptor());
      }
    } else {
      throw new RuntimeException(
          "Can not initialize SoapBinding, BindingInfo is not SoapBindingInfo");
    }

    sb.getOutFaultInterceptors().add(new StaxOutInterceptor());
    sb.getOutFaultInterceptors().add(new SoapOutInterceptor(getBus()));

    sb.getInInterceptors().add(new AttachmentInInterceptor());
    sb.getInInterceptors().add(new StaxInInterceptor());
    sb.getInInterceptors().add(new SoapActionInInterceptor());

    sb.getOutInterceptors().add(new AttachmentOutInterceptor());
    sb.getOutInterceptors().add(new StaxOutInterceptor());
    sb.getOutInterceptors().add(SoapHeaderOutFilterInterceptor.INSTANCE);

    if (SoapBindingConstants.BINDING_STYLE_RPC.equalsIgnoreCase(bindingStyle)) {
      sb.getInInterceptors().add(new RPCInInterceptor());
      sb.getOutInterceptors().add(new RPCOutInterceptor());
    } else if (SoapBindingConstants.BINDING_STYLE_DOC.equalsIgnoreCase(bindingStyle)
        && SoapBindingConstants.PARAMETER_STYLE_BARE.equalsIgnoreCase(parameterStyle)) {
      // sb.getInInterceptors().add(new BareInInterceptor());
      sb.getInInterceptors().add(new DocLiteralInInterceptor());
      if (hasWrapped) {
        sb.getOutInterceptors().add(new WrappedOutInterceptor());
      }
      sb.getOutInterceptors().add(new BareOutInterceptor());
    } else {
      // sb.getInInterceptors().add(new WrappedInInterceptor());
      sb.getInInterceptors().add(new DocLiteralInInterceptor());
      sb.getOutInterceptors().add(new WrappedOutInterceptor());
      sb.getOutInterceptors().add(new BareOutInterceptor());
    }
    sb.getInInterceptors().add(new SoapHeaderInterceptor());

    sb.getInInterceptors().add(new ReadHeadersInterceptor(getBus(), version));
    sb.getInInterceptors().add(new StartBodyInterceptor());
    sb.getInInterceptors().add(new CheckFaultInterceptor());
    sb.getInInterceptors().add(new MustUnderstandInterceptor());
    sb.getOutInterceptors().add(new SoapPreProtocolOutInterceptor());
    sb.getOutInterceptors().add(new SoapOutInterceptor(getBus()));
    sb.getOutFaultInterceptors().add(new SoapOutInterceptor(getBus()));
    sb.getOutFaultInterceptors().add(SoapHeaderOutFilterInterceptor.INSTANCE);

    // REVISIT: The phase interceptor chain seems to freak out if this added
    // first. Not sure what the deal is at the moment, I suspect the
    // ordering algorithm needs to be improved
    sb.getInInterceptors().add(new URIMappingInterceptor());

    if (version.getVersion() == 1.1) {
      sb.getInFaultInterceptors().add(new Soap11FaultInInterceptor());
      sb.getOutFaultInterceptors().add(new Soap11FaultOutInterceptor());
    } else if (version.getVersion() == 1.2) {
      sb.getInFaultInterceptors().add(new Soap12FaultInInterceptor());
      sb.getOutFaultInterceptors().add(new Soap12FaultOutInterceptor());
    }

    if (binding.getService() != null) {
      for (EndpointInfo ei : binding.getService().getEndpoints()) {
        if (ei.getAddress() != null && ei.getAddress().startsWith("soap.udp")) {
          setupUDP(sb, ei);
        }
      }
    }

    return sb;
  }
コード例 #2
0
  public BindingInfo createBindingInfo(ServiceInfo si, String bindingid, Object conf) {
    SoapBindingConfiguration config;
    if (conf instanceof SoapBindingConfiguration) {
      config = (SoapBindingConfiguration) conf;
    } else {
      config = new SoapBindingConfiguration();
    }
    if (WSDLConstants.NS_SOAP12.equals(bindingid)
        || WSDLConstants.NS_SOAP12_HTTP_BINDING.equals(bindingid)) {
      config.setVersion(Soap12.getInstance());
      config.setTransportURI(WSDLConstants.NS_SOAP_HTTP_TRANSPORT);
    }
    SoapBindingInfo info = new SoapBindingInfo(si, bindingid, config.getVersion());

    info.setName(config.getBindingName(si));
    info.setStyle(config.getStyle());

    info.setTransportURI(config.getTransportURI());

    if (config.isMtomEnabled()) {
      info.setProperty(Message.MTOM_ENABLED, Boolean.TRUE);
    }

    for (OperationInfo op : si.getInterface().getOperations()) {
      SoapOperationInfo sop = new SoapOperationInfo();
      sop.setAction(config.getSoapAction(op));
      sop.setStyle(config.getStyle(op));

      BindingOperationInfo bop =
          info.buildOperation(op.getName(), op.getInputName(), op.getOutputName());

      bop.addExtensor(sop);

      info.addOperation(bop);

      BindingMessageInfo bInput = bop.getInput();
      if (bInput != null) {
        MessageInfo input = null;
        BindingMessageInfo unwrappedMsg = bInput;
        if (bop.isUnwrappedCapable()) {
          input = bop.getOperationInfo().getUnwrappedOperation().getInput();
          unwrappedMsg = bop.getUnwrappedOperation().getInput();
        } else {
          input = bop.getOperationInfo().getInput();
        }
        setupHeaders(bop, bInput, unwrappedMsg, input, config);
      }

      BindingMessageInfo bOutput = bop.getOutput();
      if (bOutput != null) {
        MessageInfo output = null;
        BindingMessageInfo unwrappedMsg = bOutput;
        if (bop.isUnwrappedCapable()) {
          output = bop.getOperationInfo().getUnwrappedOperation().getOutput();
          unwrappedMsg = bop.getUnwrappedOperation().getOutput();
        } else {
          output = bop.getOperationInfo().getOutput();
        }
        setupHeaders(bop, bOutput, unwrappedMsg, output, config);
      }
    }

    try {
      createSoapBinding(info);
    } catch (WSDLException e) {
      e.printStackTrace();
    }

    return info;
  }