1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21 *******************************************************************************/
22 package org.onap.dmaap.mr.tools;
24 import java.io.PrintStream;
26 import java.util.List;
29 import com.att.nsa.apiClient.http.HttpTracer;
30 import com.att.nsa.cmdtool.Command;
31 import com.att.nsa.cmdtool.CommandNotReadyException;
33 public class TraceCommand implements Command<MRCommandContext>
36 public void checkReady ( MRCommandContext context ) throws CommandNotReadyException
41 public void execute ( String[] parts, MRCommandContext context, final PrintStream out ) throws CommandNotReadyException
43 if ( parts[0].equalsIgnoreCase ( "on" ))
45 context.useTracer ( new HttpTracer ()
48 public void outbound ( URI uri, Map<String, List<String>> headers, String method, byte[] entity )
50 out.println ( kLineBreak );
51 out.println ( ">>> " + method + " " + uri.toString() );
52 for ( Map.Entry<String,List<String>> e : headers.entrySet () )
54 final StringBuffer vals = new StringBuffer ();
55 for ( String val : e.getValue () )
57 if ( vals.length () > 0 ) vals.append ( ", " );
60 out.println ( ">>> " + e.getKey () + ": " + vals.toString() );
65 out.println ( new String ( entity ) );
67 out.println ( kLineBreak );
71 public void inbound ( Map<String, List<String>> headers, int statusCode, String responseLine, byte[] entity )
73 out.println ( kLineBreak );
74 out.println ( "<<< " + responseLine );
75 for ( Map.Entry<String,List<String>> e : headers.entrySet () )
77 final StringBuffer vals = new StringBuffer ();
78 for ( String val : e.getValue () )
80 if ( vals.length () > 0 ) vals.append ( ", " );
83 out.println ( "<<< " + e.getKey () + ": " + vals.toString() );
88 out.println ( new String ( entity ) );
90 out.println ( kLineBreak );
101 public void displayHelp ( PrintStream out )
103 out.println ( "trace on|off" );
104 out.println ( "\tWhen trace is on, HTTP interaction is printed to the console." );
108 public String[] getMatches ()
117 private static final String kLineBreak = "======================================================================";