use of javax.servlet.ServletConfig in project Lucee by lucee.
the class ConfigWebUtil method replacePlaceholder.
public static String replacePlaceholder(String str, Config config) {
if (StringUtil.isEmpty(str))
return str;
if (StringUtil.startsWith(str, '{')) {
// Config Server
if (str.startsWith("{lucee-config")) {
if (str.startsWith("}", 13))
str = checkResult(str, config.getConfigDir().getReal(str.substring(14)));
else if (str.startsWith("-dir}", 13))
str = checkResult(str, config.getConfigDir().getReal(str.substring(18)));
else if (str.startsWith("-directory}", 13))
str = checkResult(str, config.getConfigDir().getReal(str.substring(24)));
} else if (config != null && str.startsWith("{lucee-server")) {
Resource dir = config instanceof ConfigWeb ? ((ConfigWeb) config).getConfigServerDir() : config.getConfigDir();
// if(config instanceof ConfigServer && cs==null) cs=(ConfigServer) cw;
if (dir != null) {
if (str.startsWith("}", 13))
str = checkResult(str, dir.getReal(str.substring(14)));
else if (str.startsWith("-dir}", 13))
str = checkResult(str, dir.getReal(str.substring(18)));
else if (str.startsWith("-directory}", 13))
str = checkResult(str, dir.getReal(str.substring(24)));
}
} else // Config Web
if (str.startsWith("{lucee-web")) {
if (str.startsWith("}", 10))
str = checkResult(str, config.getConfigDir().getReal(str.substring(11)));
else if (str.startsWith("-dir}", 10))
str = checkResult(str, config.getConfigDir().getReal(str.substring(15)));
else if (str.startsWith("-directory}", 10))
str = checkResult(str, config.getConfigDir().getReal(str.substring(21)));
} else // Web Root
if (str.startsWith("{web-root")) {
if (config instanceof ConfigWeb) {
if (str.startsWith("}", 9))
str = checkResult(str, config.getRootDirectory().getReal(str.substring(10)));
else if (str.startsWith("-dir}", 9))
str = checkResult(str, config.getRootDirectory().getReal(str.substring(14)));
else if (str.startsWith("-directory}", 9))
str = checkResult(str, config.getRootDirectory().getReal(str.substring(20)));
}
} else // Temp
if (str.startsWith("{temp")) {
if (str.startsWith("}", 5))
str = checkResult(str, config.getTempDirectory().getRealResource(str.substring(6)).toString());
else if (str.startsWith("-dir}", 5))
str = checkResult(str, config.getTempDirectory().getRealResource(str.substring(10)).toString());
else if (str.startsWith("-directory}", 5))
str = checkResult(str, config.getTempDirectory().getRealResource(str.substring(16)).toString());
} else if (config instanceof ServletConfig) {
Map<String, String> labels = null;
// web
if (config instanceof ConfigWebImpl) {
labels = ((ConfigWebImpl) config).getAllLabels();
} else // server
if (config instanceof ConfigServerImpl) {
labels = ((ConfigServerImpl) config).getLabels();
}
if (labels != null)
str = SystemUtil.parsePlaceHolder(str, ((ServletConfig) config).getServletContext(), labels);
} else
str = SystemUtil.parsePlaceHolder(str);
if (StringUtil.startsWith(str, '{')) {
Struct constants = ((ConfigImpl) config).getConstants();
Iterator<Entry<Key, Object>> it = constants.entryIterator();
Entry<Key, Object> e;
while (it.hasNext()) {
e = it.next();
if (StringUtil.startsWithIgnoreCase(str, "{" + e.getKey().getString() + "}")) {
String value = (String) e.getValue();
str = checkResult(str, config.getResource(value).getReal(str.substring(e.getKey().getString().length() + 2)));
break;
}
}
}
}
return str;
}
use of javax.servlet.ServletConfig in project meecrowave by apache.
the class CxfCdiAutoSetup method onStartup.
@Override
public void onStartup(final Set<Class<?>> c, final ServletContext ctx) throws ServletException {
final Meecrowave.Builder builder = Meecrowave.Builder.class.cast(ctx.getAttribute("meecrowave.configuration"));
final MeecrowaveCXFCdiServlet delegate = new MeecrowaveCXFCdiServlet();
final FilterRegistration.Dynamic jaxrs = ctx.addFilter(NAME, new Filter() {
private final String servletPath = builder.getJaxrsMapping().endsWith("/*") ? builder.getJaxrsMapping().substring(0, builder.getJaxrsMapping().length() - 2) : builder.getJaxrsMapping();
@Override
public void init(final FilterConfig filterConfig) throws ServletException {
delegate.init(new ServletConfig() {
@Override
public String getServletName() {
return NAME;
}
@Override
public ServletContext getServletContext() {
return filterConfig.getServletContext();
}
@Override
public String getInitParameter(final String name) {
return filterConfig.getInitParameter(name);
}
@Override
public Enumeration<String> getInitParameterNames() {
return filterConfig.getInitParameterNames();
}
});
}
@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
if (!HttpServletRequest.class.isInstance(request)) {
chain.doFilter(request, response);
return;
}
final HttpServletRequest http = HttpServletRequest.class.cast(request);
final String path = http.getRequestURI().substring(http.getContextPath().length());
final Optional<String> app = Stream.of(delegate.prefixes).filter(path::startsWith).findAny();
if (app.isPresent()) {
delegate.service(new // fake servlet pathInfo and path
HttpServletRequestWrapper(// fake servlet pathInfo and path
http) {
@Override
public String getPathInfo() {
return path;
}
@Override
public String getServletPath() {
return servletPath;
}
}, response);
} else {
chain.doFilter(request, response);
}
}
@Override
public void destroy() {
delegate.destroy();
}
});
jaxrs.setAsyncSupported(true);
jaxrs.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, builder.getJaxrsMapping());
ofNullable(builder.getCxfServletParams()).ifPresent(m -> m.forEach(jaxrs::setInitParameter));
}
use of javax.servlet.ServletConfig in project Payara by payara.
the class RealmAdapter method getServletName.
/**
* Obtain servlet name from invocation.
*
* <P>
* In order to obtain the servlet name one of the following must be true: 1. The instanceName of the ComponentInvocation
* is not null 2. The ComponentInvocation contains a 'class' of type HttpServlet, which contains a valid ServletConfig
* object. This method returns the value returned by getServletName() on the ServletConfig.
*
* <P>
* If the above is not met, null is returned.
*
* @param invocation The invocation object to process.
* @return Servlet name or null.
*/
private String getServletName(ComponentInvocation invocation) {
String servletName = invocation.getInstanceName();
if (servletName != null) {
return servletName;
}
Object invocationInstance = invocation.getInstance();
if (invocationInstance instanceof HttpServlet) {
HttpServlet thisServlet = (HttpServlet) invocationInstance;
ServletConfig servletConfig = thisServlet.getServletConfig();
if (servletConfig != null) {
return thisServlet.getServletName();
}
}
return null;
}
use of javax.servlet.ServletConfig in project Payara by payara.
the class DefaultServlet method init.
/**
* Initialize this servlet.
*/
public void init() throws ServletException {
ServletConfig sc = getServletConfig();
if (sc.getInitParameter("debug") != null)
debug = Integer.parseInt(sc.getInitParameter("debug"));
if (sc.getInitParameter("input") != null)
input = Integer.parseInt(sc.getInitParameter("input"));
if (sc.getInitParameter("output") != null)
output = Integer.parseInt(sc.getInitParameter("output"));
listings = Boolean.parseBoolean(sc.getInitParameter("listings"));
String sortedByInitParam = sc.getInitParameter("sortedBy");
if (sortedByInitParam != null) {
sortedBy = Enum.valueOf(SortedBy.class, sortedByInitParam);
}
if (sc.getInitParameter("readonly") != null)
readOnly = Boolean.parseBoolean(sc.getInitParameter("readonly"));
if (sc.getInitParameter("sendfileSize") != null)
sendfileSize = Integer.parseInt(sc.getInitParameter("sendfileSize")) * 1024;
if (sc.getInitParameter("maxHeaderRangeItems") != null) {
maxHeaderRangeItems = Integer.parseInt(sc.getInitParameter("maxHeaderRangeItems"));
}
fileEncoding = sc.getInitParameter("fileEncoding");
globalXsltFile = sc.getInitParameter("globalXsltFile");
contextXsltFile = sc.getInitParameter("contextXsltFile");
localXsltFile = sc.getInitParameter("localXsltFile");
readmeFile = sc.getInitParameter("readmeFile");
if (sc.getInitParameter("useAcceptRanges") != null)
useAcceptRanges = Boolean.parseBoolean(sc.getInitParameter("useAcceptRanges"));
// Sanity check on the specified buffer sizes
if (input < 256)
input = 256;
if (output < 256)
output = 256;
if (debug > 0) {
log("DefaultServlet.init: input buffer size=" + input + ", output buffer size=" + output);
}
// Load the proxy dir context.
resources = (ProxyDirContext) getServletContext().getAttribute(Globals.RESOURCES_ATTR);
if (resources == null) {
try {
resources = (ProxyDirContext) new InitialContext().lookup(RESOURCES_JNDI_NAME);
} catch (NamingException e) {
throw new ServletException("No resources", e);
} catch (ClassCastException e) {
// Failed : Not the right type
}
}
if (resources == null) {
throw new UnavailableException("No resources");
}
try {
alternateDocBases = getAlternateDocBases();
} catch (ClassCastException e) {
// Failed : Not the right type
}
}
Aggregations