Contributions
Re: Calling java class from mock script
I dont understand what you mean. If I dont use the class - java.utils.Base64 in this case - the mock works fine, but then I cannot mess around with the username password. If I use Base64 without the import It will throw a class not found error idem if I use the import The only difference is the line where the class not found exception is thrown, the line with the import statement or the line where the Base64 is used...2KViews0likes2CommentsCalling java class from mock script
Hi, I have a mock soap service and want to do some magic with basic auth headers. When I try to import the java.utils.Base64 I get class not found errrors. Are the std java classes not on the classpath? Searching for this problem only gives examples of custom classes. The documentation and API suggest only a limited set of XML/SOAP/JSON/REST classes. Thnx, Wim-Jan Adding relevant piece of groovy: note that it is to help clarify the issue and imcomplete since I cut out or substituted sensitive info import java.utils.Base64 def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context) def alert = com.eviware.soapui.support.UISupport; log.info("------------- begin call -----------------------------"); def soapRequest = mockRequest.requestContent; def headers = mockRequest.requestHeaders; def incommingBasicAuth = headers.get("Authorization", "defaultAuth"); if (incommingBasicAuth == "defaultAuth") { log.info("no basicAuth header found!"); } else { String decodedAuth = Base64.getDecoder().decode; def uNamePw = decodedAuth.split(":"); log.info("basicAuth header for " + uNamePw + " found!"); } log.info("--- request will be forwarded to actual service ----") String basicAuth = ""; if (incommingBasicAuth == "defaultAuth") { log.info("Set hardcoded username,password"); String userCredentials = "someuser:somepw"; basicAuth = "Basic " + new String(Base64.getEncoder().encode(userCredentials.getBytes())); } else { log.info("use username password form incomming request"); basicAuth = incommingBasicAuth; } def soapUrl = new URL("https://somewebservice.nl/") def connection = soapUrl.openConnection() // insert the basic auth header connection.setRequestProperty("Authorization", basicAuth); connection.setRequestMethod("POST") connection.setRequestProperty("Content-Type", "text/html") connection.setRequestProperty("SOAPAction", "") connection.doOutput = true Writer writer = new OutputStreamWriter(connection.outputStream); writer.write(soapRequest) writer.flush() writer.close() connection.connect() def soapResponse = connection.content.text // work as proxy, i.e. just return response recieved from https://somewebservice.nl/ requestContext.responseMessage = soapResponseSolved2KViews0likes4Comments