How to use callService method of org.cerberus.service.appservice.impl.ServiceService class

Best Cerberus-source code snippet using org.cerberus.service.appservice.impl.ServiceService.callService

Source:ServiceService.java Github

copy

Full Screen

...67 private IRestService restService;68 @Autowired69 private ICountryEnvironmentDatabaseService countryEnvironmentDatabaseService;70 @Override71 public AnswerItem<AppService> callService(String service, String database, String request, String servicePathParam, String operation, TestCaseExecution tCExecution) {72 MessageEvent message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSERVICE);73 String decodedRequest;74 String decodedServicePath = null;75 String decodedOperation;76 String decodedAttachement;77 AnswerItem result = new AnswerItem();78 String system = tCExecution.getApplicationObj().getSystem();79 String country = tCExecution.getCountry();80 String environment = tCExecution.getEnvironment();81 LOG.debug("Starting callService : " + service + " with database : " + database);82 try {83 AppService appService;84 // If Service information is not defined, we create it from request, servicePath and operation parameters forcing in SOAP mode.85 if (StringUtil.isNullOrEmpty(service)) {86 LOG.debug("Creating AppService from parameters.");87 appService = factoryAppService.create("null", AppService.TYPE_SOAP, "", "", "", request, "Automatically created Service from datalib.",88 servicePathParam, "", operation, null, null, null, null);89 service = "null";90 } else {91 // If Service information is defined, we get it from database.92 LOG.debug("Getting AppService from service : " + service);93 appService = appServiceService.convert(appServiceService.readByKeyWithDependency(service, "Y"));94 }95 String servicePath;96 if (appService == null) {97 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSERVICE);98 message.setDescription(message.getDescription().replace("%DESCRIPTION%", "Service does not exist !!"));99 } else if (StringUtil.isNullOrEmpty(appService.getServicePath())) {100 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSERVICE).resolveDescription("DESCRIPTION", "Service path is not defined");101 } else {102 // We start by calculating the servicePath and decode it.103 servicePath = appService.getServicePath();104 if (!(StringUtil.isURL(servicePath))) {105 // The URL defined inside the Service or directly from parameter is not complete and we need to add the first part taken either 106 // the data from tCExecution of related database.107 if (StringUtil.isNullOrEmpty(database)) {108 // We reformat servicePath in order to add the context from the application execution.109 servicePath = StringUtil.getURLFromString(tCExecution.getCountryEnvironmentParameters().getIp(),110 tCExecution.getCountryEnvironmentParameters().getUrl(), appService.getServicePath(), "http://");111 } else {112 // We reformat servicePath in order to add the context from the databaseUrl definition and corresponding from the country and environment of the execution.113 try {114 CountryEnvironmentDatabase countryEnvironmentDatabase;115 countryEnvironmentDatabase = countryEnvironmentDatabaseService.convert(this.countryEnvironmentDatabaseService.readByKey(system,116 country, environment, database));117 if (countryEnvironmentDatabase == null) {118 message = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_URLKOANDDATABASESOAPURLNOTEXIST);119 message.setDescription(message.getDescription()120 .replace("%SERVICEURL%", appService.getServicePath())121 .replace("%SYSTEM%", system)122 .replace("%COUNTRY%", country)123 .replace("%ENV%", environment)124 .replace("%DATABASE%", database));125 result.setResultMessage(message);126 return result;127 } else {128 String soapURL = countryEnvironmentDatabase.getSoapUrl();129 if (StringUtil.isNullOrEmpty(soapURL)) {130 message = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_URLKOANDDATABASESOAPURLEMPTY);131 message.setDescription(message.getDescription()132 .replace("%SERVICEURL%", appService.getServicePath())133 .replace("%SYSTEM%", system)134 .replace("%COUNTRY%", country)135 .replace("%ENV%", environment)136 .replace("%DATABASE%", database));137 result.setResultMessage(message);138 return result;139 }140 // soapURL from database is not empty so we prefix the Service URL with it.141 servicePath = StringUtil.getURLFromString(soapURL, "", servicePath, "");142 if (!StringUtil.isURL(servicePath)) {143 message = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_URLKO);144 message.setDescription(message.getDescription()145 .replace("%SERVICEURL%", servicePath)146 .replace("%SOAPURL%", soapURL)147 .replace("%SERVICEPATH%", appService.getServicePath()));148 result.setResultMessage(message);149 return result;150 }151 }152 } catch (CerberusException ex) {153 message = new MessageEvent(MessageEventEnum.PROPERTY_FAILED_GETFROMDATALIB_SERVICE_URLKOANDDATABASESOAPURLNOTEXIST);154 message.setDescription(message.getDescription()155 .replace("%SERVICEURL%", servicePath)156 .replace("%SYSTEM%", system)157 .replace("%COUNTRY%", country)158 .replace("%ENV%", environment)159 .replace("%DATABASE%", database));160 result.setResultMessage(message);161 return result;162 }163 }164 }165 // appService object and target servicePath is now clean. We can start to decode.166 decodedServicePath = servicePath;167 decodedRequest = appService.getServiceRequest();168 LOG.debug("AppService with correct path is now OK : " + servicePath);169 AnswerItem<String> answerDecode = new AnswerItem();170 try {171 // Decode Service Path172 answerDecode = variableService.decodeStringCompletly(decodedServicePath, tCExecution, null, false);173 decodedServicePath = (String) answerDecode.getItem();174 if (!(answerDecode.isCodeStringEquals("OK"))) {175 // If anything wrong with the decode --> we stop here with decode message in the action result.176 message = answerDecode.getResultMessage().resolveDescription("FIELD", "Service Path");177 LOG.debug("Property interupted due to decode 'Service Path'.");178 result.setResultMessage(message);179 return result;180 }181 // Decode Request182 answerDecode = variableService.decodeStringCompletly(decodedRequest, tCExecution, null, false);183 decodedRequest = (String) answerDecode.getItem();184 if (!(answerDecode.isCodeStringEquals("OK"))) {185 // If anything wrong with the decode --> we stop here with decode message in the action result.186 message = answerDecode.getResultMessage().resolveDescription("FIELD", "Service Request");187 LOG.debug("Property interupted due to decode 'Service Request'.");188 result.setResultMessage(message);189 return result;190 }191 // Decode Header List192 List<AppServiceHeader> objectResponseHeaderList = new ArrayList<>();193 for (AppServiceHeader object : appService.getHeaderList()) {194 answerDecode = variableService.decodeStringCompletly(object.getKey(), tCExecution, null, false);195 object.setKey((String) answerDecode.getItem());196 if (!(answerDecode.isCodeStringEquals("OK"))) {197 // If anything wrong with the decode --> we stop here with decode message in the action result.198 String field = "Header Key " + object.getKey();199 message = answerDecode.getResultMessage().resolveDescription("FIELD", field);200 LOG.debug("Property interupted due to decode '" + field + "'.");201 result.setResultMessage(message);202 return result;203 }204 answerDecode = variableService.decodeStringCompletly(object.getValue(), tCExecution, null, false);205 object.setValue((String) answerDecode.getItem());206 if (!(answerDecode.isCodeStringEquals("OK"))) {207 // If anything wrong with the decode --> we stop here with decode message in the action result.208 String field = "Header Value " + object.getKey();209 message = answerDecode.getResultMessage().resolveDescription("FIELD", field);210 LOG.debug("Property interupted due to decode '" + field + "'.");211 result.setResultMessage(message);212 return result;213 }214 objectResponseHeaderList.add(object);215 }216 // Decode ContentDetail List217 appService.setResponseHeaderList(objectResponseHeaderList);218 List<AppServiceContent> objectResponseContentList = new ArrayList<>();219 for (AppServiceContent object : appService.getContentList()) {220 answerDecode = variableService.decodeStringCompletly(object.getKey(), tCExecution, null, false);221 object.setKey((String) answerDecode.getItem());222 if (!(answerDecode.isCodeStringEquals("OK"))) {223 // If anything wrong with the decode --> we stop here with decode message in the action result.224 String field = "Content Key " + object.getKey();225 message = answerDecode.getResultMessage().resolveDescription("FIELD", field);226 LOG.debug("Property interupted due to decode '" + field + "'.");227 result.setResultMessage(message);228 return result;229 }230 answerDecode = variableService.decodeStringCompletly(object.getValue(), tCExecution, null, false);231 object.setValue((String) answerDecode.getItem());232 if (!(answerDecode.isCodeStringEquals("OK"))) {233 // If anything wrong with the decode --> we stop here with decode message in the action result.234 String field = "Content Value " + object.getKey();235 message = answerDecode.getResultMessage().resolveDescription("FIELD", field);236 LOG.debug("Property interupted due to decode '" + field + "'.");237 result.setResultMessage(message);238 return result;239 }240 objectResponseContentList.add(object);241 }242 appService.setContentList(objectResponseContentList);243 } catch (CerberusEventException cee) {244 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSERVICEWITHPATH);245 message.setDescription(message.getDescription().replace("%SERVICENAME%", service));246 message.setDescription(message.getDescription().replace("%SERVICEPATH%", decodedServicePath));247 message.setDescription(message.getDescription().replace("%DESCRIPTION%", cee.getMessageError().getDescription()));248 result.setResultMessage(message);249 return result;250 }251 // Get from parameter whether we define a token or not (in order to trace the cerberus calls in http header)252 String token = null;253 if (parameterService.getParameterBooleanByKey("cerberus_callservice_enablehttpheadertoken", system, true)) {254 token = String.valueOf(tCExecution.getId());255 }256 // Get from parameter the call timeout to be used.257 int timeOutMs = parameterService.getParameterIntegerByKey("cerberus_callservice_timeoutms", system, 60000);258 // The rest of the data will be prepared depending on the TYPE and METHOD used.259 switch (appService.getType()) {260 case AppService.TYPE_SOAP:261 LOG.debug("This is a SOAP Service");262 /**263 * SOAP. Decode Envelope and Operation replacing264 * properties encapsulated with %265 */266 decodedOperation = appService.getOperation();267 decodedAttachement = appService.getAttachementURL();268 try {269 answerDecode = variableService.decodeStringCompletly(decodedOperation, tCExecution, null, false);270 decodedOperation = (String) answerDecode.getItem();271 if (!(answerDecode.isCodeStringEquals("OK"))) {272 // If anything wrong with the decode --> we stop here with decode message in the action result.273 String field = "Operation";274 message = answerDecode.getResultMessage().resolveDescription("FIELD", field);275 LOG.debug("Property interupted due to decode '" + field + "'.");276 result.setResultMessage(message);277 return result;278 }279 280 answerDecode = variableService.decodeStringCompletly(decodedAttachement, tCExecution, null, false);281 decodedAttachement = (String) answerDecode.getItem();282 if (!(answerDecode.isCodeStringEquals("OK"))) {283 // If anything wrong with the decode --> we stop here with decode message in the action result.284 String field = "Attachement URL";285 message = answerDecode.getResultMessage().resolveDescription("FIELD", field);286 LOG.debug("Property interupted due to decode '" + field + "'.");287 result.setResultMessage(message);288 return result;289 }290 } catch (CerberusEventException cee) {291 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSOAP);292 message.setDescription(message.getDescription().replace("%SERVICENAME%", service));293 message.setDescription(message.getDescription().replace("%SERVICEPATH%", decodedServicePath));294 message.setDescription(message.getDescription().replace("%DESCRIPTION%", cee.getMessageError().getDescription()));295 result.setResultMessage(message);296 return result;297 }298 /**299 * Call SOAP and store it into the execution.300 */301 result = soapService.callSOAP(decodedRequest, decodedServicePath, decodedOperation, decodedAttachement,302 appService.getHeaderList(), token, timeOutMs, system);303 LOG.debug("SOAP Called done.");304 LOG.debug("Result message." + result.getResultMessage());305 message = result.getResultMessage();306 break;307 case AppService.TYPE_REST:308 /**309 * REST.310 */311 switch (appService.getMethod()) {312 313 case AppService.METHOD_HTTPGET:314 315 case AppService.METHOD_HTTPPOST:316 /**317 * Call REST and store it into the execution.318 */319 result = restService.callREST(decodedServicePath, decodedRequest, appService.getMethod(),320 appService.getHeaderList(), appService.getContentList(), token, timeOutMs, system);321 message = result.getResultMessage();322 break;323 case AppService.METHOD_HTTPDELETE:324 result = restService.callREST(decodedServicePath, decodedRequest, appService.getMethod(),325 appService.getHeaderList(), appService.getContentList(), token, timeOutMs, system);326 message = result.getResultMessage();327 break;328 case AppService.METHOD_HTTPPUT:329 result = restService.callREST(decodedServicePath, decodedRequest, appService.getMethod(),330 appService.getHeaderList(), appService.getContentList(), token, timeOutMs, system);331 message = result.getResultMessage();332 break;333 case AppService.METHOD_HTTPPATCH:334 result = restService.callREST(decodedServicePath, decodedRequest, appService.getMethod(),335 appService.getHeaderList(), appService.getContentList(), token, timeOutMs, system);336 message = result.getResultMessage();337 break;338 339 default:340 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSERVICE);341 message.setDescription(message.getDescription().replace("%DESCRIPTION%", "Method : '" + appService.getMethod() + "' for REST Service is not supported by the engine."));342 result.setResultMessage(message);343 }344 break;345 default:346 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSERVICE);347 message.setDescription(message.getDescription().replace("%SERVICE%", service));348 message.setDescription(message.getDescription().replace("%DESCRIPTION%", "Service Type : '" + appService.getType() + "' is not supported by the engine."));349 result.setResultMessage(message);350 }351 }352 } catch (CerberusException ex) {353 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSERVICE);354 message.setDescription(message.getDescription().replace("%SERVICENAME%", service));355 message.setDescription(message.getDescription().replace("%DESCRIPTION%", "Cerberus exception on CallService : " + ex.getMessageError().getDescription()));356 result.setResultMessage(message);357 return result;358 } catch (Exception ex) {359 LOG.error("Exception when performing CallService Action. " + ex.toString());360 message = new MessageEvent(MessageEventEnum.ACTION_FAILED_CALLSERVICE);361 message.setDescription(message.getDescription().replace("%SERVICENAME%", service));362 message.setDescription(message.getDescription().replace("%DESCRIPTION%", "Cerberus exception on CallService : " + ex.toString()));363 return result;364 }365 message.setDescription(message.getDescription().replace("%SERVICENAME%", service));366 result.setResultMessage(message);367 LOG.debug("Ended callService : " + service + " with database : " + database + " Result : " + message.getDescription());368 return result;369 }370}...

Full Screen

Full Screen

callService

Using AI Code Generation

copy

Full Screen

1Service service = serviceService.callService(service, request, response);2Service service = serviceService.callService(service, request, response);3Service service = serviceService.callService(service, request, response);4Service service = serviceService.callService(service, request, response);5Service service = serviceService.callService(service, request, response);6Service service = serviceService.callService(service, request, response);7Service service = serviceService.callService(service, request, response);8Service service = serviceService.callService(service, request, response);9Service service = serviceService.callService(service, request, response);10Service service = serviceService.callService(service, request, response);11Service service = serviceService.callService(service, request, response);12Service service = serviceService.callService(service, request,

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.

Most used method in ServiceService

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful