Skip to content

Commit

Permalink
fix for png/gif resource mounting in gui, it had classpath loading is…
Browse files Browse the repository at this point in the history
…sues.
  • Loading branch information
1azyman committed Jun 23, 2014
1 parent 3859d6e commit 00126eb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 112 deletions.
Expand Up @@ -22,17 +22,12 @@
import com.evolveum.midpoint.model.api.TaskService;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.crypto.Protector;
import com.evolveum.midpoint.schema.result.OperationResultStatus;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.task.api.TaskListener;
import com.evolveum.midpoint.task.api.TaskManager;
import com.evolveum.midpoint.task.api.TaskRunResult;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.application.DescriptorLoader;
import com.evolveum.midpoint.web.component.GuiComponents;
import com.evolveum.midpoint.web.component.atmosphere.NotifyMessage;
import com.evolveum.midpoint.web.page.admin.home.PageDashboard;
import com.evolveum.midpoint.web.page.error.PageError;
import com.evolveum.midpoint.web.page.error.PageError401;
Expand All @@ -41,13 +36,10 @@
import com.evolveum.midpoint.web.page.login.PageLogin;
import com.evolveum.midpoint.web.resource.img.ImgResources;
import com.evolveum.midpoint.web.util.MidPointPageParametersEncoder;
import com.evolveum.midpoint.web.util.WebMiscUtil;
import com.evolveum.midpoint.wf.api.WorkflowManager;

import org.apache.commons.configuration.Configuration;
import org.apache.wicket.RuntimeConfigurationType;
import org.apache.wicket.atmosphere.EventBus;
import org.apache.wicket.atmosphere.config.AtmosphereLogLevel;
import org.apache.wicket.authroles.authentication.AbstractAuthenticatedWebSession;
import org.apache.wicket.authroles.authentication.AuthenticatedWebApplication;
import org.apache.wicket.core.request.handler.PageProvider;
Expand All @@ -64,10 +56,16 @@
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
import org.apache.wicket.util.lang.Bytes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.FilenameFilter;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
* @author lazyman
Expand Down Expand Up @@ -144,10 +142,10 @@ public void init() {
appSettings.setInternalErrorPage(PageError.class);
appSettings.setPageExpiredErrorPage(PageError.class);

mount(new MountedMapper("/error",PageError.class, MidPointPageParametersEncoder.ENCODER));
mount(new MountedMapper("/error/401",PageError401.class, MidPointPageParametersEncoder.ENCODER));
mount(new MountedMapper("/error/403",PageError403.class, MidPointPageParametersEncoder.ENCODER));
mount(new MountedMapper("/error/404",PageError404.class, MidPointPageParametersEncoder.ENCODER));
mount(new MountedMapper("/error", PageError.class, MidPointPageParametersEncoder.ENCODER));
mount(new MountedMapper("/error/401", PageError401.class, MidPointPageParametersEncoder.ENCODER));
mount(new MountedMapper("/error/403", PageError403.class, MidPointPageParametersEncoder.ENCODER));
mount(new MountedMapper("/error/404", PageError404.class, MidPointPageParametersEncoder.ENCODER));

getRequestCycleListeners().add(new AbstractRequestCycleListener() {

Expand All @@ -157,67 +155,32 @@ public IRequestHandler onException(RequestCycle cycle, Exception ex) {
}
});

// todo wicket atmosphere was disabled because of form file upload and redirection url problems.
// //ajax push (just an experiment)
// eventBus = new EventBus(this);
// eventBus.getParameters().setLogLevel(AtmosphereLogLevel.DEBUG);
//
// //enable simple task notifications here
// taskManager.registerTaskListener(new TaskListener() {
//
// @Override
// public void onTaskStart(Task task) {
// EventBus bus = getEventBus();
// bus.post(new NotifyMessage("Task start", WebMiscUtil.getOrigStringFromPoly(task.getName()) + " started.",
// OperationResultStatus.SUCCESS));
// }
//
// @Override
// public void onTaskFinish(Task task, TaskRunResult runResult) {
// EventBus bus = getEventBus();
// bus.post(new NotifyMessage("Task finish", WebMiscUtil.getOrigStringFromPoly(task.getName()) + " finished.",
// OperationResultStatus.parseStatusType(task.getResultStatus())));
// }
//
// @Override
// public void onTaskThreadStart(Task task, boolean isRecovering) {
//
// }
//
// @Override
// public void onTaskThreadFinish(Task task) {
//
// }
// });

//descriptor loader, used for customization
new DescriptorLoader().loadData(this);
}

private void mountFiles(String path, Class<?> clazz) {
try {
String absPath = getServletContext().getRealPath("WEB-INF/classes") + "/"
+ clazz.getPackage().getName().replace('.', '/');
List<Resource> list = new ArrayList<>();
String packagePath = clazz.getPackage().getName().replace('.', '/');

File folder = new File(absPath);
mountFiles(path, clazz, folder);
} catch (Exception ex) {
LoggingUtils.logException(LOGGER, "Couldn't mount files", ex);
}
}

private void mountFiles(String path, Class<?> clazz, File folder) {
File[] files = folder.listFiles(new ResourceFileFilter());
for (File file : files) {
if (!file.exists()) {
LOGGER.warn("Couldn't mount resource {}.", new Object[]{file.getPath()});
continue;
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] res = resolver.getResources("classpath:" + packagePath + "/*.png");
if (res != null) {
list.addAll(Arrays.asList(res));
}
res = resolver.getResources("classpath:" + packagePath + "/*.gif");
if (res != null) {
list.addAll(Arrays.asList(res));
}
if (file.isDirectory()) {
mountFiles(path + "/" + file.getName(), clazz, file);
} else {

for (Resource resource : list) {
URI uri = resource.getURI();
File file = new File(uri.toString());
mountResource(path + "/" + file.getName(), new SharedResourceReference(clazz, file.getName()));
}
} catch (Exception ex) {
LoggingUtils.logException(LOGGER, "Couldn't mount files", ex);
}
}

Expand Down
49 changes: 0 additions & 49 deletions gui/admin-gui/src/main/webapp/WEB-INF/web.xml
Expand Up @@ -110,55 +110,6 @@
<dispatcher>ERROR</dispatcher>
</filter-mapping>

<!--<servlet>-->
<!--<description>Atmospherefilter</description>-->
<!--<servlet-name>Atmospherefilter</servlet-name>-->
<!--<servlet-class>org.atmosphere.cpr.AtmosphereServlet</servlet-class>-->
<!--<init-param>-->
<!--<param-name>configuration</param-name>-->
<!--<param-value>development</param-value>-->
<!--&lt;!&ndash;<param-value>deployment</param-value>&ndash;&gt;-->
<!--</init-param>-->
<!--<init-param>-->
<!--<param-name>applicationBean</param-name>-->
<!--<param-value>midpointApplication</param-value>-->
<!--</init-param>-->
<!--<init-param>-->
<!--<param-name>applicationFactoryClassName</param-name>-->
<!--<param-value>org.apache.wicket.spring.SpringWebApplicationFactory</param-value>-->
<!--</init-param>-->
<!--<init-param>-->
<!--<param-name>org.atmosphere.useWebSocket</param-name>-->
<!--<param-value>true</param-value>-->
<!--</init-param>-->
<!--<init-param>-->
<!--<param-name>org.atmosphere.useNative</param-name>-->
<!--<param-value>true</param-value>-->
<!--</init-param>-->
<!--<init-param>-->
<!--<param-name>org.atmosphere.cpr.sessionSupport</param-name>-->
<!--<param-value>true</param-value>-->
<!--</init-param>-->
<!--<init-param>-->
<!--<param-name>filterMappingUrlPattern</param-name>-->
<!--<param-value>/*</param-value>-->
<!--</init-param>-->
<!--<init-param>-->
<!--<param-name>org.atmosphere.websocket.WebSocketProtocol</param-name>-->
<!--<param-value>org.atmosphere.websocket.protocol.EchoProtocol</param-value>-->
<!--</init-param>-->
<!--<init-param>-->
<!--<param-name>org.atmosphere.cpr.broadcastFilterClasses</param-name>-->
<!--<param-value>org.apache.wicket.atmosphere.TrackMessageSizeFilter</param-value>-->
<!--</init-param>-->
<!--<load-on-startup>1</load-on-startup>-->
<!--&lt;!&ndash;<async-supported>true</async-supported> supported in servlet 3.0 (tomcat 7) &ndash;&gt;-->
<!--</servlet>-->
<!--<servlet-mapping>-->
<!--<servlet-name>Atmospherefilter</servlet-name>-->
<!--<url-pattern>/*</url-pattern>-->
<!--</servlet-mapping>-->

<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>
Expand Down

0 comments on commit 00126eb

Please sign in to comment.