Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [
- {
- "attributeId": 12345,
- "attributeTitle": "Hello World",
- "someNumber": null,
- "totalAmount": 20,
- "emailList": [
- "emp1725@xxmail.com",
- "emp3399@xxmail.com",
- "emp9125@xxmail.com",
- "emp9978@xxmail.com",
- ]
- },
- {
- "attributeId": 23456,
- "attributeTitle": "Hello America",
- "someNumber": null,
- "totalAmount": 30,
- "emailList": [
- "dmp1725@xxmail.com",
- "dmp3399@xxmail.com",
- "dmp9125@xxmail.com",
- "dmp9978@xxmail.com",
- ]
- },
- {
- "attributeId": 34567,
- "attributeTitle": "Hello Texas",
- "someNumber": null,
- "totalAmount": 40,
- "emailList": [
- "bng1725@xxmail.com",
- "bng3399@xxmail.com",
- "bng9125@xxmail.com",
- "bng9978@xxmail.com",
- ]
- },
- {
- "attributeId": 45678,
- "attributeTitle": "Hello California",
- "someNumber": null,
- "totalAmount": 50,
- "emailList": [
- "wtm1725@xxmail.com",
- "wtm3399@xxmail.com",
- "wtm9125@xxmail.com",
- "wtm9978@xxmail.com",
- ]
- }
- enter code here
- import java.util.ArrayList;
- public class CmsObject {
- private String attributeId;
- private String attributeTitle;
- private String someNumber;
- private int totalAmount;
- private ArrayList<String> emails = new ArrayList<>();
- //Getters & Settors.... (Used Eclipse to Generate)
- }
- @Component
- public class CmsNotiHandler {
- public void handler() {
- String restURL = System.getenv("nRestUrl");
- RestTemplate restTemplate = new RestTemplate();
- ParameterizedTypeReference<List<CmsObject>> listOffrn = new
- ParameterizedTypeReference<List<CmsObject>>() {
- };
- ResponseEntity<List<CmsObject>> cmsResponse
- = restTemplate.exchange(restURL, HttpMethod.GET, new
- HttpEntity<>(getHeaders()), listOffrn);
- List<CmsObject> cmsList = cmsResponse.getBody();
- for (CmsObject cc : cmsList) {
- System.out.println("Email List Size: " + cc.getEmails().size());
- }
- }
- private static HttpHeaders getHeaders() {
- String restServiceUsername = System.getenv("username");
- String restServicePassword = System.getenv("password");
- StringBuilder plainCredentials = new StringBuilder();
- plainCredentials.append(restServiceUsername).append(":")
- .append(restServicePassword);
- String base64Credentials = new
- String(Base64Utils.encode(plainCredentials.toString()
- .getBytes(StandardCharsets.UTF_8)));
- HttpHeaders headers = new HttpHeaders();
- headers.add(AUTHORIZATION, "Basic " + base64Credentials);
- headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
- return headers;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement