diff options
Diffstat (limited to 'org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/java/org')
4 files changed, 135 insertions, 0 deletions
diff --git a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/java/org/eclipse/viatra/solver/language/web/ProblemServlet.java b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/java/org/eclipse/viatra/solver/language/web/ProblemServlet.java new file mode 100644 index 00000000..5de708f0 --- /dev/null +++ b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/java/org/eclipse/viatra/solver/language/web/ProblemServlet.java | |||
@@ -0,0 +1,36 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.25.0 | ||
3 | */ | ||
4 | package org.eclipse.viatra.solver.language.web; | ||
5 | |||
6 | import com.google.inject.Injector; | ||
7 | import javax.servlet.ServletException; | ||
8 | import javax.servlet.annotation.WebServlet; | ||
9 | import org.eclipse.xtext.util.DisposableRegistry; | ||
10 | import org.eclipse.xtext.web.servlet.XtextServlet; | ||
11 | |||
12 | /** | ||
13 | * Deploy this class into a servlet container to enable DSL-specific services. | ||
14 | */ | ||
15 | @WebServlet(name = "XtextServices", urlPatterns = "/xtext-service/*") | ||
16 | public class ProblemServlet extends XtextServlet { | ||
17 | |||
18 | private static final long serialVersionUID = 1L; | ||
19 | |||
20 | DisposableRegistry disposableRegistry; | ||
21 | |||
22 | public void init() throws ServletException { | ||
23 | super.init(); | ||
24 | Injector injector = new ProblemWebSetup().createInjectorAndDoEMFRegistration(); | ||
25 | this.disposableRegistry = injector.getInstance(DisposableRegistry.class); | ||
26 | } | ||
27 | |||
28 | public void destroy() { | ||
29 | if (disposableRegistry != null) { | ||
30 | disposableRegistry.dispose(); | ||
31 | disposableRegistry = null; | ||
32 | } | ||
33 | super.destroy(); | ||
34 | } | ||
35 | |||
36 | } | ||
diff --git a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/java/org/eclipse/viatra/solver/language/web/ProblemWebModule.java b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/java/org/eclipse/viatra/solver/language/web/ProblemWebModule.java new file mode 100644 index 00000000..0eea7f1e --- /dev/null +++ b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/java/org/eclipse/viatra/solver/language/web/ProblemWebModule.java | |||
@@ -0,0 +1,11 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.25.0 | ||
3 | */ | ||
4 | package org.eclipse.viatra.solver.language.web; | ||
5 | |||
6 | |||
7 | /** | ||
8 | * Use this class to register additional components to be used within the web application. | ||
9 | */ | ||
10 | public class ProblemWebModule extends AbstractProblemWebModule { | ||
11 | } | ||
diff --git a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/java/org/eclipse/viatra/solver/language/web/ProblemWebSetup.java b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/java/org/eclipse/viatra/solver/language/web/ProblemWebSetup.java new file mode 100644 index 00000000..8d5778af --- /dev/null +++ b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/java/org/eclipse/viatra/solver/language/web/ProblemWebSetup.java | |||
@@ -0,0 +1,23 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.25.0 | ||
3 | */ | ||
4 | package org.eclipse.viatra.solver.language.web; | ||
5 | |||
6 | import com.google.inject.Guice; | ||
7 | import com.google.inject.Injector; | ||
8 | import org.eclipse.viatra.solver.language.ProblemRuntimeModule; | ||
9 | import org.eclipse.viatra.solver.language.ProblemStandaloneSetup; | ||
10 | import org.eclipse.viatra.solver.language.ide.ProblemIdeModule; | ||
11 | import org.eclipse.xtext.util.Modules2; | ||
12 | |||
13 | /** | ||
14 | * Initialization support for running Xtext languages in web applications. | ||
15 | */ | ||
16 | public class ProblemWebSetup extends ProblemStandaloneSetup { | ||
17 | |||
18 | @Override | ||
19 | public Injector createInjector() { | ||
20 | return Guice.createInjector(Modules2.mixin(new ProblemRuntimeModule(), new ProblemIdeModule(), new ProblemWebModule())); | ||
21 | } | ||
22 | |||
23 | } | ||
diff --git a/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/java/org/eclipse/viatra/solver/language/web/ServerLauncher.java b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/java/org/eclipse/viatra/solver/language/web/ServerLauncher.java new file mode 100644 index 00000000..d25f4ae9 --- /dev/null +++ b/org.eclipse.viatra.solver.language.parent/org.eclipse.viatra.solver.language.web/src/main/java/org/eclipse/viatra/solver/language/web/ServerLauncher.java | |||
@@ -0,0 +1,65 @@ | |||
1 | /* | ||
2 | * generated by Xtext 2.25.0 | ||
3 | */ | ||
4 | package org.eclipse.viatra.solver.language.web; | ||
5 | |||
6 | import java.net.InetSocketAddress; | ||
7 | import org.eclipse.jetty.annotations.AnnotationConfiguration; | ||
8 | import org.eclipse.jetty.server.Server; | ||
9 | import org.eclipse.jetty.util.log.Slf4jLog; | ||
10 | import org.eclipse.jetty.webapp.Configuration; | ||
11 | import org.eclipse.jetty.webapp.MetaInfConfiguration; | ||
12 | import org.eclipse.jetty.webapp.WebAppContext; | ||
13 | import org.eclipse.jetty.webapp.WebInfConfiguration; | ||
14 | import org.eclipse.jetty.webapp.WebXmlConfiguration; | ||
15 | |||
16 | /** | ||
17 | * This program starts an HTTP server for testing the web integration of your DSL. | ||
18 | * Just execute it and point a web browser to http://localhost:8080/ | ||
19 | */ | ||
20 | public class ServerLauncher { | ||
21 | public static void main(String[] args) { | ||
22 | Server server = new Server(new InetSocketAddress("localhost", 1313)); | ||
23 | WebAppContext ctx = new WebAppContext(); | ||
24 | ctx.setResourceBase("src/main/webapp"); | ||
25 | ctx.setWelcomeFiles(new String[] {"index.html"}); | ||
26 | ctx.setContextPath("/"); | ||
27 | ctx.setConfigurations(new Configuration[] { | ||
28 | new AnnotationConfiguration(), | ||
29 | new WebXmlConfiguration(), | ||
30 | new WebInfConfiguration(), | ||
31 | new MetaInfConfiguration() | ||
32 | }); | ||
33 | ctx.setAttribute(WebInfConfiguration.CONTAINER_JAR_PATTERN, | ||
34 | ".*/org\\.eclipse\\.viatra\\.solver\\.language\\.web/.*,.*\\.jar"); | ||
35 | ctx.setInitParameter("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false"); | ||
36 | server.setHandler(ctx); | ||
37 | Slf4jLog log = new Slf4jLog(ServerLauncher.class.getName()); | ||
38 | try { | ||
39 | server.start(); | ||
40 | log.info("Server started " + server.getURI() + "..."); | ||
41 | new Thread() { | ||
42 | |||
43 | public void run() { | ||
44 | try { | ||
45 | log.info("Press enter to stop the server..."); | ||
46 | int key = System.in.read(); | ||
47 | if (key != -1) { | ||
48 | server.stop(); | ||
49 | } else { | ||
50 | log.warn( | ||
51 | "Console input is not available. In order to stop the server, you need to cancel process manually."); | ||
52 | } | ||
53 | } catch (Exception e) { | ||
54 | log.warn(e); | ||
55 | } | ||
56 | } | ||
57 | |||
58 | }.start(); | ||
59 | server.join(); | ||
60 | } catch (Exception exception) { | ||
61 | log.warn(exception.getMessage()); | ||
62 | System.exit(1); | ||
63 | } | ||
64 | } | ||
65 | } | ||