public SecurityToken logon( String anEndpointReference, String aUserName, String aPassword, String anApplicationID) throws LogonManagerException, SOAPException, IOException { SecurityToken result; SOAPMessage message; SOAPConnection conn = null; try { result = null; String request = REQUEST_FORMAT.format( ((Object) (new Object[] {fURL, aUserName, aPassword, anEndpointReference}))); message = MessageFactory.newInstance() .createMessage(new MimeHeaders(), new ByteArrayInputStream(request.getBytes())); conn = SOAPConnectionFactory.newInstance().createConnection(); SOAPMessage response = conn.call(message, fURL); SOAPBody body = response.getSOAPBody(); if (body.hasFault()) throw new LogonManagerException(body.getFault()); result = new SecurityToken(); result.setSOAPBody(body); for (Iterator it = body.getChildElements(); it.hasNext(); fill(result, (Node) it.next())) ; return result; } finally { if (conn != null) conn.close(); } }
private static Collection<String> parseSoapResponseForUrls(byte[] data) throws SOAPException, IOException { // System.out.println(new String(data)); final Collection<String> urls = new ArrayList<>(); MessageFactory factory = MessageFactory.newInstance(WS_DISCOVERY_SOAP_VERSION); final MimeHeaders headers = new MimeHeaders(); headers.addHeader("Content-type", WS_DISCOVERY_CONTENT_TYPE); SOAPMessage message = factory.createMessage(headers, new ByteArrayInputStream(data)); SOAPBody body = message.getSOAPBody(); for (Node node : getNodeMatching(body, ".*:XAddrs")) { if (node.getTextContent().length() > 0) { urls.addAll(Arrays.asList(node.getTextContent().split(" "))); } } return urls; }