use of org.apache.ofbiz.webapp.control.ConfigXMLReader.ControllerConfig in project ofbiz-framework by apache.
the class ArtifactInfoFactory method prepareTaskForComponentAnalysis.
private Callable<Void> prepareTaskForComponentAnalysis(final ComponentConfig componentConfig) {
return new Callable<Void>() {
@Override
public Void call() throws Exception {
String componentName = componentConfig.getGlobalName();
String rootComponentPath = componentConfig.getRootLocation();
List<File> screenFiles = new ArrayList<File>();
List<File> formFiles = new ArrayList<File>();
List<File> controllerFiles = new ArrayList<File>();
try {
screenFiles = FileUtil.findXmlFiles(rootComponentPath, null, "screens", "widget-screen.xsd");
} catch (IOException ioe) {
Debug.logWarning(ioe.getMessage(), module);
}
try {
formFiles = FileUtil.findXmlFiles(rootComponentPath, null, "forms", "widget-form.xsd");
} catch (IOException ioe) {
Debug.logWarning(ioe.getMessage(), module);
}
try {
controllerFiles = FileUtil.findXmlFiles(rootComponentPath, null, "site-conf", "site-conf.xsd");
} catch (IOException ioe) {
Debug.logWarning(ioe.getMessage(), module);
}
for (File screenFile : screenFiles) {
String screenFilePath = screenFile.getAbsolutePath();
screenFilePath = screenFilePath.replace('\\', '/');
String screenFileRelativePath = screenFilePath.substring(rootComponentPath.length());
String screenLocation = "component://" + componentName + "/" + screenFileRelativePath;
Map<String, ModelScreen> modelScreenMap = null;
try {
modelScreenMap = ScreenFactory.getScreensFromLocation(screenLocation);
} catch (Exception exc) {
Debug.logWarning(exc.getMessage(), module);
}
for (String screenName : modelScreenMap.keySet()) {
getScreenWidgetArtifactInfo(screenName, screenLocation);
}
}
for (File formFile : formFiles) {
String formFilePath = formFile.getAbsolutePath();
formFilePath = formFilePath.replace('\\', '/');
String formFileRelativePath = formFilePath.substring(rootComponentPath.length());
String formLocation = "component://" + componentName + "/" + formFileRelativePath;
Map<String, ModelForm> modelFormMap = null;
try {
modelFormMap = FormFactory.getFormsFromLocation(formLocation, getEntityModelReader(), getDispatchContext());
} catch (Exception exc) {
Debug.logWarning(exc.getMessage(), module);
}
for (String formName : modelFormMap.keySet()) {
try {
getFormWidgetArtifactInfo(formName, formLocation);
} catch (GeneralException ge) {
Debug.logWarning(ge.getMessage(), module);
}
}
}
for (File controllerFile : controllerFiles) {
URL controllerUrl = null;
try {
controllerUrl = controllerFile.toURI().toURL();
} catch (MalformedURLException mue) {
Debug.logWarning(mue.getMessage(), module);
}
if (controllerUrl == null)
continue;
ControllerConfig cc = ConfigXMLReader.getControllerConfig(controllerUrl);
for (String requestUri : cc.getRequestMapMap().keySet()) {
try {
getControllerRequestArtifactInfo(controllerUrl, requestUri);
} catch (GeneralException e) {
Debug.logWarning(e.getMessage(), module);
}
}
for (String viewUri : cc.getViewMapMap().keySet()) {
try {
getControllerViewArtifactInfo(controllerUrl, viewUri);
} catch (GeneralException e) {
Debug.logWarning(e.getMessage(), module);
}
}
}
return null;
}
};
}
use of org.apache.ofbiz.webapp.control.ConfigXMLReader.ControllerConfig in project ofbiz-framework by apache.
the class OfbizUrlBuilder method from.
/**
* Returns an <code>OfbizUrlBuilder</code> instance. Use this method when you
* don't have a <code>HttpServletRequest</code> object - like in scheduled jobs.
*
* @param webAppInfo Optional - if <code>null</code>, the builder can only build the host part,
* and that will be based only on the settings in <code>url.properties</code> (the WebSite
* entity will be ignored).
* @param delegator
* @throws WebAppConfigurationException
* @throws IOException
* @throws SAXException
* @throws GenericEntityException
*/
public static OfbizUrlBuilder from(WebappInfo webAppInfo, Delegator delegator) throws WebAppConfigurationException, IOException, SAXException, GenericEntityException {
WebSiteProperties webSiteProps = null;
ControllerConfig config = null;
String servletPath = null;
if (webAppInfo != null) {
Assert.notNull("delegator", delegator);
String webSiteId = WebAppUtil.getWebSiteId(webAppInfo);
if (webSiteId != null) {
GenericValue webSiteValue = EntityQuery.use(delegator).from("WebSite").where("webSiteId", webSiteId).cache().queryOne();
if (webSiteValue != null) {
webSiteProps = WebSiteProperties.from(webSiteValue);
}
}
config = ConfigXMLReader.getControllerConfig(webAppInfo);
servletPath = WebAppUtil.getControlServletPath(webAppInfo);
}
if (webSiteProps == null) {
webSiteProps = WebSiteProperties.defaults(delegator);
}
return new OfbizUrlBuilder(config, webSiteProps, servletPath);
}
use of org.apache.ofbiz.webapp.control.ConfigXMLReader.ControllerConfig in project ofbiz-framework by apache.
the class SeoContextFilter method doFilter.
/**
* @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
*/
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
String uri = httpRequest.getRequestURI();
boolean forwarded = forwardUri(httpResponse, uri);
if (forwarded) {
return;
}
URL controllerConfigURL = ConfigXMLReader.getControllerConfigURL(config.getServletContext());
ControllerConfig controllerConfig = null;
Map<String, ConfigXMLReader.RequestMap> requestMaps = null;
try {
controllerConfig = ConfigXMLReader.getControllerConfig(controllerConfigURL);
requestMaps = controllerConfig.getRequestMapMap();
} catch (WebAppConfigurationException e) {
Debug.logError(e, "Exception thrown while parsing controller.xml file: ", module);
throw new ServletException(e);
}
Set<String> uris = requestMaps.keySet();
// test to see if we have come through the control servlet already, if not do the processing
String requestPath = null;
String contextUri = null;
if (httpRequest.getAttribute(ControlFilter.FORWARDED_FROM_SERVLET) == null) {
requestPath = httpRequest.getServletPath();
if (requestPath == null)
requestPath = "";
if (requestPath.lastIndexOf('/') > 0) {
if (requestPath.indexOf('/') == 0) {
requestPath = '/' + requestPath.substring(1, requestPath.indexOf('/', 1));
} else {
requestPath = requestPath.substring(1, requestPath.indexOf('/'));
}
}
String requestInfo = httpRequest.getServletPath();
if (requestInfo == null)
requestInfo = "";
if (requestInfo.lastIndexOf('/') >= 0) {
requestInfo = requestInfo.substring(0, requestInfo.lastIndexOf('/')) + "/*";
}
StringBuilder contextUriBuffer = new StringBuilder();
if (httpRequest.getContextPath() != null) {
contextUriBuffer.append(httpRequest.getContextPath());
}
if (httpRequest.getServletPath() != null) {
contextUriBuffer.append(httpRequest.getServletPath());
}
if (httpRequest.getPathInfo() != null) {
contextUriBuffer.append(httpRequest.getPathInfo());
}
contextUri = contextUriBuffer.toString();
List<String> pathItemList = StringUtil.split(httpRequest.getPathInfo(), "/");
String viewName = "";
if (pathItemList != null) {
viewName = pathItemList.get(0);
}
String requestUri = UtilHttp.getRequestUriFromTarget(httpRequest.getRequestURI());
// check to make sure the requested url is allowed
if (!allowedPathList.contains(requestPath) && !allowedPathList.contains(requestInfo) && !allowedPathList.contains(httpRequest.getServletPath()) && !allowedPathList.contains(requestUri) && !allowedPathList.contains("/" + viewName) && (UtilValidate.isEmpty(requestPath) && UtilValidate.isEmpty(httpRequest.getServletPath()) && !uris.contains(viewName))) {
String filterMessage = "[Filtered request]: " + contextUri;
if (redirectPath == null) {
if (UtilValidate.isEmpty(viewName)) {
// redirect without any url change in browser
RequestDispatcher rd = request.getRequestDispatcher(SeoControlServlet.getDefaultPage());
rd.forward(request, response);
} else {
int error = 404;
if (UtilValidate.isNotEmpty(errorCode)) {
try {
error = Integer.parseInt(errorCode);
} catch (NumberFormatException nfe) {
Debug.logWarning(nfe, "Error code specified would not parse to Integer : " + errorCode, module);
}
}
filterMessage = filterMessage + " (" + error + ")";
httpResponse.sendError(error, contextUri);
request.setAttribute("filterRequestUriError", contextUri);
}
} else {
filterMessage = filterMessage + " (" + redirectPath + ")";
if (!redirectPath.toLowerCase(Locale.getDefault()).startsWith("http")) {
redirectPath = httpRequest.getContextPath() + redirectPath;
}
// httpResponse.sendRedirect(redirectPath);
if ("".equals(uri) || "/".equals(uri)) {
// redirect without any url change in browser
RequestDispatcher rd = request.getRequestDispatcher(redirectPath);
rd.forward(request, response);
} else {
// redirect with url change in browser
httpResponse.setStatus(SeoConfigUtil.getDefaultResponseCode());
httpResponse.setHeader("Location", redirectPath);
}
}
Debug.logWarning(filterMessage, module);
return;
} else if ((allowedPathList.contains(requestPath) || allowedPathList.contains(requestInfo) || allowedPathList.contains(httpRequest.getServletPath()) || allowedPathList.contains(requestUri) || allowedPathList.contains("/" + viewName)) && !webServlets.contains(httpRequest.getServletPath())) {
request.setAttribute(SeoControlServlet.REQUEST_IN_ALLOW_LIST, Boolean.TRUE);
}
}
// we're done checking; continue on
chain.doFilter(httpRequest, httpResponse);
}
use of org.apache.ofbiz.webapp.control.ConfigXMLReader.ControllerConfig in project ofbiz-framework by apache.
the class OfbizUrlBuilder method from.
/**
* Returns an <code>OfbizUrlBuilder</code> instance.
*
* @param request
* @throws GenericEntityException
* @throws WebAppConfigurationException
*/
public static OfbizUrlBuilder from(HttpServletRequest request) throws GenericEntityException, WebAppConfigurationException {
Assert.notNull("request", request);
OfbizUrlBuilder builder = (OfbizUrlBuilder) request.getAttribute("_OFBIZ_URL_BUILDER_");
if (builder == null) {
WebSiteProperties webSiteProps = WebSiteProperties.from(request);
URL url = ConfigXMLReader.getControllerConfigURL(request.getServletContext());
ControllerConfig config = ConfigXMLReader.getControllerConfig(url);
String servletPath = (String) request.getAttribute("_CONTROL_PATH_");
builder = new OfbizUrlBuilder(config, webSiteProps, servletPath);
request.setAttribute("_OFBIZ_URL_BUILDER_", builder);
}
return builder;
}
Aggregations