001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.geronimo.console.car;
018
019 import org.apache.geronimo.kernel.Kernel;
020 import org.apache.geronimo.kernel.KernelRegistry;
021 import org.apache.geronimo.kernel.config.ConfigurationManager;
022 import org.apache.geronimo.kernel.config.ConfigurationStore;
023 import org.apache.geronimo.kernel.config.ConfigurationUtil;
024 import org.apache.geronimo.kernel.config.NoSuchConfigException;
025 import org.apache.geronimo.kernel.repository.Artifact;
026
027 import javax.servlet.ServletException;
028 import javax.servlet.http.HttpServlet;
029 import javax.servlet.http.HttpServletRequest;
030 import javax.servlet.http.HttpServletResponse;
031 import java.io.IOException;
032
033 /**
034 * Servlet that lets you download a CAR from the repository
035 *
036 * @version $Rev: 476061 $ $Date: 2006-11-17 01:36:50 -0500 (Fri, 17 Nov 2006) $
037 */
038 public class CARExportServlet extends HttpServlet {
039 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
040 String configId = request.getParameter("configId");
041 if(configId == null) {
042 throw new ServletException("No configId specified for CAR download");
043 }
044 Artifact artifact = Artifact.create(configId);
045 Kernel kernel = KernelRegistry.getSingleKernel();
046 ConfigurationManager mgr = ConfigurationUtil.getConfigurationManager(kernel);
047 ConfigurationStore store = mgr.getStoreForConfiguration(artifact);
048 try {
049 response.setContentType("application/zip");
050 store.exportConfiguration(artifact, response.getOutputStream());
051 } catch (NoSuchConfigException e) {
052 throw new ServletException("No such configuration '"+configId+"'");
053 }
054 }
055 }