1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.esigate.servlet.impl;
17
18 import java.io.IOException;
19 import java.io.InputStream;
20 import java.io.OutputStream;
21
22 import javax.servlet.http.HttpServletRequest;
23
24 import org.apache.http.HttpHeaders;
25 import org.apache.http.entity.AbstractHttpEntity;
26 import org.esigate.http.HttpResponseUtils;
27
28 public class HttpServletRequestEntity extends AbstractHttpEntity {
29 private final HttpServletRequest request;
30 private final long length;
31
32 HttpServletRequestEntity(HttpServletRequest request) {
33 this.request = request;
34 String contentLengthHeader = request.getHeader(HttpHeaders.CONTENT_LENGTH);
35 if (contentLengthHeader != null) {
36 length = Long.parseLong(contentLengthHeader);
37 } else {
38 length = -1;
39 }
40 String contentTypeHeader = request.getHeader(HttpHeaders.CONTENT_TYPE);
41 if (contentTypeHeader != null) {
42 this.setContentType(contentTypeHeader);
43 }
44 String contentEncodingHeader = request.getHeader(HttpHeaders.CONTENT_ENCODING);
45 if (contentEncodingHeader != null) {
46 this.setContentEncoding(contentEncodingHeader);
47 }
48
49 }
50
51 @Override
52 public boolean isRepeatable() {
53 return false;
54 }
55
56 @Override
57 public long getContentLength() {
58 return length;
59 }
60
61 @Override
62 public InputStream getContent() throws IOException, IllegalStateException {
63 return request.getInputStream();
64 }
65
66 @Override
67 public void writeTo(OutputStream outstream) throws IOException {
68 HttpResponseUtils.writeTo(this, outstream);
69 }
70
71 @Override
72 public boolean isStreaming() {
73 return true;
74 }
75
76 }