public void actionPerformed(ActionEvent e) {
      try {
        MockResult mockResult = mockResponse.getMockResult();
        mockResponse.evaluateScript(mockResult == null ? null : mockResult.getMockRequest());

        StringToStringMap values = null;
        if (mockResponse.getMockResult() != null) {
          values = mockResponse.getMockResult().getMockRequest().getContext().toStringToStringMap();
        }

        if (values == null || values.isEmpty()) {
          UISupport.showInfoMessage("No values were returned");
        } else {
          String msg = "<html><body>Returned values:<br>";

          for (String name : values.keySet()) {
            msg += XmlUtils.entitize(name) + " : " + XmlUtils.entitize(values.get(name)) + "<br>";
          }

          msg += "</body></html>";

          UISupport.showExtendedInfo(
              "Result", "Result of MockResponse Script", msg, new Dimension(500, 400));
        }
      } catch (Throwable e1) {
        responseScriptEditor.selectError(e1.getMessage());
        UISupport.showErrorMessage(e1.toString());
      }
    }
 private StringToStringMap clearNullValues(StringToStringMap parameters) {
   StringToStringMap params = new StringToStringMap();
   for (String key : parameters.keySet()) {
     if (parameters.get(key) != null) params.put(key, parameters.get(key));
   }
   return params;
 }
  public StringToStringMapTableModel(
      StringToStringMap data, String keyCaption, String valueCaption, boolean editable) {
    this.data = data;
    this.keyCaption = keyCaption;
    this.valueCaption = valueCaption;
    this.editable = editable;

    keyList = data == null ? new ArrayList<String>() : new ArrayList<String>(data.keySet());
  }
  public String getAssertionNameForType(String type) {
    for (String assertion : assertionLabels.keySet()) {
      if (assertionLabels.get(assertion).equals(type)) {
        return assertion;
      }
    }

    return null;
  }
Beispiel #5
0
 private String initXPathNamespaces(String xpath) {
   if (declaredNamespaces != null && !declaredNamespaces.isEmpty()) {
     for (String prefix : declaredNamespaces.keySet()) {
       xpath =
           "declare namespace " + prefix + "='" + declaredNamespaces.get(prefix) + "';\n" + xpath;
     }
   } else if (!xpath.trim().startsWith("declare namespace")) {
     xpath = XmlUtils.declareXPathNamespaces(xmlObject) + xpath;
   }
   return xpath;
 }
  public String createScriptAssertionForExists(XPathData xpathData) {
    String script =
        "import com.eviware.soapui.support.XmlHolder\n\n"
            + "def holder = new XmlHolder( messageExchange.responseContentAsXml )\n";

    StringToStringMap nsMap = xpathData.getNamespaceMap();
    for (String ns : nsMap.keySet()) {
      script += "holder.namespaces[\"" + nsMap.get(ns) + "\"] = \"" + ns + "\"\n";
    }

    script += "def node = holder.getDomNode( \"" + xpathData.getPath() + "\" )\n";
    script += "\nassert node != null\n";

    return script;
  }
  private ConfigurationDocument createConfigFile(StringToStringMap values, Interface modelItem) {
    ConfigurationDocument configDocument = ConfigurationDocument.Factory.newInstance();
    ConfigurationType config = configDocument.addNewConfiguration();

    try {
      StringToStringMap nsMappings = StringToStringMap.fromXml(values.get(NAMESPACE_MAPPING));
      if (!nsMappings.isEmpty()) {
        GlobalType global = config.addNewGlobal();

        for (String namespace : nsMappings.keySet()) {
          PkgNSType entry = global.addNewPackageNamespace();
          entry.setNamespace(namespace);
          entry.setPackage(nsMappings.get(namespace));
        }
      }
    } catch (Exception e) {
      SoapUI.logError(e);
    }

    WsdlToJavaType wsdl2Java = config.addNewWsdlJava();

    String wsdlUrl = getWsdlUrl(values, modelItem);
    try {
      new URL(wsdlUrl);
      wsdl2Java.setLocation(wsdlUrl);
    } catch (MalformedURLException e) {
      ((Element) wsdl2Java.getDomNode()).setAttribute("file", wsdlUrl);
    }

    if (values.getBoolean(UNWRAP)) wsdl2Java.setParameterStyle(ParameterStyle.BARE);
    else wsdl2Java.setParameterStyle(ParameterStyle.WRAPPED);

    if (values.get(EJB_LINK) != null && values.get(EJB_LINK).length() > 0) {
      WsxmlType webservices = wsdl2Java.addNewWebservices();
      webservices.setEjbLink(values.get(EJB_LINK));
      webservices.setAppend(values.getBoolean(APPEND));
    } else if (values.get(SERVLET_LINK) != null && values.get(SERVLET_LINK).length() > 0) {
      WsxmlType webservices = wsdl2Java.addNewWebservices();
      webservices.setServletLink(values.get(SERVLET_LINK));
      webservices.setAppend(values.getBoolean(APPEND));
    }

    String mappingFile = values.get(MAPPING).toString().trim();
    if (mappingFile.length() > 0) {
      wsdl2Java.addNewMapping().setFile(mappingFile);
    }
    return configDocument;
  }
Beispiel #8
0
 public void setValues(StringToStringMap values) {
   for (Iterator<String> i = values.keySet().iterator(); i.hasNext(); ) {
     String key = i.next();
     setComponentValue(key, values.get(key));
   }
 }
  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);
  }