Skip to content

Commit

Permalink
NXP-20045: WebEngine must always be called in a transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
efge authored and nuxeojenkins committed Jul 12, 2016
1 parent 5e66446 commit edbbc91
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 264 deletions.
11 changes: 5 additions & 6 deletions nuxeo-features/nuxeo-automation/nuxeo-automation-server/pom.xml
Expand Up @@ -47,6 +47,10 @@
<groupId>org.nuxeo.runtime</groupId>
<artifactId>nuxeo-runtime</artifactId>
</dependency>
<dependency>
<groupId>org.nuxeo.runtime</groupId>
<artifactId>nuxeo-runtime-jtajca</artifactId>
</dependency>
<dependency>
<groupId>org.nuxeo.common</groupId>
<artifactId>nuxeo-common</artifactId>
Expand Down Expand Up @@ -153,11 +157,6 @@
<artifactId>jetty-util</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.nuxeo.runtime</groupId>
<artifactId>nuxeo-runtime-jtajca</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
Expand All @@ -166,4 +165,4 @@


</dependencies>
</project>
</project>
Expand Up @@ -61,6 +61,7 @@
import org.nuxeo.ecm.webengine.model.impl.ResourceTypeImpl;
import org.nuxeo.runtime.api.Framework;
import org.nuxeo.runtime.services.config.ConfigurationService;
import org.nuxeo.runtime.transaction.TransactionHelper;

/**
* Exposes {@link Batch} as a JAX-RS resource
Expand Down Expand Up @@ -125,7 +126,15 @@ protected int getUploadWaitTimeout() {
@POST
@Path("/upload")
public Object doPost(@Context HttpServletRequest request) throws IOException {
TransactionHelper.commitOrRollbackTransaction();
try {
return uploadNoTransaction(request);
} finally {
TransactionHelper.startTransaction();
}
}

protected Object uploadNoTransaction(@Context HttpServletRequest request) throws IOException {
boolean useIFrame = false;

// Parameters are passed as request header
Expand Down
Expand Up @@ -12,8 +12,7 @@ Nuxeo-Component: OSGI-INF/AutomationServer.xml,
OSGI-INF/auth-contrib.xml,
OSGI-INF/batchmanager-framework.xml,
OSGI-INF/binding-contrib.xml,
OSGI-INF/pageprovider-contrib.xml,
OSGI-INF/batch-upload-filter-contrib.xml
OSGI-INF/pageprovider-contrib.xml
Nuxeo-AllowOverride: true
Import-Package: javax.mail,
javax.mail.internet,
Expand Down

This file was deleted.

Expand Up @@ -63,6 +63,7 @@
import org.nuxeo.ecm.webengine.model.impl.AbstractResource;
import org.nuxeo.ecm.webengine.model.impl.ResourceTypeImpl;
import org.nuxeo.runtime.api.Framework;
import org.nuxeo.runtime.transaction.TransactionHelper;

/**
* Batch upload endpoint.
Expand Down Expand Up @@ -114,6 +115,17 @@ public Response initBatch() throws IOException {
@Path("{batchId}/{fileIdx}")
public Response upload(@Context HttpServletRequest request, @PathParam(REQUEST_BATCH_ID) String batchId,
@PathParam(REQUEST_FILE_IDX) String fileIdx) throws IOException {
TransactionHelper.commitOrRollbackTransaction();
try {
return uploadNoTransaction(request, batchId, fileIdx);
} finally {
TransactionHelper.startTransaction();
}
}

protected Response uploadNoTransaction(@Context HttpServletRequest request,
@PathParam(REQUEST_BATCH_ID) String batchId, @PathParam(REQUEST_FILE_IDX) String fileIdx)
throws IOException {

BatchManager bm = Framework.getService(BatchManager.class);
if (!bm.hasBatch(batchId)) {
Expand Down
Expand Up @@ -8,5 +8,4 @@ Nuxeo-WebModule: org.nuxeo.ecm.restapi.server.jaxrs.APIModule;name=api;extends=a
Nuxeo-Component: OSGI-INF/docviewurl-service-contrib.xml,
OSGI-INF/auth-contrib.xml,
OSGI-INF/searchadapter-pp-contrib.xml,
OSGI-INF/restapi-batch-upload-filter-contrib.xml,
OSGI-INF/json-enrichers-contrib.xml

This file was deleted.

Expand Up @@ -19,106 +19,12 @@
*/
package org.nuxeo.ecm.webengine;

import org.nuxeo.common.xmap.annotation.XNode;
import org.nuxeo.common.xmap.annotation.XObject;
import org.nuxeo.ecm.webengine.util.PathMatcher;

/**
* Configure how a given path is handled by the WebEngine filter.
* <p>
* If <b>autoTx</b> is true (which is the default) then a transaction will be started each time a path matching the
* given path specification is requested. (the transaction is started in a filter before the JAX-RS resource is called
* and closed after the response is sent to the output stream). If false then no transaction handling is done. The
* default is to start a transaction for any path but: [^/]+/skin/.*
* <p>
* The <b>value</b> attribute is required and must be used to specify the path pattern. The path pattern is either a
* prefix or a regular expression. If the <b>regex</b> parameter is true (the default is false) then the value will be
* expected to be a regular expression. A prefix denotes a path starting with 'prefix'. Paths are relative to the
* webengine servlet (i.e. they correspond to the servlet path info in the JAX-RS servlet) - and always begin with a
* '/'.
* Obsolete since 8.4, transactions are always active.
*/
@XObject("path")
public class PathDescriptor implements Comparable<PathDescriptor> {

@XNode("@value")
protected String value;

@XNode("@regex")
protected boolean regex = false;

@XNode("@autoTx")
protected Boolean autoTx;

protected PathMatcher matcher;

public PathDescriptor() {
}

public PathMatcher getMatcher() {
return matcher;
}

public String getValue() {
return value;
}

public Boolean getAutoTx() {
return autoTx;
}

public boolean isAutoTx(boolean defaultValue) {
return autoTx == null ? defaultValue : autoTx.booleanValue();
}

public PathMatcher createMatcher() {
if (value != null) {
if (!value.startsWith("/")) {
value = "/" + value;
}
matcher = regex ? PathMatcher.getRegexMatcher(value) : PathMatcher.getPrefixMatcher(value);
} else {
throw new IllegalArgumentException("Path value is required");
}
return matcher;
}

public boolean match(String path) {
return matcher.match(path);
}

@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof PathDescriptor) {
PathDescriptor pd = ((PathDescriptor) obj);
return value != null && value.equals(pd.value) || value == pd.value;
}
return false;
}

@Override
public int hashCode() {
return value.hashCode();
}

@Override
public String toString() {
return value + "; autoTx: " + autoTx;
}

@Override
public int compareTo(PathDescriptor o) {
if (regex != o.regex) {
return regex ? 1 : -1;
}
int len1 = value.length();
int len2 = o.value.length();
if (len1 == len2) {
return value.compareTo(o.value);
}
return len2 - len1;
}
public class PathDescriptor {

}

This file was deleted.

Expand Up @@ -120,8 +120,6 @@ public static WebContext getActiveContext() {

protected final WebLoader webLoader;

protected RequestConfiguration requestConfig;

protected volatile boolean isDirty;

public WebEngine(File root) {
Expand Down Expand Up @@ -152,13 +150,6 @@ public WebEngine(ResourceRegistry registry, File root) {
rendering = new FreemarkerEngine();
rendering.setResourceLocator(this);
rendering.setSharedVariable("env", getEnvironment());

requestConfig = new RequestConfiguration();

}

public RequestConfiguration getRequestConfiguration() {
return requestConfig;
}

/**
Expand Down
Expand Up @@ -120,8 +120,7 @@ public void registerContribution(Object contribution, String extensionPoint, Com
// Form form = (Form)contribution;
// engine.getFormManager().registerForm(form);
} else if (extensionPoint.equals(REQUEST_CONFIGURATION_XP)) {
PathDescriptor pd = (PathDescriptor) contribution;
engine.getRequestConfiguration().addPathDescriptor(pd);
log.warn("Extension point " + REQUEST_CONFIGURATION_XP + " is obsolete since 8.4, transactions are always active");
}
}

Expand All @@ -139,9 +138,6 @@ public void unregisterContribution(Object contribution, String extensionPoint, C
// } else if (extensionPoint.endsWith(FORM_XP)) {
// Form form = (Form)contribution;
// engine.getFormManager().unregisterForm(form.getId());
} else if (extensionPoint.equals(REQUEST_CONFIGURATION_XP)) {
PathDescriptor pd = (PathDescriptor) contribution;
engine.getRequestConfiguration().removePathDescriptor(pd);
}
}

Expand Down

0 comments on commit edbbc91

Please sign in to comment.