예제 #1
0
  private ArgumentBuilder buildArgs(boolean isWindows, Interface modelItem) throws IOException {
    StringToStringMap values = dialog.getValues();
    values.put(OUTPUT, Tools.ensureDir(values.get(OUTPUT), ""));
    values.put(SOURCE_OUTPUT, Tools.ensureDir(values.get(SOURCE_OUTPUT), values.get(OUTPUT)));

    ArgumentBuilder builder = new ArgumentBuilder(values);
    builder.startScript("wsconsume");

    builder.addString(OUTPUT, "-o");
    builder.addString(CATALOG, "-c");
    builder.addString(PACKAGE, "-p");
    builder.addString(SOURCE_OUTPUT, "-s");
    builder.addString(WSDLLOCATION, "-w");
    builder.addBoolean(KEEP, "-k");
    builder.addBoolean(STACKTRACE, "-t");

    String[] bindingFiles = values.get(BINDING_FILES).split(",");
    for (String file : bindingFiles) {
      if (file.trim().length() > 0) builder.addArgs("-b", file.trim());
    }

    addToolArgs(values, builder);
    builder.addArgs(getWsdlUrl(values, modelItem));

    return builder;
  }
예제 #2
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));
  }
예제 #3
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));
  }
 public MonitorMessageExchangeDataSource(String name, InputStream in, String contentType) {
   try {
     data = Tools.readAll(in, 0).toByteArray();
     this.contentType = contentType;
     this.name = name;
   } catch (Exception e) {
     SoapUI.logError(e);
   }
 }
예제 #5
0
  private ArgumentBuilder buildArgs(
      StringToStringMap values, boolean isWindows, Interface modelItem) throws IOException {
    values.put(OUTPUT, Tools.ensureDir(values.get(OUTPUT), ""));

    ArgumentBuilder builder = new ArgumentBuilder(values);
    builder.startScript("wstools");

    builder.addArgs("-config", buildConfigFile(values, modelItem));
    builder.addString(OUTPUT, "-dest");
    addToolArgs(values, builder);
    return builder;
  }
예제 #6
0
  private ArgumentBuilder buildArgs(StringToStringMap values, Interface modelItem) {
    ArgumentBuilder builder = new ArgumentBuilder(values);

    values.put(XSBTARGET, Tools.ensureDir(values.get(XSBTARGET), ""));
    values.put(SRCTARGET, Tools.ensureDir(values.get(SRCTARGET), ""));

    builder.startScript("scomp", ".cmd", "");

    builder.addString(XSBTARGET, "-d");
    builder.addString(SRCTARGET, "-src");
    builder.addString(JARFILE, "-out");

    builder.addBoolean(SRCONLY, "-srconly");
    builder.addBoolean(DOWNLOADS, "-dl");
    builder.addBoolean(NOUPA, "-noupa");
    builder.addBoolean(NOPVR, "-nopvr");
    builder.addBoolean(NOANN, "-noann");
    builder.addBoolean(NOVDOC, "-novdoc");
    builder.addBoolean(DEBUG, "-debug");

    builder.addString(JAVASOURCE, "-javasource");
    builder.addString(ALLOWMDEF, "-allowmdef");
    builder.addString(CATALOG, "-catalog");
    builder.addBoolean(VERBOSE, "-verbose");

    String javac = ToolsSupport.getToolLocator().getJavacLocation(false);

    if (StringUtils.hasContent(javac)) {
      builder.addArgs("-compiler", javac + File.separatorChar + "javac");
    }
    addToolArgs(values, builder);

    builder.addString(XSDCONFIG, null);
    builder.addArgs(getWsdlUrl(values, modelItem));

    return builder;
  }
예제 #7
0
  private ArgumentBuilder buildArgs(StringToStringMap values, Interface modelItem)
      throws IOException {
    values.put(OUTPUT, Tools.ensureDir(values.get(OUTPUT), ""));

    ArgumentBuilder builder = new ArgumentBuilder(values);
    builder.addArgs("java", "-jar", "wsa.jar", "-genProxy");
    addJavaArgs(values, builder);

    builder.addArgs("-wsdl", getWsdlUrl(values, modelItem));
    builder.addString(OUTPUT, "-output");
    builder.addString(PACKAGE, "-packageName");

    addToolArgs(values, builder);
    return builder;
  }
예제 #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));
  }
예제 #9
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));
  }
예제 #10
0
  protected void prepareRequestStep(HttpRequestTestStep requestStep) {
    AbstractHttpRequest<?> httpRequest = requestStep.getHttpRequest();
    if (StringUtils.hasContent(endpoint)) {
      httpRequest.setEndpoint(endpoint);
    } else if (StringUtils.hasContent(host)) {
      try {
        String ep = Tools.replaceHost(httpRequest.getEndpoint(), host);
        httpRequest.setEndpoint(ep);
      } catch (Exception e) {
        log.error("Failed to set host on endpoint", e);
      }
    }

    if (StringUtils.hasContent(username)) {
      httpRequest.setUsername(username);
    }

    if (StringUtils.hasContent(password)) {
      httpRequest.setPassword(password);
    }

    if (StringUtils.hasContent(domain)) {
      httpRequest.setDomain(domain);
    }

    if (httpRequest instanceof WsdlRequest) {

      if (wssPasswordType != null && wssPasswordType.length() > 0) {
        ((WsdlRequest) httpRequest)
            .setWssPasswordType(
                wssPasswordType.equals("Digest")
                    ? WsdlTestRequest.PW_TYPE_DIGEST
                    : WsdlTestRequest.PW_TYPE_TEXT);
      }
    }
  }
  public void perform(RestService target, Object param) {
    try {
      if (dialog == null) {
        dialog = ADialogBuilder.buildDialog(Form.class);
      }

      Settings settings = target.getSettings();
      dialog.setValue(Form.OUTPUT_FOLDER, settings.getString(REPORT_DIRECTORY_SETTING, ""));

      if (!dialog.show()) {
        return;
      }

      settings.setString(REPORT_DIRECTORY_SETTING, dialog.getValue(Form.OUTPUT_FOLDER));

      final File reportDirectory = new File(settings.getString(REPORT_DIRECTORY_SETTING, ""));
      String reportDirAbsolutePath = reportDirectory.getAbsolutePath();
      String filename = reportDirAbsolutePath + File.separatorChar + "report.xml";
      String reportUrl = transform(target, reportDirAbsolutePath, filename);
      Tools.openURL(reportUrl);
    } catch (Exception e) {
      UISupport.showErrorMessage(e);
    }
  }
예제 #12
0
  public void initFromWadl(String wadlUrl) {
    try {
      // XmlObject xmlObject = XmlObject.Factory.parse( new URL( wadlUrl ) );
      XmlObject xmlObject = XmlUtils.createXmlObject(new URL(wadlUrl));

      String content = xmlObject.xmlText();
      Element element = ((Document) xmlObject.getDomNode()).getDocumentElement();

      // try to allow older namespaces
      if (element.getLocalName().equals("application")
          && element.getNamespaceURI().startsWith("http://research.sun.com/wadl")) {
        isWADL11 = false;
        content =
            content.replaceAll(
                "\"" + element.getNamespaceURI() + "\"", "\"" + Constants.WADL11_NS + "\"");
      } else if (!element.getLocalName().equals("application")
          || !element.getNamespaceURI().equals(Constants.WADL11_NS)) {
        throw new Exception(
            "Document is not a WADL application with " + Constants.WADL11_NS + " namespace");
      }
      content = PropertyExpansionRemover.removeExpansions(content);
      ApplicationDocument applicationDocument = ApplicationDocument.Factory.parse(content);
      application = applicationDocument.getApplication();

      resourcesList = application.getResourcesList();

      service.setName(getFirstTitle(application.getDocList(), service.getName()));

      String base = resourcesList.size() == 1 ? resourcesList.get(0).getBase() : "";

      try {
        URL baseUrl = new URL(base);
        service.setBasePath(baseUrl.getPath());

        service.addEndpoint(Tools.getEndpointFromUrl(baseUrl));
      } catch (Exception e) {
        service.setBasePath(base);
      }

      service.setWadlUrl(wadlUrl);
      service.getConfig().setWadlVersion(isWADL11 ? Constants.WADL11_NS : Constants.WADL10_NS);

      for (Resources resources : resourcesList) {
        RestResource baseResource = null;
        if (resourcesList.size() > 1) {
          String path = resources.getBase();
          baseResource = service.addNewResource(path, path);
        }
        for (Resource resource : resources.getResourceList()) {
          String name = getFirstTitle(resource.getDocList(), resource.getPath());
          String path = resource.getPath();

          RestResource newResource = null;

          if (baseResource != null && path != null) {
            for (RestResource res : baseResource.getChildResourceList()) {
              if (path.equals(res.getPath())) {
                newResource = res;
                break;
              }
            }

            if (newResource == null) {
              newResource = baseResource.addNewChildResource(name, path);
            }
          } else if (path != null) {
            for (RestResource res : service.getResourceList()) {
              if (path.equals(res.getPath())) {
                newResource = res;
                break;
              }
            }

            if (newResource == null) {
              newResource = service.addNewResource(name, path);
            }
          } else {
            newResource = service.addNewResource(name, "");
          }

          initResourceFromWadlResource(newResource, resource);
          addSubResources(newResource, resource);
        }
      }
    } catch (InvalidDefinitionException ex) {
      ex.show();
    } catch (Exception e) {
      UISupport.showErrorMessage(e);
    }
  }
예제 #13
0
  public void service(ServletRequest request, ServletResponse response)
      throws ServletException, IOException {
    listenerCallBack.fireOnRequest(project, request, response);
    if (response.isCommitted()) {
      return;
    }

    ExtendedHttpMethod method;
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    if (httpRequest.getMethod().equals("GET")) {
      method = new ExtendedGetMethod();
    } else if (httpRequest.getMethod().equals("POST")) {
      method = new ExtendedPostMethod();
    } else if (httpRequest.getMethod().equals("PUT")) {
      method = new ExtendedPutMethod();
    } else if (httpRequest.getMethod().equals("HEAD")) {
      method = new ExtendedHeadMethod();
    } else if (httpRequest.getMethod().equals("OPTIONS")) {
      method = new ExtendedOptionsMethod();
    } else if (httpRequest.getMethod().equals("TRACE")) {
      method = new ExtendedTraceMethod();
    } else if (httpRequest.getMethod().equals("PATCH")) {
      method = new ExtendedPatchMethod();
    } else {
      method = new ExtendedGenericMethod(httpRequest.getMethod());
    }

    method.setDecompress(false);

    ByteArrayOutputStream requestBody = null;
    if (method instanceof HttpEntityEnclosingRequest) {
      requestBody = Tools.readAll(request.getInputStream(), 0);
      ByteArrayEntity entity = new ByteArrayEntity(requestBody.toByteArray());
      entity.setContentType(request.getContentType());
      ((HttpEntityEnclosingRequest) method).setEntity(entity);
    }

    // for this create ui server and port, properties.
    JProxyServletWsdlMonitorMessageExchange capturedData =
        new JProxyServletWsdlMonitorMessageExchange(project);
    capturedData.setRequestHost(httpRequest.getServerName());
    capturedData.setRequestMethod(httpRequest.getMethod());
    capturedData.setRequestHeader(httpRequest);
    capturedData.setHttpRequestParameters(httpRequest);
    capturedData.setQueryParameters(httpRequest.getQueryString());
    capturedData.setTargetURL(httpRequest.getRequestURL().toString());

    //		CaptureInputStream capture = new CaptureInputStream( httpRequest.getInputStream() );

    // check connection header
    String connectionHeader = httpRequest.getHeader("Connection");
    if (connectionHeader != null) {
      connectionHeader = connectionHeader.toLowerCase();
      if (!connectionHeader.contains("keep-alive") && !connectionHeader.contains("close")) {
        connectionHeader = null;
      }
    }

    // copy headers
    boolean xForwardedFor = false;
    @SuppressWarnings("unused")
    Enumeration<?> headerNames = httpRequest.getHeaderNames();
    while (headerNames.hasMoreElements()) {
      String hdr = (String) headerNames.nextElement();
      String lhdr = hdr.toLowerCase();

      if (dontProxyHeaders.contains(lhdr)) {
        continue;
      }
      if (connectionHeader != null && connectionHeader.contains(lhdr)) {
        continue;
      }

      Enumeration<?> vals = httpRequest.getHeaders(hdr);
      while (vals.hasMoreElements()) {
        String val = (String) vals.nextElement();
        if (val != null) {
          method.setHeader(lhdr, val);
          xForwardedFor |= "X-Forwarded-For".equalsIgnoreCase(hdr);
        }
      }
    }

    // Proxy headers
    method.setHeader("Via", "SoapUI Monitor");
    if (!xForwardedFor) {
      method.addHeader("X-Forwarded-For", request.getRemoteAddr());
    }

    StringBuffer url = new StringBuffer("http://");
    url.append(httpRequest.getServerName());
    if (httpRequest.getServerPort() != 80) {
      url.append(":" + httpRequest.getServerPort());
    }

    if (httpRequest.getServletPath() != null) {
      url.append(httpRequest.getServletPath());
      try {
        method.setURI(new java.net.URI(url.toString().replaceAll(" ", "%20")));
      } catch (URISyntaxException e) {
        SoapUI.logError(e);
      }

      if (httpRequest.getQueryString() != null) {
        url.append("?" + httpRequest.getQueryString());
        try {
          method.setURI(new java.net.URI(url.toString()));
        } catch (URISyntaxException e) {
          SoapUI.logError(e);
        }
      }
    }

    method.getParams().setParameter(ClientPNames.HANDLE_REDIRECTS, false);
    setProtocolversion(method, request.getProtocol());
    ProxyUtils.setForceDirectConnection(method.getParams());
    listenerCallBack.fireBeforeProxy(project, request, response, method);

    if (settings.getBoolean(LaunchForm.SSLTUNNEL_REUSESTATE)) {
      if (httpState == null) {
        httpState = new BasicHttpContext();
      }
      HttpClientSupport.execute(method, httpState);
    } else {
      HttpClientSupport.execute(method);
    }

    // wait for transaction to end and store it.
    capturedData.stopCapture();

    capturedData.setRequest(requestBody == null ? null : requestBody.toByteArray());
    capturedData.setRawResponseBody(method.getResponseBody());
    capturedData.setResponseHeader(method.getHttpResponse());
    capturedData.setRawRequestData(getRequestToBytes(request.toString(), requestBody));
    capturedData.setRawResponseData(getResponseToBytes(method, capturedData.getRawResponseBody()));
    byte[] decompressedResponseBody = method.getDecompressedResponseBody();
    capturedData.setResponseContent(
        decompressedResponseBody != null ? new String(decompressedResponseBody) : "");
    capturedData.setResponseStatusCode(
        method.hasHttpResponse() ? method.getHttpResponse().getStatusLine().getStatusCode() : null);
    capturedData.setResponseStatusLine(
        method.hasHttpResponse() ? method.getHttpResponse().getStatusLine().toString() : null);

    listenerCallBack.fireAfterProxy(project, request, response, method, capturedData);

    ((HttpServletResponse) response)
        .setStatus(
            method.hasHttpResponse()
                ? method.getHttpResponse().getStatusLine().getStatusCode()
                : null);

    if (!response.isCommitted()) {
      StringToStringsMap responseHeaders = capturedData.getResponseHeaders();
      // capturedData = null;

      // copy headers to response
      HttpServletResponse httpServletResponse = (HttpServletResponse) response;
      for (Map.Entry<String, List<String>> headerEntry : responseHeaders.entrySet()) {
        for (String header : headerEntry.getValue()) {
          httpServletResponse.addHeader(headerEntry.getKey(), header);
        }
      }

      if (capturedData.getRawResponseBody() != null) {
        IO.copy(
            new ByteArrayInputStream(capturedData.getRawResponseBody()),
            httpServletResponse.getOutputStream());
      }
    }

    synchronized (this) {
      if (contentTypeMatches(method)) {
        listenerCallBack.fireAddMessageExchange(capturedData);
      }
    }
  }
예제 #14
0
  @Override
  public void afterStep(
      TestCaseRunner testRunner, TestCaseRunContext runContext, TestStepResult result) {
    super.afterStep(testRunner, runContext, result);
    TestStep currentStep = runContext.getCurrentStep();

    if (currentStep instanceof Assertable) {
      Assertable requestStep = (Assertable) currentStep;
      for (int c = 0; c < requestStep.getAssertionCount(); c++) {
        TestAssertion assertion = requestStep.getAssertionAt(c);
        log.info("Assertion [" + assertion.getName() + "] has status " + assertion.getStatus());
        if (assertion.getStatus() == AssertionStatus.FAILED) {
          for (AssertionError error : assertion.getErrors()) {
            log.error("ASSERTION FAILED -> " + error.getMessage());
          }

          assertions.add(assertion);
          assertionResults.put(assertion, (WsdlTestStepResult) result);
        }

        testAssertionCount++;
      }
    }

    String countPropertyName = currentStep.getName() + " run count";
    Long count = (Long) runContext.getProperty(countPropertyName);
    if (count == null) {
      count = new Long(0);
    }

    runContext.setProperty(countPropertyName, new Long(count.longValue() + 1));

    if (result.getStatus() == TestStepStatus.FAILED || exportAll) {
      try {
        String exportSeparator = System.getProperty(SOAPUI_EXPORT_SEPARATOR, "-");

        TestCase tc = currentStep.getTestCase();
        String nameBase =
            StringUtils.createFileName(tc.getTestSuite().getName(), '_')
                + exportSeparator
                + StringUtils.createFileName(tc.getName(), '_')
                + exportSeparator
                + StringUtils.createFileName(currentStep.getName(), '_')
                + "-"
                + count.longValue()
                + "-"
                + result.getStatus();

        WsdlTestCaseRunner callingTestCaseRunner =
            (WsdlTestCaseRunner) runContext.getProperty("#CallingTestCaseRunner#");

        if (callingTestCaseRunner != null) {
          WsdlTestCase ctc = callingTestCaseRunner.getTestCase();
          WsdlRunTestCaseTestStep runTestCaseTestStep =
              (WsdlRunTestCaseTestStep) runContext.getProperty("#CallingRunTestCaseStep#");

          nameBase =
              StringUtils.createFileName(ctc.getTestSuite().getName(), '_')
                  + exportSeparator
                  + StringUtils.createFileName(ctc.getName(), '_')
                  + exportSeparator
                  + StringUtils.createFileName(runTestCaseTestStep.getName(), '_')
                  + exportSeparator
                  + StringUtils.createFileName(tc.getTestSuite().getName(), '_')
                  + exportSeparator
                  + StringUtils.createFileName(tc.getName(), '_')
                  + exportSeparator
                  + StringUtils.createFileName(currentStep.getName(), '_')
                  + "-"
                  + count.longValue()
                  + "-"
                  + result.getStatus();
        }

        String absoluteOutputFolder = getAbsoluteOutputFolder(ModelSupport.getModelItemProject(tc));
        String fileName = absoluteOutputFolder + File.separator + nameBase + ".txt";

        if (result.getStatus() == TestStepStatus.FAILED) {
          log.error(currentStep.getName() + " failed, exporting to [" + fileName + "]");
        }

        new File(fileName).getParentFile().mkdirs();

        PrintWriter writer = new PrintWriter(fileName);
        result.writeTo(writer);
        writer.close();

        // write attachments
        if (result instanceof MessageExchange) {
          Attachment[] attachments = ((MessageExchange) result).getResponseAttachments();
          if (attachments != null && attachments.length > 0) {
            for (int c = 0; c < attachments.length; c++) {
              fileName = nameBase + "-attachment-" + (c + 1) + ".";

              Attachment attachment = attachments[c];
              String contentType = attachment.getContentType();
              if (!"application/octet-stream".equals(contentType)
                  && contentType != null
                  && contentType.indexOf('/') != -1) {
                fileName += contentType.substring(contentType.lastIndexOf('/') + 1);
              } else {
                fileName += "dat";
              }

              fileName = absoluteOutputFolder + File.separator + fileName;

              FileOutputStream outFile = new FileOutputStream(fileName);
              Tools.writeAll(outFile, attachment.getInputStream());
              outFile.close();
            }
          }
        }

        exportCount++;
      } catch (Exception e) {
        log.error("Error saving failed result: " + e, e);
      }
    }

    testStepCount++;
  }
예제 #15
0
 protected void addToolArgs(StringToStringMap values, ArgumentBuilder builder) {
   String[] toolArgs = Tools.tokenizeArgs(values.get(TOOL_ARGS));
   if (toolArgs != null) builder.addArgs(toolArgs);
 }
예제 #16
0
 protected void addJavaArgs(StringToStringMap values, ArgumentBuilder builder) {
   String[] javaArgs = Tools.tokenizeArgs(values.get(JAVA_ARGS));
   if (javaArgs != null) builder.addArgs(javaArgs);
 }
예제 #17
0
 public void actionPerformed(ActionEvent e) {
   Tools.openURL(url);
 }