Ejemplo n.º 1
0
  /**
   * Cursor position Before: <theElement>^</theElement> After: <theElement><lots of
   * stuff/>^</theElement>
   */
  public void createSampleForType(SchemaType stype, XmlCursor xmlc) {
    _exampleContent =
        SoapUI.getSettings().getBoolean(WsdlSettings.XML_GENERATION_TYPE_EXAMPLE_VALUE);
    _typeComment = SoapUI.getSettings().getBoolean(WsdlSettings.XML_GENERATION_TYPE_COMMENT_TYPE);
    _skipComments = SoapUI.getSettings().getBoolean(WsdlSettings.XML_GENERATION_SKIP_COMMENTS);

    QName nm = stype.getName();
    if (nm == null && stype.getContainerField() != null) nm = stype.getContainerField().getName();

    if (nm != null && excludedTypes.contains(nm)) {
      if (!_skipComments) xmlc.insertComment("Ignoring type [" + nm + "]");
      return;
    }

    if (_typeStack.contains(stype)) return;

    _typeStack.add(stype);

    try {
      if (stype.isSimpleType() || stype.isURType()) {
        processSimpleType(stype, xmlc);
        return;
      }

      // complex Type
      // <theElement>^</theElement>
      processAttributes(stype, xmlc);

      // <theElement attri1="string">^</theElement>
      switch (stype.getContentType()) {
        case SchemaType.NOT_COMPLEX_TYPE:
        case SchemaType.EMPTY_CONTENT:
          // noop
          break;
        case SchemaType.SIMPLE_CONTENT:
          {
            processSimpleType(stype, xmlc);
          }
          break;
        case SchemaType.MIXED_CONTENT:
          xmlc.insertChars(pick(WORDS) + " ");
          if (stype.getContentModel() != null) {
            processParticle(stype.getContentModel(), xmlc, true);
          }
          xmlc.insertChars(pick(WORDS));
          break;
        case SchemaType.ELEMENT_CONTENT:
          if (stype.getContentModel() != null) {
            processParticle(stype.getContentModel(), xmlc, false);
          }
          break;
      }
    } finally {
      _typeStack.remove(_typeStack.size() - 1);
    }
  }
Ejemplo n.º 2
0
  protected void generate(StringToStringMap values, ToolHost toolHost, Interface modelItem)
      throws Exception {
    String wsimportDir =
        SoapUI.getSettings().getString(ToolsSettings.JBOSSWS_WSTOOLS_LOCATION, null);
    if (Tools.isEmpty(wsimportDir)) {
      UISupport.showErrorMessage(
          "JBossWS wstools/wsconsume directory must be set in global preferences");
      return;
    }

    String wsimportExtension = UISupport.isWindows() ? ".bat" : ".sh";

    File wscompileFile =
        new File(wsimportDir + File.separatorChar + "wsconsume" + wsimportExtension);
    if (!wscompileFile.exists()) {
      UISupport.showErrorMessage("Could not find wsconsume script at [" + wscompileFile + "]");
      return;
    }

    ProcessBuilder builder = new ProcessBuilder();
    ArgumentBuilder args = buildArgs(UISupport.isWindows(), modelItem);
    builder.command(args.getArgs());
    builder.directory(new File(wsimportDir));

    toolHost.run(new ProcessToolRunner(builder, "JBossWS wsconsume", modelItem));
  }
Ejemplo n.º 3
0
  protected void generate(StringToStringMap values, ToolHost toolHost, WsdlProject project)
      throws Exception {
    String wstoolsDir =
        SoapUI.getSettings().getString(ToolsSettings.JBOSSWS_WSTOOLS_LOCATION, null);
    if (Tools.isEmpty(wstoolsDir)) {
      UISupport.showErrorMessage("wstools directory must be set in global preferences");
      return;
    }

    String wsToolsExtension = UISupport.isWindows() ? ".bat" : ".sh";

    File wstoolsFile = new File(wstoolsDir + File.separatorChar + "wstools" + wsToolsExtension);
    if (!wstoolsFile.exists()) {
      UISupport.showErrorMessage("Could not find wstools script at [" + wstoolsFile + "]");
      return;
    }

    ProcessBuilder builder = new ProcessBuilder();
    ArgumentBuilder args = buildArgs(values, UISupport.isWindows());
    builder.command(args.getArgs());
    builder.directory(new File(wstoolsDir));

    toolHost.run(
        new ToolRunner(builder, new File(values.get(OUTPUT)), values.get(SERVICE_NAME), project));
  }
Ejemplo n.º 4
0
  /**
   * Method for processing policy on interface level it should include processing of all types of
   * policies, but for now there's only Addressing policy implemented
   *
   * @param policy
   * @return this interface changed in a proper way indicated by the policy
   */
  public void processPolicy(Policy policy) throws Exception {

    // default is optional
    // String anonymous = AnonymousTypeConfig.OPTIONAL.toString();
    // if (StringUtils.isNullOrEmpty(interfaceAnonymous) || policyFlag)
    // interfaceAnonymous = AnonymousTypeConfig.OPTIONAL.toString() ;
    // if (StringUtils.isNullOrEmpty(interfaceWsaVersion)|| policyFlag)
    // interfaceWsaVersion = WsaVersionTypeConfig.NONE.toString();
    if (!policyFlag) {
      interfaceAnonymous = AnonymousTypeConfig.OPTIONAL.toString();
      interfaceWsaVersion = WsaVersionTypeConfig.NONE.toString();
    }
    policyFlag = true;

    if (policy != null) {
      List<Addressing> addressingList = policy.getAddressingList();
      List<?> usingAddressingList = policy.getUsingAddressingList();
      for (Addressing addressing : addressingList) {
        policyFlag = true;
        String optional = addressing.getOptional().toString();
        if (StringUtils.isNullOrEmpty(optional)
            || optional.equals("false")
            || (optional.equals("true")
                && SoapUI.getSettings().getBoolean(WsaSettings.ENABLE_FOR_OPTIONAL))) {
          interfaceWsaVersion = WsaVersionTypeConfig.X_200508.toString();
        }
        Policy innerPolicy = addressing.getPolicy();
        if (innerPolicy != null) {
          List<AnonymousResponses> anonymousList = innerPolicy.getAnonymousResponsesList();
          List<NonAnonymousResponses> nonAnonymousList = innerPolicy.getNonAnonymousResponsesList();
          if (anonymousList.size() > 0 && nonAnonymousList.size() > 0) {
            throw new Exception(
                "Wrong addressing policy, anonymousResponses and nonAnonymousResponses can not be specified together");
          }
          if (anonymousList.size() > 0) {
            interfaceAnonymous = AnonymousTypeConfig.REQUIRED.toString();
          } else {
            if (nonAnonymousList.size() > 0) {
              interfaceAnonymous = AnonymousTypeConfig.PROHIBITED.toString();
            }
          }
        }
      }
      if (interfaceWsaVersion == WsaVersionTypeConfig.NONE.toString()
          && !usingAddressingList.isEmpty()) {
        /*
         * UsingAddressing can also be specified insde Policy check
         * http://www.w3.org/TR/ws-addr-wsdl/#id2263339
         */
        interfaceWsaVersion = WsaVersionTypeConfig.X_200508.toString();
      }
    }
    setAnonymous(interfaceAnonymous);
    // set wsaVersion to one from policy only if it was null from wsdl binding
    if (getConfig().getWsaVersion().equals(WsaVersionTypeConfig.NONE)) {
      setWsaVersion(interfaceWsaVersion);
    }
  }
Ejemplo n.º 5
0
  /** To be overridden.. */
  public void onClose(T modelItem) {
    if (dialog == null) return;

    if (modelItem == null) {
      SoapUI.getSettings().setString(valuesSettingID, dialog.getValues().toXml());
    } else {
      modelItem.getSettings().setString(valuesSettingID, dialog.getValues().toXml());
    }
  }
Ejemplo n.º 6
0
 @Override
 public void itemStateChanged(ItemEvent arg0) {
   assertionsTable.getColumnModel().getColumn(0).setCellRenderer(assertionEntryRenderer);
   assertionsListTableModel.fireTableDataChanged();
   SoapUI.getSettings()
       .setBoolean(
           AssertionDescriptionSettings.SHOW_ASSERTION_DESCRIPTION,
           arg0.getStateChange() == ItemEvent.SELECTED);
 }
Ejemplo n.º 7
0
  protected void createGetMethod(String url) {
    getMethod = new HttpGet(url);
    getMethod.getParams().setParameter(ClientPNames.HANDLE_REDIRECTS, true);
    state.setAttribute(ClientContext.CREDS_PROVIDER, new WsdlCredentialsProvider());

    if (SoapUI.getSettings().getBoolean(HttpSettings.AUTHENTICATE_PREEMPTIVELY)) {
      if (!StringUtils.isNullOrEmpty(getUsername()) && !StringUtils.isNullOrEmpty(getPassword())) {
        UsernamePasswordCredentials creds =
            new UsernamePasswordCredentials(getUsername(), getPassword());
        getMethod.addHeader(BasicScheme.authenticate(creds, "utf-8", false));
      }
    }
  }
Ejemplo n.º 8
0
  protected void generate(StringToStringMap values, ToolHost toolHost, Interface modelItem)
      throws Exception {
    String xbDir = SoapUI.getSettings().getString(ToolsSettings.XMLBEANS_LOCATION, null);
    if (Tools.isEmpty(xbDir)) {
      UISupport.showErrorMessage("XmlBeans location must be set in global preferences");
      return;
    }

    ProcessBuilder builder = new ProcessBuilder();
    ArgumentBuilder argumentBuilder = buildArgs(values, modelItem);
    builder.command(argumentBuilder.getArgs());
    builder.directory(new File(xbDir + File.separatorChar + "bin"));

    toolHost.run(new ProcessToolRunner(builder, "XmlBeans", modelItem));
  }
Ejemplo n.º 9
0
    public Object construct() {
      HttpClientSupport.SoapUIHttpClient httpClient = HttpClientSupport.getHttpClient();
      try {
        Settings soapuiSettings = SoapUI.getSettings();

        HttpClientSupport.applyHttpSettings(getMethod, soapuiSettings);

        httpResponse = httpClient.execute(getMethod, state);
      } catch (Exception e) {
        return e;
      } finally {
        finished = true;
      }

      return null;
    }
Ejemplo n.º 10
0
  public void setConfig(T config) {
    this.config = config;

    if (config != null && config.isSetName()) {
      config.setName(config.getName().trim());
    }

    if (settings != null) settings.release();

    if (!config.isSetSettings()) config.addNewSettings();

    settings =
        new XmlBeansSettingsImpl(
            this,
            parent == null ? SoapUI.getSettings() : parent.getSettings(),
            this.config.getSettings());
  }
Ejemplo n.º 11
0
  public boolean show(String initialTab) {
    if (dialog == null) buildDialog();

    Settings settings = SoapUI.getSettings();
    for (Prefs pref : prefs) pref.setFormValues(settings);

    if (initialTab != null) {
      int ix = tabs.indexOfTab(initialTab);
      if (ix != -1) tabs.setSelectedIndex(ix);
    }

    if (dialog.show(new StringToStringMap())) {
      for (Prefs pref : prefs) pref.getFormValues(settings);

      return true;
    }

    return false;
  }
Ejemplo n.º 12
0
  protected StringToStringMap initValues(T modelItem, Object param) {
    String settingValues =
        modelItem == null
            ? SoapUI.getSettings().getString(valuesSettingID, null)
            : modelItem.getSettings().getString(valuesSettingID, null);

    StringToStringMap result =
        settingValues == null ? new StringToStringMap() : StringToStringMap.fromXml(settingValues);

    if (modelItem instanceof WsdlInterface) {
      initWSDL(result, (WsdlInterface) modelItem);
    }

    if (dialog != null && modelItem != null) {
      String projectRoot = modelItem.getSettings().getString(ProjectSettings.PROJECT_ROOT, null);
      if (projectRoot != null)
        dialog.setFormFieldProperty(ProjectSettings.PROJECT_ROOT, projectRoot);
    }

    return result;
  }
Ejemplo n.º 13
0
  protected void generate(StringToStringMap values, ToolHost toolHost, Interface modelItem)
      throws Exception {
    String wsaDir = SoapUI.getSettings().getString(ToolsSettings.ORACLE_WSA_LOCATION, null);
    if (Tools.isEmpty(wsaDir)) {
      UISupport.showErrorMessage("wsa.jar directory must be set in global preferences");
      return;
    }

    File wsaFile = new File(wsaDir + File.separatorChar + "wsa.jar");
    if (!wsaFile.exists()) {
      UISupport.showErrorMessage("Could not find wsa.jar at [" + wsaFile + "]");
      return;
    }

    ProcessBuilder builder = new ProcessBuilder();
    ArgumentBuilder args = buildArgs(values, modelItem);
    builder.command(args.getArgs());
    builder.directory(new File(wsaDir));

    toolHost.run(new ProcessToolRunner(builder, "Oracle wsa.jar", modelItem));
  }
Ejemplo n.º 14
0
  @Override
  protected Component buildContent() {
    JPanel mainPanel = new JPanel(new BorderLayout());
    JSplitPane splitPane =
        UISupport.createHorizontalSplit(buildCategoriesList(), buildAssertionsList());
    splitPane.setDividerLocation(220);
    getAssertionsTable().setSelectable(true);
    JXToolBar toolbar = UISupport.createSmallToolbar();
    hideDescCB = new JCheckBox("Hide descriptions");
    hideDescCB.setOpaque(false);
    hideDescCB.addItemListener(hideDescListener);
    hideDescCB.setSelected(
        SoapUI.getSettings().getBoolean(AssertionDescriptionSettings.SHOW_ASSERTION_DESCRIPTION));
    toolbar.add(new JLabel("Assertions"));
    toolbar.addGlue();
    toolbar.add(hideDescCB);

    mainPanel.add(toolbar, BorderLayout.NORTH);
    mainPanel.add(splitPane, BorderLayout.CENTER);
    return mainPanel;
  }
 public Settings getSettings() {
   return SoapUI.getSettings();
 }
Ejemplo n.º 16
0
  private static void setSoapUISettings() {
    SoapUI.getSettings().setBoolean(WsdlSettings.XML_GENERATION_TYPE_EXAMPLE_VALUE, false);
    SoapUI.getSettings().setBoolean(WsdlSettings.XML_GENERATION_SKIP_COMMENTS, false);
    // SoapUI.getSettings().setString(SoapUI.DEFAULT_WORKSPACE_FILE, "soapui-settings.xml");

  }
Ejemplo n.º 17
0
  public Response sendRequest(SubmitContext submitContext, Request request) throws Exception {
    AbstractHttpRequestInterface<?> httpRequest = (AbstractHttpRequestInterface<?>) request;

    HttpClient httpClient = HttpClientSupport.getHttpClient();
    ExtendedHttpMethod httpMethod = createHttpMethod(httpRequest);
    boolean createdState = false;

    HttpState httpState = (HttpState) submitContext.getProperty(SubmitContext.HTTP_STATE_PROPERTY);
    if (httpState == null) {
      httpState = new HttpState();
      submitContext.setProperty(SubmitContext.HTTP_STATE_PROPERTY, httpState);
      createdState = true;
    }

    HostConfiguration hostConfiguration = new HostConfiguration();

    String localAddress = System.getProperty("soapui.bind.address", httpRequest.getBindAddress());
    if (localAddress == null || localAddress.trim().length() == 0)
      localAddress = SoapUI.getSettings().getString(HttpSettings.BIND_ADDRESS, null);

    if (localAddress != null && localAddress.trim().length() > 0) {
      try {
        hostConfiguration.setLocalAddress(InetAddress.getByName(localAddress));
      } catch (Exception e) {
        SoapUI.logError(e);
      }
    }

    submitContext.removeProperty(RESPONSE);
    submitContext.setProperty(HTTP_METHOD, httpMethod);
    submitContext.setProperty(POST_METHOD, httpMethod);
    submitContext.setProperty(HTTP_CLIENT, httpClient);
    submitContext.setProperty(REQUEST_CONTENT, httpRequest.getRequestContent());
    submitContext.setProperty(HOST_CONFIGURATION, hostConfiguration);
    submitContext.setProperty(WSDL_REQUEST, httpRequest);
    submitContext.setProperty(RESPONSE_PROPERTIES, new StringToStringMap());

    for (RequestFilter filter : filters) {
      filter.filterRequest(submitContext, httpRequest);
    }

    try {
      Settings settings = httpRequest.getSettings();

      // custom http headers last so they can be overridden
      StringToStringMap headers = httpRequest.getRequestHeaders();
      for (String header : headers.keySet()) {
        String headerValue = headers.get(header);
        headerValue = PropertyExpander.expandProperties(submitContext, headerValue);
        httpMethod.setRequestHeader(header, headerValue);
      }

      // do request
      WsdlProject project = (WsdlProject) ModelSupport.getModelItemProject(httpRequest);
      WssCrypto crypto = null;
      if (project != null) {
        crypto =
            project
                .getWssContainer()
                .getCryptoByName(
                    PropertyExpander.expandProperties(submitContext, httpRequest.getSslKeystore()));
      }

      if (crypto != null && WssCrypto.STATUS_OK.equals(crypto.getStatus())) {
        hostConfiguration
            .getParams()
            .setParameter(
                SoapUIHostConfiguration.SOAPUI_SSL_CONFIG,
                crypto.getSource() + " " + crypto.getPassword());
      }

      // dump file?
      httpMethod.setDumpFile(
          PathUtils.expandPath(
              httpRequest.getDumpFile(), (AbstractWsdlModelItem<?>) httpRequest, submitContext));

      // include request time?
      if (settings.getBoolean(HttpSettings.INCLUDE_REQUEST_IN_TIME_TAKEN))
        httpMethod.initStartTime();

      // submit!
      httpClient.executeMethod(hostConfiguration, httpMethod, httpState);
      httpMethod.getTimeTaken();
    } catch (Throwable t) {
      httpMethod.setFailed(t);

      if (t instanceof Exception) throw (Exception) t;

      SoapUI.logError(t);
      throw new Exception(t);
    } finally {
      for (int c = filters.size() - 1; c >= 0; c--) {
        filters.get(c).afterRequest(submitContext, httpRequest);
      }

      if (!submitContext.hasProperty(RESPONSE)) {
        createDefaultResponse(submitContext, httpRequest, httpMethod);
      }

      Response response = (Response) submitContext.getProperty(BaseHttpRequestTransport.RESPONSE);
      StringToStringMap responseProperties =
          (StringToStringMap)
              submitContext.getProperty(BaseHttpRequestTransport.RESPONSE_PROPERTIES);

      for (String key : responseProperties.keySet()) {
        response.setProperty(key, responseProperties.get(key));
      }

      if (httpMethod != null) {
        httpMethod.releaseConnection();
      } else log.error("PostMethod is null");

      if (createdState) {
        submitContext.setProperty(SubmitContext.HTTP_STATE_PROPERTY, null);
      }
    }

    return (Response) submitContext.getProperty(BaseHttpRequestTransport.RESPONSE);
  }