How to use callSOAP method of org.cerberus.service.soap.impl.SoapService class

Best Cerberus-source code snippet using org.cerberus.service.soap.impl.SoapService.callSOAP

Source:SoapService.java Github

copy

Full Screen

...183 System.setProperty("http.proxyPassword", proxyPassword);184 }185 }186 @Override187 public AnswerItem<AppService> callSOAP(String envelope, String servicePath, String soapOperation, String attachmentUrl, List<AppServiceHeader> header, String token, int timeOutMs, String system) {188 AnswerItem<AppService> result = new AnswerItem<>();189 String unescapedEnvelope = StringEscapeUtils.unescapeXml(envelope);190 boolean is12SoapVersion = SOAP_1_2_NAMESPACE_PATTERN.matcher(unescapedEnvelope).matches();191 AppService serviceSOAP = factoryAppService.create("", AppService.TYPE_SOAP, null, "", "", envelope, "", "", "", "", "", "", "", servicePath, true, "", soapOperation, false, "", null, "", null, "", null, null);192 serviceSOAP.setTimeoutms(timeOutMs);193 ByteArrayOutputStream out = null;194 MessageEvent message = null;195 if (StringUtil.isNullOrEmpty(servicePath)) {196 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSOAP_SERVICEPATHMISSING);197 result.setResultMessage(message);198 return result;199 }200 if (StringUtil.isNullOrEmpty(envelope)) {201 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSOAP_ENVELOPEMISSING);202 result.setResultMessage(message);203 return result;204 }205 // If header is null we create the list empty.206 if (header == null) {207 header = new ArrayList<>();208 }209 // We feed the header with token + Standard SOAP header.210 if (token != null) {211 header.add(factoryAppServiceHeader.create(null, "cerberus-token", token, true, 0, "", "", null, "", null));212 }213 if (StringUtil.isNullOrEmpty(soapOperation)) {214 header.add(factoryAppServiceHeader.create(null, "SOAPAction", "", true, 0, "", "", null, "", null));215 } else {216 header.add(factoryAppServiceHeader.create(null, "SOAPAction", "\"" + soapOperation + "\"", true, 0, "", "", null, "", null));217 }218 header.add(factoryAppServiceHeader.create(null, "Content-Type", is12SoapVersion ? SOAPConstants.SOAP_1_2_CONTENT_TYPE : SOAPConstants.SOAP_1_1_CONTENT_TYPE, true, 0, "", "", null, "", null));219 serviceSOAP.setHeaderList(header);220 SOAPConnectionFactory soapConnectionFactory;221 SOAPConnection soapConnection = null;222 try {223 //Initialize SOAP Connection224 soapConnectionFactory = SOAPConnectionFactory.newInstance();225 soapConnection = soapConnectionFactory.createConnection();226 LOG.debug("Connection opened");227 // Create SOAP Request228 LOG.debug("Create request");229 SOAPMessage input = createSoapRequest(envelope, soapOperation, header, token);230 //Add attachment File if specified231 if (!StringUtil.isNullOrEmpty(attachmentUrl)) {232 this.addAttachmentPart(input, attachmentUrl);233 // Store the SOAP Call234 out = new ByteArrayOutputStream();235 input.writeTo(out);236 LOG.debug("WS call with attachement : " + out.toString());237 serviceSOAP.setServiceRequest(out.toString());238 } else {239 // Store the SOAP Call240 out = new ByteArrayOutputStream();241 input.writeTo(out);242 LOG.debug("WS call : " + out.toString());243 }244 // We already set the item in order to keep the request message in case of failure of SOAP calls.245 serviceSOAP.setService(servicePath);246 result.setItem(serviceSOAP);247 // Call the WS248 LOG.debug("Calling WS.");249 // Reset previous Authentification.250 Authenticator.setDefault(null);251 serviceSOAP.setProxyWithCredential(false);252 serviceSOAP.setProxyUser(null);253 SOAPMessage soapResponse = null;254 if (proxyService.useProxy(servicePath, system)) {255 // Get Proxy host and port from parameters.256 String proxyHost = parameterService.getParameterStringByKey("cerberus_proxy_host", system, DEFAULT_PROXY_HOST);257 int proxyPort = parameterService.getParameterIntegerByKey("cerberus_proxy_port", system, DEFAULT_PROXY_PORT);258 serviceSOAP.setProxy(true);259 serviceSOAP.setProxyHost(proxyHost);260 serviceSOAP.setProxyPort(proxyPort);261 // Create the Proxy.262 SocketAddress sockaddr = new InetSocketAddress(proxyHost, proxyPort);263 try (Socket socket = new Socket();) {264 socket.connect(sockaddr, 10000);265 Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(socket.getInetAddress(), proxyPort));266 if (parameterService.getParameterBooleanByKey("cerberus_proxyauthentification_active", system, DEFAULT_PROXYAUTHENT_ACTIVATE)) {267 // Get the credentials from parameters.268 String proxyUser = parameterService.getParameterStringByKey("cerberus_proxyauthentification_user", system, DEFAULT_PROXYAUTHENT_USER);269 String proxyPass = parameterService.getParameterStringByKey("cerberus_proxyauthentification_password", system, DEFAULT_PROXYAUTHENT_PASSWORD);270 serviceSOAP.setProxyWithCredential(true);271 serviceSOAP.setProxyUser(proxyUser);272 // Define the credential to the proxy.273 initializeProxyAuthenticator(proxyUser, proxyPass);274 }275 // Call with Proxy.276 soapResponse = sendSOAPMessage(input, servicePath, proxy, timeOutMs);277 } catch (Exception e) {278 LOG.error("Exception when trying to callSOAP on URL : '" + servicePath + "' for operation : '" + soapOperation + "'", e);279 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSOAP);280 message.setDescription(message.getDescription()281 .replace("%SERVICEPATH%", servicePath)282 .replace("%SOAPMETHOD%", soapOperation)283 .replace("%DESCRIPTION%", e.getMessage()));284 result.setResultMessage(message);285 return result;286 }287 } else {288 serviceSOAP.setProxy(false);289 serviceSOAP.setProxyHost(null);290 serviceSOAP.setProxyPort(0);291 // Call without proxy.292 soapResponse = sendSOAPMessage(input, servicePath, null, timeOutMs);293// soapResponse = soapConnection.call(input, servicePath);294 }295 LOG.debug("Called WS.");296 out = new ByteArrayOutputStream();297 // Store the response298 soapResponse.writeTo(out);299 LOG.debug("WS response received.");300 LOG.debug("WS response : " + out.toString());301 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CALLSOAP);302 message.setDescription(message.getDescription()303 .replace("%SERVICEPATH%", servicePath)304 .replace("%SOAPMETHOD%", soapOperation));305 result.setResultMessage(message);306 //soapResponse.getSOAPPart().getEnvelope().getBody().getFault().getFaultCode();307 // We save convert to string the final response from SOAP request.308 serviceSOAP.setResponseHTTPBody(SoapUtil.convertSoapMessageToString(soapResponse));309 // Get result Content Type.310 serviceSOAP.setResponseHTTPBodyContentType(appServiceService.guessContentType(serviceSOAP, AppService.RESPONSEHTTPBODYCONTENTTYPE_XML));311 result.setItem(serviceSOAP);312 } catch (SOAPException | UnsupportedOperationException | IOException | SAXException |313 ParserConfigurationException | CerberusException e) {314 LOG.error("Exception when trying to callSOAP on URL : '" + servicePath + "' for operation : '" + soapOperation + "'", e);315 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSOAP);316 message.setDescription(message.getDescription()317 .replace("%SERVICEPATH%", servicePath)318 .replace("%SOAPMETHOD%", soapOperation)319 .replace("%DESCRIPTION%", e.getMessage()));320 result.setResultMessage(message);321 return result;322 } finally {323 try {324 if (soapConnection != null) {325 soapConnection.close();326 }327 if (out != null) {328 out.close();...

Full Screen

Full Screen

callSOAP

Using AI Code Generation

copy

Full Screen

1import org.cerberus.service.soap.impl.SoapService;2import org.cerberus.util.answer.AnswerItem;3import org.cerberus.util.answer.AnswerUtil;4import org.w3c.dom.Document;5import org.xml.sax.SAXException;6import javax.xml.parsers.ParserConfigurationException;7import javax.xml.transform.TransformerException;8import java.io.IOException;9import java.util.HashMap;10import java.util.Map;11SoapService soapService = new SoapService();12Map<String, String> parameters = new HashMap<>();13parameters.put("CountryName", "France");14AnswerItem response = soapService.callSOAP("GetCitiesByCountry", parameters);15Document responseDocument = (Document) response.getItem();16try {17 System.out.println(AnswerUtil.answerItem2String(response));18} catch (TransformerException | ParserConfigurationException | SAXException | IOException e) {19 e.printStackTrace();20}21System.out.println(soapService.getSOAPResponseAsString(responseDocument));22System.out.println(soapService.getSOAPResponseAsXML(responseDocument));23System.out.println(soapService.getSOAPResponseAsJSON(responseDocument));24System.out.println(soapService.getSOAPResponseAsHTML(responseDocument));25System.out.println(soapService.getSOAPResponseAsCSV(responseDocument));26System.out.println(soapService.getSOAPResponseAsPDF(responseDocument));27System.out.println(soapService.getSOAPResponseAsXLS(responseDocument));28System.out.println(soapService.getSOAPResponseAsXLSX(responseDocument));29System.out.println(soapService.getSOAPResponseAsDOCX(responseDocument));30System.out.println(soapService.getSOAPResponseAs

Full Screen

Full Screen

callSOAP

Using AI Code Generation

copy

Full Screen

1import org.cerberus.service.soap.impl.SoapService;2import org.cerberus.service.soap.impl.SoapServiceException;3String operation = "operation";4String[] parameters = {"parameter1", "parameter2"};5String[] parameterTypes = {"string", "string"};6String[] parameterValues = {"value1", "value2"};7String[] parameterModes = {"IN", "IN"};8String soapVersion = "1.1";9String envelope = "";10String headers = "";11String body = "";12String response = "";13String responseStatus = "";14String responseStatusCode = "";15String responseStatusMessage = "";16String responseHeaders = "";17String responseBody = "";18String responseBodyContent = "";19String responseBodyContentType = "";20String responseBodyContentLength = "";21String responseBodyContentEncoding = "";

Full Screen

Full Screen

callSOAP

Using AI Code Generation

copy

Full Screen

1String method = "sayHello";2Map<String, String> params = new HashMap<String, String>();3params.put("arg0", "Cerberus");4Map<String, String> headers = new HashMap<String, String>();5Map<String, String> cookies = new HashMap<String, String>();6Map<String, String> properties = new HashMap<String, String>();7Map<String, String> attachments = new HashMap<String, String>();8Map<String, String> attachmentsContentType = new HashMap<String, String>();9Map<String, String> attachmentsContentId = new HashMap<String, String>();10Map<String, String> attachmentsContentLocation = new HashMap<String, String>();11Map<String, String> attachmentsContentTransferEncoding = new HashMap<String, String>();12Map<String, String> attachmentsContentDisposition = new HashMap<String, String>();13Map<String, String> attachmentsContentDescription = new HashMap<String, String>();14Map<String, String> attachmentsContentLanguage = new HashMap<String, String>();15Map<String, String> attachmentsContentMD5 = new HashMap<String, String>();16Map<String, String> attachmentsContentSchema = new HashMap<String, String>();17Map<String, String> attachmentsContentSoapAction = new HashMap<String, String>();18Map<String, String> attachmentsContentSoapActionRequired = new HashMap<String, String>();19Map<String, String> attachmentsContentSoapEncodingStyle = new HashMap<String, String>();20Map<String, String> attachmentsContentSoapRole = new HashMap<String, String>();21Map<String, String> attachmentsContentSoapUse = new HashMap<String, String>();22Map<String, String> attachmentsContentSoapVersion = new HashMap<String, String>();

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Cerberus-source automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful