Skip to content

Commit e96c75a

Browse files
author
eschleb
committed
Adjust ReregisterServletsTask - delete servlet config and recreate it
1 parent 28cd41d commit e96c75a

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

common-task/src/main/java/com/merkle/oss/magnolia/setup/task/common/ReregisterServletsTask.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@
88
import info.magnolia.module.model.ModuleDefinition;
99
import info.magnolia.module.model.ServletDefinition;
1010

11+
import java.util.Optional;
12+
1113
import javax.inject.Inject;
14+
import javax.jcr.Node;
15+
import javax.jcr.PathNotFoundException;
1216
import javax.jcr.RepositoryException;
1317
import javax.jcr.Session;
1418

19+
import com.machinezoo.noexception.Exceptions;
1520
import com.merkle.oss.magnolia.setup.task.type.InstallAndUpdateTask;
1621

1722
/**
@@ -28,7 +33,7 @@ public ReregisterServletsTask(final NodeNameHelper nodeNameHelper) {
2833
}
2934

3035
@Override
31-
public void execute(InstallContext installContext) throws TaskExecutionException {
36+
public void execute(final InstallContext installContext) throws TaskExecutionException {
3237
final ModuleDefinition moduleDefinition = installContext.getCurrentModuleDefinition();
3338
for (ServletDefinition servletDefinition : moduleDefinition.getServlets()) {
3439
addTask(new ReregisterServletTask(servletDefinition, nodeNameHelper));
@@ -43,17 +48,20 @@ public ReregisterServletTask(ServletDefinition servletDefinition, NodeNameHelper
4348

4449
@Override
4550
public void execute(final InstallContext installContext) throws TaskExecutionException {
46-
if(!isRegistered(installContext)) {
51+
try {
52+
getServletNode(installContext).ifPresent(servletNode -> Exceptions.wrap().run(servletNode::remove));
4753
super.execute(installContext);
54+
} catch (Exception e) {
55+
throw new TaskExecutionException("Failed to reregister servlet "+getServletDefinition().getName(), e);
4856
}
4957
}
5058

51-
private boolean isRegistered(final InstallContext installContext) throws TaskExecutionException {
59+
private Optional<Node> getServletNode(final InstallContext installContext) throws RepositoryException {
5260
try {
5361
final Session session = installContext.getConfigJCRSession();
54-
return session.getRootNode().hasNode(DEFAULT_SERVLET_FILTER_PATH + "/" + getServletDefinition().getName());
55-
} catch (RepositoryException e) {
56-
throw new TaskExecutionException("Failed to reregister servlet "+getServletDefinition().getName(), e);
62+
return Optional.of(session.getRootNode().getNode(DEFAULT_SERVLET_FILTER_PATH + "/" + getServletDefinition().getName()));
63+
} catch (PathNotFoundException e) {
64+
return Optional.empty();
5765
}
5866
}
5967
}

0 commit comments

Comments
 (0)