forked from danatcaret/open-experiments
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* project: Fixed jetty startup to listen on all hosts for trusted and user connectors Adapted Felix Http Jetty service activation to use jetty.xml rather than OSGi properties as our deployment is generally more complex than can be handled by the standard Felix bundle (we need 3 connectiors on differnt ports) Set default to on MessageBucket URL to something that works on an IPv6 machine. Fixed rather inefficient stream handling.
- Loading branch information
Showing
7 changed files
with
295 additions
and
20 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...es/jetty-config/src/main/java/org/apache/felix/http/jetty/internal/NakamuraActivator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.apache.felix.http.jetty.internal; | ||
|
||
import org.apache.felix.http.base.internal.AbstractHttpActivator; | ||
|
||
public class NakamuraActivator extends AbstractHttpActivator { | ||
|
||
private NakamuraJettyService jetty; | ||
|
||
protected void doStart() | ||
throws Exception | ||
{ | ||
super.doStart(); | ||
this.jetty = new NakamuraJettyService(getBundleContext(), getDispatcherServlet(), getEventDispatcher(), | ||
getHttpServiceController()); | ||
this.jetty.start(); | ||
} | ||
|
||
protected void doStop() | ||
throws Exception | ||
{ | ||
this.jetty.stop(); | ||
super.doStop(); | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
...onfig/src/main/java/org/apache/felix/http/jetty/internal/NakamuraJettyManagedService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.felix.http.jetty.internal; | ||
|
||
import java.util.Dictionary; | ||
|
||
import org.osgi.framework.Bundle; | ||
import org.osgi.framework.ServiceFactory; | ||
import org.osgi.framework.ServiceRegistration; | ||
import org.osgi.service.cm.ManagedService; | ||
|
||
public class NakamuraJettyManagedService implements ServiceFactory | ||
{ | ||
|
||
private final NakamuraJettyService jettyService; | ||
|
||
NakamuraJettyManagedService(final NakamuraJettyService jettyService) | ||
{ | ||
this.jettyService = jettyService; | ||
} | ||
|
||
public Object getService(Bundle bundle, ServiceRegistration registration) | ||
{ | ||
return new ManagedService() | ||
{ | ||
@SuppressWarnings("rawtypes") | ||
public void updated(Dictionary properties) | ||
{ | ||
jettyService.updated(properties); | ||
} | ||
}; | ||
} | ||
|
||
public void ungetService(Bundle bundle, ServiceRegistration registration, Object service) | ||
{ | ||
// just have the reference dropped, nothing to cleanup | ||
} | ||
|
||
} |
174 changes: 174 additions & 0 deletions
174
...jetty-config/src/main/java/org/apache/felix/http/jetty/internal/NakamuraJettyService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.felix.http.jetty.internal; | ||
|
||
import org.apache.felix.http.base.internal.DispatcherServlet; | ||
import org.apache.felix.http.base.internal.EventDispatcher; | ||
import org.apache.felix.http.base.internal.HttpServiceController; | ||
import org.apache.felix.http.base.internal.logger.SystemLogger; | ||
import org.mortbay.jetty.Server; | ||
import org.mortbay.jetty.security.HashUserRealm; | ||
import org.mortbay.jetty.servlet.Context; | ||
import org.mortbay.jetty.servlet.ServletHolder; | ||
import org.mortbay.xml.XmlConfiguration; | ||
import org.osgi.framework.BundleContext; | ||
import org.osgi.framework.Constants; | ||
import org.osgi.framework.ServiceRegistration; | ||
|
||
import java.io.InputStream; | ||
import java.util.Dictionary; | ||
import java.util.Hashtable; | ||
import java.util.Properties; | ||
|
||
public final class NakamuraJettyService | ||
implements Runnable | ||
{ | ||
/** PID for configuration of the HTTP service. */ | ||
private static final String PID = "org.apache.felix.http"; | ||
|
||
private final BundleContext context; | ||
private boolean running; | ||
private Thread thread; | ||
private ServiceRegistration configServiceReg; | ||
private Server server; | ||
private DispatcherServlet dispatcher; | ||
private EventDispatcher eventDispatcher; | ||
private final HttpServiceController controller; | ||
|
||
public NakamuraJettyService(BundleContext context, DispatcherServlet dispatcher, EventDispatcher eventDispatcher, | ||
HttpServiceController controller) | ||
{ | ||
this.context = context; | ||
this.dispatcher = dispatcher; | ||
this.eventDispatcher = eventDispatcher; | ||
this.controller = controller; | ||
} | ||
|
||
public void start() | ||
throws Exception | ||
{ | ||
JettyLogger.init(); | ||
|
||
Properties props = new Properties(); | ||
props.put(Constants.SERVICE_PID, PID); | ||
this.configServiceReg = this.context.registerService("org.osgi.service.cm.ManagedService", | ||
new NakamuraJettyManagedService(this), props); | ||
|
||
this.thread = new Thread(this, "Jetty HTTP Service"); | ||
this.thread.start(); | ||
} | ||
|
||
public void stop() | ||
throws Exception | ||
{ | ||
if (this.configServiceReg != null) { | ||
this.configServiceReg.unregister(); | ||
} | ||
|
||
this.running = false; | ||
this.thread.interrupt(); | ||
|
||
try { | ||
this.thread.join(3000); | ||
} catch (InterruptedException e) { | ||
// Do nothing | ||
} | ||
} | ||
|
||
private void publishServiceProperties() | ||
{ | ||
Hashtable<String, Object> props = new Hashtable<String, Object>(); | ||
this.controller.setProperties(props); | ||
} | ||
|
||
@SuppressWarnings("rawtypes") | ||
public void updated(Dictionary props) | ||
{ | ||
if (this.running && (this.thread != null)) { | ||
this.thread.interrupt(); | ||
} | ||
} | ||
|
||
private void startJetty() | ||
{ | ||
try { | ||
initializeJetty(); | ||
} catch (Exception e) { | ||
SystemLogger.error("Exception while initializing Jetty.", e); | ||
} | ||
} | ||
|
||
private void stopJetty() | ||
{ | ||
if (this.server != null) | ||
{ | ||
try | ||
{ | ||
this.server.stop(); | ||
this.server = null; | ||
} | ||
catch (Exception e) | ||
{ | ||
SystemLogger.error("Exception while stopping Jetty.", e); | ||
} | ||
} | ||
} | ||
|
||
private void initializeJetty() | ||
throws Exception | ||
{ | ||
StringBuffer message = new StringBuffer("Started jetty ").append(Server.getVersion()).append(" at port(s)"); | ||
HashUserRealm realm = new HashUserRealm("OSGi HTTP Service Realm"); | ||
this.server = new Server(); | ||
this.server.addUserRealm(realm); | ||
InputStream configStream = this.getClass().getClassLoader().getResourceAsStream("jetty.xml"); | ||
XmlConfiguration configuration = new XmlConfiguration(configStream); | ||
configuration.configure(server); | ||
configStream.close(); | ||
|
||
|
||
Context context = new Context(this.server, "/", Context.SESSIONS); | ||
context.addEventListener(eventDispatcher); | ||
context.getSessionHandler().addEventListener(eventDispatcher); | ||
context.addServlet(new ServletHolder(this.dispatcher), "/*"); | ||
|
||
this.server.start(); | ||
SystemLogger.info(message.toString()); | ||
publishServiceProperties(); | ||
} | ||
|
||
|
||
public void run() | ||
{ | ||
this.running = true; | ||
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); | ||
|
||
while (this.running) { | ||
startJetty(); | ||
|
||
synchronized (this) { | ||
try { | ||
wait(); | ||
} catch (InterruptedException e) { | ||
// we will definitely be interrupted | ||
} | ||
} | ||
|
||
stopJetty(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters