Skip to content

Instantly share code, notes, and snippets.

@matrixcloud
Created November 27, 2023 01:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matrixcloud/49cb63cc411b68bafd337eb47e7392c3 to your computer and use it in GitHub Desktop.
Save matrixcloud/49cb63cc411b68bafd337eb47e7392c3 to your computer and use it in GitHub Desktop.
Send raw soap request with headers
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