View | Details | Raw Unified | Return to bug 49426
Collapse All | Expand All

(-)java/org/apache/catalina/manager/ManagerServlet.java (-72 / +102 lines)
Lines 25-31 Link Here
25
import java.io.FileOutputStream;
25
import java.io.FileOutputStream;
26
import java.io.IOException;
26
import java.io.IOException;
27
import java.io.PrintWriter;
27
import java.io.PrintWriter;
28
import java.text.MessageFormat;
28
import java.util.Iterator;
29
import java.util.Iterator;
30
import java.util.ResourceBundle;
29
31
30
import javax.management.MBeanServer;
32
import javax.management.MBeanServer;
31
import javax.management.ObjectName;
33
import javax.management.ObjectName;
Lines 57-64 Link Here
57
import org.apache.catalina.util.RequestUtil;
59
import org.apache.catalina.util.RequestUtil;
58
import org.apache.catalina.util.ServerInfo;
60
import org.apache.catalina.util.ServerInfo;
59
import org.apache.tomcat.util.ExceptionUtils;
61
import org.apache.tomcat.util.ExceptionUtils;
60
import org.apache.tomcat.util.res.StringManager;
61
import org.apache.tomcat.util.modeler.Registry;
62
import org.apache.tomcat.util.modeler.Registry;
63
import org.apache.tomcat.util.res.StringManager;
62
64
63
65
64
/**
66
/**
Lines 237-242 Link Here
237
    protected static final StringManager sm =
239
    protected static final StringManager sm =
238
        StringManager.getManager(Constants.Package);
240
        StringManager.getManager(Constants.Package);
239
241
242
    private ResourceBundle bundle;
240
243
241
    /**
244
    /**
242
     * The Wrapper container associated with this servlet.
245
     * The Wrapper container associated with this servlet.
Lines 256-261 Link Here
256
259
257
    }
260
    }
258
261
262
    protected String getMessage(final String key, final Object... args) {
263
    	String value = bundle.getString(key);
264
    	if (value == null) {
265
    		value = key;
266
    	}
267
    	if (args.length == 0) {
268
        	return value;
269
    	}
270
271
    	final MessageFormat mf = new MessageFormat(value);
272
        mf.setLocale(bundle.getLocale());
273
        return mf.format(args, new StringBuffer(), null).toString();
274
    }
259
275
260
    /**
276
    /**
261
     * Set the Wrapper with which we are associated.
277
     * Set the Wrapper with which we are associated.
Lines 301-306 Link Here
301
    }
317
    }
302
318
303
319
320
    @Override
321
    protected final void service(HttpServletRequest req, HttpServletResponse resp)
322
    		throws ServletException, IOException {
323
324
    	bundle = ResourceBundle.getBundle(Constants.Package + ".LocalStrings", req.getLocale());
325
    	try {
326
    	    super.service(req, resp);
327
    	}
328
    	finally {
329
    		bundle = null;
330
    	}
331
    }
332
    
304
    /**
333
    /**
305
     * Process a GET request for the specified resource.
334
     * Process a GET request for the specified resource.
306
     *
335
     *
Lines 332-342 Link Here
332
361
333
        // Prepare our output writer to generate the response message
362
        // Prepare our output writer to generate the response message
334
        response.setContentType("text/plain; charset=" + Constants.CHARSET);
363
        response.setContentType("text/plain; charset=" + Constants.CHARSET);
364
        response.setCharacterEncoding(Constants.CHARSET);
335
        PrintWriter writer = response.getWriter();
365
        PrintWriter writer = response.getWriter();
336
366
337
        // Process the requested command (note - "/deploy" is not listed here)
367
        // Process the requested command (note - "/deploy" is not listed here)
338
        if (command == null) {
368
        if (command == null) {
339
            writer.println(sm.getString("managerServlet.noCommand"));
369
            writer.println(getMessage("managerServlet.noCommand"));
340
        } else if (command.equals("/deploy")) {
370
        } else if (command.equals("/deploy")) {
341
            if (war != null || config != null) {
371
            if (war != null || config != null) {
342
                deploy(writer, config, path, war, update);
372
                deploy(writer, config, path, war, update);
Lines 368-374 Link Here
368
        } else if (command.equals("/findleaks")) {
398
        } else if (command.equals("/findleaks")) {
369
            findleaks(writer);
399
            findleaks(writer);
370
        } else {
400
        } else {
371
            writer.println(sm.getString("managerServlet.unknownCommand",
401
            writer.println(getMessage("managerServlet.unknownCommand",
372
                                        command));
402
                                        command));
373
        }
403
        }
374
404
Lines 411-421 Link Here
411
441
412
        // Process the requested command
442
        // Process the requested command
413
        if (command == null) {
443
        if (command == null) {
414
            writer.println(sm.getString("managerServlet.noCommand"));
444
            writer.println(getMessage("managerServlet.noCommand"));
415
        } else if (command.equals("/deploy")) {
445
        } else if (command.equals("/deploy")) {
416
            deploy(writer, path, tag, update, request);
446
            deploy(writer, path, tag, update, request);
417
        } else {
447
        } else {
418
            writer.println(sm.getString("managerServlet.unknownCommand",
448
            writer.println(getMessage("managerServlet.unknownCommand",
419
                                        command));
449
                                        command));
420
        }
450
        }
421
451
Lines 505-511 Link Here
505
    protected void findleaks(PrintWriter writer) {
535
    protected void findleaks(PrintWriter writer) {
506
        
536
        
507
        if (!(host instanceof StandardHost)) {
537
        if (!(host instanceof StandardHost)) {
508
            writer.println(sm.getString("managerServlet.findleaksFail"));
538
            writer.println(getMessage("managerServlet.findleaksFail"));
509
            return;
539
            return;
510
        }
540
        }
511
        
541
        
Lines 531-547 Link Here
531
        Server server = ((Engine)host.getParent()).getService().getServer();
561
        Server server = ((Engine)host.getParent()).getService().getServer();
532
562
533
        if (!(server instanceof StandardServer)) {
563
        if (!(server instanceof StandardServer)) {
534
            writer.println(sm.getString("managerServlet.saveFail", server));
564
            writer.println(getMessage("managerServlet.saveFail", server));
535
            return;
565
            return;
536
        }
566
        }
537
567
538
        if ((path == null) || path.length() == 0 || !path.startsWith("/")) {
568
        if ((path == null) || path.length() == 0 || !path.startsWith("/")) {
539
            try {
569
            try {
540
                ((StandardServer) server).storeConfig();
570
                ((StandardServer) server).storeConfig();
541
                writer.println(sm.getString("managerServlet.saved"));
571
                writer.println(getMessage("managerServlet.saved"));
542
            } catch (Exception e) {
572
            } catch (Exception e) {
543
                log("managerServlet.storeConfig", e);
573
                log("managerServlet.storeConfig", e);
544
                writer.println(sm.getString("managerServlet.exception",
574
                writer.println(getMessage("managerServlet.exception",
545
                                            e.toString()));
575
                                            e.toString()));
546
                return;
576
                return;
547
            }
577
            }
Lines 552-567 Link Here
552
            }
582
            }
553
            Context context = (Context) host.findChild(contextPath);
583
            Context context = (Context) host.findChild(contextPath);
554
            if (context == null) {
584
            if (context == null) {
555
                writer.println(sm.getString("managerServlet.noContext", path));
585
                writer.println(getMessage("managerServlet.noContext", path));
556
                return;
586
                return;
557
            }
587
            }
558
            try {
588
            try {
559
                ((StandardServer) server).storeContext(context);
589
                ((StandardServer) server).storeContext(context);
560
                writer.println(sm.getString("managerServlet.savedContext", 
590
                writer.println(getMessage("managerServlet.savedContext", 
561
                               path));
591
                               path));
562
            } catch (Exception e) {
592
            } catch (Exception e) {
563
                log("managerServlet.save[" + path + "]", e);
593
                log("managerServlet.save[" + path + "]", e);
564
                writer.println(sm.getString("managerServlet.exception",
594
                writer.println(getMessage("managerServlet.exception",
565
                                            e.toString()));
595
                                            e.toString()));
566
                return;
596
                return;
567
            }
597
            }
Lines 589-595 Link Here
589
619
590
        // Validate the requested context path
620
        // Validate the requested context path
591
        if ((path == null) || path.length() == 0 || !path.startsWith("/")) {
621
        if ((path == null) || path.length() == 0 || !path.startsWith("/")) {
592
            writer.println(sm.getString("managerServlet.invalidPath", path));
622
            writer.println(getMessage("managerServlet.invalidPath", path));
593
            return;
623
            return;
594
        }
624
        }
595
        String displayPath = path;
625
        String displayPath = path;
Lines 607-613 Link Here
607
        }
637
        }
608
        if (context != null) {
638
        if (context != null) {
609
            writer.println
639
            writer.println
610
                (sm.getString("managerServlet.alreadyContext",
640
                (getMessage("managerServlet.alreadyContext",
611
                              displayPath));
641
                              displayPath));
612
            return;
642
            return;
613
        }
643
        }
Lines 648-664 Link Here
648
            }
678
            }
649
        } catch (Exception e) {
679
        } catch (Exception e) {
650
            log("managerServlet.check[" + displayPath + "]", e);
680
            log("managerServlet.check[" + displayPath + "]", e);
651
            writer.println(sm.getString("managerServlet.exception",
681
            writer.println(getMessage("managerServlet.exception",
652
                                        e.toString()));
682
                                        e.toString()));
653
            return;
683
            return;
654
        }
684
        }
655
        
685
        
656
        context = (Context) host.findChild(path);
686
        context = (Context) host.findChild(path);
657
        if (context != null && context.getConfigured()) {
687
        if (context != null && context.getConfigured()) {
658
            writer.println(sm.getString("managerServlet.deployed", displayPath));
688
            writer.println(getMessage("managerServlet.deployed", displayPath));
659
        } else {
689
        } else {
660
            // Something failed
690
            // Something failed
661
            writer.println(sm.getString("managerServlet.deployFailed", displayPath));
691
            writer.println(getMessage("managerServlet.deployFailed", displayPath));
662
        }
692
        }
663
        
693
        
664
    }
694
    }
Lines 676-682 Link Here
676
706
677
        // Validate the requested context path
707
        // Validate the requested context path
678
        if ((path == null) || path.length() == 0 || !path.startsWith("/")) {
708
        if ((path == null) || path.length() == 0 || !path.startsWith("/")) {
679
            writer.println(sm.getString("managerServlet.invalidPath", path));
709
            writer.println(getMessage("managerServlet.invalidPath", path));
680
            return;
710
            return;
681
        }
711
        }
682
        String displayPath = path;
712
        String displayPath = path;
Lines 712-728 Link Here
712
            }
742
            }
713
        } catch (Exception e) {
743
        } catch (Exception e) {
714
            log("managerServlet.check[" + displayPath + "]", e);
744
            log("managerServlet.check[" + displayPath + "]", e);
715
            writer.println(sm.getString("managerServlet.exception",
745
            writer.println(getMessage("managerServlet.exception",
716
                                        e.toString()));
746
                                        e.toString()));
717
            return;
747
            return;
718
        }
748
        }
719
        
749
        
720
        context = (Context) host.findChild(path);
750
        context = (Context) host.findChild(path);
721
        if (context != null && context.getConfigured()) {
751
        if (context != null && context.getConfigured()) {
722
            writer.println(sm.getString("managerServlet.deployed", displayPath));
752
            writer.println(getMessage("managerServlet.deployed", displayPath));
723
        } else {
753
        } else {
724
            // Something failed
754
            // Something failed
725
            writer.println(sm.getString("managerServlet.deployFailed", displayPath));
755
            writer.println(getMessage("managerServlet.deployFailed", displayPath));
726
        }
756
        }
727
        
757
        
728
    }
758
    }
Lines 768-774 Link Here
768
        }
798
        }
769
        
799
        
770
        if (path == null || path.length() == 0 || !path.startsWith("/")) {
800
        if (path == null || path.length() == 0 || !path.startsWith("/")) {
771
            writer.println(sm.getString("managerServlet.invalidPath",
801
            writer.println(getMessage("managerServlet.invalidPath",
772
                                        RequestUtil.filter(path)));
802
                                        RequestUtil.filter(path)));
773
            return;
803
            return;
774
        }
804
        }
Lines 787-793 Link Here
787
        }
817
        }
788
        if (context != null) {
818
        if (context != null) {
789
            writer.println
819
            writer.println
790
            (sm.getString("managerServlet.alreadyContext",
820
            (getMessage("managerServlet.alreadyContext",
791
                    displayPath));
821
                    displayPath));
792
            return;
822
            return;
793
        }
823
        }
Lines 825-840 Link Here
825
            }
855
            }
826
            context = (Context) host.findChild(path);
856
            context = (Context) host.findChild(path);
827
            if (context != null && context.getConfigured() && context.getAvailable()) {
857
            if (context != null && context.getConfigured() && context.getAvailable()) {
828
                writer.println(sm.getString("managerServlet.deployed", displayPath));
858
                writer.println(getMessage("managerServlet.deployed", displayPath));
829
            } else if (context!=null && !context.getAvailable()) {
859
            } else if (context!=null && !context.getAvailable()) {
830
                writer.println(sm.getString("managerServlet.deployedButNotStarted", displayPath));
860
                writer.println(getMessage("managerServlet.deployedButNotStarted", displayPath));
831
            } else {
861
            } else {
832
                // Something failed
862
                // Something failed
833
                writer.println(sm.getString("managerServlet.deployFailed", displayPath));
863
                writer.println(getMessage("managerServlet.deployFailed", displayPath));
834
            }
864
            }
835
        } catch (Throwable t) {
865
        } catch (Throwable t) {
836
            log("ManagerServlet.install[" + displayPath + "]", t);
866
            log("ManagerServlet.install[" + displayPath + "]", t);
837
            writer.println(sm.getString("managerServlet.exception",
867
            writer.println(getMessage("managerServlet.exception",
838
                    t.toString()));
868
                    t.toString()));
839
        }
869
        }
840
        
870
        
Lines 852-858 Link Here
852
            log("list: Listing contexts for virtual host '" +
882
            log("list: Listing contexts for virtual host '" +
853
                host.getName() + "'");
883
                host.getName() + "'");
854
884
855
        writer.println(sm.getString("managerServlet.listed",
885
        writer.println(getMessage("managerServlet.listed",
856
                                    host.getName()));
886
                                    host.getName()));
857
        Container[] contexts = host.findChildren();
887
        Container[] contexts = host.findChildren();
858
        for (int i = 0; i < contexts.length; i++) {
888
        for (int i = 0; i < contexts.length; i++) {
Lines 862-874 Link Here
862
                if( displayPath.equals("") )
892
                if( displayPath.equals("") )
863
                    displayPath = "/";
893
                    displayPath = "/";
864
                if (context.getAvailable()) {
894
                if (context.getAvailable()) {
865
                    writer.println(sm.getString("managerServlet.listitem",
895
                    writer.println(getMessage("managerServlet.listitem",
866
                                                displayPath,
896
                                                displayPath,
867
                                                "running",
897
                                                "running",
868
                                      "" + context.getManager().findSessions().length,
898
                                      "" + context.getManager().findSessions().length,
869
                                                context.getDocBase()));
899
                                                context.getDocBase()));
870
                } else {
900
                } else {
871
                    writer.println(sm.getString("managerServlet.listitem",
901
                    writer.println(getMessage("managerServlet.listitem",
872
                                                displayPath,
902
                                                displayPath,
873
                                                "stopped",
903
                                                "stopped",
874
                                                "0",
904
                                                "0",
Lines 891-897 Link Here
891
            log("restart: Reloading web application at '" + path + "'");
921
            log("restart: Reloading web application at '" + path + "'");
892
922
893
        if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
923
        if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
894
            writer.println(sm.getString("managerServlet.invalidPath",
924
            writer.println(getMessage("managerServlet.invalidPath",
895
                                        RequestUtil.filter(path)));
925
                                        RequestUtil.filter(path)));
896
            return;
926
            return;
897
        }
927
        }
Lines 902-923 Link Here
902
        try {
932
        try {
903
            Context context = (Context) host.findChild(path);
933
            Context context = (Context) host.findChild(path);
904
            if (context == null) {
934
            if (context == null) {
905
                writer.println(sm.getString
935
                writer.println(getMessage
906
                               ("managerServlet.noContext",
936
                               ("managerServlet.noContext",
907
                                   RequestUtil.filter(displayPath)));
937
                                   RequestUtil.filter(displayPath)));
908
                return;
938
                return;
909
            }
939
            }
910
            // It isn't possible for the manager to reload itself
940
            // It isn't possible for the manager to reload itself
911
            if (context.getPath().equals(this.context.getPath())) {
941
            if (context.getPath().equals(this.context.getPath())) {
912
                writer.println(sm.getString("managerServlet.noSelf"));
942
                writer.println(getMessage("managerServlet.noSelf"));
913
                return;
943
                return;
914
            }
944
            }
915
            context.reload();
945
            context.reload();
916
            writer.println
946
            writer.println
917
                (sm.getString("managerServlet.reloaded", displayPath));
947
                (getMessage("managerServlet.reloaded", displayPath));
918
        } catch (Throwable t) {
948
        } catch (Throwable t) {
919
            log("ManagerServlet.reload[" + displayPath + "]", t);
949
            log("ManagerServlet.reload[" + displayPath + "]", t);
920
            writer.println(sm.getString("managerServlet.exception",
950
            writer.println(getMessage("managerServlet.exception",
921
                                        t.toString()));
951
                                        t.toString()));
922
        }
952
        }
923
953
Lines 942-957 Link Here
942
972
943
        // Is the global JNDI resources context available?
973
        // Is the global JNDI resources context available?
944
        if (global == null) {
974
        if (global == null) {
945
            writer.println(sm.getString("managerServlet.noGlobal"));
975
            writer.println(getMessage("managerServlet.noGlobal"));
946
            return;
976
            return;
947
        }
977
        }
948
978
949
        // Enumerate the global JNDI resources of the requested type
979
        // Enumerate the global JNDI resources of the requested type
950
        if (type != null) {
980
        if (type != null) {
951
            writer.println(sm.getString("managerServlet.resourcesType",
981
            writer.println(getMessage("managerServlet.resourcesType",
952
                                        type));
982
                                        type));
953
        } else {
983
        } else {
954
            writer.println(sm.getString("managerServlet.resourcesAll"));
984
            writer.println(getMessage("managerServlet.resourcesAll"));
955
        }
985
        }
956
986
957
        Class<?> clazz = null;
987
        Class<?> clazz = null;
Lines 961-967 Link Here
961
            }
991
            }
962
        } catch (Throwable t) {
992
        } catch (Throwable t) {
963
            log("ManagerServlet.resources[" + type + "]", t);
993
            log("ManagerServlet.resources[" + type + "]", t);
964
            writer.println(sm.getString("managerServlet.exception",
994
            writer.println(getMessage("managerServlet.exception",
965
                                        t.toString()));
995
                                        t.toString()));
966
            return;
996
            return;
967
        }
997
        }
Lines 1000-1006 Link Here
1000
            }
1030
            }
1001
        } catch (Throwable t) {
1031
        } catch (Throwable t) {
1002
            log("ManagerServlet.resources[" + type + "]", t);
1032
            log("ManagerServlet.resources[" + type + "]", t);
1003
            writer.println(sm.getString("managerServlet.exception",
1033
            writer.println(getMessage("managerServlet.exception",
1004
                                        t.toString()));
1034
                                        t.toString()));
1005
        }
1035
        }
1006
1036
Lines 1028-1044 Link Here
1028
            InitialContext ic = new InitialContext();
1058
            InitialContext ic = new InitialContext();
1029
            database = (UserDatabase) ic.lookup("java:comp/env/users");
1059
            database = (UserDatabase) ic.lookup("java:comp/env/users");
1030
        } catch (NamingException e) {
1060
        } catch (NamingException e) {
1031
            writer.println(sm.getString("managerServlet.userDatabaseError"));
1061
            writer.println(getMessage("managerServlet.userDatabaseError"));
1032
            log("java:comp/env/users", e);
1062
            log("java:comp/env/users", e);
1033
            return;
1063
            return;
1034
        }
1064
        }
1035
        if (database == null) {
1065
        if (database == null) {
1036
            writer.println(sm.getString("managerServlet.userDatabaseMissing"));
1066
            writer.println(getMessage("managerServlet.userDatabaseMissing"));
1037
            return;
1067
            return;
1038
        }
1068
        }
1039
1069
1040
        // Enumerate the available roles
1070
        // Enumerate the available roles
1041
        writer.println(sm.getString("managerServlet.rolesList"));
1071
        writer.println(getMessage("managerServlet.rolesList"));
1042
        Iterator<Role> roles = database.getRoles();
1072
        Iterator<Role> roles = database.getRoles();
1043
        if (roles != null) {
1073
        if (roles != null) {
1044
            while (roles.hasNext()) {
1074
            while (roles.hasNext()) {
Lines 1081-1087 Link Here
1081
            writer.println(props.toString());
1111
            writer.println(props.toString());
1082
        } catch (Throwable t) {
1112
        } catch (Throwable t) {
1083
            getServletContext().log("ManagerServlet.serverinfo",t);
1113
            getServletContext().log("ManagerServlet.serverinfo",t);
1084
            writer.println(sm.getString("managerServlet.exception",
1114
            writer.println(getMessage("managerServlet.exception",
1085
                                        t.toString()));
1115
                                        t.toString()));
1086
        }
1116
        }
1087
    }
1117
    }
Lines 1104-1110 Link Here
1104
        }
1134
        }
1105
1135
1106
        if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
1136
        if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
1107
            writer.println(sm.getString("managerServlet.invalidPath",
1137
            writer.println(getMessage("managerServlet.invalidPath",
1108
                                        RequestUtil.filter(path)));
1138
                                        RequestUtil.filter(path)));
1109
            return;
1139
            return;
1110
        }
1140
        }
Lines 1114-1126 Link Here
1114
        try {
1144
        try {
1115
            Context context = (Context) host.findChild(path);
1145
            Context context = (Context) host.findChild(path);
1116
            if (context == null) {
1146
            if (context == null) {
1117
                writer.println(sm.getString("managerServlet.noContext",
1147
                writer.println(getMessage("managerServlet.noContext",
1118
                                            RequestUtil.filter(displayPath)));
1148
                                            RequestUtil.filter(displayPath)));
1119
                return;
1149
                return;
1120
            }
1150
            }
1121
            Manager manager = context.getManager() ;
1151
            Manager manager = context.getManager() ;
1122
            if(manager == null) {
1152
            if(manager == null) {
1123
                writer.println(sm.getString("managerServlet.noManager",
1153
                writer.println(getMessage("managerServlet.noManager",
1124
                        RequestUtil.filter(displayPath)));
1154
                        RequestUtil.filter(displayPath)));
1125
                return;               
1155
                return;               
1126
            }
1156
            }
Lines 1135-1142 Link Here
1135
            if ( histoInterval * maxCount < maxInactiveInterval ) 
1165
            if ( histoInterval * maxCount < maxInactiveInterval ) 
1136
                maxCount++;
1166
                maxCount++;
1137
1167
1138
            writer.println(sm.getString("managerServlet.sessions", displayPath));
1168
            writer.println(getMessage("managerServlet.sessions", displayPath));
1139
            writer.println(sm.getString("managerServlet.sessiondefaultmax",
1169
            writer.println(getMessage("managerServlet.sessiondefaultmax",
1140
                                "" + maxInactiveInterval));
1170
                                "" + maxInactiveInterval));
1141
            Session [] sessions = manager.findSessions();
1171
            Session [] sessions = manager.findSessions();
1142
            int [] timeout = new int[maxCount];
1172
            int [] timeout = new int[maxCount];
Lines 1158-1184 Link Here
1158
                    timeout[time]++;
1188
                    timeout[time]++;
1159
            }
1189
            }
1160
            if (timeout[0] > 0)
1190
            if (timeout[0] > 0)
1161
                writer.println(sm.getString("managerServlet.sessiontimeout",
1191
                writer.println(getMessage("managerServlet.sessiontimeout",
1162
                                            "<" + histoInterval, "" + timeout[0]));
1192
                                            "<" + histoInterval, "" + timeout[0]));
1163
            for (int i = 1; i < maxCount-1; i++) {
1193
            for (int i = 1; i < maxCount-1; i++) {
1164
                if (timeout[i] > 0)
1194
                if (timeout[i] > 0)
1165
                    writer.println(sm.getString("managerServlet.sessiontimeout",
1195
                    writer.println(getMessage("managerServlet.sessiontimeout",
1166
                                     "" + (i)*histoInterval + " - <" + (i+1)*histoInterval,
1196
                                     "" + (i)*histoInterval + " - <" + (i+1)*histoInterval,
1167
                                                "" + timeout[i]));
1197
                                                "" + timeout[i]));
1168
            }
1198
            }
1169
            if (timeout[maxCount-1] > 0)
1199
            if (timeout[maxCount-1] > 0)
1170
                writer.println(sm.getString("managerServlet.sessiontimeout",
1200
                writer.println(getMessage("managerServlet.sessiontimeout",
1171
                                            ">=" + maxCount*histoInterval,
1201
                                            ">=" + maxCount*histoInterval,
1172
                                            "" + timeout[maxCount-1]));
1202
                                            "" + timeout[maxCount-1]));
1173
            if (notimeout > 0)
1203
            if (notimeout > 0)
1174
                writer.println(sm.getString("managerServlet.sessiontimeout.unlimited",
1204
                writer.println(getMessage("managerServlet.sessiontimeout.unlimited",
1175
                                            "" + notimeout));
1205
                                            "" + notimeout));
1176
            if (idle >= 0)
1206
            if (idle >= 0)
1177
                writer.println(sm.getString("managerServlet.sessiontimeout.expired",
1207
                writer.println(getMessage("managerServlet.sessiontimeout.expired",
1178
                                            "" + idle,"" + expired));
1208
                                            "" + idle,"" + expired));
1179
        } catch (Throwable t) {
1209
        } catch (Throwable t) {
1180
            log("ManagerServlet.sessions[" + displayPath + "]", t);
1210
            log("ManagerServlet.sessions[" + displayPath + "]", t);
1181
            writer.println(sm.getString("managerServlet.exception",
1211
            writer.println(getMessage("managerServlet.exception",
1182
                                        t.toString()));
1212
                                        t.toString()));
1183
        }
1213
        }
1184
1214
Lines 1230-1236 Link Here
1230
            log("start: Starting web application at '" + path + "'");
1260
            log("start: Starting web application at '" + path + "'");
1231
1261
1232
        if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
1262
        if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
1233
            writer.println(sm.getString("managerServlet.invalidPath",
1263
            writer.println(getMessage("managerServlet.invalidPath",
1234
                                        RequestUtil.filter(path)));
1264
                                        RequestUtil.filter(path)));
1235
            return;
1265
            return;
1236
        }
1266
        }
Lines 1241-1263 Link Here
1241
        try {
1271
        try {
1242
            Context context = (Context) host.findChild(path);
1272
            Context context = (Context) host.findChild(path);
1243
            if (context == null) {
1273
            if (context == null) {
1244
                writer.println(sm.getString("managerServlet.noContext", 
1274
                writer.println(getMessage("managerServlet.noContext", 
1245
                                            RequestUtil.filter(displayPath)));
1275
                                            RequestUtil.filter(displayPath)));
1246
                return;
1276
                return;
1247
            }
1277
            }
1248
            context.start();
1278
            context.start();
1249
            if (context.getAvailable())
1279
            if (context.getAvailable())
1250
                writer.println
1280
                writer.println
1251
                    (sm.getString("managerServlet.started", displayPath));
1281
                    (getMessage("managerServlet.started", displayPath));
1252
            else
1282
            else
1253
                writer.println
1283
                writer.println
1254
                    (sm.getString("managerServlet.startFailed", displayPath));
1284
                    (getMessage("managerServlet.startFailed", displayPath));
1255
        } catch (Throwable t) {
1285
        } catch (Throwable t) {
1256
            getServletContext().log
1286
            getServletContext().log
1257
                (sm.getString("managerServlet.startFailed", displayPath), t);
1287
                (getMessage("managerServlet.startFailed", displayPath), t);
1258
            writer.println
1288
            writer.println
1259
                (sm.getString("managerServlet.startFailed", displayPath));
1289
                (getMessage("managerServlet.startFailed", displayPath));
1260
            writer.println(sm.getString("managerServlet.exception",
1290
            writer.println(getMessage("managerServlet.exception",
1261
                                        t.toString()));
1291
                                        t.toString()));
1262
        }
1292
        }
1263
1293
Lines 1276-1282 Link Here
1276
            log("stop: Stopping web application at '" + path + "'");
1306
            log("stop: Stopping web application at '" + path + "'");
1277
1307
1278
        if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
1308
        if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
1279
            writer.println(sm.getString("managerServlet.invalidPath",
1309
            writer.println(getMessage("managerServlet.invalidPath",
1280
                                        RequestUtil.filter(path)));
1310
                                        RequestUtil.filter(path)));
1281
            return;
1311
            return;
1282
        }
1312
        }
Lines 1287-1306 Link Here
1287
        try {
1317
        try {
1288
            Context context = (Context) host.findChild(path);
1318
            Context context = (Context) host.findChild(path);
1289
            if (context == null) {
1319
            if (context == null) {
1290
                writer.println(sm.getString("managerServlet.noContext", 
1320
                writer.println(getMessage("managerServlet.noContext", 
1291
                                            RequestUtil.filter(displayPath)));
1321
                                            RequestUtil.filter(displayPath)));
1292
                return;
1322
                return;
1293
            }
1323
            }
1294
            // It isn't possible for the manager to stop itself
1324
            // It isn't possible for the manager to stop itself
1295
            if (context.getPath().equals(this.context.getPath())) {
1325
            if (context.getPath().equals(this.context.getPath())) {
1296
                writer.println(sm.getString("managerServlet.noSelf"));
1326
                writer.println(getMessage("managerServlet.noSelf"));
1297
                return;
1327
                return;
1298
            }
1328
            }
1299
            context.stop();
1329
            context.stop();
1300
            writer.println(sm.getString("managerServlet.stopped", displayPath));
1330
            writer.println(getMessage("managerServlet.stopped", displayPath));
1301
        } catch (Throwable t) {
1331
        } catch (Throwable t) {
1302
            log("ManagerServlet.stop[" + displayPath + "]", t);
1332
            log("ManagerServlet.stop[" + displayPath + "]", t);
1303
            writer.println(sm.getString("managerServlet.exception",
1333
            writer.println(getMessage("managerServlet.exception",
1304
                                        t.toString()));
1334
                                        t.toString()));
1305
        }
1335
        }
1306
1336
Lines 1319-1325 Link Here
1319
            log("undeploy: Undeploying web application at '" + path + "'");
1349
            log("undeploy: Undeploying web application at '" + path + "'");
1320
1350
1321
        if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
1351
        if ((path == null) || (!path.startsWith("/") && path.equals(""))) {
1322
            writer.println(sm.getString("managerServlet.invalidPath",
1352
            writer.println(getMessage("managerServlet.invalidPath",
1323
                                        RequestUtil.filter(path)));
1353
                                        RequestUtil.filter(path)));
1324
            return;
1354
            return;
1325
        }
1355
        }
Lines 1332-1344 Link Here
1332
            // Validate the Context of the specified application
1362
            // Validate the Context of the specified application
1333
            Context context = (Context) host.findChild(path);
1363
            Context context = (Context) host.findChild(path);
1334
            if (context == null) {
1364
            if (context == null) {
1335
                writer.println(sm.getString("managerServlet.noContext",
1365
                writer.println(getMessage("managerServlet.noContext",
1336
                                            RequestUtil.filter(displayPath)));
1366
                                            RequestUtil.filter(displayPath)));
1337
                return;
1367
                return;
1338
            }
1368
            }
1339
1369
1340
            if (!isDeployed(path)) {
1370
            if (!isDeployed(path)) {
1341
                writer.println(sm.getString("managerServlet.notDeployed",
1371
                writer.println(getMessage("managerServlet.notDeployed",
1342
                        RequestUtil.filter(displayPath)));
1372
                        RequestUtil.filter(displayPath)));
1343
                return;
1373
                return;
1344
            }
1374
            }
Lines 1371-1381 Link Here
1371
                    removeServiced(path.replace('#','/'));
1401
                    removeServiced(path.replace('#','/'));
1372
                }
1402
                }
1373
            }
1403
            }
1374
            writer.println(sm.getString("managerServlet.undeployed",
1404
            writer.println(getMessage("managerServlet.undeployed",
1375
                                        displayPath));
1405
                                        displayPath));
1376
        } catch (Throwable t) {
1406
        } catch (Throwable t) {
1377
            log("ManagerServlet.undeploy[" + displayPath + "]", t);
1407
            log("ManagerServlet.undeploy[" + displayPath + "]", t);
1378
            writer.println(sm.getString("managerServlet.exception",
1408
            writer.println(getMessage("managerServlet.exception",
1379
                                        t.toString()));
1409
                                        t.toString()));
1380
        }
1410
        }
1381
1411
(-)test/org/apache/catalina/manager/TestManagerServlet.java (+81 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 * 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 * 
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
package org.apache.catalina.manager;
18
19
import java.io.IOException;
20
import java.util.HashMap;
21
import java.util.List;
22
import java.util.Locale;
23
import java.util.Map;
24
25
import org.apache.catalina.Context;
26
import org.apache.catalina.startup.Tomcat;
27
import org.apache.catalina.startup.TomcatBaseTest;
28
import org.apache.tomcat.util.buf.ByteChunk;
29
30
/**
31
 * Unit test for the {@link ManagerServlet}.
32
 * @author Marc Guillemot
33
 * @version $Revision$
34
 */
35
public class TestManagerServlet extends TomcatBaseTest {
36
37
    /**
38
     * Tests that the language used for the response depends from the request
39
     * and not from the server's default Locale.
40
     */
41
    public void testResponseLocalization() throws Exception {
42
        Tomcat tomcat = getTomcatInstance();
43
        
44
        // Must have a real docBase - just use temp
45
        Context ctx = tomcat.addContext("/", System.getProperty("java.io.tmpdir"));
46
        ctx.setPrivileged(true);
47
        
48
        Tomcat.addServlet(ctx, "manager", ManagerServlet.class.getName());
49
        ctx.addServletMapping("/text/*", "manager");
50
        
51
        tomcat.start();
52
53
        assertEquals("en", "OK - Listed applications for virtual host localhost", 
54
                getFirstResponseLine_queryList("en"));
55
        assertEquals("OK - Applications list\u00e9es pour l'h\u00f4te virtuel (virtual host) localhost", 
56
                getFirstResponseLine_queryList("fr"));
57
58
        // a language for which no special support exist (here Basque) should fall back to default (English)
59
        assertEquals("OK - Listed applications for virtual host localhost", getFirstResponseLine_queryList("eu"));
60
        
61
        // without acceptLanguage header, fallback should be the same respose as for default Locale of the server
62
        assertEquals(getFirstResponseLine_queryList(Locale.getDefault().getLanguage()),
63
                getFirstResponseLine_queryList(null));
64
        
65
    }
66
67
    private String getFirstResponseLine_queryList(final String acceptLanguage) throws IOException {
68
        final Map<String, String> headers = new HashMap<String, String>();
69
        if (acceptLanguage != null) {
70
            headers.put("Accept-Language", acceptLanguage);
71
        }
72
        final ByteChunk chunk = new ByteChunk();
73
        chunk.setEncoding(Constants.CHARSET);
74
75
        final Map<String, List<String>> responseHeaders = new HashMap<String, List<String>>();
76
        getUrl("http://localhost:" + getPort() + "/text/list", headers, chunk, responseHeaders);
77
        
78
        final String[] lines = chunk.toString().split("\n");
79
        return lines[0];
80
    }
81
}
0
  + native
82
  + native
1
  + Author Date Id Revision
83
  + Author Date Id Revision
(-)test/org/apache/catalina/startup/TomcatBaseTest.java (-2 / +11 lines)
Lines 23-28 Link Here
23
import java.io.PrintWriter;
23
import java.io.PrintWriter;
24
import java.net.HttpURLConnection;
24
import java.net.HttpURLConnection;
25
import java.net.URL;
25
import java.net.URL;
26
import java.util.Collections;
26
import java.util.List;
27
import java.util.List;
27
import java.util.Map;
28
import java.util.Map;
28
29
Lines 164-174 Link Here
164
165
165
    public static int getUrl(String path, ByteChunk out,
166
    public static int getUrl(String path, ByteChunk out,
166
            Map<String, List<String>> resHead) throws IOException {
167
            Map<String, List<String>> resHead) throws IOException {
168
    	return getUrl(path, Collections.<String, String>emptyMap(), out, resHead);
169
    }
170
    
171
    public static int getUrl(final String path, final Map<String, String> reqHeaders,
172
    		final ByteChunk out, final Map<String, List<String>> resHead) throws IOException {
167
173
168
        URL url = new URL(path);
174
        final URL url = new URL(path);
169
        HttpURLConnection connection = 
175
        final HttpURLConnection connection = 
170
            (HttpURLConnection) url.openConnection();
176
            (HttpURLConnection) url.openConnection();
171
        connection.setReadTimeout(1000000);
177
        connection.setReadTimeout(1000000);
178
        for (final Map.Entry<String, String> header : reqHeaders.entrySet()) {
179
        	connection.addRequestProperty(header.getKey(), header.getValue());
180
        }
172
        connection.connect();
181
        connection.connect();
173
        int rc = connection.getResponseCode();
182
        int rc = connection.getResponseCode();
174
        if (resHead != null) {
183
        if (resHead != null) {

Return to bug 49426