01: /*
02: * Copyright 2005-2007 Noelios Consulting.
03: *
04: * The contents of this file are subject to the terms of the Common Development
05: * and Distribution License (the "License"). You may not use this file except in
06: * compliance with the License.
07: *
08: * You can obtain a copy of the license at
09: * http://www.opensource.org/licenses/cddl1.txt See the License for the specific
10: * language governing permissions and limitations under the License.
11: *
12: * When distributing Covered Code, include this CDDL HEADER in each file and
13: * include the License file at http://www.opensource.org/licenses/cddl1.txt If
14: * applicable, add the following below this CDDL HEADER, with the fields
15: * enclosed by brackets "[]" replaced with your own identifying information:
16: * Portions Copyright [yyyy] [name of copyright owner]
17: */
18:
19: package com.noelios.restlet.http;
20:
21: import java.io.IOException;
22: import java.io.InputStream;
23: import java.io.OutputStream;
24: import java.nio.channels.ReadableByteChannel;
25: import java.nio.channels.WritableByteChannel;
26: import java.util.logging.Level;
27:
28: import org.restlet.Server;
29: import org.restlet.data.Response;
30:
31: /**
32: * HTTP server call based on streams.
33: *
34: * @author Jerome Louvel (contact@noelios.com)
35: */
36: public class StreamServerCall extends HttpServerCall {
37: /** The request input stream. */
38: private InputStream requestStream;
39:
40: /** The response output stream. */
41: private OutputStream responseStream;
42:
43: /**
44: * Constructor.
45: *
46: * @param server
47: * The server connector.
48: * @param requestStream
49: * The request input stream.
50: * @param responseStream
51: * The response output stream.
52: */
53: public StreamServerCall(Server server, InputStream requestStream,
54: OutputStream responseStream) {
55: super (server);
56: this .requestStream = requestStream;
57: this .responseStream = responseStream;
58:
59: try {
60: readRequestHead(getRequestStream());
61: } catch (IOException ioe) {
62: getLogger().log(Level.WARNING,
63: "Unable to parse the HTTP request", ioe);
64: }
65: }
66:
67: @Override
68: public ReadableByteChannel getRequestChannel() {
69: return null;
70: }
71:
72: @Override
73: public InputStream getRequestStream() {
74: return this .requestStream;
75: }
76:
77: @Override
78: public WritableByteChannel getResponseChannel() {
79: return null;
80: }
81:
82: @Override
83: public OutputStream getResponseStream() {
84: return this .responseStream;
85: }
86:
87: @Override
88: public void writeResponseHead(Response response) throws IOException {
89: writeResponseHead(getResponseStream());
90: }
91:
92: }
|