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

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

Source:SoapService.java Github

copy

Full Screen

...131 } catch (Exception ex) {132 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.SOAPLIB_MALFORMED_URL));133 }134 }135 private static SOAPMessage sendSOAPMessage(SOAPMessage message, String url, final Proxy p, final int timeoutms) throws SOAPException, MalformedURLException {136 SOAPConnectionFactory factory = SOAPConnectionFactory.newInstance();137 SOAPConnection connection = factory.createConnection();138 URL endpoint = new URL(null, url, new URLStreamHandler() {139 protected URLConnection openConnection(URL url) throws IOException {140 // The url is the parent of this stream handler, so must141 // create clone142 URL clone = new URL(url.toString());143 URLConnection connection = null;144 if (p == null) {145 connection = clone.openConnection();146 } else if (p.address().toString().equals("0.0.0.0/0.0.0.0:80")) {147 connection = clone.openConnection();148 } else {149 connection = clone.openConnection(p);150 }151 // Set Timeout152 connection.setConnectTimeout(timeoutms);153 connection.setReadTimeout(timeoutms);154 // Custom header155// connection.addRequestProperty("Developer-Mood", "Happy");156 return connection;157 }158 });159 try {160 SOAPMessage response = connection.call(message, endpoint);161 connection.close();162 return response;163 } catch (Exception e) {164 // Re-try if the connection failed165 SOAPMessage response = connection.call(message, endpoint);166 connection.close();167 return response;168 }169 }170 private void initializeProxyAuthenticator(final String proxyUser, final String proxyPassword) {171 if (proxyUser != null && proxyPassword != null) {172 Authenticator.setDefault(173 new Authenticator() {174 @Override175 public PasswordAuthentication getPasswordAuthentication() {176 return new PasswordAuthentication(177 proxyUser, proxyPassword.toCharArray()178 );179 }180 }181 );182 System.setProperty("http.proxyUser", proxyUser);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, "", soapOperation, "", 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, "Y", 0, "", "", null, "", null));212 }213 if (StringUtil.isNullOrEmpty(soapOperation)) {214 header.add(factoryAppServiceHeader.create(null, "SOAPAction", "", "Y", 0, "", "", null, "", null));215 } else {216 header.add(factoryAppServiceHeader.create(null, "SOAPAction", "\"" + soapOperation + "\"", "Y", 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, "Y", 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.warn(e.toString(), e);279 }280 } else {281 serviceSOAP.setProxy(false);282 serviceSOAP.setProxyHost(null);283 serviceSOAP.setProxyPort(0);284 // Call without proxy.285 soapResponse = sendSOAPMessage(input, servicePath, null, timeOutMs);286// soapResponse = soapConnection.call(input, servicePath);287 }288 LOG.debug("Called WS.");289 out = new ByteArrayOutputStream();290 // Store the response291 soapResponse.writeTo(out);292 LOG.debug("WS response received.");293 LOG.debug("WS response : " + out.toString());294 message = new MessageEvent(MessageEventEnum.ACTION_SUCCESS_CALLSOAP);295 message.setDescription(message.getDescription()296 .replace("%SERVICEPATH%", servicePath)297 .replace("%SOAPMETHOD%", soapOperation));298 result.setResultMessage(message);299 //soapResponse.getSOAPPart().getEnvelope().getBody().getFault().getFaultCode();...

Full Screen

Full Screen

sendSOAPMessage

Using AI Code Generation

copy

Full Screen

1 + "</soapenv:Envelope>";2String response = org.cerberus.service.soap.impl.SoapService.sendSOAPMessage(message, url, soapAction);3System.out.println(response);4org.cerberus.util.answer.AnswerItem answerItem = new org.cerberus.util.answer.AnswerItem();5answerItem.setMessage(response);6org.cerberus.util.answer.AnswerUtil.addAnswerItemLog(answerItem);7org.cerberus.util.answer.AnswerUtil.addAnswerItemPopup(answerItem);

Full Screen

Full Screen

sendSOAPMessage

Using AI Code Generation

copy

Full Screen

1import org.cerberus.service.soap.impl.SoapService;2import org.cerberus.service.soap.impl.SoapServiceException;3import java.net.URL;4import java.util.HashMap;5import java.util.Map;6public class SoapServiceTest {7 public static void main(String[] args) throws SoapServiceException {8 SoapService soapService = new SoapService();9 "</soapenv:Envelope>";10 Map<String, String> headers = new HashMap<>();11 headers.put("SOAPAction", "readInvariant");12 headers.put("Content-Type", "text/xml;charset=UTF-8");13 headers.put("Accept", "text/xml");14 System.out.println(response);15 String jsonResponse = soapService.convertSoapResponseToJson(response);16 System.out.println(jsonResponse);17 String xmlResponse = soapService.convertSoapResponseToXml(response);18 System.out.println(xmlResponse);19 String htmlResponse = soapService.convertSoapResponseToHtml(response);

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