From ab654a7a0623957fb4808a1fe0d2eaebd6616108 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Thu, 21 Apr 2011 11:39:20 +0000 Subject: [PATCH] added toString to HttpEntity --- .../org/springframework/http/HttpEntity.java | 17 ++++++++++++- .../springframework/http/ResponseEntity.java | 25 ++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/org.springframework.web/src/main/java/org/springframework/http/HttpEntity.java b/org.springframework.web/src/main/java/org/springframework/http/HttpEntity.java index 20187c1044..cceafc8876 100644 --- a/org.springframework.web/src/main/java/org/springframework/http/HttpEntity.java +++ b/org.springframework.web/src/main/java/org/springframework/http/HttpEntity.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -122,4 +122,19 @@ public class HttpEntity { return (this.body != null); } + @Override + public String toString() { + StringBuilder builder = new StringBuilder("<"); + if (body != null) { + builder.append(body); + if (headers != null) { + builder.append(','); + } + } + if (headers != null) { + builder.append(headers); + } + builder.append('>'); + return builder.toString(); + } } diff --git a/org.springframework.web/src/main/java/org/springframework/http/ResponseEntity.java b/org.springframework.web/src/main/java/org/springframework/http/ResponseEntity.java index 45f6e27bb4..26ff6e0f0a 100644 --- a/org.springframework.web/src/main/java/org/springframework/http/ResponseEntity.java +++ b/org.springframework.web/src/main/java/org/springframework/http/ResponseEntity.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -93,4 +93,27 @@ public class ResponseEntity extends HttpEntity { public HttpStatus getStatusCode() { return statusCode; } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder("<"); + builder.append(statusCode.toString()); + builder.append(' '); + builder.append(statusCode.getReasonPhrase()); + builder.append(','); + T body = getBody(); + HttpHeaders headers = getHeaders(); + if (body != null) { + builder.append(body); + if (headers != null) { + builder.append(','); + } + } + if (headers != null) { + builder.append(headers); + } + builder.append('>'); + return builder.toString(); + } + }