You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/10/18 23:30:30 UTC
[sling-org-apache-sling-tooling-support-install] 02/18: SLING-3019
- Provide a mechanism to install a bundle based on a directory
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-tooling-support-install.git
commit fddb6be35baab1bf6e4ee9aed201d53dcb92d11f
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Tue Oct 22 14:31:34 2013 +0000
SLING-3019 - Provide a mechanism to install a bundle based on a
directory
Added JSON rendering of responses.
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1534644 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 18 ++++++++
.../support/install/impl/InstallServlet.java | 22 ++++++++++
.../support/install/impl/InstallationResult.java | 51 ++++++++++++++++++++++
3 files changed, 91 insertions(+)
diff --git a/pom.xml b/pom.xml
index 85e151a..0ec7b01 100644
--- a/pom.xml
+++ b/pom.xml
@@ -81,5 +81,23 @@
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.commons.json</artifactId>
+ <version>2.0.6</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.4</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.4</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java b/src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java
index 3c6f48d..765eda7 100644
--- a/src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java
+++ b/src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java
@@ -18,6 +18,7 @@ package org.apache.sling.tooling.support.install.impl;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -73,9 +74,20 @@ public class InstallServlet extends HttpServlet {
if ( dirPath == null ) {
logger.error("No dir parameter specified : {}", req.getParameterMap());
resp.setStatus(500);
+ InstallationResult result = new InstallationResult(false, "No dir parameter specified: "
+ + req.getParameterMap());
+ result.render(resp.getWriter());
return;
}
final File dir = new File(dirPath);
+ installBasedOnDirectory(resp, dir);
+ }
+
+ private void installBasedOnDirectory(HttpServletResponse resp, final File dir) throws FileNotFoundException,
+ IOException {
+
+ InstallationResult result = null;
+
if ( dir.exists() && dir.isDirectory() ) {
logger.info("Checking dir {} for bundle install", dir);
final File manifestFile = new File(dir, JarFile.MANIFEST_NAME);
@@ -110,16 +122,21 @@ public class InstallServlet extends HttpServlet {
final Bundle b = bundleContext.installBundle(dir.getAbsolutePath(), in);
b.start();
}
+ result = new InstallationResult(true, null);
resp.setStatus(200);
+ result.render(resp.getWriter());
return;
} catch ( final BundleException be ) {
logger.info("Unable to install/update bundle from dir " + dir, be);
+ result = new InstallationResult(false,
+ "Unable to install/update bundle from dir " + dir);
}
} finally {
tempFile.delete();
}
} else {
logger.info("Manifest in {} does not have a symbolic name", dir);
+ result = new InstallationResult(false, "Manifest in " + dir + " does not have a symbolic name");
}
} finally {
if ( fis != null ) {
@@ -127,12 +144,17 @@ public class InstallServlet extends HttpServlet {
}
}
} else {
+ result = new InstallationResult(false, "Dir " + dir + " does not have a manifest");
logger.info("Dir {} does not have a manifest", dir);
}
} else {
+ result = new InstallationResult(false, "Dir " + dir + " does not exist");
logger.info("Dir {} does not exist", dir);
}
resp.setStatus(500);
+ if (result != null) {
+ result.render(resp.getWriter());
+ }
}
private static void createJar(final File sourceDir, final File jarFile, final Manifest mf)
diff --git a/src/main/java/org/apache/sling/tooling/support/install/impl/InstallationResult.java b/src/main/java/org/apache/sling/tooling/support/install/impl/InstallationResult.java
new file mode 100644
index 0000000..c498d88
--- /dev/null
+++ b/src/main/java/org/apache/sling/tooling/support/install/impl/InstallationResult.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.tooling.support.install.impl;
+
+import java.io.Writer;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.sling.commons.json.JSONException;
+import org.apache.sling.commons.json.io.JSONWriter;
+
+public class InstallationResult {
+
+ private final boolean status;
+ private final String message;
+
+ public InstallationResult(boolean status, String message) {
+ this.status = status;
+ this.message = message;
+ }
+
+ public void render(Writer out) {
+
+ try {
+ JSONWriter writer = new JSONWriter(out);
+ writer.object();
+ writer.key("status").value(status ? "OK" : "FAILURE");
+ if (!StringUtils.isEmpty(message)) {
+ writer.key("message").value(message);
+ }
+ writer.endObject();
+ } catch (JSONException e) {
+ // never happens
+ throw new RuntimeException(e);
+ }
+ }
+
+}
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.