/** * 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; }
public void actionPerformed(ActionEvent e) { boolean createOptional = request .getSettings() .getBoolean(WsdlSettings.XML_GENERATION_ALWAYS_INCLUDE_OPTIONAL_ELEMENTS); if (!createOptional) { Boolean create = UISupport.confirmOrCancel("Create optional elements in schema?", "Create Request"); if (create == null) return; createOptional = create.booleanValue(); } WsdlOperation wsdlOperation = (WsdlOperation) request.getOperation(); String req = wsdlOperation.createRequest(createOptional); if (req == null) { UISupport.showErrorMessage("Request creation failed"); return; } if (request.getRequestContent() != null && request.getRequestContent().trim().length() > 0) { if (UISupport.confirm("Keep existing values", "Recreate Request")) { req = SoapUtils.transferSoapHeaders( request.getRequestContent(), req, wsdlOperation.getInterface().getSoapVersion()); req = XmlUtils.transferValues(request.getRequestContent(), req); } } request.setRequestContent(req); }
/** * 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; }
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); } } }