1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.client.ui.commons.rest;
20
21 import java.io.InputStream;
22 import java.io.Serializable;
23 import javax.ws.rs.core.HttpHeaders;
24 import javax.ws.rs.core.Response;
25 import org.apache.commons.lang3.StringUtils;
26
27 public class ResponseHolder implements Serializable {
28
29 private static final long serialVersionUID = 2627155013246805827L;
30
31 private transient InputStream inputStream;
32
33 private String contentType;
34
35 private String location;
36
37 private String filename;
38
39 public ResponseHolder(final Response response) {
40 Object entity = response.getEntity();
41 if (response.getStatusInfo().getStatusCode() == Response.Status.OK.getStatusCode()
42 && (entity instanceof InputStream)) {
43
44 this.inputStream = (InputStream) entity;
45 this.contentType = response.getHeaderString(HttpHeaders.CONTENT_TYPE);
46 this.location = response.getLocation() == null ? null : response.getLocation().toASCIIString();
47 String contentDisposition = response.getHeaderString(HttpHeaders.CONTENT_DISPOSITION);
48 if (StringUtils.isNotBlank(contentDisposition)) {
49 String[] splitted = contentDisposition.split("=");
50 if (splitted != null && splitted.length > 1) {
51 this.filename = splitted[1].trim();
52 }
53 }
54 }
55 }
56
57 public InputStream getInputStream() {
58 return inputStream;
59 }
60
61 public String getContentType() {
62 return contentType;
63 }
64
65 public String getLocation() {
66 return location;
67 }
68
69 public String getFilename() {
70 return filename;
71 }
72 }