Response.java
6.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.servlet.ServletOutputStream
* javax.servlet.http.Cookie
* javax.servlet.http.HttpServletResponse
* org.apache.commons.io.IOUtils
* org.apache.commons.lang.StringUtils
* org.slf4j.Logger
*/
package com.adobe.cq.dam.s7imaging.impl.gfx;
import com.adobe.cq.dam.s7imaging.impl.gfx.S7ImageServerRenderer;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PipedOutputStream;
import java.io.PrintWriter;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
public class Response
implements HttpServletResponse {
private final Logger log;
private final OutputStream out;
private final ServletOutputStream servletOut;
private final String assetPath;
private final String modifiers;
private final S7ImageServerRenderer.Pipe pipe;
private int status = -1;
private int contentLength = -1;
private String contentType;
public Response(S7ImageServerRenderer.Pipe pipe, String assetPath, String modifiers, Logger log) {
this.pipe = pipe;
this.out = pipe.outputStream();
this.assetPath = assetPath;
this.modifiers = modifiers;
this.log = log;
this.servletOut = new ErrorRecordingServletOutputStream();
}
public void close() {
IOUtils.closeQuietly((OutputStream)this.servletOut);
}
public ServletOutputStream getOutputStream() throws IOException {
return this.servletOut;
}
public void setStatus(int sc) {
this.log.debug("platformserver returned status : {}", (Object)sc);
this.status = sc;
}
public void setContentType(String type) {
this.log.debug("platformserver set content type : {}", (Object)type);
this.contentType = type;
}
public void setContentLength(int len) {
this.log.debug("platformserver set content length: {}", (Object)len);
this.contentLength = len;
}
public void setDateHeader(String name, long date) {
if (this.log.isDebugEnabled()) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(date);
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
this.log.debug("platformserver set date header : {}: {}", (Object)name, (Object)dateFormat.format(calendar.getTime()));
}
}
public void setHeader(String name, String value) {
this.log.debug("platformserver set header : {}: {}", (Object)name, (Object)value);
}
public void addCookie(Cookie cookie) {
}
public boolean containsHeader(String name) {
return false;
}
public String encodeURL(String url) {
return null;
}
public String encodeRedirectURL(String url) {
return null;
}
@Deprecated
public String encodeUrl(String url) {
return null;
}
@Deprecated
public String encodeRedirectUrl(String url) {
return null;
}
public void sendError(int sc, String msg) throws IOException {
}
public void sendError(int sc) throws IOException {
}
public void sendRedirect(String location) throws IOException {
}
public void addDateHeader(String name, long date) {
}
public void addHeader(String name, String value) {
}
public void setIntHeader(String name, int value) {
}
public void addIntHeader(String name, int value) {
}
@Deprecated
public void setStatus(int sc, String sm) {
}
public String getCharacterEncoding() {
return null;
}
public String getContentType() {
return null;
}
public PrintWriter getWriter() throws IOException {
return new PrintWriter((OutputStream)this.servletOut);
}
public void setCharacterEncoding(String charset) {
}
public void setBufferSize(int size) {
}
public int getBufferSize() {
return 0;
}
public void flushBuffer() throws IOException {
}
public void resetBuffer() {
}
public boolean isCommitted() {
return false;
}
public void reset() {
}
public void setLocale(Locale loc) {
}
public Locale getLocale() {
return null;
}
private class ErrorRecordingServletOutputStream
extends ServletOutputStream {
private static final int MAX_ERROR_BODY_SIZE = 4096;
private ByteArrayOutputStream errorBody;
private ErrorRecordingServletOutputStream() {
}
public void write(int b) throws IOException {
if (Response.this.status != 200) {
if (Response.this.contentType != null && Response.this.contentType.startsWith("text/")) {
if (this.errorBody == null) {
if (Response.this.contentLength < 0) {
Response.this.contentLength = 4096;
} else if (Response.this.contentLength > 4096) {
Response.this.contentLength = 4096;
}
this.errorBody = new ByteArrayOutputStream(Response.this.contentLength);
}
if (this.errorBody.size() < Response.this.contentLength) {
this.errorBody.write(b);
}
}
} else {
Response.this.out.write(b);
}
}
public void close() throws IOException {
if (Response.this.status != 200) {
String msg;
if (this.errorBody != null) {
String errorMessage = StringUtils.trim((String)new String(this.errorBody.toByteArray(), "utf-8"));
msg = MessageFormat.format("Platform Server could not render image, returned status {0} for asset {1} with modifiers {2}, error message: {3}", Response.this.status, Response.this.assetPath, Response.this.modifiers, errorMessage);
} else {
msg = MessageFormat.format("Platform Server could not render image, returned status {0} for asset {1} with modifiers {2}, no error message", Response.this.status, Response.this.assetPath, Response.this.modifiers);
}
Response.this.pipe.sendException(new IOException(msg));
}
Response.this.out.close();
}
}
}