Modified: ace/trunk/org.apache.ace.client.repository/test/org/apache/ace/client/repository/helper/bundle/impl/BundleHelperTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository/test/org/apache/ace/client/repository/helper/bundle/impl/BundleHelperTest.java?rev=1527522&r1=1527521&r2=1527522&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository/test/org/apache/ace/client/repository/helper/bundle/impl/BundleHelperTest.java (original)
+++ ace/trunk/org.apache.ace.client.repository/test/org/apache/ace/client/repository/helper/bundle/impl/BundleHelperTest.java Mon Sep 30 12:00:26 2013
@@ -55,7 +55,6 @@ public class BundleHelperTest {
@Test(groups = { UNIT })
public void testManifestExtraction() {
ArtifactResource artifact = new ArtifactResource() {
-
@Override
public InputStream openStream() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -71,6 +70,11 @@ public class BundleHelperTest {
}
@Override
+ public long getSize() throws IOException {
+ return -1L;
+ }
+
+ @Override
public URL getURL() {
return null;
}
@@ -84,7 +88,6 @@ public class BundleHelperTest {
@Test(groups = { UNIT })
public void testLocalizedManifestExtraction() {
ArtifactResource artifact = new ArtifactResource() {
-
@Override
public InputStream openStream() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -111,6 +114,11 @@ public class BundleHelperTest {
}
@Override
+ public long getSize() throws IOException {
+ return -1L;
+ }
+
+ @Override
public URL getURL() {
return null;
}
@@ -127,7 +135,6 @@ public class BundleHelperTest {
// note that we do not set the Bundle-Localization header
ArtifactResource artifact = new ArtifactResource() {
-
@Override
public InputStream openStream() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -147,6 +154,11 @@ public class BundleHelperTest {
}
@Override
+ public long getSize() throws IOException {
+ return -1L;
+ }
+
+ @Override
public URL getURL() {
return null;
}
@@ -160,7 +172,6 @@ public class BundleHelperTest {
@Test(groups = { UNIT })
public void testLocalizedManifestExtractionWithLocale() {
ArtifactResource artifact = new ArtifactResource() {
-
@Override
public InputStream openStream() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -181,6 +192,11 @@ public class BundleHelperTest {
}
@Override
+ public long getSize() throws IOException {
+ return -1L;
+ }
+
+ @Override
public URL getURL() {
return null;
}
@@ -194,7 +210,6 @@ public class BundleHelperTest {
@Test(groups = { UNIT })
public void testLocalizedManifestExtractionWithLocaleOverrule() {
ArtifactResource artifact = new ArtifactResource() {
-
@Override
public InputStream openStream() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -224,6 +239,11 @@ public class BundleHelperTest {
}
@Override
+ public long getSize() throws IOException {
+ return -1L;
+ }
+
+ @Override
public URL getURL() {
return null;
}
Modified: ace/trunk/org.apache.ace.client.repository/test/org/apache/ace/client/repository/helper/configuration/impl/ConfigurationHelperImplTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository/test/org/apache/ace/client/repository/helper/configuration/impl/ConfigurationHelperImplTest.java?rev=1527522&r1=1527521&r2=1527522&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository/test/org/apache/ace/client/repository/helper/configuration/impl/ConfigurationHelperImplTest.java (original)
+++ ace/trunk/org.apache.ace.client.repository/test/org/apache/ace/client/repository/helper/configuration/impl/ConfigurationHelperImplTest.java Mon Sep 30 12:00:26 2013
@@ -83,6 +83,11 @@ public class ConfigurationHelperImplTest
return url;
}
+ @Override
+ public long getSize() throws IOException {
+ return -1L;
+ }
+
public InputStream openStream() throws IOException {
return getURL().openStream();
}
Modified: ace/trunk/org.apache.ace.client.repository/test/org/apache/ace/client/repository/impl/ArtifactTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository/test/org/apache/ace/client/repository/impl/ArtifactTest.java?rev=1527522&r1=1527521&r2=1527522&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository/test/org/apache/ace/client/repository/impl/ArtifactTest.java (original)
+++ ace/trunk/org.apache.ace.client.repository/test/org/apache/ace/client/repository/impl/ArtifactTest.java Mon Sep 30 12:00:26 2013
@@ -64,7 +64,7 @@ public class ArtifactTest {
ArtifactHelper helper = new MockHelper("yourURL");
try {
- createArtifact("myMime", "myUrl", null, null);
+ createArtifact("myMime", "myUrl", null, null, null);
assert false : "There is no helper for this type of artifact.";
}
catch (IllegalArgumentException iae) {
@@ -73,9 +73,10 @@ public class ArtifactTest {
m_artifactRepository.addHelper("myMime", helper);
- ArtifactObject obj = createArtifact("myMime", "myUrl", null, null);
+ ArtifactObject obj = createArtifact("myMime", "myUrl", null, null, "10");
assert obj.getURL().equals("yourURL");
+ assert obj.getSize() == 10;
try {
m_artifactRepository.getHelper("yourMime");
@@ -91,12 +92,12 @@ public class ArtifactTest {
m_artifactRepository.addHelper("myMime", new MockHelper());
m_artifactRepository.addHelper(BundleHelper.MIMETYPE, new BundleHelperImpl());
- createArtifact(BundleHelper.MIMETYPE, "normalBundle", "normalBundle", null);
+ createArtifact(BundleHelper.MIMETYPE, "normalBundle", "normalBundle", null, "10");
- ArtifactObject resourceProcessor1 = createArtifact(BundleHelper.MIMETYPE, "resourceProcessor1", "resourceProcessor1", "somePID");
- ArtifactObject resourceProcessor2 = createArtifact(BundleHelper.MIMETYPE, "resourceProcessor2", "resourceProcessor2", "someOtherPID");
+ ArtifactObject resourceProcessor1 = createArtifact(BundleHelper.MIMETYPE, "resourceProcessor1", "resourceProcessor1", "somePID", "11");
+ ArtifactObject resourceProcessor2 = createArtifact(BundleHelper.MIMETYPE, "resourceProcessor2", "resourceProcessor2", "someOtherPID", "12");
- ArtifactObject myArtifact = createArtifact("myMime", "myArtifact", null, null);
+ ArtifactObject myArtifact = createArtifact("myMime", "myArtifact", null, null, "13");
assert m_artifactRepository.get().size() == 2 : "We expect to find two artifacts, but we find " + m_artifactRepository.get().size();
@@ -106,15 +107,31 @@ public class ArtifactTest {
list = m_artifactRepository.getResourceProcessors();
assert (list.size() == 2) && list.contains(resourceProcessor1) && list.contains(resourceProcessor2) : "We expect to find both our resource processors when asking for them; we find " + list.size() + " artifacts.";
- m_artifactRepository.get(m_artifactRepository.createFilter("(" + BundleHelper.MIMETYPE + "=my\\(Mi\\*me)"));
+ list = m_artifactRepository.get(m_artifactRepository.createFilter("(mimetype=myMime)"));
+ assert (list.size() == 1) && list.contains(myArtifact) : "Expected a single artifact with the specified mimetype!";
+
+ list = m_artifactRepository.get(m_artifactRepository.createFilter("(mimetype=my\\(Mi\\*me)"));
+ assert (list.size() == 0) : "Expected no artifact to match the requested filter!";
+ }
+
+ @Test( groups = { TestUtils.UNIT } )
+ public void testArtifactSizeDeterminedByRepository() throws InvalidSyntaxException {
+ m_artifactRepository.addHelper(BundleHelper.MIMETYPE, new BundleHelperImpl());
+ ArtifactObject artifact = createArtifact(BundleHelper.MIMETYPE, "normalBundle", "normalBundle", null, "10");
+
+ List<ArtifactObject> list = m_artifactRepository.get();
+ assert (list.size() == 1) && list.contains(artifact) : "Expected a single artifact with the specified mimetype!";
+
+ assert list.get(0).getSize() == 10 : "Expected the size to be filled in!";
}
- private ArtifactObject createArtifact(String mimetype, String URL, String symbolicName, String processorPID) {
+ private ArtifactObject createArtifact(String mimetype, String URL, String symbolicName, String processorPID, String size) {
Map<String, String> attributes = new HashMap<String, String>();
attributes.put(ArtifactObject.KEY_MIMETYPE, mimetype);
attributes.put(ArtifactObject.KEY_URL, URL);
- Map<String, String> tags = new HashMap<String, String>();
-
+ if (size != null) {
+ attributes.put(ArtifactObject.KEY_SIZE, size);
+ }
if (symbolicName != null) {
attributes.put(BundleHelper.KEY_SYMBOLICNAME, symbolicName);
}
@@ -122,6 +139,7 @@ public class ArtifactTest {
attributes.put(BundleHelper.KEY_RESOURCE_PROCESSOR_PID, processorPID);
}
+ Map<String, String> tags = new HashMap<String, String>();
return m_artifactRepository.create(attributes, tags);
}
}
Modified: ace/trunk/org.apache.ace.client.repository/test/org/apache/ace/client/repository/impl/ModelTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository/test/org/apache/ace/client/repository/impl/ModelTest.java?rev=1527522&r1=1527521&r2=1527522&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository/test/org/apache/ace/client/repository/impl/ModelTest.java (original)
+++ ace/trunk/org.apache.ace.client.repository/test/org/apache/ace/client/repository/impl/ModelTest.java Mon Sep 30 12:00:26 2013
@@ -36,18 +36,18 @@ import org.apache.ace.client.repository.
import org.apache.ace.client.repository.object.ArtifactObject;
import org.apache.ace.client.repository.object.DeploymentArtifact;
import org.apache.ace.client.repository.object.DeploymentVersionObject;
-import org.apache.ace.client.repository.object.TargetObject;
+import org.apache.ace.client.repository.object.DistributionObject;
import org.apache.ace.client.repository.object.Feature2DistributionAssociation;
import org.apache.ace.client.repository.object.FeatureObject;
-import org.apache.ace.client.repository.object.DistributionObject;
+import org.apache.ace.client.repository.object.TargetObject;
import org.apache.ace.client.repository.repository.Artifact2FeatureAssociationRepository;
import org.apache.ace.client.repository.repository.ArtifactRepository;
import org.apache.ace.client.repository.repository.DeploymentVersionRepository;
-import org.apache.ace.client.repository.repository.TargetRepository;
-import org.apache.ace.client.repository.repository.Feature2DistributionAssociationRepository;
-import org.apache.ace.client.repository.repository.FeatureRepository;
import org.apache.ace.client.repository.repository.Distribution2TargetAssociationRepository;
import org.apache.ace.client.repository.repository.DistributionRepository;
+import org.apache.ace.client.repository.repository.Feature2DistributionAssociationRepository;
+import org.apache.ace.client.repository.repository.FeatureRepository;
+import org.apache.ace.client.repository.repository.TargetRepository;
import org.apache.ace.test.utils.TestUtils;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Filter;
@@ -126,6 +126,21 @@ public class ModelTest {
}
/**
+ * Tests that we can create artifacts which contain a certain size (estimate). See ACE-384.
+ */
+ @Test( groups = { TestUtils.UNIT } )
+ public void testArtifactObjectSize() {
+ ArtifactObject artifactWithSize = createBasicArtifactObject("myartifact", "1.0.0", "10");
+ assert artifactWithSize.getSize() == 10 : "The artifact did not have a valid size?!";
+
+ ArtifactObject artifactWithoutSize = createBasicArtifactObject("artifactWithoutSize", "1.0.0", null);
+ assert artifactWithoutSize.getSize() == -1L : "The artifact did have a size?!";
+
+ ArtifactObject artifactWithInvalidSize = createBasicArtifactObject("artifactWithInvalidSize", "1.0.0", "xyz");
+ assert artifactWithInvalidSize.getSize() == -1L : "The artifact did have a size?!";
+ }
+
+ /**
* The artifact object can test functionality coming from
* RepositoryObjectImpl, and ArtifactRepository checks much of
* ObjectRepositoryImpl.
@@ -134,7 +149,7 @@ public class ModelTest {
@Test( groups = { TestUtils.UNIT } )
public void testArtifactObjectAndRepository() throws InvalidSyntaxException {
// Create a very simple artifact.
- ArtifactObject a = createBasicArtifactObject("myartifact", "1.0.0");
+ ArtifactObject a = createBasicArtifactObject("myartifact", "1.0.0", "1");
// Try to create an illegal one
try {
@@ -648,12 +663,18 @@ public class ModelTest {
}
private ArtifactObject createBasicArtifactObject(String symbolicName, String version) {
+ return createBasicArtifactObject(symbolicName, version, null);
+ }
+
+ private ArtifactObject createBasicArtifactObject(String symbolicName, String version, String size) {
Map<String, String> attr = new HashMap<String, String>();
attr.put(BundleHelper.KEY_SYMBOLICNAME, symbolicName);
attr.put(ArtifactObject.KEY_MIMETYPE, BundleHelper.MIMETYPE);
attr.put(ArtifactObject.KEY_URL, "http://" + symbolicName + "-v" + ((version == null) ? "null" : version));
+ if (size != null) {
+ attr.put(ArtifactObject.KEY_SIZE, size); // bytes
+ }
Map<String, String> tags = new HashMap<String, String>();
-
if (version != null) {
attr.put(BundleHelper.KEY_VERSION, version);
}
@@ -692,7 +713,7 @@ public class ModelTest {
List<DeploymentArtifactImpl> deploymentArtifacts = new ArrayList<DeploymentArtifactImpl>();
for (String s : artifacts) {
- deploymentArtifacts.add(new DeploymentArtifactImpl(s));
+ deploymentArtifacts.add(new DeploymentArtifactImpl(s, -1L));
}
return m_deploymentVersionRepository.create(attr, tags, deploymentArtifacts.toArray(new DeploymentArtifact[0]));
}
Modified: ace/trunk/org.apache.ace.deployment.itest/src/org/apache/ace/it/deployment/DeploymentIntegrationTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.deployment.itest/src/org/apache/ace/it/deployment/DeploymentIntegrationTest.java?rev=1527522&r1=1527521&r2=1527522&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.deployment.itest/src/org/apache/ace/it/deployment/DeploymentIntegrationTest.java (original)
+++ ace/trunk/org.apache.ace.deployment.itest/src/org/apache/ace/it/deployment/DeploymentIntegrationTest.java Mon Sep 30 12:00:26 2013
@@ -53,6 +53,7 @@ import org.osgi.service.event.EventConst
import org.osgi.service.event.EventHandler;
import org.osgi.service.http.HttpService;
+@SuppressWarnings("restriction")
public class DeploymentIntegrationTest extends IntegrationTestBase implements BundleListener, EventHandler {
protected void configureProvisionedServices() throws IOException {
@@ -332,7 +333,7 @@ public class DeploymentIntegrationTest e
}
private ArtifactData generateBundle(File file, String symbolicName, String version) throws Exception {
- ArtifactData bundle = new ArtifactDataImpl(file.getName(), symbolicName, version, file.toURI().toURL(), false);
+ ArtifactData bundle = new ArtifactDataImpl(file.getName(), symbolicName, file.length(), version, file.toURI().toURL(), false);
BundleStreamGenerator.generateBundle(bundle);
return bundle;
}
Modified: ace/trunk/org.apache.ace.deployment/bnd.bnd
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.deployment/bnd.bnd?rev=1527522&r1=1527521&r2=1527522&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.deployment/bnd.bnd (original)
+++ ace/trunk/org.apache.ace.deployment/bnd.bnd Mon Sep 30 12:00:26 2013
@@ -1,5 +1,4 @@
--buildpath: \
- osgi.core,\
+-buildpath: osgi.core,\
osgi.cmpn,\
javax.servlet,\
org.apache.felix.dependencymanager,\
@@ -15,5 +14,6 @@
org.apache.ace.repository.ext;version=latest,\
org.apache.ace.scheduler.api;version=latest,\
org.apache.ace.test;version=latest,\
- org.apache.ace.range.api;version=latest
+ org.apache.ace.range.api;version=latest,\
+ org.easymock
-sub: *.bnd
Modified: ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/provider/ArtifactData.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/provider/ArtifactData.java?rev=1527522&r1=1527521&r2=1527522&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/provider/ArtifactData.java (original)
+++ ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/provider/ArtifactData.java Mon Sep 30 12:00:26 2013
@@ -22,15 +22,15 @@ import java.net.URL;
import java.util.jar.Attributes;
/**
- * The ArtifactData as returned by the <code>DeploymentProvider</code> class in this package.
- * It contains several pieces of data which describe the artifact and the place where it can be found.
+ * The ArtifactData as returned by the <code>DeploymentProvider</code> class in this package. It contains several pieces
+ * of data which describe the artifact and the place where it can be found.
*/
public interface ArtifactData {
/**
* Indicate if the bundle has changed. This is used when comparing artifacts in 2 versions. (see DeploymentProvider)
* If you requested one version it always returns true.
- *
+ *
* @return if this artifact has changed.
*/
public boolean hasChanged();
@@ -41,7 +41,8 @@ public interface ArtifactData {
public boolean isBundle();
/**
- * @return <code>true</code> if this artifact is a customizer that contains a resource processor; <code>false</code> otherwise.
+ * @return <code>true</code> if this artifact is a customizer that contains a resource processor; <code>false</code>
+ * otherwise.
*/
public boolean isCustomizer();
@@ -51,13 +52,18 @@ public interface ArtifactData {
public String getFilename();
/**
- * @return the symbolic name, if this artifact is a bundle.
+ * @return the (estimated) size of the artifact, in bytes, >= 0L. If -1L, the size is unknown.
+ */
+ public long getSize();
+
+ /**
+ * @return the symbolic name, if this artifact is a bundle.
*/
public String getSymbolicName();
/**
- * @return the version, if this artifact is a bundle. If it is an artifact, this function
- * will always return "0.0.0".
+ * @return the version, if this artifact is a bundle. If it is an artifact, this function will always return
+ * "0.0.0".
*/
public String getVersion();
@@ -73,9 +79,9 @@ public interface ArtifactData {
/**
* @return a set of attributes that describes this artifact in a manifest.
- * @param fixPackage Indicating whether this set of headers is intended to be part
- * of a fixpackage.
+ * @param fixPackage
+ * Indicating whether this set of headers is intended to be part of a fixpackage.
*/
public Attributes getManifestAttributes(boolean fixPackage);
-}
\ No newline at end of file
+}
Modified: ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/provider/filebased/FileBasedProvider.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/provider/filebased/FileBasedProvider.java?rev=1527522&r1=1527521&r2=1527522&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/provider/filebased/FileBasedProvider.java (original)
+++ ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/provider/filebased/FileBasedProvider.java Mon Sep 30 12:00:26 2013
@@ -132,7 +132,6 @@ public class FileBasedProvider implement
// Do a file.toURI().toURL() to preserve special path characters
// see http://www.javalobby.org/java/forums/t19698.html
URL bundleUrl = new URL(null, jarFile.toURI().toURL().toString(), new URLStreamHandler() {
-
@Override
protected URLConnection openConnection(final URL u) throws IOException {
return new URLConnection(u) {
@@ -180,7 +179,7 @@ public class FileBasedProvider implement
};
}
});
- bundleData.add(new ArtifactDataImpl(jarFile.getName(), symbolicName, bundleVersion, bundleUrl, true));
+ bundleData.add(new ArtifactDataImpl(jarFile.getName(), symbolicName, jarFile.length(), bundleVersion, bundleUrl, true));
}
catch (IllegalArgumentException iae) {
m_log.log(LogService.LOG_WARNING, "Invalid bundle:" + jarFile.getAbsolutePath() + " has an illegal version", iae);
Modified: ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/provider/impl/ArtifactDataImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/provider/impl/ArtifactDataImpl.java?rev=1527522&r1=1527521&r2=1527522&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/provider/impl/ArtifactDataImpl.java (original)
+++ ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/provider/impl/ArtifactDataImpl.java Mon Sep 30 12:00:26 2013
@@ -33,85 +33,113 @@ public class ArtifactDataImpl implements
public static final String PROCESSORPID = "Resource-Processor";
/**
- * Key, intended to be used for artifacts which are bundles and will publish
- * a resource processor (see OSGi compendium section 114.10).
+ * Key, intended to be used for artifacts which are bundles and will publish a resource processor (see OSGi
+ * compendium section 114.10).
*/
public static final String DIRECTIVE_ISCUSTOMIZER = "DeploymentPackage-Customizer";
/**
- * Key, intended to be used for resources which require a resource processor
- * (see OSGi compendium section 114.10).
+ * Key, intended to be used for resources which require a resource processor (see OSGi compendium section 114.10).
*/
public static final String DIRECTIVE_KEY_PROCESSORID = "Resource-Processor";
/**
- * Key, intended to be used for artifacts which have a resourceID that's different
- * from their generated name (based on URL).
+ * Key, intended to be used for artifacts which have a resourceID that's different from their generated name (based
+ * on URL).
*/
public static final String DIRECTIVE_KEY_RESOURCE_ID = "Resource-ID";
/**
- * Key, intended to be used for matching processed (see ArtifactPreprocessor) to their
- * 'original' one.
+ * Key, intended to be used for matching processed (see ArtifactPreprocessor) to their 'original' one.
*/
public static final String DIRECTIVE_KEY_BASEURL = "Base-Url";
- public static final String REPOSITORY_PATH = "ACE-RepositoryPath";
+ public static final String REPOSITORY_PATH = "ACE-RepositoryPath";
-
-
private final String m_filename;
private final String m_symbolicName;
private final String m_version;
+ private final long m_size;
private final Map<String, String> m_directives;
-
private final URL m_url;
+
private volatile boolean m_hasChanged;
/**
* Constructs an ArtifactDataImpl object.
- * @param url The URL to the bundle. It will also be used to create the filename.
- * The file-part of the url (after the last /) should It must only contain characters [A-Za-z0-9._-].
- * @param directives A map of extra directives.
- * @param symbolicName The symbolicname of the bundle.
- * @param version The version of the bundle. If this is <code>null</code> or empty, it will be
- * normalized to "0.0.0".
- * @param hasChanged Indication of whether this bundle has changed relative to the previous deployment.
+ *
+ * @param url
+ * The URL to the bundle. It will also be used to create the filename. The file-part of the url (after
+ * the last /) should It must only contain characters [A-Za-z0-9._-].
+ * @param directives
+ * A map of extra directives.
+ * @param symbolicName
+ * The symbolicname of the bundle.
+ * @param size
+ * the (estimated) size of the artifact, or -1L if the size is unknown;
+ * @param version
+ * The version of the bundle. If this is <code>null</code> or empty, it will be normalized to "0.0.0".
+ * @param hasChanged
+ * Indication of whether this bundle has changed relative to the previous deployment.
*/
- public ArtifactDataImpl(URL url, Map<String, String> directives, String symbolicName, String version, boolean hasChanged) {
- this(url, symbolicName, version, null, directives, hasChanged);
+ public ArtifactDataImpl(URL url, Map<String, String> directives, String symbolicName, long size, String version, boolean hasChanged) {
+ this(url, symbolicName, size, version, null, directives, hasChanged);
}
/**
* Constructs an ArtifactDataImpl object.
- * @param url The URL to the bundle. It will also be used to create the filename.
- * The file-part of the url (after the last /) should It must only contain characters [A-Za-z0-9._-].
- * @param directives A map of extra directives.
- * @param hasChanged Indication of whether this bundle has changed relative to the previous deployment.
+ *
+ * @param url
+ * The URL to the bundle. It will also be used to create the filename. The file-part of the url (after
+ * the last /) should It must only contain characters [A-Za-z0-9._-].
+ * @param directives
+ * A map of extra directives;
+ * @param filename
+ * the name of the artifact;
+ * @param size
+ * the (estimated) size of the artifact, or -1L if the size is unknown;
+ * @param hasChanged
+ * Indication of whether this bundle has changed relative to the previous deployment.
*/
- public ArtifactDataImpl(URL url, Map<String, String> directives, boolean hasChanged) {
- this(url, null, null, null, directives, hasChanged);
+ public ArtifactDataImpl(URL url, Map<String, String> directives, String filename, long size, boolean hasChanged) {
+ this(url, null, size, null, filename, directives, hasChanged);
}
- public ArtifactDataImpl(String filename, URL url, Map<String, String> directives, boolean hasChanged) {
- this(url, null, null, filename, directives, hasChanged);
+ /**
+ * Constructs an ArtifactDataImpl object.
+ *
+ * @param url
+ * The URL to the bundle. It will also be used to create the filename. The file-part of the url (after
+ * the last /) should It must only contain characters [A-Za-z0-9._-].
+ * @param directives
+ * A map of extra directives.
+ * @param hasChanged
+ * Indication of whether this bundle has changed relative to the previous deployment.
+ */
+ public ArtifactDataImpl(URL url, Map<String, String> directives, boolean hasChanged) {
+ this(url, null, -1L, null, null, directives, hasChanged);
}
/**
* Constructs an ArtifactDataImpl object.
- * @param filename The filename of the bundle. If passed, it must only contain characters [A-Za-z0-9._-]; can be null.
- * @param symbolicName The symbolicname of the bundle.
- * @param version The version of the bundle. If this is <code>null</code> or empty, it will be
- * normalized to "0.0.0".
- * @param url The URL to the bundle. If filename is null, this will be used to create the filename; hence, the file-part of
- * the url (after the last /) should adhere to the same rules as filename.
- * @param hasChanged Indication of whether this bundle has changed relative to the previous deployment.
+ *
+ * @param filename
+ * The filename of the bundle. If passed, it must only contain characters [A-Za-z0-9._-]; can be null.
+ * @param symbolicName
+ * The symbolicname of the bundle.
+ * @param version
+ * The version of the bundle. If this is <code>null</code> or empty, it will be normalized to "0.0.0".
+ * @param url
+ * The URL to the bundle. If filename is null, this will be used to create the filename; hence, the
+ * file-part of the url (after the last /) should adhere to the same rules as filename.
+ * @param hasChanged
+ * Indication of whether this bundle has changed relative to the previous deployment.
*/
- public ArtifactDataImpl(String filename, String symbolicName, String version, URL url, boolean hasChanged) {
- this(url, symbolicName, version, filename, null, hasChanged);
+ public ArtifactDataImpl(String filename, String symbolicName, long size, String version, URL url, boolean hasChanged) {
+ this(url, symbolicName, size, version, filename, null, hasChanged);
}
- private ArtifactDataImpl(URL url, String symbolicName, String version, String filename, Map<String, String> directives, boolean hasChanged) {
+ private ArtifactDataImpl(URL url, String symbolicName, long size, String version, String filename, Map<String, String> directives, boolean hasChanged) {
m_url = url;
if (filename != null) {
@@ -124,10 +152,11 @@ public class ArtifactDataImpl implements
for (byte b : m_filename.getBytes()) {
if (!(((b >= 'A') && (b <= 'Z')) || ((b >= 'a') && (b <= 'z')) || ((b >= '0') && (b <= '9')) || (b == '.') || (b == '-') || (b == '_'))) {
- throw new IllegalArgumentException("Filename " + m_filename + " " + (filename == null ? "constructed from the url" : "") + " contains an illegal character '" + new String(new byte[] {b}) + "'");
+ throw new IllegalArgumentException("Filename " + m_filename + " " + (filename == null ? "constructed from the url" : "") + " contains an illegal character '" + new String(new byte[] { b }) + "'");
}
}
+ m_size = size;
m_symbolicName = symbolicName;
if ((version == null) || (version.trim().length() == 0)) {
m_version = "0.0.0";
@@ -139,18 +168,27 @@ public class ArtifactDataImpl implements
m_hasChanged = hasChanged;
}
+ @Override
public String getFilename() {
return m_filename;
}
+ @Override
+ public long getSize() {
+ return m_size;
+ }
+
+ @Override
public String getSymbolicName() {
return m_symbolicName;
}
+ @Override
public String getVersion() {
return m_version;
}
+ @Override
public String getProcessorPid() {
if (m_directives != null) {
return m_directives.get(DIRECTIVE_KEY_PROCESSORID);
@@ -158,16 +196,19 @@ public class ArtifactDataImpl implements
return null;
}
+ @Override
public URL getUrl() {
return m_url;
}
+ @Override
public boolean hasChanged() {
return m_hasChanged;
}
/**
- * @param hasChanged Indicate the bundle has changed
+ * @param hasChanged
+ * Indicate the bundle has changed
*/
public void setChanged(boolean hasChanged) {
m_hasChanged = hasChanged;
@@ -183,7 +224,7 @@ public class ArtifactDataImpl implements
if (getSymbolicName() != null) {
// this is a bundle
return getSymbolicName().equals(jarFile2.getSymbolicName()) &&
- getVersion().equals(jarFile2.getVersion());
+ getVersion().equals(jarFile2.getVersion());
}
else {
// this is another artifact.
@@ -202,6 +243,7 @@ public class ArtifactDataImpl implements
return result;
}
+ @Override
public Attributes getManifestAttributes(boolean fixPackage) {
Attributes a = new Attributes();
@@ -217,11 +259,11 @@ public class ArtifactDataImpl implements
a.putValue(CUSTOMIZER, "true");
}
}
-
+
if (m_directives != null) {
String path = m_directives.get(REPOSITORY_PATH);
if (path != null) {
- a.putValue(REPOSITORY_PATH, path);
+ a.putValue(REPOSITORY_PATH, path);
}
}
if (!hasChanged() && fixPackage) {
@@ -231,12 +273,13 @@ public class ArtifactDataImpl implements
return a;
}
+ @Override
public boolean isCustomizer() {
return (m_directives != null) && "true".equals(m_directives.get(DIRECTIVE_ISCUSTOMIZER));
}
+ @Override
public boolean isBundle() {
return getSymbolicName() != null;
}
-
-}
\ No newline at end of file
+}
Modified: ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/provider/repositorybased/BaseRepositoryHandler.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/provider/repositorybased/BaseRepositoryHandler.java?rev=1527522&r1=1527521&r2=1527522&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/provider/repositorybased/BaseRepositoryHandler.java (original)
+++ ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/provider/repositorybased/BaseRepositoryHandler.java Mon Sep 30 12:00:26 2013
@@ -45,13 +45,18 @@ class BaseRepositoryHandler extends Defa
private XmlDeploymentArtifact m_currentArtifact;
/** Denotes the directive key of the current deployment artifact. */
private String m_currentDirectiveKey;
+ /** Denotes the size of an artifact. */
+ private long m_artifactSize;
+ /** Denotes the actual URL to the artifact. */
+ private URL m_artifactURL;
/** To collect characters() */
private final StringBuilder m_buffer;
/**
* Creates a new {@link BaseRepositoryHandler} instance.
*
- * @param targetID the target ID to search for, cannot be <code>null</code>.
+ * @param targetID
+ * the target ID to search for, cannot be <code>null</code>.
*/
public BaseRepositoryHandler(String targetID) {
m_targetID = targetID;
@@ -62,7 +67,8 @@ class BaseRepositoryHandler extends Defa
/**
* Parses the given text as {@link Version}.
*
- * @param text the text to parse as version, can not be <code>null</code>.
+ * @param text
+ * the text to parse as version, can not be <code>null</code>.
* @return a {@link Version} if the given text represent a correct version, never <code>null</code>.
*/
static final Version parseVersion(String text) {
@@ -84,6 +90,8 @@ class BaseRepositoryHandler extends Defa
m_targetFound = false;
m_currentArtifact = null;
m_currentDirectiveKey = null;
+ m_artifactURL = null;
+ m_artifactSize = -1L;
}
@Override
@@ -102,6 +110,9 @@ class BaseRepositoryHandler extends Defa
if (XmlTag.directives.equals(m_currentTag)) {
m_currentDirectiveKey = qName;
}
+ if (XmlTag.size.equals(m_currentTag)) {
+ m_artifactSize = -1L;
+ }
m_buffer.setLength(0);
}
@@ -130,23 +141,30 @@ class BaseRepositoryHandler extends Defa
}
else if (XmlTag.url.equals(m_currentTag)) {
try {
- URL artifactUrl = new URL(text);
- m_currentArtifact = new XmlDeploymentArtifact(artifactUrl);
+ m_artifactURL = new URL(text);
}
catch (MalformedURLException e) {
throw new SAXException("Unexpected URL!", e);
}
}
+ else if (XmlTag.size.equals(m_currentTag)) {
+ try {
+ m_artifactSize = Long.valueOf(text);
+ }
+ catch (NumberFormatException exception) {
+ m_artifactSize = -1L;
+ }
+ }
else if (XmlTag.directives.equals(m_currentTag)) {
if (m_currentArtifact == null) {
- throw new SAXException("Unexpected directive tag!");
+ m_currentArtifact = new XmlDeploymentArtifact(m_artifactURL, m_artifactSize);
}
String value = text.trim();
if (m_currentDirectiveKey != null && !value.equals("")) {
m_currentArtifact.m_directives.put(m_currentDirectiveKey, value);
}
}
-
+
XmlTag tag = XmlTag.asXmlTag(qName);
// When we're ending the current tag, traverse up to its parent...
if (!XmlTag.unknown.equals(tag) && (m_currentTag == tag)) {
@@ -169,6 +187,8 @@ class BaseRepositoryHandler extends Defa
}
m_currentArtifact = null;
+ m_artifactURL = null;
+ m_artifactSize = -1L;
}
else if (XmlTag.directives.equals(tag)) {
m_currentDirectiveKey = null;
@@ -177,9 +197,12 @@ class BaseRepositoryHandler extends Defa
/**
* Allows subclasses to handle the given version of a target's deployment package.
- * <p>By default, this method does nothing.</p>
+ * <p>
+ * By default, this method does nothing.
+ * </p>
*
- * @param version the version found, never <code>null</code>.
+ * @param version
+ * the version found, never <code>null</code>.
*/
protected void handleVersion(Version version) {
// NO-op
@@ -187,10 +210,14 @@ class BaseRepositoryHandler extends Defa
/**
* Allows subclasses to handle the given deployment artifact for the given version of the deployment package.
- * <p>By default, this method does nothing.</p>
+ * <p>
+ * By default, this method does nothing.
+ * </p>
*
- * @param version the version of the deployment package;
- * @param artifact the deployment artifact itself.
+ * @param version
+ * the version of the deployment package;
+ * @param artifact
+ * the deployment artifact itself.
*/
protected void handleArtifact(Version version, XmlDeploymentArtifact artifact) {
// NO-op
@@ -199,9 +226,10 @@ class BaseRepositoryHandler extends Defa
/**
* Parses the given text as {@link Version}.
*
- * @param text the text to parse as version, can not be <code>null</code>.
- * @return a {@link Version} if the given text represent a correct version,
- * can be <code>null</code> in case of an incorrect/empty version..
+ * @param text
+ * the text to parse as version, can not be <code>null</code>.
+ * @return a {@link Version} if the given text represent a correct version, can be <code>null</code> in case of an
+ * incorrect/empty version..
*/
protected final Version parseAsVersion(String text) {
Version result = parseVersion(text);
@@ -215,14 +243,20 @@ class BaseRepositoryHandler extends Defa
* Helper class to store a pair of URL and directive, in which the directive may be empty.
*/
public static class XmlDeploymentArtifact {
- final private URL m_url;
- final private Map<String, String> m_directives;
+ private final URL m_url;
+ private final long m_size;
+ private final Map<String, String> m_directives;
- private XmlDeploymentArtifact(URL url) {
+ private XmlDeploymentArtifact(URL url, long size) {
m_url = url;
+ m_size = size;
m_directives = new HashMap<String, String>();
}
+ public long getSize() {
+ return m_size;
+ }
+
public URL getUrl() {
return m_url;
}
@@ -240,8 +274,9 @@ class BaseRepositoryHandler extends Defa
version,
attributes(targetID, version),
url,
+ size,
directives,
- deploymentArtifact(url, directives),
+ deploymentArtifact(url, size, directives),
artifacts(deploymentArtifact),
tags,
deploymentversion(attributes, tags, artifacts),
@@ -272,7 +307,8 @@ class BaseRepositoryHandler extends Defa
/**
* Returns whether the given XML tag is an expected child of this tag.
*
- * @param xmlTag the XML tag to test, cannot be <code>null</code>.
+ * @param xmlTag
+ * the XML tag to test, cannot be <code>null</code>.
* @return <code>true</code> if the given tag is an expected child of this tag, <code>false</code> otherwise.
*/
public boolean isExpectedChild(XmlTag xmlTag) {
@@ -285,19 +321,21 @@ class BaseRepositoryHandler extends Defa
}
/**
- * Provides a "safe" way of representing the given tag name as instance of this enum. If the given name does not represent a defined tag, "unknown" will be returned.
+ * Provides a "safe" way of representing the given tag name as instance of this enum. If the given name does not
+ * represent a defined tag, "unknown" will be returned.
*
- * @param name the XML tag-name to represent as enum value, cannot be <code>null</code>.
+ * @param name
+ * the XML tag-name to represent as enum value, cannot be <code>null</code>.
* @return a {@link XmlTag} representation of the given tag-name, never <code>null</code>.
*/
public static XmlTag asXmlTag(String name) {
- XmlTag[] values = { artifacts, attributes, deploymentArtifact, deploymentversion, deploymentversions, directives, repository, tags, targetID, url, version };
- for (int i = 0; i < values.length; i++) {
- if (values[i].name().equals(name)) {
- return values[i];
- }
- }
+ XmlTag[] values = { artifacts, attributes, deploymentArtifact, deploymentversion, deploymentversions, directives, repository, size, tags, targetID, url, version };
+ for (int i = 0; i < values.length; i++) {
+ if (values[i].name().equals(name)) {
+ return values[i];
+ }
+ }
return XmlTag.unknown;
}
}
-}
\ No newline at end of file
+}
Modified: ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/provider/repositorybased/RepositoryBasedProvider.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/provider/repositorybased/RepositoryBasedProvider.java?rev=1527522&r1=1527521&r2=1527522&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/provider/repositorybased/RepositoryBasedProvider.java (original)
+++ ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/provider/repositorybased/RepositoryBasedProvider.java Mon Sep 30 12:00:26 2013
@@ -258,26 +258,27 @@ public class RepositoryBasedProvider imp
// get the bundledata for each URL
for (XmlDeploymentArtifact pair : deploymentArtifacts) {
+ long artifactSize = pair.getSize();
+
Map<String, String> directives = pair.getDirective();
-
if (directives.get(DIRECTIVE_KEY_PROCESSORID) == null) {
// this is a bundle.
String symbolicName = directives.get(KEY_SYMBOLICNAME);
String bundleVersion = directives.get(KEY_VERSION);
if (symbolicName != null) {
// it is the right symbolic name
- if (symbolicName.trim().equals("")) {
+ if ("".equals(symbolicName.trim())) {
m_log.log(LogService.LOG_WARNING, "Invalid bundle:" + pair.toString() + " the symbolic name is empty.");
}
else {
- result.add(new ArtifactDataImpl(pair.getUrl(), directives, symbolicName, bundleVersion, true));
+ result.add(new ArtifactDataImpl(pair.getUrl(), directives, symbolicName, artifactSize, bundleVersion, true /* hasChanged */));
}
}
}
else {
// it is an artifact.
String filename = directives.get(DIRECTIVE_KEY_RESOURCE_ID);
- result.add(new ArtifactDataImpl(filename, pair.getUrl(), directives, true));
+ result.add(new ArtifactDataImpl(pair.getUrl(), directives, filename, artifactSize, true /* hasChanged */));
}
}
Modified: ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/servlet/DeploymentServlet.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/servlet/DeploymentServlet.java?rev=1527522&r1=1527521&r2=1527522&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/servlet/DeploymentServlet.java (original)
+++ ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/servlet/DeploymentServlet.java Mon Sep 30 12:00:26 2013
@@ -36,6 +36,7 @@ import javax.servlet.http.HttpServletRes
import org.apache.ace.authentication.api.AuthenticationService;
import org.apache.ace.deployment.processor.DeploymentProcessor;
+import org.apache.ace.deployment.provider.ArtifactData;
import org.apache.ace.deployment.provider.DeploymentProvider;
import org.apache.ace.deployment.streamgenerator.StreamGenerator;
import org.apache.felix.dm.Component;
@@ -47,25 +48,29 @@ import org.osgi.service.log.LogService;
import org.osgi.service.useradmin.User;
/**
- * The DeploymentServlet class provides in a list of versions available for a target and a stream
- * of data containing the DeploymentPackage (or fix package) for a specific target and version.
+ * The DeploymentServlet class provides in a list of versions available for a target and a stream of data containing the
+ * DeploymentPackage (or fix package) for a specific target and version.
*/
public class DeploymentServlet extends HttpServlet implements ManagedService {
private static final long serialVersionUID = 1L;
/** A boolean denoting whether or not authentication is enabled. */
private static final String KEY_USE_AUTHENTICATION = "authentication.enabled";
+ /** HTTP header name used for Deployment Package size estimate, in bytes. */
+ private static final String HEADER_DPSIZE = "X-ACE-DPSize";
+ /** Multiplication factor for the DP size to account for slight changes in file change due to resource processors. */
+ private static final double DPSIZE_FACTOR = 1.1;
public static final String CURRENT = "current";
public static final String PROCESSOR = "processor";
public static final String VERSIONS = "versions";
public static final String DP_MIMETYPE = "application/vnd.osgi.dp";
public static final String TEXT_MIMETYPE = "text/plain";
-
+
private final ConcurrentMap<String, DeploymentProcessor> m_processors = new ConcurrentHashMap<String, DeploymentProcessor>();
-
+
// injected by Dependency Manager
- private volatile DependencyManager m_dm;
+ private volatile DependencyManager m_dm;
private volatile LogService m_log;
private volatile StreamGenerator m_streamGenerator;
private volatile DeploymentProvider m_provider;
@@ -74,30 +79,77 @@ public class DeploymentServlet extends H
private volatile boolean m_useAuth = false;
/**
- * Responds to GET requests sent to this endpoint, the response depends on the requested path:
- * <li>http://host/endpoint/targetid/versions/ returns a list of versions available for the specified target
- * <li>http://host/endpoint/targetid/versions/x.y.z returns a deployment package stream for the specified target and version
- *
- * The status code of the response can be one of the following:
- * <li><code>HttpServletResponse.SC_BAD_REQUEST</code> - If no target is specified or the request is malformed in a different way.
- * <li><code>HttpServletResponse.SC_NOT_FOUND</code> - If the specified target or version does not exist.
- * <li><code>HttpServletResponse.SC_INTERNAL_SERVER_ERROR</code> - If there was a problem processing the request.
- * <li><code>HttpServletResponse.SC_OK</code> - If all went fine
+ * Responds to GET requests sent to this endpoint, the response depends on the requested path: <li>
+ * http://host/endpoint/targetid/versions/ returns a list of versions available for the specified target <li>
+ * http://host/endpoint/targetid/versions/x.y.z returns a deployment package stream for the specified target and
+ * version
+ *
+ * The status code of the response can be one of the following: <li><code>HttpServletResponse.SC_BAD_REQUEST</code>
+ * - If no target is specified or the request is malformed in a different way. <li>
+ * <code>HttpServletResponse.SC_NOT_FOUND</code> - If the specified target or version does not exist. <li>
+ * <code>HttpServletResponse.SC_INTERNAL_SERVER_ERROR</code> - If there was a problem processing the request. <li>
+ * <code>HttpServletResponse.SC_OK</code> - If all went fine
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
try {
String[] pathElements = verifyAndGetPathElements(request.getPathInfo());
String targetID = pathElements[1];
- List<String> versions = getVersions(targetID);
int numberOfElements = pathElements.length;
if (numberOfElements == 3) {
- handleVersionsRequest(versions, response);
+ handleVersionsRequest(targetID, response);
}
else {
String version = pathElements[3];
- handlePackageDelivery(targetID, version, versions, request, response);
+ handlePackageDelivery(targetID, version, request, response);
+ }
+ }
+ catch (AceRestException e) {
+ m_log.log(LogService.LOG_WARNING, e.getMessage(), e);
+ e.handleAsHttpError(response);
+ }
+ }
+
+ /**
+ * Responds to HEAD requests for particular deployment versions by sending back the estimated size of an update.
+ */
+ @Override
+ protected void doHead(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ try {
+ String[] pathElements = verifyAndGetPathElements(request.getPathInfo());
+ int numberOfElements = pathElements.length;
+
+ if (numberOfElements == 4) {
+ String targetID = pathElements[1];
+ String version = pathElements[3];
+
+ String current = request.getParameter(CURRENT);
+
+ List<ArtifactData> artifacts;
+ if (current != null) {
+ artifacts = m_provider.getBundleData(targetID, current, version);
+ } else {
+ artifacts = m_provider.getBundleData(targetID, version);
+ }
+
+ long dpSize = 0L;
+ for (ArtifactData artifactData : artifacts) {
+ long size = artifactData.getSize();
+ if (size > 0L) {
+ dpSize += size;
+ }
+ else {
+ dpSize = -1L;
+ break; // cannot determine the DP size...
+ }
+ }
+
+ response.setContentType(DP_MIMETYPE);
+
+ if (dpSize > 0) {
+ response.addHeader(HEADER_DPSIZE, Long.toString((long) (DPSIZE_FACTOR * dpSize)));
+ }
}
}
catch (AceRestException e) {
@@ -109,7 +161,8 @@ public class DeploymentServlet extends H
/**
* Called by Dependency Manager upon initialization of this component.
*
- * @param comp the component to initialize, cannot be <code>null</code>.
+ * @param comp
+ * the component to initialize, cannot be <code>null</code>.
*/
protected void init(Component comp) {
comp.add(m_dm.createServiceDependency()
@@ -124,7 +177,8 @@ public class DeploymentServlet extends H
if (!authenticate(req)) {
// Authentication failed; don't proceed with the original request...
resp.sendError(SC_UNAUTHORIZED);
- } else {
+ }
+ else {
// Authentication successful, proceed with original request...
super.service(req, resp);
}
@@ -133,7 +187,8 @@ public class DeploymentServlet extends H
/**
* Authenticates, if needed the user with the information from the given request.
*
- * @param request the request to obtain the credentials from, cannot be <code>null</code>.
+ * @param request
+ * the request to obtain the credentials from, cannot be <code>null</code>.
* @return <code>true</code> if the authentication was successful, <code>false</code> otherwise.
*/
private boolean authenticate(HttpServletRequest request) {
@@ -148,15 +203,19 @@ public class DeploymentServlet extends H
}
/**
- * Serve the case where requested path is like:
- * http://host/endpoint/targetid/versions/ returns a list of versions available for the specified target
- *
- * @param versions versions to be put into response
- * @param response response object.
+ * Serve the case where requested path is like: http://host/endpoint/targetid/versions/ returns a list of versions
+ * available for the specified target
+ *
+ * @param targetID
+ * the target ID for which to return all available versions;
+ * @param response
+ * response object.
*/
- private void handleVersionsRequest(List<String> versions, HttpServletResponse response) throws AceRestException {
+ private void handleVersionsRequest(String targetID, HttpServletResponse response) throws AceRestException {
ServletOutputStream output = null;
+ List<String> versions = getVersions(targetID);
+
response.setContentType(TEXT_MIMETYPE);
try {
output = response.getOutputStream();
@@ -173,17 +232,19 @@ public class DeploymentServlet extends H
}
}
- private void handlePackageDelivery(String targetID, String version, List<String> versions, HttpServletRequest request, HttpServletResponse response) throws AceRestException {
-
+ private void handlePackageDelivery(String targetID, String version, HttpServletRequest request, HttpServletResponse response) throws AceRestException {
ServletOutputStream output = null;
+ List<String> versions = getVersions(targetID);
+ if (!versions.contains(version)) {
+ throw new AceRestException(HttpServletResponse.SC_NOT_FOUND, "Unknown version (" + version + ")");
+ }
+
try {
// Wrap response to add support for range requests
response = new ContentRangeResponseWrapper(request, response);
+ response.setContentType(DP_MIMETYPE);
- if (!versions.contains(version)) {
- throw new AceRestException(HttpServletResponse.SC_NOT_FOUND, "Unknown version (" + version + ")");
- }
String current = request.getParameter(CURRENT);
String processor = request.getParameter(PROCESSOR);
@@ -205,7 +266,7 @@ public class DeploymentServlet extends H
throw new AceRestException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not find a deployment processor called: " + processor);
}
}
- response.setContentType(DP_MIMETYPE);
+
output = response.getOutputStream();
byte[] buffer = new byte[1024 * 32];
for (int bytesRead = inputStream.read(buffer); bytesRead != -1; bytesRead = inputStream.read(buffer)) {
@@ -249,14 +310,15 @@ public class DeploymentServlet extends H
}
/**
- * Make sure the path is valid.
- * Also returns the splited version of #path.
- *
- * @param path http request path
- *
+ * Make sure the path is valid. Also returns the splited version of #path.
+ *
+ * @param path
+ * http request path
+ *
* @return splitted version of #path. Split delim is "/"
- *
- * @throws org.apache.ace.deployment.servlet.AceRestException if path is not valid or cannot be processed.
+ *
+ * @throws org.apache.ace.deployment.servlet.AceRestException
+ * if path is not valid or cannot be processed.
*/
private String[] verifyAndGetPathElements(String path) throws AceRestException {
if (path == null) {
@@ -310,4 +372,4 @@ public class DeploymentServlet extends H
}
m_processors.remove(key);
}
-}
\ No newline at end of file
+}
Modified: ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/util/test/TestData.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/util/test/TestData.java?rev=1527522&r1=1527521&r2=1527522&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/util/test/TestData.java (original)
+++ ace/trunk/org.apache.ace.deployment/src/org/apache/ace/deployment/util/test/TestData.java Mon Sep 30 12:00:26 2013
@@ -38,22 +38,32 @@ public class TestData implements Artifac
m_changed = changed;
}
+ @Override
public boolean hasChanged() {
return m_changed;
}
+ @Override
public String getFilename() {
return m_fileName;
}
+ @Override
+ public long getSize() {
+ return -1L;
+ }
+
+ @Override
public String getSymbolicName() {
return m_symbolicName;
}
+ @Override
public URL getUrl() {
return m_url;
}
+ @Override
public String getVersion() {
return m_version;
}
@@ -63,6 +73,7 @@ public class TestData implements Artifac
return null;
}
+ @Override
public Attributes getManifestAttributes(boolean fixPackage) {
Attributes a = new Attributes();
a.putValue("Bundle-SymbolicName", getSymbolicName());
@@ -70,15 +81,18 @@ public class TestData implements Artifac
return a;
}
+ @Override
public String getProcessorPid() {
// TODO Auto-generated method stub
return null;
}
+ @Override
public boolean isBundle() {
return true;
}
+ @Override
public boolean isCustomizer() {
return false;
}
Modified: ace/trunk/org.apache.ace.deployment/test/org/apache/ace/deployment/DeploymentTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.deployment/test/org/apache/ace/deployment/DeploymentTest.java?rev=1527522&r1=1527521&r2=1527522&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.deployment/test/org/apache/ace/deployment/DeploymentTest.java (original)
+++ ace/trunk/org.apache.ace.deployment/test/org/apache/ace/deployment/DeploymentTest.java Mon Sep 30 12:00:26 2013
@@ -70,6 +70,7 @@ public class DeploymentTest {
assert exceptionthrown : "Illegal argument for getVersion() did not throw exception";
}
+ @SuppressWarnings("unused")
private class MockDeploymentAdmin {
public DeploymentPackage installDeploymentPackage(InputStream is) {
return m_mockDeploymentPackage;
@@ -80,6 +81,7 @@ public class DeploymentTest {
}
}
+ @SuppressWarnings("unused")
private class MockDeploymentPackage {
public String getName() {
return MOCK_NAME;
Modified: ace/trunk/org.apache.ace.deployment/test/org/apache/ace/deployment/provider/filebased/FileBasedProviderTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.deployment/test/org/apache/ace/deployment/provider/filebased/FileBasedProviderTest.java?rev=1527522&r1=1527521&r2=1527522&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.deployment/test/org/apache/ace/deployment/provider/filebased/FileBasedProviderTest.java (original)
+++ ace/trunk/org.apache.ace.deployment/test/org/apache/ace/deployment/provider/filebased/FileBasedProviderTest.java Mon Sep 30 12:00:26 2013
@@ -83,7 +83,7 @@ public class FileBasedProviderTest {
* make a bundle with the given symbolic name and version in the given file.
*/
private ArtifactData generateBundle(File file, String symbolicName, String version) throws Exception {
- ArtifactData bundle = new ArtifactDataImpl(file.getName(), symbolicName, version, file.toURI().toURL(), false);
+ ArtifactData bundle = new ArtifactDataImpl(file.getName(), symbolicName, file.length(), version, file.toURI().toURL(), false);
BundleStreamGenerator.generateBundle(bundle);
return bundle;
}
@@ -201,6 +201,7 @@ public class FileBasedProviderTest {
Iterator<ArtifactData> it = bundleData.iterator();
while(it.hasNext()) {
ArtifactData data = it.next();
+ assert data.getSize() > 200 : "Bundle has no sensible size?!";
assert !data.hasChanged() : "The data should not have been changed.";
}
}
Modified: ace/trunk/org.apache.ace.deployment/test/org/apache/ace/deployment/provider/repositorybased/RepositoryBasedProviderTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.deployment/test/org/apache/ace/deployment/provider/repositorybased/RepositoryBasedProviderTest.java?rev=1527522&r1=1527521&r2=1527522&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.deployment/test/org/apache/ace/deployment/provider/repositorybased/RepositoryBasedProviderTest.java (original)
+++ ace/trunk/org.apache.ace.deployment/test/org/apache/ace/deployment/provider/repositorybased/RepositoryBasedProviderTest.java Mon Sep 30 12:00:26 2013
@@ -69,6 +69,7 @@ public class RepositoryBasedProviderTest
private static final String ARTIFACTS_TAG = "artifacts";
private static final String ARTIFACT_TAG = "deploymentArtifact";
private static final String URL_TAG = "url";
+ private static final String SIZE_TAG = "size";
private static final String DIRECTIVES_TAG = "directives";
private static final String ATTRIBUTES_TAG = "attributes";
private static final String DEPLOYMENTVERSION_TAG = "deploymentversion";
@@ -156,7 +157,8 @@ public class RepositoryBasedProviderTest
*/
private ArtifactData generateBundle(File file, Map<String, String> directives, String symbolicName, String version,
Map<String, String> additionalHeaders) throws Exception {
- ArtifactData bundle = new ArtifactDataImpl(file.toURI().toURL(), directives, symbolicName, version, false);
+ // create a mock bundle, which is only used to generate the bundle on disk, and not used for anything else...
+ ArtifactData bundle = new ArtifactDataImpl(file.toURI().toURL(), directives, symbolicName, -1L, version, false);
if (additionalHeaders == null) {
BundleStreamGenerator.generateBundle(bundle);
}
@@ -332,6 +334,9 @@ public class RepositoryBasedProviderTest
Element url = doc.createElement(URL_TAG);
url.setTextContent(s[0]);
artifact.appendChild(url);
+ Element size = doc.createElement(SIZE_TAG);
+ size.setTextContent("100");
+ artifact.appendChild(size);
Element directives = doc.createElement(DIRECTIVES_TAG);
for (int i = 1; i < s.length; i += 2) {
Element directive = doc.createElement(s[i]);
@@ -458,6 +463,7 @@ public class RepositoryBasedProviderTest
Iterator<ArtifactData> it = bundleData.iterator();
while (it.hasNext()) {
ArtifactData data = it.next();
+ assert data.getSize() == 100 : "Bundle has no sensible size?! " + data.getSize();
assert !data.hasChanged() : "The data should not have been changed.";
}
}
|