Skip to content

Commit

Permalink
release 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentvdl committed Mar 13, 2015
1 parent 1591aa7 commit b579ac9
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 16 deletions.
3 changes: 3 additions & 0 deletions alfresco-module/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,6 @@ task amp(type: Zip, dependsOn: jar) {
}

build.dependsOn("amp")

publish.dependsOn("amp")
publishToMavenLocal.dependsOn("amp")
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ subprojects {
}

group = 'com.github.dynamicextensionsalfresco'
version = '1.1.3'
version = '1.2.0'

configurations.all {
exclude group: 'jaxen'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,24 @@ public static boolean isDynamicExtension(final Bundle bundle) {
@Autowired @Resource(name = "webscripts.container")
org.springframework.extensions.webscripts.Container webScriptsContainer;

/**
* async backlog of bundles to start when the package-admin is done refreshing dependencies
*/
private final Queue<Bundle> bundlesToStart = new ConcurrentLinkedQueue<Bundle>();

/**
* installBundle operations block on this queue until either an error or successful install is reported
*/
private final BlockingQueue<InstallResult> installResults = new LinkedBlockingDeque<InstallResult>();

/* Main operations */

@PostConstruct
void registerEventListeners() throws Exception {
// get notified of Spring context start failures
bundleContext.registerService(EventListener.class, this, null);

// get notified of PackageAdmin refresh events
bundleContext.addFrameworkListener(this);
}

Expand Down Expand Up @@ -237,6 +245,8 @@ protected Bundle doInstallBundleInRepository(File tempFile, String fileName) thr
final String filename = identifier.toJarFilename();
final String location = generateRepositoryLocation(filename);
Bundle bundle = bundleContext.getBundle(location);

// a classpath bundle cannot be replaced in a persistent way, so we only do temporary updates here
boolean classpathBundle = false;
if (bundle == null) {
bundle = findBundleBySymbolicName(identifier);
Expand All @@ -257,7 +267,6 @@ protected Bundle doInstallBundleInRepository(File tempFile, String fileName) thr
final InputStream in = createStreamForFile(tempFile);
if (bundle != null) {
// we stop and delay restarting the bundle, as otherwise, the refresh would cause 2 immediate restarts,
// this in turn causes havoc upon the asynchronous Spring integration startup
bundle.stop();
bundle.update(in);

Expand Down Expand Up @@ -289,7 +298,7 @@ protected Bundle doInstallBundleInRepository(File tempFile, String fileName) thr
}

try {
evaluateInstallationResult(installResults.poll(15, TimeUnit.SECONDS));
evaluateInstallationResult(installResults.poll(1, TimeUnit.MINUTES));
} catch (InterruptedException tx) {
logger.warn("Timed out waiting for an installation result", tx);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private JsonMessage(JSONObject jsonObject, Integer status) {

@Override
public void resolve() throws Exception {
getResponse().getWriter().append(jsonObject.toString(2));
getWriter().append(jsonObject.toString(2));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.github.dynamicextensionsalfresco.controlpanel.template.TemplateBundle;
import com.github.dynamicextensionsalfresco.controlpanel.template.Variables;
import com.github.dynamicextensionsalfresco.webscripts.annotations.*;
import com.github.dynamicextensionsalfresco.webscripts.resolutions.ErrorResolution;
import com.github.dynamicextensionsalfresco.webscripts.resolutions.StatusResolution;
import com.github.dynamicextensionsalfresco.webscripts.resolutions.RedirectResolution;
import com.github.dynamicextensionsalfresco.webscripts.resolutions.Resolution;
import com.github.dynamicextensionsalfresco.webscripts.resolutions.TemplateResolution;
Expand Down Expand Up @@ -47,7 +47,7 @@ public Resolution show(final @Attribute Bundle bundle, @Attribute final Response
}
model.put(Variables.BUNDLE, new TemplateBundle(bundle));
} else {
return new ErrorResolution(HttpServletResponse.SC_NOT_FOUND);
return new StatusResolution(HttpServletResponse.SC_NOT_FOUND);
}
return new TemplateResolution(model);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package com.github.dynamicextensionsalfresco.gradle.configuration
*/

class Versions {
String dynamicExtensions = "1.1.3"
String dynamicExtensions = "1.2.0"

String surf = "5.0.b"

Expand Down
1 change: 1 addition & 0 deletions webscripts/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ dependencies {
compile "org.springframework.extensions.surf:spring-webscripts:${project.ext.alfrescoVersion}"
compile "org.osgi:org.osgi.core:${project.ext.osgiVersion}"
compile("org.alfresco:alfresco-data-model:${project.ext.alfrescoVersion}") { transitive = false }
compile 'com.google.code.findbugs:jsr305:2.0.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.github.dynamicextensionsalfresco.webscripts.AnnotationWebscriptResponse;
import org.alfresco.repo.content.MimetypeMap;

import javax.annotation.Nonnull;
import javax.servlet.http.HttpServletResponse;

/**
Expand All @@ -12,22 +13,31 @@
public abstract class AbstractJsonResolution extends AbstractResolution {
public static final String UTF_8 = "UTF-8";

private int status = HttpServletResponse.SC_OK;
private Integer status = null;

protected AbstractJsonResolution() {
}

/**
* @deprecated use {@link #withStatus(int)} instead
*
* @param status http status code
*/
protected AbstractJsonResolution(int status) {
this.status = status;
}

@Override
public void resolve(AnnotationWebScriptRequest request, AnnotationWebscriptResponse response,
ResolutionParameters params) throws Exception {
public void resolve(@Nonnull AnnotationWebScriptRequest request,
@Nonnull AnnotationWebscriptResponse response,
@Nonnull ResolutionParameters params) throws Exception {
super.resolve(request, response, params);
response.setContentType(MimetypeMap.MIMETYPE_JSON);
response.setContentEncoding(UTF_8);
response.setHeader("Cache-Control", "no-cache");
response.setStatus(status);

if (status != null) {
response.setStatus(status);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,70 @@
import org.springframework.extensions.webscripts.WebScriptResponse;
import org.springframework.util.StringUtils;

import javax.annotation.Nonnull;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;

/**
* Template for other Resolution implementations
*
* @author Laurent Van der Linden
*/
public abstract class AbstractResolution implements Resolution {
private AnnotationWebScriptRequest request;
private AnnotationWebscriptResponse response;
private ResolutionParameters params;

@Override
public void resolve(AnnotationWebScriptRequest request, AnnotationWebscriptResponse response, ResolutionParameters params) throws Exception {
private String encoding;
private String contentType;
private int statusCode = HttpServletResponse.SC_OK;

public void resolve(@Nonnull AnnotationWebScriptRequest request,
@Nonnull AnnotationWebscriptResponse response,
@Nonnull ResolutionParameters params) throws Exception {
this.request = request;
this.response = response;
this.params = params;

if (this.contentType != null) {
response.setContentType(this.contentType);
}

if (this.encoding != null) {
response.setContentEncoding(this.encoding);
}

if (this.statusCode != HttpServletResponse.SC_OK) {
response.setStatus(this.statusCode);
}

resolve();
}

public AbstractResolution withContentType(@Nonnull final String contentType) {
this.contentType = contentType;
return this;
}

public AbstractResolution withEncoding(@Nonnull final String encoding) {
this.encoding = encoding;
return this;
}

public AbstractResolution withHeader(@Nonnull final String headerName, @Nonnull final String headerValue) {
// we set these directly as they are unlikely to be overruled by subclasses
getResponse().setHeader(headerName, headerValue);
return this;
}

public AbstractResolution withStatus(final int statusCode) {
this.statusCode = statusCode;
return this;
}

protected void addCacheControlHeaders(final WebScriptResponse response, ResolutionParameters params) {
final Description.RequiredCache requiredCache = params.getDescription().getRequiredCache();
if (requiredCache != null) {
Expand All @@ -51,6 +95,10 @@ protected AnnotationWebscriptResponse getResponse() {
return response;
}

protected Writer getWriter() throws IOException {
return getResponse().getWriter();
}

protected ResolutionParameters getParams() {
return params;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

/**
* @author Laurent Van der Linden
*
* @deprecated replaced with {@see StatusResolution}
*/
public class ErrorResolution implements Resolution {
private int status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.github.dynamicextensionsalfresco.webscripts.AnnotationWebscriptResponse;
import org.springframework.util.Assert;

import javax.annotation.Nonnull;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

Expand All @@ -18,7 +19,9 @@ public RedirectResolution(String path) {
}

@Override
public void resolve(AnnotationWebScriptRequest request, AnnotationWebscriptResponse response, ResolutionParameters params) throws IOException {
public void resolve(@Nonnull AnnotationWebScriptRequest request,
@Nonnull AnnotationWebscriptResponse response,
@Nonnull ResolutionParameters params) throws IOException {
Assert.hasText(path);
if (path.startsWith("/") == false) {
path = "/" + path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
import com.github.dynamicextensionsalfresco.webscripts.AnnotationWebScriptRequest;
import com.github.dynamicextensionsalfresco.webscripts.AnnotationWebscriptResponse;

import javax.annotation.Nonnull;

/**
* Basic contract for an operation that can generate output based on request data or implementation state or behaviour.
* <br/>
* This is the preferred return type for @Uri methods as it allows for reusable response handling.
*
* @author Laurent Van der Linden
*/
public interface Resolution {
void resolve(final AnnotationWebScriptRequest request, final AnnotationWebscriptResponse response,
final ResolutionParameters params) throws Exception;
void resolve(@Nonnull final AnnotationWebScriptRequest request,
@Nonnull final AnnotationWebscriptResponse response,
@Nonnull final ResolutionParameters params) throws Exception;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.github.dynamicextensionsalfresco.webscripts.resolutions;

/**
* @author Laurent Van der Linden
*/
public class StatusResolution extends AbstractResolution {
private int status;
private String message;

public StatusResolution(int status) {
this.status = status;
}

public StatusResolution(int status, String message) {
this.status = status;
this.message = message;
}

@Override
public void resolve() throws Exception {
getResponse().setStatus(status);
if (message != null) {
getResponse().getWriter().append(message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
* Can be used directly by controllers or implicitly by returning a Map.
*
* @author Laurent Van der Linden
*/
public class TemplateResolution extends AbstractResolution {
Expand All @@ -26,6 +29,10 @@ public class TemplateResolution extends AbstractResolution {
private String template;
private Map<String,Object> model;

public TemplateResolution() {
this.model = new HashMap<String, Object>(3);
}

public TemplateResolution(Map<String, Object> model) {
this.model = model;
}
Expand Down

0 comments on commit b579ac9

Please sign in to comment.