comparison artifact-database/src/main/java/de/intevation/artifactdatabase/rest/Standalone.java @ 264:fa0d9acea897

flys/issue65: Added Jetty HTTP server as a replacement option to foster better scalability. Needs testing. artifacts/trunk@1975 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 22 May 2011 12:40:32 +0000
parents c0fb96f88ad1
children d52947ce8629
comparison
equal deleted inserted replaced
263:c0fb96f88ad1 264:fa0d9acea897
65 protected String maxThreads; 65 protected String maxThreads;
66 66
67 public Standalone() { 67 public Standalone() {
68 } 68 }
69 69
70 @Override
70 public void setup(Document document) { 71 public void setup(Document document) {
71 String portString = XMLUtils.xpathString(document, REST_PORT, null); 72 String portString = XMLUtils.xpathString(document, REST_PORT, null);
72
73 73
74 port = DEFAULT_PORT; 74 port = DEFAULT_PORT;
75 75
76 if (portString != null) { 76 if (portString != null) {
77 try { 77 try {
88 88
89 listen = XMLUtils.xpathString(document, LISTEN_INTERFACE, null); 89 listen = XMLUtils.xpathString(document, LISTEN_INTERFACE, null);
90 maxThreads = XMLUtils.xpathString(document, MAX_THREADS, null); 90 maxThreads = XMLUtils.xpathString(document, MAX_THREADS, null);
91 } 91 }
92 92
93 protected Server createServer() {
94 return listen != null
95 ? new Server(Protocol.HTTP, listen, port)
96 : new Server(Protocol.HTTP, port);
97 }
98
99 protected void logServerStart() {
100 logger.info("Starting " + getClass().getName() + " HTTP server on "
101 + (listen != null ? listen : "*")
102 + ":" + port);
103 }
104
93 /** 105 /**
94 * Builds a RestApp wrapped around the given artifact database, 106 * Builds a RestApp wrapped around the given artifact database,
95 * and bind this application to HTTP server. The HTTP server 107 * and bind this application to HTTP server. The HTTP server
96 * is configured by the global configuration. If no port is 108 * is configured by the global configuration. If no port is
97 * given by the configuration the default port is used. If 109 * given by the configuration the default port is used. If
98 * no interface is given the HTTP server is reachable from 110 * no interface is given the HTTP server is reachable from
99 * all interfaces. 111 * all interfaces.
100 * @param db The artifact database to be exposed via the 112 * @param db The artifact database to be exposed via the
101 * REST application. 113 * REST application.
102 */ 114 */
115 @Override
103 public void startAsServer(ArtifactDatabase db) { 116 public void startAsServer(ArtifactDatabase db) {
104 117
105 RestApp app = new RestApp(db); 118 RestApp app = new RestApp(db);
106 119
107 Component component = new Component(); 120 Component component = new Component();
108 121
109 Server server = null; 122 Server server = createServer();
110
111 if (listen != null) {
112 server = new Server(Protocol.HTTP, listen, port);
113 }
114 else {
115 server = new Server(Protocol.HTTP, port);
116 }
117 123
118 component.getServers().add(server); 124 component.getServers().add(server);
119 125
120 server.getContext().getParameters().add( 126 server.getContext().getParameters().add(
121 "maxThreads", maxThreads != null 127 "maxThreads", maxThreads != null
122 ? maxThreads 128 ? maxThreads
123 : MAX_THREADS_DEFAULT); 129 : MAX_THREADS_DEFAULT);
124 130
125 component.getDefaultHost().attach(app); 131 component.getDefaultHost().attach(app);
126 132
127 logger.info("Starting rest HTTP server on " 133 logServerStart();
128 + (listen != null ? listen : "*")
129 + ":" + port);
130 134
131 try { 135 try {
132 component.start(); 136 component.start();
133 } 137 }
134 catch (Exception e) { 138 catch (Exception e) {

http://dive4elements.wald.intevation.org