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

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

Source:SoapService.java Github

copy

Full Screen

...98 private IParameterService parameterService;99 @Autowired100 IProxyService proxyService;101 @Override102 public SOAPMessage createSoapRequest(String envelope, String method, List<AppServiceHeader> header, String token) throws SOAPException, IOException, SAXException, ParserConfigurationException {103 String unescapedEnvelope = StringEscapeUtils.unescapeXml(envelope);104 boolean is12SoapVersion = SOAP_1_2_NAMESPACE_PATTERN.matcher(unescapedEnvelope).matches();105 MimeHeaders headers = new MimeHeaders();106 for (AppServiceHeader appServiceHeader : header) {107 headers.addHeader(appServiceHeader.getKey(), appServiceHeader.getValue());108 }109 InputStream input = new ByteArrayInputStream(unescapedEnvelope.getBytes("UTF-8"));110 MessageFactory messageFactory = MessageFactory.newInstance(is12SoapVersion ? SOAPConstants.SOAP_1_2_PROTOCOL : SOAPConstants.SOAP_1_1_PROTOCOL);111 return messageFactory.createMessage(headers, input);112 }113 @Override114 public void addAttachmentPart(SOAPMessage input, String path) throws CerberusException {115 URL url;116 try {117 LOG.debug("Adding Attachement to SOAP request : " + path);118 url = new URL(path);119 DataHandler handler = new DataHandler(url);120 //TODO: verify if this code is necessary121 /*String str = "";122 StringBuilder sb = new StringBuilder();123 BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));124 while (null != (str = br.readLine())) {125 sb.append(str);126 }*/127 AttachmentPart attachPart = input.createAttachmentPart(handler);128 input.addAttachmentPart(attachPart);129 } catch (MalformedURLException ex) {130 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.SOAPLIB_MALFORMED_URL));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 }...

Full Screen

Full Screen

createSoapRequest

Using AI Code Generation

copy

Full Screen

1import org.cerberus.service.soap.impl.SoapService;2import org.cerberus.service.soap.impl.SoapOperation;3import org.cerberus.service.soap.impl.SoapRequest;4import org.cerberus.service.soap.impl.SoapResponse;5SoapService soapService = new SoapService();6SoapOperation soapOperation = new SoapOperation();7soapOperation.setOperationName("GetWeather");8soapOperation.setInputMessageName("GetWeather");9soapOperation.setInputMessageElementName("GetWeather");10soapOperation.setInputMessageElementParameterName("CityName");11soapOperation.setInputMessageElementParameterValue("London");12soapOperation.setOutputMessageName("GetWeatherResponse");13soapOperation.setOutputMessageElementName("GetWeatherResponse");14soapOperation.setOutputMessageElementParameterName("GetWeatherResult");15SoapRequest soapRequest = soapService.createSoapRequest(soapOperation);16SoapResponse soapResponse = soapService.executeSoapRequest(soapRequest);17println(soapResponse.getSoapResponse());18println(soapResponse.getOutputMessageElementParameterValue());

Full Screen

Full Screen

createSoapRequest

Using AI Code Generation

copy

Full Screen

1def soapService = appContext.getBean("soapService")2soapRequest.addParameter("country", "US")3soapRequest.addParameter("language", "en")4def soapResponse = soapService.sendSOAP(soapRequest)5def soapResponseParsed = soapService.parseSoapResponse(soapResponse)6logEvent("SOAP Response: " + soapResponseParsed)7def restService = appContext.getBean("restService")8restRequest.addParameter("country", "US")9restRequest.addParameter("language", "en")10def restResponse = restService.executeREST(restRequest)11def restResponseParsed = restService.parseRestResponse(restResponse)12logEvent("REST Response: " + restResponseParsed)13def httpService = appContext.getBean("httpService")

Full Screen

Full Screen

createSoapRequest

Using AI Code Generation

copy

Full Screen

1SoapService soapService = new SoapService();2SoapOperation soapOperation = new SoapOperation();3</soap:Envelope>");4soapService.createSoapRequest(soapOperation);5String request = soapOperation.getRequest();6System.out.println(request);7SoapService soapService = new SoapService();8SoapOperation soapOperation = new SoapOperation();

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