String method =
"GetLanguages"
;
String company =
""
;
String userName =
""
;
String password =
""
;
String languageCode =
"en"
;
String soapProtocol = SOAPConstants.SOAP_1_1_PROTOCOL;
if
(useSoap12) {
soapProtocol = SOAPConstants.SOAP_1_2_PROTOCOL;
}
MessageFactory mf = MessageFactory.newInstance(soapProtocol);
SOAPMessage soapMessage = mf.createMessage();
if
(!useSoap12) {
MimeHeaders mimeHeaders = soapMessage.getMimeHeaders();
mimeHeaders.addHeader(
"SOAPAction"
, namespace + method);
}
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
SOAPBody soapBody = soapEnvelope.getBody();
Name bodyName = soapEnvelope.createName(method,
""
, namespace);
SOAPBodyElement soapBodyElement = soapBody.addBodyElement(bodyName);
SOAPElement inputElement = soapBodyElement.addChildElement(
"input"
);
inputElement.addChildElement(
"CompanyName"
).addTextNode(company);
inputElement.addChildElement(
"UserName"
).addTextNode(userName);
inputElement.addChildElement(
"Password"
).addTextNode(password);
inputElement.addChildElement(
"LanguageCode"
).addTextNode(languageCode);
soapMessage.saveChanges();
SOAPConnectionFactory connectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = connectionFactory.createConnection();
SOAPMessage soapResponse = soapConnection.call(soapMessage, url);
soapConnection.close();
SOAPBody soapResponseBody = soapResponse.getSOAPBody();
SOAPFault soapFault = soapResponseBody.getFault();
if
(soapFault !=
null
) {
throw
new
SOAPException(soapFault.getFaultString());
}
System.out.println(
"LanguageId | LanguageCode | LanguageName"
);
System.out.println(
"-----------------------------------------"
);
NodeList list = soapResponseBody.getElementsByTagName(
"Language"
);
for
(
int
i =
0
; i < list.getLength(); i++) {
Element language = (Element)list.item(i);
System.out.print(language.getElementsByTagName(
"LanguageId"
).item(
0
).getTextContent());
System.out.print(
"\t|\t"
);
System.out.print(language.getElementsByTagName(
"LanguageCode"
).item(
0
).getTextContent());
System.out.print(
"\t|\t"
);
System.out.print(language.getElementsByTagName(
"LanguageName"
).item(
0
).getTextContent());
System.out.println();
}