/** * Validates the request SOAP message against the WSDL. * * @param wsdlUrl WSDL URL. * @param operationName operation name. * @param request request SOAP message. * @return list of error messages if any. */ public static List<String> validateRequest(String wsdlUrl, String operationName, String request) { WsdlInterface intf = loadWsdl(wsdlUrl); WsdlOperation operation = intf.getOperationByName(operationName); if (operation == null) { throw new MockException("Operation " + operationName + " not found."); } WsdlRequest req = operation.addNewRequest("something"); req.setRequestContent(request); WsdlValidator validator = new WsdlValidator(intf.getWsdlContext()); List<String> errorList = new ArrayList<String>(); try { AssertionError[] errors = validator.assertRequest(new WsdlResponseMessageExchange(req), false); for (AssertionError error : errors) { errorList.add(error.toString()); } } catch (Exception e) { e.printStackTrace(); throw new MockException("Unable to validate the message."); } return errorList; }
protected String getDefinition(T modelItem) { if (modelItem == null) return ""; WsdlInterface iface = (WsdlInterface) modelItem; String definition = PathUtils.expandPath(iface.getDefinition(), iface); if (definition.startsWith("file:")) definition = definition.substring(5); return definition; }
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)); }
/** * Gets the operations for the WSDL. * * @param wsdlUrl WSDL URL. * @return list of operation names for the WSDL. */ public static List<String> getOperationList(String wsdlUrl) { WsdlInterface intf = loadWsdl(wsdlUrl); List<String> operationList = new ArrayList<String>(); try { for (int i = 0; i < intf.getOperationCount(); i++) { operationList.add(intf.getOperationAt(i).getName()); } } catch (Exception e) { throw new MockException("Unable to import WSDL. " + e.getMessage()); } return operationList; }
public AddAssertionPanel(Assertable assertable) { super( "Add Assertion", "Select the source property and which assertion to apply below ", HelpUrls.ADD_ASSERTION_PANEL); this.assertable = assertable; assertionEntryRenderer.setAssertable(assertable); categoriesListRenderer.setAssertable(assertable); selectionListener = new InternalListSelectionListener(); categoriesAssertionsMap = AssertionCategoryMapping.getCategoriesAssertionsMap(assertable, recentAssertionHandler); // load interfaces or have a issue with table and cell renderer WsdlProject project = (WsdlProject) ModelSupport.getModelItemProject(assertable.getModelItem()); for (Interface inf : project.getInterfaceList()) { try { // There seems to be no good reason to load the definitions for rest interfaces // hence that call has been removed for the time being. if (inf instanceof WsdlInterface) { ((WsdlInterface) inf).getWsdlContext().loadIfNecessary(); } } catch (Exception e) { // TODO Improve this e.printStackTrace(); } } }
private static WsdlOperation getOperation(WsdlInterface intf, String operationName) { WsdlOperation operation = intf.getOperationByName(operationName); if (operation == null) { throw new MockException("Operation not found - " + operationName); } return operation; }
/** * Gets the dummy fault messages for the WSDL and operation name. * * @param wsdlUrl WSDL URL. * @param operationName operation name. * @return map of fault messages. */ public static HashMap<String, String> getDummyFaults(String wsdlUrl, String operationName) { WsdlInterface intf = loadWsdl(wsdlUrl); WsdlOperation operation = intf.getOperationByName(operationName); FaultPart[] faultParts = operation.getFaultParts(); HashMap<String, String> faultRespMap = new HashMap<String, String>(); for (FaultPart faultPart : faultParts) { String faultString = intf.getMessageBuilder().buildFault(faultPart); faultString = faultString.replaceAll("\r\n <!--Optional:-->", ""); faultString = faultString.replaceAll("\r\n <faultactor>\\?</faultactor>", ""); faultString = faultString.replaceAll("\r\n <!--You may enter ANY elements at this point-->", ""); faultString = faultString.replaceFirst( "<faultcode>\\?</faultcode>", "<faultcode>soapenv:Server</faultcode>"); if ("technicalFault".equals(faultPart.getName())) { faultString = faultString.replaceFirst( "<faultstring xml:lang=\"\\?\">\\?</faultstring>", "<faultstring>Technical Exception</faultstring>"); } else if ("businessFault".equals(faultPart.getName())) { faultString = faultString.replaceFirst( "<faultstring xml:lang=\"\\?\">\\?</faultstring>", "<faultstring>Business Exception</faultstring>"); } faultRespMap.put(faultPart.getName(), faultString); } return faultRespMap; }
/** * Gets the service name for the WSDL. * * @param wsdlUrl WSDL URL. * @return service name. */ public static String getServiceName(String wsdlUrl) { WsdlInterface intf = loadWsdl(wsdlUrl); String[] eps = intf.getEndpoints(); if (eps == null || eps.length == 0) { return null; } String ep = eps[0]; int lastIndex = ep.lastIndexOf("/service/"); if (lastIndex == -1) { return null; } String serviceName = ep.substring(lastIndex + 9, ep.length()); return serviceName; }
private void testLoader(String wsdlUrl) throws Exception { WsdlProject project = new WsdlProject(); project.getSettings().setBoolean(WsdlSettings.CACHE_WSDLS, true); WsdlInterface wsdlInterface = WsdlImporter.importWsdl(project, wsdlUrl)[0]; assertTrue(wsdlInterface.isCached()); WsdlDefinitionExporter exporter = new WsdlDefinitionExporter(wsdlInterface); String root = exporter.export("test" + File.separatorChar + "output"); WsdlProject project2 = new WsdlProject(); WsdlInterface wsdl2 = WsdlImporter.importWsdl(project2, new File(root).toURI().toURL().toString())[0]; assertEquals(wsdlInterface.getBindingName(), wsdl2.getBindingName()); assertEquals(wsdlInterface.getOperationCount(), wsdl2.getOperationCount()); assertEquals( wsdlInterface.getWsdlContext().getInterfaceDefinition().getDefinedNamespaces(), wsdl2.getWsdlContext().getInterfaceDefinition().getDefinedNamespaces()); }
public void perform(WsdlTestRequestStep target, Object param) { this.testStep = target; if (dialog == null) { dialog = ADialogBuilder.buildDialog(Form.class); dialog .getFormField(Form.INTERFACE) .addFormFieldListener( new XFormFieldListener() { public void valueChanged(XFormField sourceField, String newValue, String oldValue) { WsdlProject project = testStep.getTestCase().getTestSuite().getProject(); dialog.setOptions( Form.OPERATION, ModelSupport.getNames( project.getInterfaceByName(newValue).getOperationList())); dialog.setValue(Form.OPERATION, testStep.getOperationName()); } }); dialog .getFormField(Form.RECREATE_REQUEST) .addFormFieldListener( new XFormFieldListener() { public void valueChanged(XFormField sourceField, String newValue, String oldValue) { boolean enabled = Boolean.parseBoolean(newValue); dialog.getFormField(Form.CREATE_OPTIONAL).setEnabled(enabled); dialog.getFormField(Form.KEEP_EXISTING).setEnabled(enabled); } }); dialog.getFormField(Form.CREATE_OPTIONAL).setEnabled(false); dialog.getFormField(Form.KEEP_EXISTING).setEnabled(false); } WsdlProject project = target.getTestCase().getTestSuite().getProject(); dialog.setOptions( Form.INTERFACE, ModelSupport.getNames( project.getInterfaceList(), new ModelSupport.InterfaceTypeFilter(WsdlInterfaceFactory.WSDL_TYPE))); dialog.setValue(Form.INTERFACE, target.getInterfaceName()); dialog.setOptions( Form.OPERATION, ModelSupport.getNames( project.getInterfaceByName(target.getInterfaceName()).getOperationList())); dialog.setValue(Form.OPERATION, target.getOperationName()); dialog.setValue(Form.NAME, target.getName()); if (dialog.show()) { String ifaceName = dialog.getValue(Form.INTERFACE); String operationName = dialog.getValue(Form.OPERATION); WsdlInterface iface = (WsdlInterface) project.getInterfaceByName(ifaceName); WsdlOperation operation = iface.getOperationByName(operationName); target.setOperation(operation); String name = dialog.getValue(Form.NAME).trim(); if (name.length() > 0 && !target.getName().equals(name)) target.setName(name); if (dialog.getBooleanValue(Form.RECREATE_REQUEST)) { String req = operation.createRequest(dialog.getBooleanValue(Form.CREATE_OPTIONAL)); if (req == null) { UISupport.showErrorMessage("Request creation failed"); return; } WsdlTestRequest request = target.getTestRequest(); if (dialog.getBooleanValue(Form.KEEP_EXISTING)) { req = XmlUtils.transferValues(request.getRequestContent(), req); } request.setRequestContent(req); } } }