1
2
3
4
5
6
7
8
9
10
11 package org.astrogrid.dataservice.queriers;
12
13 import java.io.IOException;
14 import java.io.InputStream;
15 import java.io.OutputStream;
16 import java.security.Principal;
17 import org.astrogrid.dataservice.queriers.QueryResults;
18 import org.astrogrid.dataservice.queriers.status.QuerierStatus;
19 import org.astrogrid.io.Piper;
20 import org.astrogrid.query.returns.ReturnSpec;
21 import org.astrogrid.slinger.targets.TargetIdentifier;
22 import org.astrogrid.tableserver.out.TableWriter;
23
24 /***
25 * Pipes results as-they-are from the given inputstream to the target.
26 * If you are confident that the results are already in the right form suitable
27 * for delivering to the client, and you have an inputstream to them, this
28 * is the appropriate results wrapper to use. For example, if you are proxying
29 * to a service that provides results in the right form, there's no point in
30 * interpreting them here. Of course it woulld be nice to send them direct if
31 * possible, rather than routing them through here, but some stateless services
32 * can't do this.
33 *
34 */
35 public class RawPipeResults implements QueryResults {
36
37 protected final InputStream in;
38 protected final String mimeType;
39 protected final Querier querier;
40
41 /*** Std Constructor. xmlIn is a stream containing the xml document
42 */
43 public RawPipeResults(Querier aQuerier, InputStream source, String sourceMimeType) {
44 this.querier = aQuerier;
45 this.in = source;
46 this.mimeType = sourceMimeType;
47 }
48
49 /***
50 * Sends as is - pipes out. Mo status info yet...
51 */
52 public void send(ReturnSpec returnSpec, Principal user) throws IOException {
53
54 TargetIdentifier target = returnSpec.getTarget();
55
56 if (mimeType != null) {
57 target.setMimeType(mimeType, user);
58 }
59 OutputStream out = target.resolveOutputStream(user);
60
61 Piper.bufferedPipe(in, out);
62 }
63
64 /***
65 * Don't know how to write this out in table form...
66 */
67 public void writeTable(TableWriter tableWriter, QuerierStatus statusToUpdate) throws IOException {
68 throw new UnsupportedOperationException("Can't write Xml out to tables...");
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