Created
November 27, 2023 01:17
-
-
Save matrixcloud/49cb63cc411b68bafd337eb47e7392c3 to your computer and use it in GitHub Desktop.
Send raw soap request with headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean login(String userId, String password) { | |
try { | |
val content = soapMessageLoader.load("soap/login_message.xml", usernameOfCredential, passwordOfCredential, userId, password); | |
log.info("Login content: {}", content); | |
val soapConnectionFactory = SOAPConnectionFactory.newInstance(); | |
val endpoint = new URL(loginUrl); | |
val connection = soapConnectionFactory.createConnection(); | |
val factory = MessageFactory.newInstance(); | |
val message = factory.createMessage(new MimeHeaders(), new ByteArrayInputStream(content.getBytes())); | |
val response = connection.call(message, endpoint); | |
try(val out = new ByteArrayOutputStream()) { | |
response.writeTo(out); | |
String res = out.toString(); | |
if (res != null && res.contains("Normal end")) { | |
return true; | |
} else { | |
log.warn("Failed to login due to " + res); | |
} | |
return false; | |
} | |
} catch (SOAPException | IOException e) { | |
log.error("Failed to login due to " + e.getMessage(), e); | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment