View Javadoc
1   /*******************************************************************************
2    * Copyhacked (H) 2012-2025.
3    * This program and the accompanying materials
4    * are made available under no term at all, use it like
5    * you want, but share and discuss it
6    * every time possible with every body.
7    * 
8    * Contributors:
9    *      ron190 at ymail dot com - initial implementation
10   ******************************************************************************/
11  package com.jsql.view.terminal.interaction;
12  
13  import com.jsql.model.bean.util.Header;
14  import com.jsql.util.AnsiColorUtil;
15  import com.jsql.view.interaction.InteractionCommand;
16  import org.apache.commons.lang3.StringUtils;
17  import org.apache.logging.log4j.LogManager;
18  import org.apache.logging.log4j.Logger;
19  
20  import java.util.Collections;
21  import java.util.Map;
22  
23  public class MessageHeader implements InteractionCommand {
24      
25      private static final Logger LOGGER = LogManager.getRootLogger();
26  
27      private final String url;
28      private final String post;
29      private final Map<String, String> header;
30      private final Map<String, String> response;
31      private final String source;
32  
33      @SuppressWarnings("unchecked")
34      public MessageHeader(Object[] interactionParams) {
35          Map<Header, Object> params = (Map<Header, Object>) interactionParams[0];
36          this.url = (String) params.getOrDefault(Header.URL, StringUtils.EMPTY);
37          this.post = (String) params.getOrDefault(Header.POST, StringUtils.EMPTY);
38          this.header = (Map<String, String>) params.getOrDefault(Header.HEADER, Collections.emptyMap());
39          this.response = (Map<String, String>) params.getOrDefault(Header.RESPONSE, Collections.emptyMap());
40          this.source = (String) params.getOrDefault(Header.SOURCE, StringUtils.EMPTY);
41      }
42  
43      @Override
44      public void execute() {
45          LOGGER.debug(() -> AnsiColorUtil.addGreenColor(this.getClass().getSimpleName()));
46          LOGGER.debug("Method: {}", () -> this.response.get("Method"));
47          LOGGER.debug("Url: {}", this.url);
48          LOGGER.debug("Post: {}", this.post);
49          LOGGER.debug("Header: {}", this.header);
50          LOGGER.debug("Content-Length: {}", () -> this.response.get("Content-Length"));
51          LOGGER.debug("Content-Type: {}", () -> this.response.get("Content-Type"));
52          LOGGER.debug("Source: {}", () -> this.source);
53      }
54  }