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.ext.simple;
20:
21: import java.net.ServerSocket;
22: import java.net.InetAddress;
23:
24: import org.restlet.Server;
25: import org.restlet.data.Protocol;
26:
27: import simple.http.PipelineHandlerFactory;
28: import simple.http.connect.ConnectionFactory;
29:
30: /**
31: * Simple HTTPS server connector.
32: *
33: * @author Lars Heuer (heuer[at]semagia.com)
34: * @author Jerome Louvel (contact@noelios.com)
35: */
36: public class HttpServerHelper extends SimpleServerHelper {
37: /**
38: * Constructor.
39: *
40: * @param server
41: * The server to help.
42: */
43: public HttpServerHelper(Server server) {
44: super (server);
45: getProtocols().add(Protocol.HTTP);
46: }
47:
48: /** Starts the Restlet. */
49: public void start() throws Exception {
50: String addr = getServer().getAddress();
51: if (addr != null) {
52: // This call may throw UnknownHostException and otherwise always
53: // returns an instance of INetAddress.
54: // Note: textual representation of inet addresses are supported
55: InetAddress iaddr = InetAddress.getByName(addr);
56:
57: // Note: the backlog of 50 is the default
58: setSocket(new ServerSocket(getServer().getPort(), 50, iaddr));
59: } else {
60: setSocket(new ServerSocket(getServer().getPort()));
61: }
62: setConfidential(false);
63: setHandler(PipelineHandlerFactory.getInstance(
64: new SimpleProtocolHandler(this ), getDefaultThreads(),
65: getMaxWaitTimeMs()));
66: setConnection(ConnectionFactory.getConnection(getHandler(),
67: new SimplePipelineFactory()));
68: getConnection().connect(getSocket());
69: super.start();
70: }
71:
72: }
|