11package org .magic .servers .impl ;
22
33import java .awt .Image ;
4- import java .io .File ;
5- import java .io .IOException ;
64import java .util .Map ;
75
86import javax .swing .Icon ;
97import javax .swing .ImageIcon ;
108
119import org .apache .activemq .artemis .core .config .impl .ConfigurationImpl ;
1210import org .apache .activemq .artemis .core .server .impl .ActiveMQServerImpl ;
13- import org .eclipse .jetty .ee10 .webapp .WebAppContext ;
14- import org .eclipse .jetty .server .Handler ;
15- import org .eclipse .jetty .server .Server ;
1611import org .magic .api .beans .technical .MTGProperty ;
1712import org .magic .api .interfaces .abstracts .AbstractMTGPlugin ;
18- import org .magic .api .interfaces .abstracts .AbstractMTGServer ;
13+ import org .magic .api .interfaces .abstracts .extra . AbstractWarServer ;
1914import org .magic .services .MTGConstants ;
20- import org .magic .services .network .URLTools ;
2115
22- public class ActiveMQConsoleServer extends AbstractMTGServer {
16+ public class ActiveMQConsoleServer extends AbstractWarServer {
2317
24- private Server server ;
25-
26- private File downloadVersion () throws IOException
27- {
28- var url = "https://repo1.maven.org/maven2/org/apache/activemq/artemis-console/" +getVersion ()+"/artemis-console-2.42.0.war" ;
29- var f = new File (MTGConstants .DATA_DIR ,"artemis-console-" +getVersion ()+".war" );
30-
31- if (!f .exists ())
32- URLTools .download (url , f );
33-
34- return f ;
18+
19+ @ Override
20+ protected String getWarFileName () {
21+ return "artemis-console-" +getVersion ()+".war" ;
3522 }
3623
37-
38- public void init ()
39- {
24+ @ Override
25+ protected String warUri () {
26+ return "https://repo1.maven.org/maven2/org/apache/activemq/artemis-console/" +getVersion ()+"/artemis-console-" +getVersion ()+".war" ;
27+ }
28+
29+ @ Override
30+ public void preinit () {
4031 System .setProperty ("hawtio.authenticationEnabled" , getString ("AUTHENTICATION" ));
4132
42-
43- server = new Server (getInt ("PORT" ));
44- var handlers = new Handler .Sequence ();
45- handlers .setServer (server );
46- server .setHandler (handlers );
47- try {
48- handlers .addHandler (createWebapp (server , "http" ,"/" ));
49- } catch (IOException e ) {
50- logger .error ("error on hawtio Init" , e );
51- }
5233 }
5334
5435
55- private WebAppContext createWebapp (Server server , String scheme ,String context ) throws IOException {
56- var webapp = new WebAppContext ();
57- webapp .setServer (server );
58- webapp .setContextPath (context );
59- webapp .setParentLoaderPriority (true );
60- webapp .setLogUrlOnStart (true );
61- webapp .setInitParameter ("scheme" , scheme );
62- webapp .setTempDirectory (new File (MTGConstants .DATA_DIR ,"artemis" ));
63-
64- webapp .setWar (downloadVersion ().toURI ().toString ());
65-
66-
67- logger .info ("Init ArtemisConsole on {}://localhost:{}{}. deploying war {}" , scheme ,getInt ("PORT" ),context ,webapp .getWar ());
68- return webapp ;
69- }
70-
71-
7236 @ Override
7337 public Map <String , MTGProperty > getDefaultAttributes () {
74- return Map .of ("AUTOSTART" , MTGProperty .newBooleanProperty (FALSE , "Run server at startup" ),
75- "PORT" , MTGProperty .newIntegerProperty ("8083" , "listening port for webserver" , 80 , -1 ),
76- "AUTHENTICATION" ,MTGProperty .newBooleanProperty ("false" ,"enable or not hawt authentication" ));
38+ var m = super .getDefaultAttributes ();
39+ m .put ("AUTHENTICATION" ,MTGProperty .newBooleanProperty ("false" ,"enable or not hawt authentication" ));
40+
41+ return m ;
7742 }
7843
44+
7945 @ Override
8046 public String getVersion () {
8147 return new ActiveMQServerImpl (new ConfigurationImpl ()).getVersion ().getFullVersion ();
8248 }
8349
84- @ Override
85- public void start () throws IOException {
86- try {
87- init ();
88- server .start ();
89- } catch (Exception e ) {
90- throw new IOException (e );
91- }
92-
93- }
94-
95- @ Override
96- public void stop () throws IOException {
97- try {
98- server .stop ();
99- } catch (Exception _) {
100- throw new IOException ();
101- }
102-
103- }
104-
105- @ Override
106- public boolean isAlive () {
107- if (server !=null )
108- return server .isRunning ();
109-
110- return false ;
111- }
112-
113- @ Override
114- public boolean isAutostart () {
115- return getBoolean ("AUTOSTART" );
116- }
117-
11850 @ Override
11951 public String description () {
12052 return "A modular web console for managing your Artemis Server" ;
@@ -135,6 +67,6 @@ public Icon getIcon() {
13567 return MTGConstants .ICON_DEFAULT_PLUGIN ;
13668 }
13769 }
138-
70+
13971
14072}
0 commit comments