|
| 1 | +package com.example.application.httprestclient.general.service.impl.rest; |
| 2 | + |
| 3 | +import javax.inject.Inject; |
| 4 | +import javax.inject.Named; |
| 5 | + |
| 6 | +import com.devonfw.module.service.common.api.client.ServiceClientFactory; |
| 7 | +import com.devonfw.module.service.common.api.client.config.ServiceClientConfigBuilder; |
| 8 | +import com.example.application.httprestclient.general.service.api.rest.TestRestService; |
| 9 | +import com.example.application.httprestclient.general.service.api.rest.VisitormanagementRestService; |
| 10 | + |
| 11 | +@Named("TestRestService") |
| 12 | +public class TestRestServiceImpl implements TestRestService { |
| 13 | + |
| 14 | + @Inject |
| 15 | + private ServiceClientFactory serviceClientFactory; |
| 16 | + |
| 17 | + @Override |
| 18 | + public String showResponse() { |
| 19 | + |
| 20 | + String result = callSynchronous(); |
| 21 | + System.out.println("**********inside client method***********"); |
| 22 | + System.out.println(result); |
| 23 | + System.out.println("************Thank you for choosing devon4j ****************"); |
| 24 | + return result; |
| 25 | + |
| 26 | + } |
| 27 | + |
| 28 | + private String callSynchronous() { |
| 29 | + |
| 30 | + System.out.println("***********inside synchronous call************"); |
| 31 | + VisitormanagementRestService visitormanagementRestService = this.serviceClientFactory.create( |
| 32 | + VisitormanagementRestService.class, |
| 33 | + new ServiceClientConfigBuilder().authBasic().userLogin("admin").userPassword("admin").buildMap()); |
| 34 | + // call of service over the wire, synchronously blocking until result is received or error occurred |
| 35 | + String resultFromAPICall = visitormanagementRestService.returnResponseToClient(); |
| 36 | + System.out.println("************************got result from api" + resultFromAPICall + "***************"); |
| 37 | + return resultFromAPICall; |
| 38 | + } |
| 39 | + |
| 40 | + @Override |
| 41 | + public String verifyServiceWork() { |
| 42 | + |
| 43 | + return "Verified... service is working"; |
| 44 | + } |
| 45 | + |
| 46 | +} |
0 commit comments