1 16 17 package org.apache.commons.latka.http; 18 19 import java.io.InputStream ; 20 import java.io.IOException ; 21 22 import org.apache.commons.httpclient.Header; 23 import org.apache.commons.httpclient.HttpMethod; 24 25 34 public class ResponseImpl implements Response { 35 36 37 protected RequestImpl _request; 38 39 protected HttpMethod _httpMethod; 40 41 46 ResponseImpl(RequestImpl request) { 47 _request = request; 48 _httpMethod = request.getHttpMethod(); 49 } 50 51 56 public Request getRequest() { 57 return _request; 58 } 59 60 64 67 public int getStatusCode() { 68 return _httpMethod.getStatusCode(); 69 } 70 71 74 public String getStatusText() { 75 return _httpMethod.getStatusText(); 76 } 77 78 85 public String getResource() { 86 try { 87 return _httpMethod.getResponseBodyAsString(); 88 } catch (Exception e) { 89 return null; 90 } 91 } 92 93 102 public String getHeader(String headerName) { 103 Header header = _httpMethod.getResponseHeader(headerName); 104 if (header != null) { 105 return header.getValue(); 106 } 107 return null; 108 } 109 110 116 public int getByteLength() { 117 byte[] responseBytes = null; 118 try { 119 responseBytes = _httpMethod.getResponseBody(); 120 } catch (Exception e) { 121 } 122 if (responseBytes == null) { 123 return -1; 124 } 125 126 return responseBytes.length; 127 } 128 129 135 public InputStream getStream() { 136 InputStream stream; 137 138 try { 139 stream = _httpMethod.getResponseBodyAsStream(); 140 } catch (IOException ioX) { 141 stream = null; 142 } 143 144 return stream; 145 } 146 } | Popular Tags |