1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.webapp;
20
21 import java.io.File;
22 import java.io.IOException;
23 import java.net.MalformedURLException;
24 import java.net.URL;
25 import java.security.PermissionCollection;
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.Collections;
29 import java.util.EventListener;
30 import java.util.HashMap;
31 import java.util.List;
32 import java.util.Map;
33
34 import javax.servlet.ServletContext;
35 import javax.servlet.http.HttpSessionActivationListener;
36 import javax.servlet.http.HttpSessionAttributeListener;
37 import javax.servlet.http.HttpSessionBindingListener;
38 import javax.servlet.http.HttpSessionListener;
39
40 import org.eclipse.jetty.security.SecurityHandler;
41 import org.eclipse.jetty.server.Connector;
42 import org.eclipse.jetty.server.HandlerContainer;
43 import org.eclipse.jetty.server.Server;
44 import org.eclipse.jetty.server.handler.ContextHandler;
45 import org.eclipse.jetty.server.handler.ErrorHandler;
46 import org.eclipse.jetty.server.session.SessionHandler;
47 import org.eclipse.jetty.servlet.ErrorPageErrorHandler;
48 import org.eclipse.jetty.servlet.ServletContextHandler;
49 import org.eclipse.jetty.servlet.ServletHandler;
50 import org.eclipse.jetty.util.LazyList;
51 import org.eclipse.jetty.util.Loader;
52 import org.eclipse.jetty.util.MultiException;
53 import org.eclipse.jetty.util.StringUtil;
54 import org.eclipse.jetty.util.URIUtil;
55 import org.eclipse.jetty.util.log.Log;
56 import org.eclipse.jetty.util.log.Logger;
57 import org.eclipse.jetty.util.resource.Resource;
58 import org.eclipse.jetty.util.resource.ResourceCollection;
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73 public class WebAppContext extends ServletContextHandler implements WebAppClassLoader.Context
74 {
75 private static final Logger LOG = Log.getLogger(WebAppContext.class);
76
77 public static final String TEMPDIR = "javax.servlet.context.tempdir";
78 public static final String BASETEMPDIR = "org.eclipse.jetty.webapp.basetempdir";
79 public final static String WEB_DEFAULTS_XML="org/eclipse/jetty/webapp/webdefault.xml";
80 public final static String ERROR_PAGE="org.eclipse.jetty.server.error_page";
81 public final static String SERVER_CONFIG = "org.eclipse.jetty.webapp.configuration";
82 public final static String SERVER_SYS_CLASSES = "org.eclipse.jetty.webapp.systemClasses";
83 public final static String SERVER_SRV_CLASSES = "org.eclipse.jetty.webapp.serverClasses";
84
85 private String[] __dftProtectedTargets = {"/web-inf", "/meta-inf"};
86
87 private static String[] __dftConfigurationClasses =
88 {
89 "org.eclipse.jetty.webapp.WebInfConfiguration",
90 "org.eclipse.jetty.webapp.WebXmlConfiguration",
91 "org.eclipse.jetty.webapp.MetaInfConfiguration",
92 "org.eclipse.jetty.webapp.FragmentConfiguration",
93 "org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
94 "org.eclipse.jetty.webapp.TagLibConfiguration"
95 } ;
96
97
98
99
100 public final static String[] __dftSystemClasses =
101 {
102 "java.",
103 "javax.",
104 "org.xml.",
105 "org.w3c.",
106 "org.apache.commons.logging.",
107 "org.eclipse.jetty.continuation.",
108 "org.eclipse.jetty.jndi.",
109 "org.eclipse.jetty.plus.jaas.",
110 "org.eclipse.jetty.websocket.WebSocket",
111 "org.eclipse.jetty.websocket.WebSocketFactory",
112 "org.eclipse.jetty.websocket.WebSocketServlet",
113 "org.eclipse.jetty.servlet.DefaultServlet"
114 } ;
115
116
117
118
119
120 public final static String[] __dftServerClasses =
121 {
122 "-org.eclipse.jetty.continuation.",
123 "-org.eclipse.jetty.jndi.",
124 "-org.eclipse.jetty.plus.jaas.",
125 "-org.eclipse.jetty.websocket.WebSocket",
126 "-org.eclipse.jetty.websocket.WebSocketFactory",
127 "-org.eclipse.jetty.websocket.WebSocketServlet",
128 "-org.eclipse.jetty.servlet.DefaultServlet",
129 "-org.eclipse.jetty.servlet.listener.",
130 "org.eclipse.jetty."
131 } ;
132
133 private String[] _configurationClasses = __dftConfigurationClasses;
134 private ClasspathPattern _systemClasses = null;
135 private ClasspathPattern _serverClasses = null;
136
137 private Configuration[] _configurations;
138 private String _defaultsDescriptor=WEB_DEFAULTS_XML;
139 private String _descriptor=null;
140 private final List<String> _overrideDescriptors = new ArrayList<String>();
141 private boolean _distributable=false;
142 private boolean _extractWAR=true;
143 private boolean _copyDir=false;
144 private boolean _copyWebInf=false;
145 private boolean _logUrlOnStart =false;
146 private boolean _parentLoaderPriority= Boolean.getBoolean("org.eclipse.jetty.server.webapp.parentLoaderPriority");
147 private PermissionCollection _permissions;
148
149 private String[] _contextWhiteList = null;
150
151 private File _tmpDir;
152 private String _war;
153 private String _extraClasspath;
154 private Throwable _unavailableException;
155
156 private Map<String, String> _resourceAliases;
157 private boolean _ownClassLoader=false;
158 private boolean _configurationDiscovered=true;
159 private boolean _configurationClassesSet=false;
160 private boolean _configurationsSet=false;
161 private boolean _allowDuplicateFragmentNames = false;
162 private boolean _throwUnavailableOnStartupException = false;
163
164
165
166 private MetaData _metadata=new MetaData();
167
168 public static WebAppContext getCurrentWebAppContext()
169 {
170 ContextHandler.Context context=ContextHandler.getCurrentContext();
171 if (context!=null)
172 {
173 ContextHandler handler = context.getContextHandler();
174 if (handler instanceof WebAppContext)
175 return (WebAppContext)handler;
176 }
177 return null;
178 }
179
180
181 public WebAppContext()
182 {
183 super(SESSIONS|SECURITY);
184 _scontext=new Context();
185 setErrorHandler(new ErrorPageErrorHandler());
186 setProtectedTargets(__dftProtectedTargets);
187 }
188
189
190
191
192
193
194 public WebAppContext(String webApp,String contextPath)
195 {
196 super(null,contextPath,SESSIONS|SECURITY);
197 _scontext=new Context();
198 setContextPath(contextPath);
199 setWar(webApp);
200 setErrorHandler(new ErrorPageErrorHandler());
201 setProtectedTargets(__dftProtectedTargets);
202 }
203
204
205
206
207
208
209
210 public WebAppContext(HandlerContainer parent, String webApp, String contextPath)
211 {
212 super(parent,contextPath,SESSIONS|SECURITY);
213 _scontext=new Context();
214 setWar(webApp);
215 setErrorHandler(new ErrorPageErrorHandler());
216 setProtectedTargets(__dftProtectedTargets);
217 }
218
219
220
221
222
223
224
225
226
227
228
229 public WebAppContext(SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler) {
230 super(null, sessionHandler, securityHandler, servletHandler, errorHandler);
231 _scontext = new Context();
232 setErrorHandler(errorHandler != null ? errorHandler : new ErrorPageErrorHandler());
233 setProtectedTargets(__dftProtectedTargets);
234 }
235
236
237
238
239
240 @Override
241 public void setDisplayName(String servletContextName)
242 {
243 super.setDisplayName(servletContextName);
244 ClassLoader cl = getClassLoader();
245 if (cl!=null && cl instanceof WebAppClassLoader && servletContextName!=null)
246 ((WebAppClassLoader)cl).setName(servletContextName);
247 }
248
249
250
251
252
253 public Throwable getUnavailableException()
254 {
255 return _unavailableException;
256 }
257
258
259
260
261
262
263
264
265
266
267 public void setResourceAlias(String alias, String uri)
268 {
269 if (_resourceAliases == null)
270 _resourceAliases= new HashMap<String, String>(5);
271 _resourceAliases.put(alias, uri);
272 }
273
274
275 public Map<String, String> getResourceAliases()
276 {
277 if (_resourceAliases == null)
278 return null;
279 return _resourceAliases;
280 }
281
282
283 public void setResourceAliases(Map<String, String> map)
284 {
285 _resourceAliases = map;
286 }
287
288
289 public String getResourceAlias(String path)
290 {
291 if (_resourceAliases == null)
292 return null;
293 String alias = _resourceAliases.get(path);
294
295 int slash=path.length();
296 while (alias==null)
297 {
298 slash=path.lastIndexOf("/",slash-1);
299 if (slash<0)
300 break;
301 String match=_resourceAliases.get(path.substring(0,slash+1));
302 if (match!=null)
303 alias=match+path.substring(slash+1);
304 }
305 return alias;
306 }
307
308
309 public String removeResourceAlias(String alias)
310 {
311 if (_resourceAliases == null)
312 return null;
313 return _resourceAliases.remove(alias);
314 }
315
316
317
318
319
320 @Override
321 public void setClassLoader(ClassLoader classLoader)
322 {
323 super.setClassLoader(classLoader);
324
325
326
327
328
329
330 if (classLoader!=null && classLoader instanceof WebAppClassLoader && getDisplayName()!=null)
331 ((WebAppClassLoader)classLoader).setName(getDisplayName());
332 }
333
334
335 @Override
336 public Resource getResource(String uriInContext) throws MalformedURLException
337 {
338 if (uriInContext==null || !uriInContext.startsWith(URIUtil.SLASH))
339 throw new MalformedURLException(uriInContext);
340
341 IOException ioe= null;
342 Resource resource= null;
343 int loop=0;
344 while (uriInContext!=null && loop++<100)
345 {
346 try
347 {
348 resource= super.getResource(uriInContext);
349 if (resource != null && resource.exists())
350 return resource;
351
352 uriInContext = getResourceAlias(uriInContext);
353 }
354 catch (IOException e)
355 {
356 LOG.ignore(e);
357 if (ioe==null)
358 ioe= e;
359 }
360 }
361
362 if (ioe != null && ioe instanceof MalformedURLException)
363 throw (MalformedURLException)ioe;
364
365 return resource;
366 }
367
368
369
370
371
372
373
374 public boolean isConfigurationDiscovered()
375 {
376 return _configurationDiscovered;
377 }
378
379
380
381
382
383
384
385
386
387
388
389 public void setConfigurationDiscovered(boolean discovered)
390 {
391 _configurationDiscovered = discovered;
392 }
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409 public void preConfigure() throws Exception
410 {
411
412 loadConfigurations();
413
414
415 loadSystemClasses();
416
417
418 loadServerClasses();
419
420
421 _ownClassLoader=false;
422 if (getClassLoader()==null)
423 {
424 WebAppClassLoader classLoader = new WebAppClassLoader(this);
425 setClassLoader(classLoader);
426 _ownClassLoader=true;
427 }
428
429 if (LOG.isDebugEnabled())
430 {
431 ClassLoader loader = getClassLoader();
432 LOG.debug("Thread Context classloader {}",loader);
433 loader=loader.getParent();
434 while(loader!=null)
435 {
436 LOG.debug("Parent class loader: {} ",loader);
437 loader=loader.getParent();
438 }
439 }
440
441
442 for (int i=0;i<_configurations.length;i++)
443 {
444 LOG.debug("preConfigure {} with {}",this,_configurations[i]);
445 _configurations[i].preConfigure(this);
446 }
447 }
448
449
450 public void configure() throws Exception
451 {
452
453 for (int i=0;i<_configurations.length;i++)
454 {
455 LOG.debug("configure {} with {}",this,_configurations[i]);
456 _configurations[i].configure(this);
457 }
458 }
459
460
461 public void postConfigure() throws Exception
462 {
463
464 for (int i=0;i<_configurations.length;i++)
465 {
466 LOG.debug("postConfigure {} with {}",this,_configurations[i]);
467 _configurations[i].postConfigure(this);
468 }
469 }
470
471
472
473
474
475 @Override
476 protected void doStart() throws Exception
477 {
478 try
479 {
480 _metadata.setAllowDuplicateFragmentNames(isAllowDuplicateFragmentNames());
481 preConfigure();
482 super.doStart();
483 postConfigure();
484
485 if (isLogUrlOnStart())
486 dumpUrl();
487 }
488 catch (Exception e)
489 {
490
491 LOG.warn("Failed startup of context "+this, e);
492 _unavailableException=e;
493 setAvailable(false);
494 if (isThrowUnavailableOnStartupException())
495 throw e;
496 }
497 }
498
499
500
501
502
503 @Override
504 protected void doStop() throws Exception
505 {
506 super.doStop();
507
508 try
509 {
510 for (int i=_configurations.length;i-->0;)
511 _configurations[i].deconfigure(this);
512
513 if (_metadata != null)
514 _metadata.clear();
515 _metadata=new MetaData();
516
517 }
518 finally
519 {
520 if (_ownClassLoader)
521 setClassLoader(null);
522
523 setAvailable(true);
524 _unavailableException=null;
525 }
526 }
527
528
529 @Override
530 public void destroy()
531 {
532
533 MultiException mx=new MultiException();
534 if (_configurations!=null)
535 {
536 for (int i=_configurations.length;i-->0;)
537 {
538 try
539 {
540 _configurations[i].destroy(this);
541 }
542 catch(Exception e)
543 {
544 mx.add(e);
545 }
546 }
547 }
548 _configurations=null;
549 super.destroy();
550 mx.ifExceptionThrowRuntime();
551 }
552
553
554
555
556
557
558 private void dumpUrl()
559 {
560 Connector[] connectors = getServer().getConnectors();
561 for (int i=0;i<connectors.length;i++)
562 {
563 String connectorName = connectors[i].getName();
564 String displayName = getDisplayName();
565 if (displayName == null)
566 displayName = "WebApp@"+connectors.hashCode();
567
568 LOG.info(displayName + " at http://" + connectorName + getContextPath());
569 }
570 }
571
572
573
574
575
576 public String[] getConfigurationClasses()
577 {
578 return _configurationClasses;
579 }
580
581
582
583
584
585 public Configuration[] getConfigurations()
586 {
587 return _configurations;
588 }
589
590
591
592
593
594
595 public String getDefaultsDescriptor()
596 {
597 return _defaultsDescriptor;
598 }
599
600
601
602
603
604
605
606 @Deprecated
607 public String getOverrideDescriptor()
608 {
609 if (_overrideDescriptors.size()!=1)
610 return null;
611 return _overrideDescriptors.get(0);
612 }
613
614
615
616
617
618
619 public List<String> getOverrideDescriptors()
620 {
621 return Collections.unmodifiableList(_overrideDescriptors);
622 }
623
624
625
626
627
628 public PermissionCollection getPermissions()
629 {
630 return _permissions;
631 }
632
633
634
635
636
637
638 public String[] getServerClasses()
639 {
640 if (_serverClasses == null)
641 loadServerClasses();
642
643 return _serverClasses.getPatterns();
644 }
645
646 public void addServerClass(String classname)
647 {
648 if (_serverClasses == null)
649 loadServerClasses();
650
651 _serverClasses.addPattern(classname);
652 }
653
654
655
656
657
658
659 public String[] getSystemClasses()
660 {
661 if (_systemClasses == null)
662 loadSystemClasses();
663
664 return _systemClasses.getPatterns();
665 }
666
667
668 public void addSystemClass(String classname)
669 {
670 if (_systemClasses == null)
671 loadSystemClasses();
672
673 _systemClasses.addPattern(classname);
674 }
675
676
677 public boolean isServerClass(String name)
678 {
679 if (_serverClasses == null)
680 loadServerClasses();
681
682 return _serverClasses.match(name);
683 }
684
685
686 public boolean isSystemClass(String name)
687 {
688 if (_systemClasses == null)
689 loadSystemClasses();
690
691 return _systemClasses.match(name);
692 }
693
694
695 protected void loadSystemClasses()
696 {
697 if (_systemClasses != null)
698 return;
699
700
701
702 Server server = getServer();
703 if (server != null)
704 {
705 Object systemClasses = server.getAttribute(SERVER_SYS_CLASSES);
706 if (systemClasses != null && systemClasses instanceof String[])
707 _systemClasses = new ClasspathPattern((String[])systemClasses);
708 }
709
710 if (_systemClasses == null)
711 _systemClasses = new ClasspathPattern(__dftSystemClasses);
712 }
713
714
715 private void loadServerClasses()
716 {
717 if (_serverClasses != null)
718 {
719 return;
720 }
721
722
723
724 Server server = getServer();
725 if (server != null)
726 {
727 Object serverClasses = server.getAttribute(SERVER_SRV_CLASSES);
728 if (serverClasses != null && serverClasses instanceof String[])
729 {
730 _serverClasses = new ClasspathPattern((String[])serverClasses);
731 }
732 }
733
734 if (_serverClasses == null)
735 {
736 _serverClasses = new ClasspathPattern(__dftServerClasses);
737 }
738 }
739
740
741
742
743
744 public String getWar()
745 {
746 if (_war==null)
747 _war=getResourceBase();
748 return _war;
749 }
750
751
752 public Resource getWebInf() throws IOException
753 {
754 if (super.getBaseResource() == null)
755 return null;
756
757
758 Resource web_inf= super.getBaseResource().addPath("WEB-INF/");
759 if (!web_inf.exists() || !web_inf.isDirectory())
760 return null;
761
762 return web_inf;
763 }
764
765
766
767
768
769 public boolean isDistributable()
770 {
771 return _distributable;
772 }
773
774
775
776
777
778 public boolean isExtractWAR()
779 {
780 return _extractWAR;
781 }
782
783
784
785
786
787 public boolean isCopyWebDir()
788 {
789 return _copyDir;
790 }
791
792
793
794
795
796 public boolean isCopyWebInf()
797 {
798 return _copyWebInf;
799 }
800
801
802
803
804
805
806
807
808 public boolean isParentLoaderPriority()
809 {
810 return _parentLoaderPriority;
811 }
812
813
814
815 public String[] getDefaultConfigurationClasses ()
816 {
817 return __dftConfigurationClasses;
818 }
819
820
821 public String[] getDefaultServerClasses ()
822 {
823 return __dftServerClasses;
824 }
825
826
827 public String[] getDefaultSystemClasses ()
828 {
829 return __dftSystemClasses;
830 }
831
832
833 protected void loadConfigurations()
834 throws Exception
835 {
836
837 if (_configurations!=null)
838 return;
839
840
841 if (!_configurationClassesSet)
842 _configurationClasses=__dftConfigurationClasses;
843
844 _configurations = new Configuration[_configurationClasses.length];
845 for (int i = 0; i < _configurationClasses.length; i++)
846 {
847 _configurations[i]=(Configuration)Loader.loadClass(this.getClass(), _configurationClasses[i]).newInstance();
848 }
849 }
850
851
852
853
854 @Override
855 public String toString()
856 {
857 return super.toString()+(_war==null?"":(","+_war));
858 }
859
860
861
862
863
864
865 public void setConfigurationClasses(String[] configurations)
866 {
867 if (isRunning())
868 throw new IllegalStateException();
869 _configurationClasses = configurations==null?null:(String[])configurations.clone();
870 _configurationClassesSet = true;
871 _configurations=null;
872 }
873
874
875
876
877
878 public void setConfigurations(Configuration[] configurations)
879 {
880 if (isRunning())
881 throw new IllegalStateException();
882 _configurations = configurations==null?null:(Configuration[])configurations.clone();
883 _configurationsSet = true;
884 }
885
886
887
888
889
890
891 public void setDefaultsDescriptor(String defaultsDescriptor)
892 {
893 _defaultsDescriptor = defaultsDescriptor;
894 }
895
896
897
898
899
900
901
902 @Deprecated
903 public void setOverrideDescriptor(String overrideDescriptor)
904 {
905 _overrideDescriptors.clear();
906 _overrideDescriptors.add(overrideDescriptor);
907 }
908
909
910
911
912
913
914 public void setOverrideDescriptors(List<String> overrideDescriptors)
915 {
916 _overrideDescriptors.clear();
917 _overrideDescriptors.addAll(overrideDescriptors);
918 }
919
920
921
922
923
924
925 public void addOverrideDescriptor(String overrideDescriptor)
926 {
927 _overrideDescriptors.add(overrideDescriptor);
928 }
929
930
931
932
933
934 public String getDescriptor()
935 {
936 return _descriptor;
937 }
938
939
940
941
942
943 public void setDescriptor(String descriptor)
944 {
945 _descriptor=descriptor;
946 }
947
948
949
950
951
952 public void setDistributable(boolean distributable)
953 {
954 this._distributable = distributable;
955 }
956
957
958 @Override
959 public void setEventListeners(EventListener[] eventListeners)
960 {
961 if (_sessionHandler!=null)
962 _sessionHandler.clearEventListeners();
963
964 super.setEventListeners(eventListeners);
965
966 for (int i=0; eventListeners!=null && i<eventListeners.length;i ++)
967 {
968 EventListener listener = eventListeners[i];
969
970 if ((listener instanceof HttpSessionActivationListener)
971 || (listener instanceof HttpSessionAttributeListener)
972 || (listener instanceof HttpSessionBindingListener)
973 || (listener instanceof HttpSessionListener))
974 {
975 if (_sessionHandler!=null)
976 _sessionHandler.addEventListener(listener);
977 }
978
979 }
980 }
981
982
983
984
985
986
987 @Override
988 public void addEventListener(EventListener listener)
989 {
990 setEventListeners(LazyList.addToArray(getEventListeners(), listener, EventListener.class));
991 }
992
993
994
995
996
997
998 public void setExtractWAR(boolean extractWAR)
999 {
1000 _extractWAR = extractWAR;
1001 }
1002
1003
1004
1005
1006
1007 public void setCopyWebDir(boolean copy)
1008 {
1009 _copyDir = copy;
1010 }
1011
1012
1013
1014
1015
1016 public void setCopyWebInf(boolean copyWebInf)
1017 {
1018 _copyWebInf = copyWebInf;
1019 }
1020
1021
1022
1023
1024
1025 public void setParentLoaderPriority(boolean java2compliant)
1026 {
1027 _parentLoaderPriority = java2compliant;
1028 }
1029
1030
1031
1032
1033
1034 public void setPermissions(PermissionCollection permissions)
1035 {
1036 _permissions = permissions;
1037 }
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048 public void setContextWhiteList(String[] contextWhiteList)
1049 {
1050 _contextWhiteList = contextWhiteList;
1051 }
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068 public void setServerClasses(String[] serverClasses)
1069 {
1070 _serverClasses = new ClasspathPattern(serverClasses);
1071 }
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088 public void setSystemClasses(String[] systemClasses)
1089 {
1090 _systemClasses = new ClasspathPattern(systemClasses);
1091 }
1092
1093
1094
1095
1096
1097
1098
1099 public void setTempDirectory(File dir)
1100 {
1101 if (isStarted())
1102 throw new IllegalStateException("Started");
1103
1104 if (dir!=null)
1105 {
1106 try{dir=new File(dir.getCanonicalPath());}
1107 catch (IOException e){LOG.warn(Log.EXCEPTION,e);}
1108 }
1109
1110 if (dir!=null && !dir.exists())
1111 {
1112 dir.mkdir();
1113 dir.deleteOnExit();
1114 }
1115
1116 if (dir!=null && ( !dir.exists() || !dir.isDirectory() || !dir.canWrite()))
1117 throw new IllegalArgumentException("Bad temp directory: "+dir);
1118
1119 try
1120 {
1121 if (dir!=null)
1122 dir=dir.getCanonicalFile();
1123 }
1124 catch(Exception e)
1125 {
1126 LOG.warn(e);
1127 }
1128 _tmpDir=dir;
1129 setAttribute(TEMPDIR,_tmpDir);
1130 }
1131
1132
1133 public File getTempDirectory ()
1134 {
1135 return _tmpDir;
1136 }
1137
1138
1139
1140
1141
1142 public void setWar(String war)
1143 {
1144 _war = war;
1145 }
1146
1147
1148
1149
1150
1151
1152
1153 public String getExtraClasspath()
1154 {
1155 return _extraClasspath;
1156 }
1157
1158
1159
1160
1161
1162
1163
1164 public void setExtraClasspath(String extraClasspath)
1165 {
1166 _extraClasspath=extraClasspath;
1167 }
1168
1169
1170 public boolean isLogUrlOnStart()
1171 {
1172 return _logUrlOnStart;
1173 }
1174
1175
1176
1177
1178
1179
1180
1181 public void setLogUrlOnStart(boolean logOnStart)
1182 {
1183 this._logUrlOnStart = logOnStart;
1184 }
1185
1186
1187
1188 @Override
1189 public void setServer(Server server)
1190 {
1191 super.setServer(server);
1192
1193
1194
1195
1196 if (!_configurationsSet && !_configurationClassesSet && server != null)
1197 {
1198 String[] serverConfigs = (String[])server.getAttribute(SERVER_CONFIG);
1199 if (serverConfigs != null)
1200 setConfigurationClasses(serverConfigs);
1201 }
1202 }
1203
1204
1205
1206 public boolean isAllowDuplicateFragmentNames()
1207 {
1208 return _allowDuplicateFragmentNames;
1209 }
1210
1211
1212
1213 public void setAllowDuplicateFragmentNames(boolean allowDuplicateFragmentNames)
1214 {
1215 _allowDuplicateFragmentNames = allowDuplicateFragmentNames;
1216 }
1217
1218
1219
1220 public void setThrowUnavailableOnStartupException (boolean throwIfStartupException) {
1221 _throwUnavailableOnStartupException = throwIfStartupException;
1222 }
1223
1224
1225
1226 public boolean isThrowUnavailableOnStartupException () {
1227 return _throwUnavailableOnStartupException;
1228 }
1229
1230
1231 @Override
1232 protected void startContext()
1233 throws Exception
1234 {
1235 configure();
1236
1237
1238 _metadata.resolve(this);
1239
1240 super.startContext();
1241 }
1242
1243
1244 public class Context extends ServletContextHandler.Context
1245 {
1246
1247 @Override
1248 public URL getResource(String path) throws MalformedURLException
1249 {
1250 Resource resource=WebAppContext.this.getResource(path);
1251 if (resource==null || !resource.exists())
1252 return null;
1253
1254
1255 if (resource.isDirectory() && resource instanceof ResourceCollection && !WebAppContext.this.isExtractWAR())
1256 {
1257 Resource[] resources = ((ResourceCollection)resource).getResources();
1258 for (int i=resources.length;i-->0;)
1259 {
1260 if (resources[i].getName().startsWith("jar:file"))
1261 return resources[i].getURL();
1262 }
1263 }
1264
1265 return resource.getURL();
1266 }
1267
1268
1269 @Override
1270 public ServletContext getContext(String uripath)
1271 {
1272 ServletContext servletContext = super.getContext(uripath);
1273
1274 if ( servletContext != null && _contextWhiteList != null )
1275 {
1276 for ( String context : _contextWhiteList )
1277 {
1278 if ( context.equals(uripath) )
1279 {
1280 return servletContext;
1281 }
1282 }
1283
1284 return null;
1285 }
1286 else
1287 {
1288 return servletContext;
1289 }
1290 }
1291
1292 }
1293
1294
1295 public MetaData getMetaData()
1296 {
1297 return _metadata;
1298 }
1299
1300 }