1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright © 2021 Orange.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 *******************************************************************************/
25 package org.onap.dmaap.mr.tools;
27 import com.att.nsa.apiClient.http.HttpTracer;
28 import com.att.nsa.cmdtool.Command;
29 import com.att.nsa.cmdtool.CommandNotReadyException;
31 import java.io.PrintStream;
33 import java.util.List;
36 public class TraceCommand implements Command<MRCommandContext> {
38 public void checkReady(MRCommandContext context) throws CommandNotReadyException {
42 public void execute(String[] parts, MRCommandContext context, final PrintStream out) throws CommandNotReadyException {
43 if (parts[0].equalsIgnoreCase("on")) {
44 context.useTracer(new HttpTracer() {
46 public void outbound(URI uri, Map<String, List<String>> headers, String method, byte[] entity) {
47 out.println(K_LINE_BREAK);
48 out.println(">>> " + method + " " + uri.toString());
49 for (Map.Entry<String, List<String>> e : headers.entrySet()) {
50 final StringBuilder vals = new StringBuilder();
51 for (String val : e.getValue()) {
52 if (vals.length() > 0) vals.append(", ");
55 out.println(">>> " + e.getKey() + ": " + vals);
59 out.println(new String(entity));
61 out.println(K_LINE_BREAK);
65 public void inbound(Map<String, List<String>> headers, int statusCode, String responseLine, byte[] entity) {
66 out.println(K_LINE_BREAK);
67 out.println("<<< " + responseLine);
68 for (Map.Entry<String, List<String>> e : headers.entrySet()) {
69 final StringBuilder vals = new StringBuilder();
70 for (String val : e.getValue()) {
71 if (vals.length() > 0) {
76 out.println("<<< " + e.getKey() + ": " + vals);
80 out.println(new String(entity));
82 out.println(K_LINE_BREAK);
91 public void displayHelp(PrintStream out) {
92 out.println("trace on|off");
93 out.println("\tWhen trace is on, HTTP interaction is printed to the console.");
97 public String[] getMatches() {
104 private static final String K_LINE_BREAK = "======================================================================";