1/* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17/** 18 * A test EventHandler: Logs everything received 19 */ 20 21package android.net.http; 22 23import android.net.http.Headers; 24 25public class LoggingEventHandler implements EventHandler { 26 27 public void requestSent() { 28 HttpLog.v("LoggingEventHandler:requestSent()"); 29 } 30 31 public void status(int major_version, 32 int minor_version, 33 int code, /* Status-Code value */ 34 String reason_phrase) { 35 if (HttpLog.LOGV) { 36 HttpLog.v("LoggingEventHandler:status() major: " + major_version + 37 " minor: " + minor_version + 38 " code: " + code + 39 " reason: " + reason_phrase); 40 } 41 } 42 43 public void headers(Headers headers) { 44 if (HttpLog.LOGV) { 45 HttpLog.v("LoggingEventHandler:headers()"); 46 HttpLog.v(headers.toString()); 47 } 48 } 49 50 public void locationChanged(String newLocation, boolean permanent) { 51 if (HttpLog.LOGV) { 52 HttpLog.v("LoggingEventHandler: locationChanged() " + newLocation + 53 " permanent " + permanent); 54 } 55 } 56 57 public void data(byte[] data, int len) { 58 if (HttpLog.LOGV) { 59 HttpLog.v("LoggingEventHandler: data() " + len + " bytes"); 60 } 61 // HttpLog.v(new String(data, 0, len)); 62 } 63 public void endData() { 64 if (HttpLog.LOGV) { 65 HttpLog.v("LoggingEventHandler: endData() called"); 66 } 67 } 68 69 public void certificate(SslCertificate certificate) { 70 if (HttpLog.LOGV) { 71 HttpLog.v("LoggingEventHandler: certificate(): " + certificate); 72 } 73 } 74 75 public void error(int id, String description) { 76 if (HttpLog.LOGV) { 77 HttpLog.v("LoggingEventHandler: error() called Id:" + id + 78 " description " + description); 79 } 80 } 81 82 public boolean handleSslErrorRequest(SslError error) { 83 if (HttpLog.LOGV) { 84 HttpLog.v("LoggingEventHandler: handleSslErrorRequest():" + error); 85 } 86 // return false so that the caller thread won't wait forever 87 return false; 88 } 89} 90