/** * 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; }
private void complementRequest( SubmitContext context, AbstractHttpRequestInterface<?> httpRequest, EndpointDefaults def, String requestUsername, String requestPassword, String requestDomain, String defUsername, String defPassword, String defDomain, com.eviware.soapui.config.CredentialsConfig.AuthType.Enum authType) { String username = StringUtils.hasContent(requestUsername) ? requestUsername : defUsername; String password = StringUtils.hasContent(requestPassword) ? requestPassword : defPassword; if (httpRequest instanceof WsdlRequest) { WsdlRequest wsdlRequest = (WsdlRequest) httpRequest; // only set if not set in request String wssType = StringUtils.isNullOrEmpty(wsdlRequest.getWssPasswordType()) ? def.getWssType() : (StringUtils.hasContent(username) && StringUtils.hasContent(password)) ? null : wsdlRequest.getWssPasswordType(); String wssTimeToLive = StringUtils.isNullOrEmpty(wsdlRequest.getWssTimeToLive()) ? def.getWssTimeToLive() : null; if (!StringUtils.hasContent(wssType) && (StringUtils.hasContent(username) || StringUtils.hasContent(password))) { String domain = StringUtils.hasContent(requestDomain) ? requestDomain : defDomain; HttpAuthenticationRequestFilter.initRequestCredentials( context, username, project.getSettings(), password, domain, authType); } else if (StringUtils.hasContent(wssType) || StringUtils.hasContent(wssTimeToLive)) { try { // set to null so existing don't get removed if (wssTimeToLive != null && wssTimeToLive.length() == 0) { wssTimeToLive = null; } if (StringUtils.hasContent(username) || StringUtils.hasContent(password)) { WssAuthenticationRequestFilter.setWssHeaders( context, username, password, wssType, wssTimeToLive); } } catch (Exception e) { SoapUI.logError(e); } } } else { if ((StringUtils.hasContent(username) || StringUtils.hasContent(password))) { String domain = StringUtils.hasContent(requestDomain) ? requestDomain : defDomain; HttpAuthenticationRequestFilter.initRequestCredentials( context, username, project.getSettings(), password, domain, authType); } } }
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); }
private Attachment addAttachement(TestStep testStep) { Attachment attach = null; if (isAttachXmlBomb()) { WsdlRequest request = (WsdlRequest) getRequest(testStep); if (currentIndex < getXmlBombList().size()) { String bomb = getXmlBombList().get(currentIndex); try { File bombFile = File.createTempFile(getAttachmentPrefix(), ".xml"); BufferedWriter writer = new BufferedWriter(new FileWriter(bombFile)); writer.write(bomb); writer.flush(); request.setInlineFilesEnabled(false); attach = request.attachFile(bombFile, false); attach.setContentType("text/xml;"); currentIndex++; } catch (IOException e) { SoapUI.logError(e); } } } return attach; }
public void filterRequest(SubmitContext context, WsdlRequest wsdlRequest) { TimeablePostMethod postMethod = (TimeablePostMethod) context.getProperty(BaseHttpRequestTransport.POST_METHOD); // set maxsize Settings settings = wsdlRequest.getSettings(); // close connections? if (settings.getBoolean(HttpSettings.CLOSE_CONNECTIONS)) postMethod.setRequestHeader("Connection", "close"); // max size.. postMethod.setMaxSize(settings.getLong(HttpSettings.MAX_RESPONSE_SIZE, 0)); // apply global settings HttpClientSupport.applyHttpSettings(postMethod, settings); }
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); } } }