Example #1
0
  public Binding createDefaultSoapBinding(
      String bindingName, Endpoint endpoint, InterfaceType itf) {
    // create binding
    Binding binding = (Binding) ((AbstractInterfaceTypeImpl) itf).getDescription().createBinding();
    binding.setQName(
        new QName(
            ((AbstractInterfaceTypeImpl) itf).getDescription().getTargetNamespace(), bindingName));
    binding.setInterface(itf);
    binding.setTransportProtocol(
        org.ow2.easywsdl.wsdl.impl.wsdl11.Constants.HTTP_SCHEMAS_XMLSOAP_ORG_SOAP_HTTP);

    for (Operation operation : itf.getOperations()) {
      BindingOperation bindingOperation = binding.createBindingOperation();
      bindingOperation.setQName(operation.getQName());

      // We set soapAction attribut as an URI build from the operation
      // qualified name.
      bindingOperation.setSoapAction(
          operation.getQName().getNamespaceURI()
              + (operation.getQName().getNamespaceURI().endsWith("/") ? "" : "/")
              + operation.getQName().getLocalPart());

      // input
      if (operation.getInput() != null) {
        BindingInput binput = bindingOperation.createInput();
        bindingOperation.setInput(binput);
        SOAP11Binding4Wsdl11 soap11binding = binput.createSOAP11Binding4Wsdl11();

        SOAP11Body body = soap11binding.createBody();
        body.setUse(UseConstants.LITERAL);
        try {
          soap11binding.setBody(body);
        } catch (WSDLException e) {
          // do nothing
        }
        binput.setSOAP11Binding4Wsdl11(soap11binding);
      }

      // output
      if (operation.getOutput() != null) {
        BindingOutput boutput = bindingOperation.createOutput();
        bindingOperation.setOutput(boutput);
        SOAP11Binding4Wsdl11 soap11binding = boutput.createSOAP11Binding4Wsdl11();

        SOAP11Body body = soap11binding.createBody();
        body.setUse(UseConstants.LITERAL);
        try {
          soap11binding.setBody(body);
        } catch (WSDLException e) {
          // do nothing
        }
        boutput.setSOAP11Binding4Wsdl11(soap11binding);
      }

      // fault
      if (operation.getFaults() != null) {
        for (Fault faultop : operation.getFaults()) {
          BindingFault bfault = bindingOperation.createFault();
          bfault.setName(faultop.getName());
          bindingOperation.addFault(bfault);
          SOAP11Binding4Wsdl11 soap11binding = bfault.createSOAP11Binding4Wsdl11();

          SOAP11Fault soap11fault = soap11binding.createFault();
          soap11fault.setName(faultop.getName());
          soap11fault.setUse(UseConstants.LITERAL);
          try {
            soap11binding.setFault(soap11fault);
          } catch (WSDLException e) {
            // do nothing
          }
          bfault.setSOAP11Binding4Wsdl11(soap11binding);
        }
      }

      binding.addBindingOperation(bindingOperation);
    }

    // set the binding to endpoint
    endpoint.setBinding(binding);

    return binding;
  }
Example #2
0
  /**
   * Initializes the suggestion provider. Will create the templatizer, extract the operation element
   * and set the http context provider to be able to suggest the template later on.
   *
   * @param wsdlUrl the WSDL url
   * @param serviceQName the service QName
   * @param endpointQName the endpoint QName
   * @param operationQName the operation QName
   * @param shouldEncodeAttr the flag to encode the attributes
   * @param clientBuilder the client builder
   * @param httpContextProvider the auth contedxt
   * @return the editor suggestion provider
   */
  public EditorSuggestionProvider initializeSuggestionProvider(
      String wsdlUrl,
      QName serviceQName,
      QName endpointQName,
      QName operationQName,
      Boolean shouldEncodeAttr,
      ClientBuilder clientBuilder,
      HttpContextProvider httpContextProvider) {
    URL wsdlURL = introspectionService.urlObjectFor(wsdlUrl);
    Description description = introspectionService.parseWsdl(wsdlURL, httpContextProvider);
    org.ow2.easywsdl.wsdl.api.Binding operationBinding =
        description.getService(serviceQName).getEndpoint(endpointQName.getLocalPart()).getBinding();
    Operation operation =
        operationBinding.getBindingOperation(operationQName.getLocalPart()).getOperation();
    Input input = operation.getInput();
    List<SOAPMessageTemplatizer.Input> inputs;
    switch (description.getVersion()) {
      case WSDL11:
        List<Part> parts = input.getParts();
        if (parts == null || parts.isEmpty()) {
          throw new ConfigurationException(ERROR_WHILE_READING_OPERATION_SCHEMA)
              .withReason(REQUEST_SCHEMA_NOT_AVAILABLE)
              .withResolution(PLEASE_SPECIFY_REQUEST_SCHEMA);
        }
        inputs = inputFactory.createTemplatizerInputListFrom(operationQName, parts);
        break;
      case WSDL20:
        // NOTE: The wsdl 2.0 grammar says that there can be 0 or more inputs in an
        // operation but there doesn't seem to be any methods which can return all of them
        inputs = new ArrayList<>(1);
        inputs.add(inputFactory.createTemplatizerInputFrom(operationQName, input.getElement()));
        break;
      default:
        throw new ConfigurationException(WSDL_VERSION_NOT_SUPPORTED)
            .withReason(WSDL_VERSION_NOT_SUPPORTED_REASON)
            .withResolution(WSDL_VERSION_NOT_SUPPORTED_RES);
    }

    /*Part part = parts.get(0);
    Element element = part.getElement(); // XXX: Hack - don't know what to do with other parts
    QName elemQName;
    QName typeQName;
    if (element == null) {
        // no element means the part does not define the XSD schema as an element with a
        // proper qname, instead we attempt to get the type
        Type type = part.getType();
        if (type != null) {
            elemQName = type.getQName();
        } else {
            // no type means some crappy defined WSDL, we attempt to get the type through the
            // part qname
            elemQName = part.getPartQName();
        }
        typeQName = elemQName;
    } else {
        // well defined WSDL, we have an element and a type of the element
        elemQName = element.getQName();
        typeQName = element.getType().getQName();
        if (typeQName == null) {
            typeQName = element.getQName();
        }
    }
    ((SoapEditorSuggestionsProviderImpl) editorSuggestionProvider)
            .withClientBuilder(clientBuilder)
            .withElementTypeQName(typeQName)
            .withTemplatizer(templatizer)
            .withHttpContextProvider(httpContextProvider);*/

    SOAPMessageTemplatizer.SoapProtocol soapProtocol = null;
    try {
      switch (operationBinding.getTypeOfBinding()) {
        case SOAP_BINDING4WSDL20:
        case SOAP11_BINDING4WSDL11:
          soapProtocol = SOAPMessageTemplatizer.SoapProtocol.SOAP_11;
          break;
        case SOAP12_BINDING4WSDL11:
          soapProtocol = SOAPMessageTemplatizer.SoapProtocol.SOAP_12;
          break;
        default:
          throw new ExecutionException(OPERATION_BINDING_NOT_SUPPORTED)
              .formatWith(operationBinding.getTypeOfBinding());
      }
    } catch (ClassCastException e) {
      // XXX: Hack
      switch (description.getVersion()) {
        case WSDL11:
          org.ow2.easywsdl.wsdl.impl.wsdl11.BindingImpl bindingImpl11 =
              (org.ow2.easywsdl.wsdl.impl.wsdl11.BindingImpl) operationBinding;
          List<Object> anyList = bindingImpl11.getModel().getAny();
          for (Object any : anyList) {
            if (any instanceof JAXBElement
                && (BINDING.equals(((JAXBElement) any).getName().getLocalPart()))
                && (SOAP_11_NS.equals(((JAXBElement) any).getName().getNamespaceURI()))) {
              soapProtocol = SOAPMessageTemplatizer.SoapProtocol.SOAP_11;
              break;
            } else if (any instanceof JAXBElement
                && (BINDING.equals(((JAXBElement) any).getName().getLocalPart()))
                && (SOAP_12_NS.equals(((JAXBElement) any).getName().getNamespaceURI()))) {
              soapProtocol = SOAPMessageTemplatizer.SoapProtocol.SOAP_12;
              break;
            }
          }
          break;
        case WSDL20:
          org.ow2.easywsdl.wsdl.impl.wsdl20.BindingImpl binding20 =
              (org.ow2.easywsdl.wsdl.impl.wsdl20.BindingImpl) operationBinding;
          anyList = binding20.getModel().getOperationOrFaultOrAny();
          for (Object any : anyList) {
            if (any instanceof JAXBElement
                && (BINDING.equals(((JAXBElement) any).getName().getLocalPart()))
                && (SOAP_11_NS.equals(((JAXBElement) any).getName().getLocalPart()))) {
              soapProtocol = SOAPMessageTemplatizer.SoapProtocol.SOAP_11;
              break;
            } else if (any instanceof JAXBElement
                && (BINDING.equals(((JAXBElement) any).getName().getLocalPart()))
                && (SOAP_12_NS.equals(((JAXBElement) any).getName().getLocalPart()))) {
              soapProtocol = SOAPMessageTemplatizer.SoapProtocol.SOAP_12;
              break;
            }
          }
          break;
        default:
          throw new IllegalArgumentException();
      }
    }
    Document wsdlDocument = domUtil.getResourceAsDocument(wsdlURL, httpContextProvider);
    Types types = typesFactory.generateTypes(wsdlDocument);
    SchemaVisitor schemaVisitor = new SchemaVisitorImpl();
    schemaVisitor.setProperty(SchemaConstants.ENCODE_ATTRIBUTE, shouldEncodeAttr);
    SOAPMessageTemplatizerImpl templatizer = new SOAPMessageTemplatizerImpl(types, schemaVisitor);
    templatizer.setProperty(TemplatizerConstants.ENCODE_ATTRIBUTE, shouldEncodeAttr);
    ((SoapEditorSuggestionsProviderImpl) editorSuggestionProvider)
        .withClientBuilder(clientBuilder)
        .withInputs(inputs)
        .withSoapProtocol(
            soapProtocol == null ? SOAPMessageTemplatizer.SoapProtocol.SOAP_11 : soapProtocol)
        .shouldEncodeAttr(shouldEncodeAttr)
        .withTemplatizer(templatizer)
        .withHttpContextProvider(httpContextProvider);
    return editorSuggestionProvider;
  }