Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.tuscany.sca.http.jetty;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.net.UnknownHostException;
import java.security.AccessController;
import java.security.KeyStore;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.logging.Logger;
import javax.servlet.RequestDispatcher;
import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.core.LifeCycleListener;
import org.apache.tuscany.sca.core.UtilityExtensionPoint;
import org.apache.tuscany.sca.host.http.DefaultResourceServlet;
import org.apache.tuscany.sca.host.http.HttpScheme;
import org.apache.tuscany.sca.host.http.SecurityContext;
import org.apache.tuscany.sca.host.http.ServletHost;
import org.apache.tuscany.sca.host.http.ServletMappingException;
import org.apache.tuscany.sca.host.http.extensibility.HttpPortAllocator;
import org.apache.tuscany.sca.work.WorkScheduler;
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.handler.ContextHandler;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.security.SslSocketConnector;
import org.mortbay.jetty.servlet.DefaultServlet;
import org.mortbay.jetty.servlet.ServletHandler;
import org.mortbay.jetty.servlet.ServletHolder;
import org.mortbay.jetty.servlet.ServletMapping;
import org.mortbay.jetty.servlet.SessionHandler;
import org.mortbay.log.Log;
import org.mortbay.thread.ThreadPool;
/**
* Implements an HTTP transport service using Jetty.
*
* @version $Rev: 1095242 $ $Date: 2011-04-20 01:19:13 +0100 (Wed, 20 Apr 2011) $
*/
public class JettyServer implements ServletHost, LifeCycleListener {
private static final Logger logger = Logger.getLogger(JettyServer.class.getName());
private final Object joinLock = new Object();
private String trustStore;
private String trustStorePassword;
private String keyStore;
private String keyStorePassword;
private String keyStoreType;
private String trustStoreType;
private boolean sendServerVersion;
private WorkScheduler workScheduler;
private HttpPortAllocator httpPortAllocator;
// TODO - this static seems to be set by the JSORPC binding unit test
// doesn't look to be a great way of doing things
public static int portDefault = 0;
private int defaultPort;
private int defaultSSLPort;
/**
* Represents a port and the server that serves it.
*/
private class Port {
private Server server;
private ServletHandler servletHandler;
private Port(Server server, ServletHandler servletHandler) {
this.server = server;
this.servletHandler = servletHandler;
}
public Server getServer() {
return server;
}
public ServletHandler getServletHandler() {
return servletHandler;
}
}
private Map ports = new HashMap();
private String contextPath = "/";
private org.mortbay.log.Logger jettyLogger;
public JettyServer(ExtensionPointRegistry registry) {
UtilityExtensionPoint utilityExtensionPoint = registry.getExtensionPoint(UtilityExtensionPoint.class);
this.workScheduler = utilityExtensionPoint.getUtility(WorkScheduler.class);
this.httpPortAllocator = utilityExtensionPoint.getUtility(HttpPortAllocator.class);
init();
}
protected JettyServer(WorkScheduler workScheduler, HttpPortAllocator httpPortAllocator) {
this.httpPortAllocator = httpPortAllocator;
this.workScheduler = workScheduler;
init();
}
private void init() {
this.defaultPort = this.httpPortAllocator.getDefaultPort(HttpScheme.HTTP);
//handle backdoor to set specific default port in tests
if(portDefault > 0) {
this.defaultPort = portDefault;
}
this.defaultSSLPort = this.httpPortAllocator.getDefaultPort(HttpScheme.HTTPS);
AccessController.doPrivileged(new PrivilegedAction