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)); }
public static StringToStringMap fromXml(StringToStringMapConfig nsMapping) { StringToStringMap result = new StringToStringMap(); for (Entry entry : nsMapping.getEntryList()) { result.put(entry.getKey(), entry.getValue()); } return result; }
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 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()); } }
protected String getWsdlUrl(StringToStringMap values, T modelItem) { String wsdl = values.get(WSDL); boolean useCached = values.getBoolean(CACHED_WSDL); if (modelItem instanceof AbstractInterface) { AbstractInterface<?> iface = (AbstractInterface<?>) modelItem; boolean hasDefinition = StringUtils.hasContent(iface.getDefinition()); if (wsdl == null && !useCached && hasDefinition) { return PathUtils.expandPath(iface.getDefinition(), iface); } if (!hasDefinition || (useCached && iface.getDefinitionContext().isCached())) { try { File tempFile = File.createTempFile("tempdir", null); String path = tempFile.getAbsolutePath(); tempFile.delete(); wsdl = iface.getDefinitionContext().export(path); // CachedWsdlLoader loader = (CachedWsdlLoader) // iface.createWsdlLoader(); // wsdl = loader.saveDefinition(path); } catch (Exception e) { SoapUI.logError(e); } } } return wsdl; }
protected StringToStringMap initValues(Interface modelItem, Object param) { StringToStringMap values = super.initValues(modelItem, param); if (output != null) { values.put(SRCTARGET, output); } return values; }
/** Get the inverse of this map. */ public StringToStringMap inverse() { StringToStringMap inverse = new StringToStringMap(); for (String key : keySet()) { String value = get(key); inverse.put(value, key); } return inverse; }
protected void initWSDL(StringToStringMap values, WsdlInterface iface) { boolean cached = iface.isCached(); if (useCached != null) useCached.setEnabled(cached); if (!values.containsKey(CACHED_WSDL)) values.put(CACHED_WSDL, Boolean.toString(cached)); if (values.getBoolean(CACHED_WSDL) || !values.hasValue(WSDL)) values.put(WSDL, PathUtils.expandPath(iface.getDefinition(), iface)); }
public String getAssertionNameForType(String type) { for (String assertion : assertionLabels.keySet()) { if (assertionLabels.get(assertion).equals(type)) { return assertion; } } return null; }
public void add(String key, String value) { if (keyList.contains(key)) { data.put(key, value); fireTableCellUpdated(keyList.indexOf(key), 1); } else { data.put(key, value); keyList.add(key); fireTableRowsInserted(keyList.size() - 1, keyList.size() - 1); } }
public StringToStringMap getValues() { StringToStringMap values = new StringToStringMap(); for (Iterator<String> i = components.keySet().iterator(); i.hasNext(); ) { String key = i.next(); values.put(key, getComponentValue(key)); } return values; }
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; }
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; }
@Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { StringToStringMap part = parts.get(rowIndex); if (aValue == null) aValue = ""; switch (columnIndex) { case 0: part.put("name", ""); fireTableCellUpdated(rowIndex, 1); part.put("id", aValue.toString()); break; case 1: part.put("id", ""); fireTableCellUpdated(rowIndex, 0); part.put("name", aValue.toString()); break; case 2: part.put("id", ""); fireTableCellUpdated(rowIndex, 0); part.put("namespace", aValue.toString()); break; case 3: part.put("enc", aValue.toString()); break; } entry.saveConfig(); }
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 StringToStringMap initValues() { StringToStringMap values = new StringToStringMap(); dialog.setOptions(SOURCE_STEP, getSourceSteps()); dialog.setOptions(SOURCE_PROPERTY, getSourceProperties()); values.put(TRANSFER_STEP, findPropertyTransfer()); values.put(TRANSFER_NAME, treeNode.getDomNode().getLocalName()); String xpath = XmlUtils.createXPath(treeNode.getDomNode()); values.put(TARGET_XPATH, xpath); values.put(CURRENT_VALUE, getCurrentValue(xpath)); return values; }
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; }
public void setValueAt(Object arg0, int arg1, int arg2) { String oldKey = keyList.get(arg1); if (arg2 == 0) { String value = data.get(oldKey); data.remove(oldKey); data.put(arg0.toString(), value); keyList.set(arg1, arg0.toString()); } else { data.put(oldKey, arg0.toString()); } fireTableCellUpdated(arg1, arg2); }
public void remove(int row) { String key = keyList.get(row); keyList.remove(row); data.remove(key); fireTableRowsDeleted(row, row); }
public Object getValueAt(int rowIndex, int columnIndex) { StringToStringMap part = parts.get(rowIndex); switch (columnIndex) { case 0: return part.get("id"); case 1: return part.get("name"); case 2: return part.get("namespace"); case 3: return part.get("enc"); } return null; }
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; }
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 StringToStringMap getValues(Settings settings) { StringToStringMap values = new StringToStringMap(); values.put(NO_RESIZE_REQUEST_EDITOR, settings.getBoolean(UISettings.NO_RESIZE_REQUEST_EDITOR)); values.put(START_WITH_REQUEST_TABS, settings.getBoolean(UISettings.START_WITH_REQUEST_TABS)); values.put(AUTO_VALIDATE_REQUEST, settings.getBoolean(UISettings.AUTO_VALIDATE_REQUEST)); values.put(ABORT_ON_INVALID_REQUEST, settings.getBoolean(UISettings.ABORT_ON_INVALID_REQUEST)); values.put(AUTO_VALIDATE_RESPONSE, settings.getBoolean(UISettings.AUTO_VALIDATE_RESPONSE)); values.put(XML_LINE_NUMBERS, settings.getBoolean(UISettings.SHOW_XML_LINE_NUMBERS)); values.put(GROOVY_LINE_NUMBERS, settings.getBoolean(UISettings.SHOW_GROOVY_LINE_NUMBERS)); return values; }
private static void extractNVPair(String value, StringToStringMap result) { int ix; ix = value.indexOf('='); if (ix != -1) { String str = value.substring(ix + 1).trim(); if (str.startsWith("\"") && str.endsWith("\"")) str = str.substring(1, str.length() - 1); result.put(value.substring(0, ix).trim(), str); } }
private static boolean checkIfJMS(MessageExchangeModelItem messageExchange) { try { MessageExchange me = ((MessageExchangeModelItem) messageExchange).getMessageExchange(); if (me != null) { StringToStringMap strmap = me.getProperties(); if (strmap != null && strmap.containsKey("Endpoint")) { String r = me.getProperty("Endpoint"); return r != null && r.startsWith(JMSEndpoint.JMS_ENDPIONT_PREFIX); } else { return false; } } else { return false; } } catch (NullPointerException e) { SoapUI.logError(e); } return false; }
@Override protected StringToStringMap initValues(Interface modelItem, Object param) { StringToStringMap values = super.initValues(modelItem, param); boolean hasEjbLink = values.get(EJB_LINK, "").length() > 0; boolean hasServletLink = values.get(SERVLET_LINK, "").length() > 0; if (!hasEjbLink && !hasServletLink) { ejbLinkField.setEnabled(true); servletLinkField.setEnabled(true); } else { ejbLinkField.setEnabled(hasEjbLink && !hasServletLink); servletLinkField.setEnabled(hasServletLink && !hasEjbLink); if (hasEjbLink && hasServletLink) values.put(SERVLET_LINK, ""); } appendField.setEnabled(hasEjbLink || hasServletLink); return values; }
private StringToStringMap update(TestStep testStep, SecurityTestRunContext context) throws XmlException, Exception { StringToStringMap params = new StringToStringMap(); if (parameterMutations.size() == 0) mutateParameters(testStep, context); /* * Idea is to drain for each parameter mutations. */ for (SecurityCheckedParameter param : getParameterHolder().getParameterList()) { ArrayList<String> mutations = parameterMutations.get(param); if (mutations != null && !mutations.isEmpty()) { testStep.getProperties().get(param.getName()).setValue(mutations.get(0)); params.put(param.getLabel(), mutations.get(0)); mutations.remove(0); break; } } return params; }
// Used to save values from table GUI components protected List<StringToStringMap> readTableValues( XmlObjectConfigurationReader reader, String parameterName) { List<StringToStringMap> result = new ArrayList<StringToStringMap>(); String[] tableValues = reader.readStrings(parameterName); if (tableValues != null && tableValues.length > 0) { for (String tableValue : tableValues) { result.add(StringToStringMap.fromXml(tableValue)); } } return result; }
public void perform(SecurityTest securityTest, Object param) { if (dialog == null) { XFormDialogBuilder builder = XFormFactory.createDialogBuilder("SecurityTest Options"); form = builder.createForm("Basic"); form.addCheckBox(FAIL_ON_ERROR, "Fail on error") .addFormFieldListener( new XFormFieldListener() { public void valueChanged(XFormField sourceField, String newValue, String oldValue) { form.getFormField(FAIL_SECURITYTEST_ON_ERROR) .setEnabled(!Boolean.parseBoolean(newValue)); } }); form.addCheckBox(FAIL_SECURITYTEST_ON_ERROR, "Fail SecurityTest if it has failed TestSteps"); dialog = builder.buildDialog( builder.buildOkCancelHelpActions(HelpUrls.SECURITYTESTEDITOR_HELP_URL), "Specify general options for this SecurityTest", UISupport.OPTIONS_ICON); } StringToStringMap values = new StringToStringMap(); values.put(FAIL_ON_ERROR, String.valueOf(securityTest.getFailOnError())); values.put( FAIL_SECURITYTEST_ON_ERROR, String.valueOf(securityTest.getFailSecurityTestOnScanErrors())); values = dialog.show(values); if (dialog.getReturnValue() == XFormDialog.OK_OPTION) { try { securityTest.setFailOnError(Boolean.parseBoolean(values.get(FAIL_ON_ERROR))); securityTest.setFailSecurityTestOnScanErrors( Boolean.parseBoolean(values.get(FAIL_SECURITYTEST_ON_ERROR))); } catch (Exception e1) { UISupport.showErrorMessage(e1.getMessage()); } } }
@Override protected void execute( SecurityTestRunner securityTestRunner, TestStep testStep, SecurityTestRunContext context) { scriptEngine.setScript(groovyscc.getExecuteScript().getStringValue()); scriptEngine.setVariable("context", context); scriptEngine.setVariable("testStep", testStep); scriptEngine.setVariable("securityScan", this); scriptEngine.setVariable("parameters", parameters); scriptEngine.setVariable("log", SoapUI.ensureGroovyLog()); try { scriptResult = scriptEngine.run(); hasNext = castResultToBoolean(scriptResult); XmlObjectTreeModel model = null; for (SecurityCheckedParameter scp : getParameterHolder().getParameterList()) { if (parameters.containsKey(scp.getLabel()) && parameters.get(scp.getLabel()) != null) { if (scp.isChecked() && scp.getXpath().trim().length() > 0) { model = SecurityScanUtil.getXmlObjectTreeModel(testStep, scp); XmlTreeNode[] treeNodes = null; treeNodes = model.selectTreeNodes(context.expand(scp.getXpath())); if (treeNodes.length > 0) { XmlTreeNode mynode = treeNodes[0]; mynode.setValue(1, parameters.get(scp.getLabel())); } updateRequestProperty(testStep, scp.getName(), model.getXmlObject().toString()); } else { updateRequestProperty(testStep, scp.getName(), parameters.get(scp.getLabel())); } } else if (parameters.containsKey(scp.getLabel()) && parameters.get(scp.getLabel()) == null) { // clears null values form parameters parameters.remove(scp.getLabel()); } } MessageExchange message = (MessageExchange) testStep.run((TestCaseRunner) securityTestRunner, context); createMessageExchange(clearNullValues(parameters), message, context); } catch (Exception e) { SoapUI.logError(e); hasNext = false; } finally { // if( scriptResult != null ) // { // getTestStep().getProperty( "Request" ).setValue( ( String // )scriptResult ); // // getTestStep().run( ( TestCaseRunner )securityTestRunner, // ( TestCaseRunContext )securityTestRunner.getRunContext() ); // } } }