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.
/*
Copyright 2012 Adaptrex, LLC
Licensed 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 com.adaptrex.server;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.*;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.naming.NamingException;
import javax.servlet.DispatcherType;
import org.apache.commons.dbcp.BasicDataSource;
import org.apache.log4j.Logger;
import org.eclipse.jetty.plus.jndi.Resource;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.servlets.GzipFilter;
import org.eclipse.jetty.webapp.WebAppContext;
import org.slf4j.bridge.SLF4JBridgeHandler;
public class AdaptrexServer {
private static Server jetty;
private static Map config;
private static Logger log = Logger.getLogger(AdaptrexServer.class);
/*
* Bootstrap
*/
@SuppressWarnings("unchecked")
public static void main(String... args) throws Exception {
log.info("Starting Adaptrex Server...");
/*
* Get configuration
*/
InputStream in = AdaptrexServer.class.getClassLoader().getResourceAsStream("adaptrex.config");
try {
config = new ObjectMapper().readValue(in, Map.class);
} catch (Exception e) {
log.warn("Adaptrex Config Error: Could not find load adaptrex.config.");
log.warn("Error", e);
}
if (config == null) {
return;
}
for (String arg : args) {
if (arg.equals("-stop") || arg.equals("-restart")) {
stopServer();
if (arg.equals("-stop")) {
log.info("The Adaptrex Server has been stopped.");
return;
}
}
}
/*
* Inevitably some dependency is going to use java.util.Logging
* Use jul-to-slf4j and the SLF4JBridgeHandler to send it over SLF4J
*/
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
/*
* Get a Jetty server
*/
Integer port = (Integer) config.get("port");
if (port != null) {
port = 8080;
}
jetty = new Server(port);
/*
* Create global data sources
*/
if (config.get("dataSource") != null) {
createDataSource(jetty, (Map) config.get("dataSource"));
}
if (config.get("dataSources") != null) {
for (Map dataSourceConfig : (List