Skip to content

Commit

Permalink
v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ideal committed Jul 14, 2018
1 parent 6e902a6 commit 919a1a6
Show file tree
Hide file tree
Showing 44 changed files with 2,017 additions and 290 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: java
jdk:
- oraclejdk10
- oraclejdk8
sudo: required
dist: trusty
services:
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ allprojects{
apply plugin: 'maven'
apply plugin: 'checkstyle'

sourceCompatibility = 1.10
targetCompatibility = 1.10
sourceCompatibility = 1.8
targetCompatibility = 1.8

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ public byte[] startAndGetByte()
}

try (Socket client = sock.accept()) {
try (InputStream is = client.getInputStream()) {
return is.readAllBytes();
try (InputStream input = client.getInputStream()) {
byte[] byt = new byte[input.available()];
input.read(byt);
return byt;
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion sylph-controller/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

dependencies {
compile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'

compile (project(':sylph-spi'))

compile group: 'org.eclipse.jetty', name: 'jetty-server', version:deps.jetty
compile group: 'org.eclipse.jetty', name: 'jetty-webapp', version:deps.jetty
compile group: 'org.eclipse.jetty', name: 'jetty-servlets', version:deps.jetty
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

import static java.util.Objects.requireNonNull;

/**
* 视图层目前 为实验功能
*/
public class ControllerApp
{
private ServerConfig config;
Expand All @@ -23,6 +26,6 @@ public ControllerApp(
public void start()
throws Exception
{
System.out.println("web.server.port: " + config.getServerPort());
new JettyServer(config, sylphContext).start();
}
}
100 changes: 100 additions & 0 deletions sylph-controller/src/main/java/ideal/sylph/controller/JettyServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package ideal.sylph.controller;

import ideal.sylph.controller.selvet.ETLJobServlet;
import ideal.sylph.controller.selvet.JobMangerSerlvet;
import ideal.sylph.controller.selvet.SylphServletHolder;
import ideal.sylph.spi.SylphContext;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.webapp.WebAppContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.Arrays;

import static java.util.Objects.requireNonNull;

/**
* Created by ideal on 17-3-15.
*/
@Deprecated
public final class JettyServer
{
private static final Logger logger = LoggerFactory.getLogger(JettyServer.class);
private Server server;
private final ServerConfig serverConfig;
private final SylphContext sylphContext;

JettyServer(
ServerConfig serverConfig,
SylphContext sylphContext
)
{
this.serverConfig = requireNonNull(serverConfig, "serverConfig is null");
this.sylphContext = requireNonNull(sylphContext, "sylphContext is null");
}

public void start()
throws Exception
{
//-------初始化------获取Context句柄------
int jettyPort = serverConfig.getServerPort();
int maxFormContentSize = serverConfig.getMaxFormContentSize();

// 创建Server
this.server = new Server(jettyPort);
server.setAttribute("org.eclipse.jetty.server.Request.maxFormContentSize",
maxFormContentSize);

HandlerList handlers = loadHandlers(); //加载路由
server.setHandler(handlers);

logger.info("web Server started... the port {}", jettyPort);
server.start();
}

private HandlerList loadHandlers()
{
HandlerList handlers = new HandlerList();
//--------------------全局的----------------------
//selvet
ServletContextHandler contextHandler = new ServletContextHandler(
ServletContextHandler.NO_SESSIONS);
contextHandler.setContextPath("/");

contextHandler.addServlet(new ServletHolder(new JobMangerSerlvet(sylphContext)), "/_sys/job_manger/*");
contextHandler.addServlet(new SylphServletHolder(new ETLJobServlet(sylphContext)), "/_sys/job_graph_edit/*");

final ServletHolder staticServlet = new ServletHolder(new DefaultServlet());
contextHandler.addServlet(staticServlet, "/css/*");
contextHandler.addServlet(staticServlet, "/js/*");
contextHandler.addServlet(staticServlet, "/images/*");
contextHandler.addServlet(staticServlet, "/fonts/*");
contextHandler.addServlet(staticServlet, "/favicon.ico");
contextHandler.addServlet(staticServlet, "/");
contextHandler.setResourceBase("webapps");

//-----------------加载所有app的-路由------------------
//runnerLoader.loadAppHandlers(handlers, contextHandler);

//----selvet--结束--
String mainHome = System.getProperty("user.dir");
File[] webs = new File(mainHome + "/webapps").listFiles();
if (webs != null) {
Arrays.stream(webs).forEach(file -> {
if (file.isDirectory()) {
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/_web/" + file.getName().toLowerCase()); //_web/postman
webapp.setResourceBase(file.getAbsolutePath());
handlers.addHandler(webapp);
}
});
}
handlers.addHandler(contextHandler);
return handlers;
}
}
Loading

0 comments on commit 919a1a6

Please sign in to comment.