Author: ammulder
Date: Tue Aug 1 11:16:31 2006
New Revision: 427669
URL: http://svn.apache.org/viewvc?rev=427669&view=rev
Log:
Merge fix for GERONIMO-2228 (and plumbing for GERONIMO-1869) to trunk.
Added:
geronimo/trunk/modules/common/src/java/org/apache/geronimo/common/FileUtils.java (props
changed)
- copied unchanged from r427650, geronimo/branches/1.1/modules/common/src/java/org/apache/geronimo/common/FileUtils.java
Modified:
geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/car/GeronimoAsMavenServlet.java
geronimo/trunk/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/ConfigIDExtractor.java
Modified: geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/car/GeronimoAsMavenServlet.java
URL: http://svn.apache.org/viewvc/geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/car/GeronimoAsMavenServlet.java?rev=427669&r1=427668&r2=427669&view=diff
==============================================================================
--- geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/car/GeronimoAsMavenServlet.java
(original)
+++ geronimo/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/car/GeronimoAsMavenServlet.java
Tue Aug 1 11:16:31 2006
@@ -51,6 +51,7 @@
import org.apache.geronimo.kernel.config.ConfigurationStore;
import org.apache.geronimo.kernel.config.ConfigurationUtil;
import org.apache.geronimo.kernel.config.NoSuchStoreException;
+import org.apache.geronimo.kernel.config.NoSuchConfigException;
import org.apache.geronimo.kernel.repository.Artifact;
import org.apache.geronimo.kernel.repository.Repository;
import org.apache.geronimo.kernel.repository.Version;
@@ -116,54 +117,54 @@
if(path.startsWith("/")) {
path = path.substring(1);
}
- String[] parts = path.split("/");
- if(parts.length != 3) {
- response.sendError(404, "Unrecognized path form "+path);
+ String configId = parsePath(path, response);
+ if(configId == null) { // we already sent the 404
return;
}
- String groupId = parts[0];
- String type = parts[1].substring(0, parts[1].length()-1);
- if(!parts[2].endsWith("."+type)) {
- response.sendError(404, "Unrecognized path structure "+path);
- }
- parts[2] = parts[2].substring(0, parts[2].length()-(type.length()+1));
- int pos = parts[2].lastIndexOf("-");
- String version = parts[2].substring(pos+1);
- if(version.equalsIgnoreCase("SNAPSHOT")) {
- pos = parts[2].lastIndexOf("-", pos-1);
- version = parts[2].substring(pos+1);
- }
- String artifactId = parts[2].substring(0, pos);
- String configId = groupId+"/"+artifactId+"/"+version+"/"+type;
if(!produceDownloadFile(kernel, Artifact.create(configId), response, reply))
{
response.sendError(404, "Cannot locate download file "+path);
}
}
}
+ private static String parsePath(String path, HttpServletResponse response) throws IOException
{
+ String[] parts = path.split("/");
+ String groupId, artifactId, version, type;
+ if(parts.length < 4) {
+ response.sendError(404, "Unrecognized path form "+path);
+ return null;
+ } else { // e.g. console/MyDatabase/1.0-SNAPSHOT/MyDatabase-1.0-SNAPSHOT.rar
+ groupId = parts[0];
+ for(int i=4; i<parts.length; i++) {
+ groupId = groupId+"."+parts[i-3];
+ }
+ artifactId = parts[parts.length-3];
+ version = parts[parts.length-2];
+ if(!parts[parts.length-1].startsWith(artifactId+"-"+version)) {
+ response.sendError(404, "Unrecognized path structure "+path);
+ return null;
+ }
+ type = parts[parts.length-1].substring(artifactId.length()+version.length()+2);
+ }
+ return groupId+"/"+artifactId+"/"+version+"/"+type;
+ }
+
private boolean produceDownloadFile(Kernel kernel, Artifact configId, HttpServletResponse
response, boolean reply) throws IOException {
//todo: replace kernel mumbo jumbo with JSR-77 navigation
// Step 1: check if it's in a configuration store
ConfigurationManager mgr = ConfigurationUtil.getConfigurationManager(kernel);
- List stores = mgr.listStores();
- for (int i = 0; i < stores.size(); i++) {
- AbstractName name = (AbstractName) stores.get(i);
- //todo: this is bad!!!
- if(name.getName().get(NameFactory.J2EE_NAME).equals("Local")) {
- ConfigurationStore store = (ConfigurationStore) kernel.getProxyManager().createProxy(name,
ConfigurationStore.class);
- if(store.containsConfiguration(configId)) {
- response.setContentType("application/zip");
- if(!reply) {
- return true;
- }
- try {
- kernel.invoke(name, "exportConfiguration", new Object[]{configId.toString(),
response.getOutputStream()}, new String[]{String.class.getName(), OutputStream.class.getName()});
- return true;
- } catch (Exception e) {
- log.error("Unable to export configuration ZIP", e);
- throw new IOException("Unable to write ZIP file: "+e.getMessage());
- }
- }
+ if(mgr.isConfiguration(configId)) {
+ ConfigurationStore store = mgr.getStoreForConfiguration(configId);
+ response.setContentType("application/zip");
+ if(!reply) {
+ return true;
+ }
+ try {
+ store.exportConfiguration(configId, response.getOutputStream());
+ return true;
+ } catch (NoSuchConfigException e) {
+ log.error("Inconsistent ConfigurationStore data; ConfigManager claims it
has configuration "+configId+" but store claims it doesn't",e);
+ throw new IOException("Unable to write ZIP file; see server log for details");
}
}
// Step 2: check if it's in a repository
@@ -173,7 +174,7 @@
Repository repo = (Repository) kernel.getProxyManager().createProxy(name, Repository.class);
if(repo.contains(configId)) {
File path = repo.getLocation(configId);
- if(!path.exists()) throw new IllegalStateException("Can't find file '"+path.getAbsolutePath()+"'");
+ if(!path.exists()) throw new IllegalStateException("Can't find file '"+path.getAbsolutePath()+"'
though repository said there's an artifact there!");
response.setContentType("application/zip");
if(!reply) {
return true;
@@ -202,6 +203,7 @@
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.newDocument();
Element root = doc.createElementNS("http://geronimo.apache.org/xml/ns/plugins-1.1",
"geronimo-plugin-list");
+ root.setAttribute("xmlns", "http://geronimo.apache.org/xml/ns/plugins-1.1");
doc.appendChild(root);
List stores = mgr.listStores();
for (int i = 0; i < stores.size(); i++) {
@@ -255,7 +257,7 @@
// Skip repositories since we want the download to come from here
}
}
- String repo = request.getProtocol()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+request.getServletPath();
+ String repo = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+request.getServletPath();
if(!repo.endsWith("/")) repo += "/";
createText(doc, root, "default-repository", repo);
TransformerFactory xfactory = TransformerFactory.newInstance();
Propchange: geronimo/trunk/modules/common/src/java/org/apache/geronimo/common/FileUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: geronimo/trunk/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/ConfigIDExtractor.java
URL: http://svn.apache.org/viewvc/geronimo/trunk/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/ConfigIDExtractor.java?rev=427669&r1=427668&r2=427669&view=diff
==============================================================================
--- geronimo/trunk/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/ConfigIDExtractor.java
(original)
+++ geronimo/trunk/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/ConfigIDExtractor.java
Tue Aug 1 11:16:31 2006
@@ -36,6 +36,7 @@
import javax.xml.parsers.ParserConfigurationException;
import javax.enterprise.deploy.spi.TargetModuleID;
import org.apache.geronimo.common.DeploymentException;
+import org.apache.geronimo.common.FileUtils;
import org.apache.geronimo.kernel.repository.Artifact;
import org.apache.geronimo.kernel.repository.Version;
import org.xml.sax.InputSource;
@@ -231,24 +232,14 @@
/**
* Try to determine whether a file is a JAR File (or, at least, a ZIP file).
+ *
+ * @deprecated See org.apache.geronimo.common.FileUtils.isJarFile
*/
public static boolean isJarFile(File file) throws DeploymentException {
- if(file.isDirectory()) {
- return false;
- }
- if(!file.canRead()) {
- throw new DeploymentException("Cannot read file "+file.getAbsolutePath());
- }
- if(file.length() < 4) {
- return false;
- }
try {
- DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
- int test = in.readInt();
- in.close();
- return test == 0x504b0304;
- } catch(IOException e) {
- throw new DeploymentException("Cannot read from file "+file.getAbsolutePath(),
e);
+ return FileUtils.isZipFile(file);
+ } catch (IOException e) {
+ throw new DeploymentException("Unable to read file "+file.getAbsolutePath());
}
}
|